Skip to content

Commit

Permalink
Add support for animate query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryFlames committed Nov 22, 2023
1 parent 26c331a commit 98cfb42
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ async function getDecoration(hash: string, env: Env): Promise<Decoration | null>
return null;
}

function getFileName(hash: string, animated: boolean): string {
return `${animated ? 'a_' : ''}${hash}.png`;
}

function isDecorationApproved(decoration: Decoration): boolean {
return decoration.reviewed !== false;
}
Expand Down Expand Up @@ -48,7 +52,9 @@ export default {
const decoration = await getDecoration(hash, env);
if (!decoration) return new Response('Decoration not found', { status: 404, headers: new Headers(BASE_HEADERS) });

const object = await env.UGC.get(filename);
const animate = decoration.animated && (url.searchParams.get("animate") === "true" ?? filename.startsWith('a_'));

const object = await env.UGC.get(getFileName(hash, animate));
if (!object) return new Response('Not Found', { status: 404, headers: new Headers(BASE_HEADERS) });

const ttl = isDecorationApproved(decoration) ? TTL_1_YEAR : TTL_1_HOUR;
Expand Down

0 comments on commit 98cfb42

Please sign in to comment.