changing path

This commit is contained in:
Anaïs Saraiva
2026-08-15 00:46:02 +02:00
parent 4848e7a3e7
commit ad469460a4
4 changed files with 20 additions and 6 deletions
+14
View File
@@ -7,6 +7,7 @@ import { handleAuth } from "./routes/auth";
import { handleDelete } from "./routes/delete";
import { handleDownload } from "./routes/download";
import { handleUpload } from "./routes/upload";
import { KEY_PATTERN } from "./security";
import { Storage } from "./storage";
const cfg = loadConfig();
@@ -113,6 +114,19 @@ async function route(req: Request, srv: Server<undefined>): Promise<Response> {
return handleDownload(req, storage, path.slice(3), secret);
}
const rootKey = path.slice(1);
if (
rootKey &&
!rootKey.includes("/") &&
KEY_PATTERN.test(rootKey) &&
(method === "GET" || method === "HEAD")
) {
if (cfg.rateLimitEnabled && !limiter.check(clientIp(req, srv))) {
return jsonError(429, "too many requests");
}
return handleDownload(req, storage, rootKey, secret);
}
if (path.startsWith("/api/files/") && method === "DELETE") {
if (cfg.rateLimitEnabled && !limiter.check(clientIp(req, srv))) {
return jsonError(429, "too many requests");