Customisable token duration

This commit is contained in:
Alex Rennie-Lis
2026-06-29 09:42:42 +01:00
parent 368c396d63
commit 714d5815a8

View File

@@ -16,6 +16,8 @@ export async function GET({ url }) {
} }
}); });
const tokenDuration = parseInt(env.B2_TOKEN_DURATION, 10) || 600;
// Fetch a batch of files from the thumbs/ folder // Fetch a batch of files from the thumbs/ folder
const listCommand = new ListObjectsV2Command({ const listCommand = new ListObjectsV2Command({
Bucket: env.B2_BUCKET_NAME, Bucket: env.B2_BUCKET_NAME,
@@ -44,8 +46,8 @@ export async function GET({ url }) {
// 10 minutes = 600 seconds // 10 minutes = 600 seconds
const [thumbUrl, fullUrl] = await Promise.all([ const [thumbUrl, fullUrl] = await Promise.all([
getSignedUrl(s3, thumbCommand, { expiresIn: 600 }), getSignedUrl(s3, thumbCommand, { expiresIn: tokenDuration }),
getSignedUrl(s3, fullCommand, { expiresIn: 600 }) getSignedUrl(s3, fullCommand, { expiresIn: tokenDuration })
]); ]);
return { id, thumbUrl, fullUrl }; return { id, thumbUrl, fullUrl };