summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-02-28 10:51:02 +0100
committerRory& <root@rory.gay>2026-02-28 10:51:02 +0100
commitd126319b5b3047a625e8f2d04609fa24983a12e7 (patch)
tree89a15183d8c25f8b796a5243a1f0659b7c5744f7
parentIPC: unix socket reinit + backlog system (diff)
downloadserver-ts-d126319b5b3047a625e8f2d04609fa24983a12e7.tar.xz
Add sticker migration
-rw-r--r--src/cdn/routes/stickers.ts22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cdn/routes/stickers.ts b/src/cdn/routes/stickers.ts

index bb7ab2ad..7ddff335 100644 --- a/src/cdn/routes/stickers.ts +++ b/src/cdn/routes/stickers.ts
@@ -24,6 +24,8 @@ import { HTTPError } from "lambert-server"; import crypto from "crypto"; import { multer } from "../util/multer"; import { cache } from "../util/cache"; +import { FileStorage } from "@spacebar/cdn*"; +import fs from "fs/promises"; // TODO: check premium and animated pfp are allowed in the config // TODO: generate different sizes of icon @@ -103,7 +105,25 @@ router.delete("/:guild_id/:id", async (req: Request, res: Response) => { async function getOrMoveFile(newPath: string, oldPath: string) { let file = await storage.get(newPath); - if (!file) { + if (file) { + if (!(await storage.isFile(newPath))) { + console.log(`[CDN] Migrating sticker from subdirectory+fallback to direct path for ${newPath}`); + // noinspection SuspiciousTypeOfGuard -- not sure whats up with this + if (storage instanceof FileStorage) { + const files = await fs.readdir(storage.getFsPath(newPath)); + if (files.length === 1) { + const oldFilePath = storage.getFsPath(`${newPath}/${files[0]}`); + const newFilePath = storage.getFsPath(newPath); + await fs.rename(oldFilePath, newFilePath + ".tmp"); + await fs.rmdir(storage.getFsPath(newPath)); + await fs.rename(newFilePath + ".tmp", newFilePath); + file = await storage.get(newPath); + } else console.log(`[CDN] Warning: not migrating sticker ${newPath}, as there are multiple files in the old directory`); + } else { + console.log("[CDN] Warning: no migration for s3 storage stickers, as it is not a filesystem"); + } + } + } else { if (await storage.exists(oldPath)) { console.log(`[${pathPrefix}] found file at old path ${oldPath}, moving to new path ${newPath}`); await storage.move(oldPath, newPath);