Files
community-rule/lib/server/uploads/extractUploadIds.ts
T
adilallo 5cbda35e32 Start every Rule private, with a rotating link and files that follow its readers.
New Rules stay off lists until the person who holds the pen turns on a share link, or the team features one. Uploaded files are readable only by those readers, stripped of location metadata, and deleted with the Rule, draft, or account.
2026-11-09 19:54:04 -07:00

21 lines
618 B
TypeScript

import { isValidUploadFileId } from "./uploadConstants";
const UPLOAD_PATH_RE =
/\/api\/uploads\/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/gi;
/** UUID stems referenced as `/api/uploads/{id}` inside JSON. */
export function extractUploadIdsFromUnknown(value: unknown): string[] {
let text: string;
try {
text = JSON.stringify(value ?? null);
} catch {
return [];
}
const ids = new Set<string>();
for (const match of text.matchAll(UPLOAD_PATH_RE)) {
const id = match[1]?.toLowerCase();
if (id && isValidUploadFileId(id)) ids.add(id);
}
return [...ids];
}