commit
Remove the migration tool
diff --git a/src/lib/server/plural/routes/admin.ts b/src/lib/server/plural/routes/admin.ts
index f0cb272..274586b 100644
--- a/src/lib/server/plural/routes/admin.ts
+++ b/src/lib/server/plural/routes/admin.ts
@@ -8,10 +8,9 @@ import { createRoute, z } from "@hono/zod-openapi";
import { router, ok, signedIn } from "../openapi";
import { MessageSchema } from "../schemas";
-import { requireAuth, requireAdmin, requireOwner } from "../middleware/auth";
+import { requireAuth, requireAdmin } from "../middleware/auth";
import { broadcastFrontendUpdate } from "../ws";
import { rt } from "../runtime";
-import { localiseMedia } from "../services/localise";
export const adminRoutes = router();
@@ -31,30 +30,6 @@ adminRoutes.openapi(
},
);
-// One-off: copy every outside image link into this site's R2, dropping links that are gone
-adminRoutes.openapi(
- createRoute({
- method: "post",
- path: "/admin/media/localise",
- tags: ["Admin"],
- summary: "Move every member and system image onto this site (owner). Links that fail with 4xx or 5xx are removed",
- security: signedIn,
- middleware: [requireAuth, requireOwner] as const,
- responses: ok(
- z.object({
- copied: z.array(z.string()),
- removed: z.array(z.string()),
- kept: z.array(z.string()),
- }),
- ),
- }),
- async (c) => {
- const report = await localiseMedia();
- await broadcastFrontendUpdate("members_update", {});
- return c.json(report, 200);
- },
-);
-
// Member avatars uploaded from the admin page. Public, so Discord and browsers can load them
adminRoutes.openapi(
createRoute({
diff --git a/src/lib/server/plural/services/localise.ts b/src/lib/server/plural/services/localise.ts
deleted file mode 100644
index 30ad817..0000000
--- a/src/lib/server/plural/services/localise.ts
+++ /dev/null
@@ -1,133 +0,0 @@
-/* src/lib/server/plural/services/localise.ts
- * Copyright (c) 2026 Clove Nytrix Doughmination Twilight
- * Licensed under the DASL-1.2 Licence.
- * See LICENCE.md in the project root for full licence information.
- */
-
-import { rt } from "../runtime";
-import type { JsonObject } from "../types";
-import { MAX_MEDIA_BYTES, mediaUrl } from "./media";
-import { getMembers, getSystem, updateMember, updateSystem } from "./system";
-
-// No SVG: it would run scripts from this site's own origin
-const IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
-
-export interface LocaliseReport {
- copied: string[];
- removed: string[];
- kept: string[];
-}
-
-type Outcome = { kind: "copied"; url: string } | { kind: "removed" } | { kind: "kept"; reason: string };
-
-function external(url: unknown): url is string {
- return typeof url === "string" && url !== "" && !url.startsWith(mediaUrl(""));
-}
-
-// Any 4xx or 5xx means gone; only a network failure keeps the old link
-async function copyInto(source: string, key: string): Promise<Outcome> {
- let response: Response;
- try {
- response = await fetch(source);
- } catch (error) {
- return {
- kind: "kept",
- reason: error instanceof Error ? error.message : "network error",
- };
- }
-
- if (response.status >= 400) return { kind: "removed" };
-
- const type = (response.headers.get("Content-Type") ?? "").split(";")[0]?.trim() ?? "";
- if (!IMAGE_TYPES.includes(type)) return { kind: "kept", reason: `not a PNG, JPEG, GIF or WebP (${type || "no type"})` };
-
- const body = await response.arrayBuffer();
- if (body.byteLength > MAX_MEDIA_BYTES) return { kind: "kept", reason: "over 10 MB" };
-
- await rt().env.MEDIA.put(key, body, {
- httpMetadata: {
- contentType: type,
- },
- });
- return {
- kind: "copied",
- url: `${mediaUrl(key)}?v=${Date.now()}`,
- };
-}
-
-// Applies one outcome to the patch and the report. Returns the new value for the field
-function record(outcome: Outcome, label: string, report: LocaliseReport): string | null | undefined {
- if (outcome.kind === "copied") {
- report.copied.push(label);
- return outcome.url;
- }
- if (outcome.kind === "removed") {
- report.removed.push(label);
- return null;
- }
- report.kept.push(`${label}: ${outcome.reason}`);
- return undefined;
-}
-
-async function localiseMember(member: JsonObject, report: LocaliseReport): Promise<void> {
- const id = String(member.id);
- const name = String(member.name ?? id);
- const patch: JsonObject = {};
-
- // The avatar is the one image now; an old separate proxy avatar fills in when there's no avatar
- const avatarSource = external(member.avatar_url)
- ? member.avatar_url
- : member.avatar_url
- ? null
- : external(member.webhook_avatar_url)
- ? member.webhook_avatar_url
- : null;
-
- if (avatarSource) {
- const value = record(await copyInto(avatarSource, `member-${id}-avatar_url`), `${name} avatar`, report);
- if (value !== undefined) {
- patch.avatar_url = value;
- patch.webhook_avatar_url = null;
- }
- } else if (external(member.webhook_avatar_url)) {
- // The avatar is already local, so the proxy uses it too
- patch.webhook_avatar_url = null;
- report.removed.push(`${name} separate proxy avatar (now uses the avatar)`);
- }
-
- if (external(member.banner)) {
- const value = record(await copyInto(member.banner, `member-${id}-banner`), `${name} banner`, report);
- if (value !== undefined) patch.banner = value;
- }
-
- if (Object.keys(patch).length > 0) await updateMember(id, patch);
-}
-
-async function localiseSystem(report: LocaliseReport): Promise<void> {
- const system = await getSystem();
- const patch: JsonObject = {};
-
- for (const field of ["avatar_url", "banner"] as const) {
- const source = system[field];
- if (!external(source)) continue;
-
- const value = record(await copyInto(source, `system-${field}`), `system ${field}`, report);
- if (value !== undefined) patch[field] = value;
- }
-
- if (Object.keys(patch).length > 0) await updateSystem(patch);
-}
-
-// One-off: moves every member and system image onto this site's R2
-export async function localiseMedia(): Promise<LocaliseReport> {
- const report: LocaliseReport = {
- copied: [],
- removed: [],
- kept: [],
- };
-
- for (const member of await getMembers()) await localiseMember(member, report);
- await localiseSystem(report);
-
- return report;
-}
diff --git a/src/routes/admin/members/+page.svelte b/src/routes/admin/members/+page.svelte
index 93ffe54..ba5f15a 100644
--- a/src/routes/admin/members/+page.svelte
+++ b/src/routes/admin/members/+page.svelte
@@ -54,7 +54,6 @@
let avatarFile = $state<FileList | null>(null);
let bannerFile = $state<FileList | null>(null);
- let localiseKept = $state<string[]>([]);
const chosen = $derived(members.find((member) => member.id === chosenId) ?? null);
@@ -200,22 +199,6 @@
}, "Failed to save member");
}
- // One-off: moves outside image links onto this site
- function localise() {
- if (!confirm("Copy every member and system image onto this site? Links that fail (4xx or 5xx) get removed.")) return;
-
- void run(async () => {
- const report = await authFetch<{
- copied: string[];
- removed: string[];
- kept: string[];
- }>("/plural/admin/media/localise", { method: "POST" }, "Moving images failed");
- await reload();
- localiseKept = report.kept;
- return `Copied ${report.copied.length}, removed ${report.removed.length}, kept ${report.kept.length} as they were`;
- }, "Moving images failed");
- }
-
function remove() {
if (!chosen || !confirm(`Delete ${memberName(chosen)}? Their past switches stay in the history.`)) return;
@@ -321,24 +304,6 @@
</section>
</div>
- {#if auth.isOwner}
- <section class="panel stack localise">
- <h2>Move images to this site</h2>
- <p class="muted small">Copies every avatar and banner that still lives elsewhere into this site's storage. Links that fail with 4xx or 5xx are removed.</p>
- <div class="buttons">
- <button type="button" disabled={saving} onclick={localise}>Move images</button>
- </div>
- {#if localiseKept.length > 0}
- <p class="small">Kept as they were, try again later:</p>
- <ul class="small">
- {#each localiseKept as line (line)}
- <li>{line}</li>
- {/each}
- </ul>
- {/if}
- </section>
- {/if}
-
{/if}
</div>
</Protected>
@@ -353,8 +318,4 @@
font-size: 1.05rem;
}
- .localise {
- margin-top: 1.25rem;
- }
-
</style>