Handling fs

This commit is contained in:
Anaïs Saraiva
2026-08-15 10:31:52 +02:00
parent f1a8a05417
commit 12d9e99aa2
8 changed files with 64 additions and 17 deletions
+10
View File
@@ -27,6 +27,7 @@ export async function handleUpload(
maxFileSize: number,
ttlMs: number,
publicBaseUrl?: string,
maxStorageUsage = 0.5,
): Promise<Response> {
const contentType = req.headers.get("content-type");
const boundary = contentType ? getBoundary(contentType) : null;
@@ -36,6 +37,15 @@ export async function handleUpload(
const key = id;
try {
const usage = await storage.storageUsageRatio();
if (usage > maxStorageUsage) {
log(
"warn",
`upload rejected id=${id}: storage usage ${(usage * 100).toFixed(1)}% exceeds limit ${(maxStorageUsage * 100).toFixed(0)}%`,
);
return jsonError(503, "storage is full, try again later");
}
let filename = "";
let mime = "application/octet-stream";
let size = 0;