Initial local backup snapshot

This commit is contained in:
Selecta Keke 2026-06-24 00:02:55 -03:00
commit acd9e14ba5
367 changed files with 118038 additions and 0 deletions

39
server/storage.ts Normal file
View file

@ -0,0 +1,39 @@
import fs from "node:fs/promises";
import path from "node:path";
function normalizeKey(relKey: string): string {
return relKey
.replace(/^\/+/, "")
.split("/")
.filter(Boolean)
.map(segment => segment.replace(/[^a-zA-Z0-9._-]/g, "_"))
.join("/");
}
function getUploadRoot() {
return path.resolve(process.cwd(), "uploads");
}
function getPublicUrl(key: string) {
return `/uploads/${key}`;
}
export async function storagePut(
relKey: string,
data: Buffer | Uint8Array | string,
contentType = "application/octet-stream"
): Promise<{ key: string; url: string }> {
const key = normalizeKey(relKey);
const filePath = path.join(getUploadRoot(), key);
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, data);
return { key, url: getPublicUrl(key) };
}
export async function storageGet(relKey: string): Promise<{ key: string; url: string; }> {
const key = normalizeKey(relKey);
return {
key,
url: getPublicUrl(key),
};
}