add project size ratelimiting

This commit is contained in:
Ishaan Dey
2024-05-09 22:32:21 -07:00
parent e86e86dbe2
commit 3325b20aed
4 changed files with 65 additions and 23 deletions

View File

@ -16,7 +16,23 @@ export default {
const path = url.pathname;
const method = request.method;
if (path === '/api') {
if (path === '/api/size' && method === 'GET') {
const params = url.searchParams;
const sandboxId = params.get('sandboxId');
if (sandboxId) {
const res = await env.R2.list({ prefix: `projects/${sandboxId}` });
// sum up the size of all files
let size = 0;
for (const file of res.objects) {
size += file.size;
}
return new Response(JSON.stringify({ size }), { status: 200 });
} else return invalidRequest;
}
else if (path === '/api') {
if (method === 'GET') {
const params = url.searchParams;
const sandboxId = params.get('sandboxId');