2025-05-01 01:45:46 +02:00
|
|
|
import { toTypedSchema } from "@vee-validate/zod";
|
|
|
|
|
import { z } from "zod";
|
2025-07-16 07:48:39 +02:00
|
|
|
import * as m from "~~/paraglide/messages.js";
|
2025-05-01 01:45:46 +02:00
|
|
|
|
|
|
|
|
const characterRegex = new RegExp(/^[a-z0-9_-]+$/);
|
|
|
|
|
|
|
|
|
|
export const formSchema = (identity: Identity) =>
|
|
|
|
|
toTypedSchema(
|
|
|
|
|
z.strictObject({
|
|
|
|
|
banner: z
|
|
|
|
|
.instanceof(File)
|
|
|
|
|
.refine(
|
|
|
|
|
(v) =>
|
|
|
|
|
v.size <=
|
|
|
|
|
(identity.instance.configuration.accounts
|
2025-05-26 11:19:15 +02:00
|
|
|
.header_limit ?? Number.POSITIVE_INFINITY),
|
2025-05-01 01:45:46 +02:00
|
|
|
m.civil_icy_ant_mend({
|
|
|
|
|
size: identity.instance.configuration.accounts
|
2025-05-26 11:19:15 +02:00
|
|
|
.header_limit,
|
2025-05-01 01:45:46 +02:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.optional(),
|
|
|
|
|
avatar: z
|
|
|
|
|
.instanceof(File)
|
|
|
|
|
.refine(
|
|
|
|
|
(v) =>
|
|
|
|
|
v.size <=
|
|
|
|
|
(identity.instance.configuration.accounts
|
2025-05-26 11:19:15 +02:00
|
|
|
.avatar_limit ?? Number.POSITIVE_INFINITY),
|
2025-05-01 01:45:46 +02:00
|
|
|
m.zippy_caring_raven_edit({
|
|
|
|
|
size: identity.instance.configuration.accounts
|
2025-05-26 11:19:15 +02:00
|
|
|
.avatar_limit,
|
2025-05-01 01:45:46 +02:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.or(z.string().url())
|
|
|
|
|
.optional(),
|
|
|
|
|
name: z
|
|
|
|
|
.string()
|
|
|
|
|
.max(
|
|
|
|
|
identity.instance.configuration.accounts
|
|
|
|
|
.max_displayname_characters,
|
|
|
|
|
),
|
|
|
|
|
username: z
|
|
|
|
|
.string()
|
|
|
|
|
.regex(characterRegex, m.still_upper_otter_dine())
|
|
|
|
|
.max(
|
|
|
|
|
identity.instance.configuration.accounts
|
|
|
|
|
.max_username_characters,
|
|
|
|
|
),
|
|
|
|
|
bio: z
|
|
|
|
|
.string()
|
|
|
|
|
.max(
|
|
|
|
|
identity.instance.configuration.accounts
|
|
|
|
|
.max_note_characters,
|
|
|
|
|
),
|
|
|
|
|
bot: z.boolean().default(false),
|
|
|
|
|
locked: z.boolean().default(false),
|
|
|
|
|
discoverable: z.boolean().default(true),
|
|
|
|
|
fields: z.array(
|
|
|
|
|
z.strictObject({ name: z.string(), value: z.string() }),
|
|
|
|
|
),
|
|
|
|
|
}),
|
|
|
|
|
);
|