frontend/app/components/preferences/profile.ts
Jesse Wierzbinski 7f7cf20311
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 1s
Deploy to GitHub Pages / build (push) Failing after 1s
Deploy to GitHub Pages / deploy (push) Has been skipped
Docker / build (push) Failing after 1s
Mirror to Codeberg / Mirror (push) Failing after 1s
chore: ⬆️ Upgrade to Nuxt 4
2025-07-16 07:48:39 +02:00

64 lines
2.2 KiB
TypeScript

import { toTypedSchema } from "@vee-validate/zod";
import { z } from "zod";
import * as m from "~~/paraglide/messages.js";
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
.header_limit ?? Number.POSITIVE_INFINITY),
m.civil_icy_ant_mend({
size: identity.instance.configuration.accounts
.header_limit,
}),
)
.optional(),
avatar: z
.instanceof(File)
.refine(
(v) =>
v.size <=
(identity.instance.configuration.accounts
.avatar_limit ?? Number.POSITIVE_INFINITY),
m.zippy_caring_raven_edit({
size: identity.instance.configuration.accounts
.avatar_limit,
}),
)
.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() }),
),
}),
);