A remote user is name@host here, in users.username, in paths (/@alice@music.example) and in mentions, through one handle rule in shared/validation.ts that paths, MENTION_RE and Markdown all build on; Markdown undoes GFM's email autolink of a handle. Their name, email and avatar come from their home at each sign-in and by its signed events (federation_outbox, delivered by the federation job with backoff): a rename at home leaves the old handle an alias here, and a password change or a withdrawn grant ends their sessions here. Their password, email, avatar and name can't change here (assertLocalUser), nor can they sign in elsewhere from here. An admin keeps the trusted and blocked instances on /manage (federation:manage): a trusted instance's users sign in from a button on the login page, a blocked one's can't and are signed out at once, and any other's join with an invite from the register page. The /authorize page asks the user once per instance, and /settings lists the instances their account signs in to, each disconnectable; /login?next= brings a signed-out visitor back to /authorize. Emails stay unique among local accounts only, and migration 0024 adds the tables, makes that index partial and reserves authorize and federation as category slugs. remote/gerbeur-instance.ts is the only way to other instances: https and public addresses only, no redirects, no certificate fallback, unless GERBEUR_FEDERATION_ALLOW_PRIVATE lets two instances on one machine talk. 298 backend tests and 702 frontend tests pass, and deno check, deno fmt, deno lint, tsc, eslint, doc:lint and i18n:compile --strict are clean; checked end to end with two built instances on one machine: sign-in through the other's login and consent pages, consent skipped once granted and asked again after disconnecting, a rename and a password change at home reaching the other, and blocking; screenshots of the login, consent, profile, settings and manage pages at 1280 and 390px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
/**
|
|
* Checks which slugs a category may take. A category's feed lives at the URL
|
|
* root (`/music`), so its slug must not shadow another top-level page. The
|
|
* category service runs this check when a category is created or renamed, and
|
|
* the migrations that reserve more words rename the categories that had one
|
|
* with {@link renameReservedCategories}.
|
|
*
|
|
* Dump and playlist slugs reserve nothing: they live under their owner's
|
|
* `dumps/` and `playlists/`, where nothing else is named by a user. A user
|
|
* can't clash with a category either, since `@` is never in a slug.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { DatabaseSync } from "node:sqlite";
|
|
import { FEED_TABS } from "../../shared/paths.ts";
|
|
|
|
/**
|
|
* Lists the top-level path segments a category slug may not take: the feed
|
|
* tabs (`/hot`), the SPA's own pages (`src/App.tsx`), and `api`, `ws`,
|
|
* `assets` and `emojibase`, which the server answers before the SPA. Keep it
|
|
* in step with the route table and the build's top-level folders.
|
|
*/
|
|
export const RESERVED_SLUGS: readonly string[] = [
|
|
...FEED_TABS,
|
|
"search",
|
|
"login",
|
|
"register",
|
|
"notifications",
|
|
"reset-password",
|
|
"unsubscribe",
|
|
"settings",
|
|
"manage",
|
|
"community",
|
|
"authorize",
|
|
"federation",
|
|
"api",
|
|
"ws",
|
|
"assets",
|
|
"emojibase",
|
|
];
|
|
|
|
/** Checks whether `slug` is one of the {@link RESERVED_SLUGS}. */
|
|
export function isReservedSlug(slug: string): boolean {
|
|
return RESERVED_SLUGS.includes(slug);
|
|
}
|
|
|
|
/**
|
|
* Renames each category whose slug is now reserved, such as `hot`, to the
|
|
* first of `<slug>-2`, `<slug>-3`… that is free, and logs it. Migration 0021
|
|
* runs it for v4's words, 0022 for `community`, and 0024 for `authorize` and
|
|
* `federation`.
|
|
*/
|
|
export function renameReservedCategories(db: DatabaseSync): void {
|
|
const rows = db.prepare(`SELECT id, slug FROM categories;`).all() as {
|
|
id: string;
|
|
slug: string;
|
|
}[];
|
|
const taken = new Set(rows.map((r) => r.slug));
|
|
for (const { id, slug } of rows) {
|
|
if (!isReservedSlug(slug)) continue;
|
|
let n = 2;
|
|
while (taken.has(`${slug}-${n}`) || isReservedSlug(`${slug}-${n}`)) n++;
|
|
const renamed = `${slug}-${n}`;
|
|
taken.add(renamed);
|
|
db.prepare(`UPDATE categories SET slug = ? WHERE id = ?;`).run(renamed, id);
|
|
console.log(
|
|
`[migrate] category "${slug}" is now "${renamed}": its slug is reserved`,
|
|
);
|
|
}
|
|
}
|