Handling fs
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user