Add download link expiration time

This commit is contained in:
HoshinoKoji 2024-10-07 23:42:22 +08:00
parent 56963834b1
commit 4c0255bb25

View File

@ -14,11 +14,12 @@ export async function downloadDispatcher(request, env, ctx) {
if (!signature && request.headers.get('x-access-token') !== adminSecret) if (!signature && request.headers.get('x-access-token') !== adminSecret)
return new Response(null, { status: 403, statusText: 'Forbidden' }); return new Response(null, { status: 403, statusText: 'Forbidden' });
else {
const hash = await getHashString(`${key}${timestamp}${signatureBase}`, 'SHA-1'); const hash = await getHashString(`${key}${timestamp}${signatureBase}`, 'SHA-1');
if (signature !== hash) if (signature !== hash)
return new Response(null, { status: 403, statusText: 'Forbidden' }); return new Response(null, { status: 403, statusText: 'Forbidden' });
} if (Date.now() - Number(timestamp) > 1000 * 60 * 5) // 5 minutes
return new Response(null, { status: 403, statusText: 'Signature Expired' });
try { try {
const object = await bucket.get(key); const object = await bucket.get(key);