Files
gerbeur/shared/validation.ts
khannurien 0a16d3c96c v4: users can't rename themselves, /settings lays out again, and its selectors fit a phone — PATCH /api/me refuses a username with a 400 and changes nothing else in that request; a name changes only through PATCH /api/users/:key/username, which needs user:manage, from /@name/manage. The old name still stays an alias for good. renameUser lost its 30-day limit and its exempt flag, and RENAME_LIMITS holds the slug limit alone. /settings shows the username as plain text, and the rename hint left the catalogs. The settings grid sized its control column to its widest content, the rename hint, which stretched every control under it; that column now takes the remaining width and each control keeps its own size. A segmented control wraps instead of overflowing; in a settings row on a phone it takes the full width, and one of more than 4 options (the styles) lays out in two even rows. .btn-border turned red on hover, so Settings, Manage, Retry and Back looked like Log out; it is now neutral (Smooth's accent is red too), and only Log out takes the new btn-border--danger, muted until hovered red. A <button> and a <Link> .btn-border are now the same height. API.md and the module docs say who renames; the backend tests rename through the moderator route and check a self-rename is refused, and the malformed-name check moved to the manage tab's test. 254 backend and 667 frontend tests pass, and tsc, deno check and doc:lint are clean; Smooth, Brutalist, GeoCities and Kanagawa were checked in screenshots at desktop and phone widths.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 06:50:43 +00:00

60 lines
1.8 KiB
TypeScript

/**
* Makes the forms check the same limits on what users submit as the server
* enforces, by holding them in one place.
*
* @module
*/
/**
* Read by the validators and services, which refuse what breaks a limit, and
* by the forms, which say so before sending. Lengths are JavaScript string
* lengths, so an emoji may count for two. The category limits are checked on
* the server only.
*/
export const VALIDATION = {
USERNAME_MIN: 1,
USERNAME_MAX: 32,
PASSWORD_MIN: 8,
PASSWORD_MAX: 128,
DUMP_TITLE_MAX: 200,
/** Applies to a dump's note, which the API calls its comment. */
DUMP_COMMENT_MAX: 5000,
PLAYLIST_TITLE_MAX: 100,
PLAYLIST_DESCRIPTION_MAX: 2000,
COMMENT_BODY_MAX: 5000,
USER_DESCRIPTION_MAX: 2000,
CATEGORY_NAME_MAX: 50,
CATEGORY_SLUG_MAX: 50,
CHAT_MESSAGE_MAX: 2000,
} as const;
/**
* Matches a valid username, made of letters, digits and underscores within the
* `VALIDATION` limits. Sign-up checks it on both sides. It uses the same `\w`
* that a mention's pattern reads a name with.
*/
export const USERNAME_RE: RegExp = new RegExp(
`^[a-zA-Z0-9_]{${VALIDATION.USERNAME_MIN},${VALIDATION.USERNAME_MAX}}$`,
);
/**
* How often a dump's or a playlist's slug may change, counted from the aliases
* the changes left: 3 times a day. Moderators are exempt. slug-service refuses
* a change past it with a 429, and the edit forms say what the limit is.
*/
export const RENAME_LIMITS = {
SLUG: { count: 3, windowMs: 24 * 3_600_000 },
} as const;
/**
* Matches an email address well enough to catch a typo; only the reset email
* arriving proves it.
*/
export const EMAIL_RE: RegExp = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
/**
* The largest file a file dump may hold, in bytes. dump-service refuses a
* bigger one, and the create form before uploading it.
*/
export const DUMP_MAX_FILE_SIZE_BYTES: number = 50 * 1024 * 1024;