Skip to content

Commit

Permalink
fix: Do not redeclare avatars (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink authored Dec 1, 2024
1 parent 2aba72f commit 0175127
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export default {
const { pathname } = new URL(request.url);

if (!pathname || pathname === '/') {
return Response.redirect('https://github.com/prompt/avatars.dog', 307);
return Response.redirect(env.README_REDIRECT, 307);
}

const [actor, format] = pathname.toLowerCase().slice(1).split('@');

let avatar = await env.avatars.get(actor);

if (!avatar) {
let avatar = await fetch(`${env.BLUESKY_GET_PROFILE}?actor=${actor}`, { method: 'GET' })
avatar = await fetch(`${env.BLUESKY_GET_PROFILE}?actor=${actor}`, { method: 'GET' })
.then<{ avatar: string }>((response) => response.json())
.then<string>((profile) => profile.avatar || '404');

Expand All @@ -20,7 +20,7 @@ export default {
});
}

if (!avatar || !avatar.startsWith('https://cdn.bsky.app/img/avatar')) {
if (!avatar || !avatar.startsWith(`${env.BLUESKY_CDN}/img/avatar`)) {
return new Response(`Avatar not found for ${actor}.`, { status: 404 });
}

Expand Down
5 changes: 3 additions & 2 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

interface Env {
avatars: KVNamespace;
BLUESKY_CDN: 'https://cdn.bsky.app';
BLUESKY_GET_PROFILE: 'https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile';
BLUESKY_CDN: "https://cdn.bsky.app";
BLUESKY_GET_PROFILE: "https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile";
CACHE_EXPIRY_TTL: 300;
README_REDIRECT: "https://github.com/prompt/avatars.dog";
}
1 change: 1 addition & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ id = "77bab70fe5cf495ea02dcc372bf6d124"
BLUESKY_CDN = "https://cdn.bsky.app"
BLUESKY_GET_PROFILE = "https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile"
CACHE_EXPIRY_TTL = 300
README_REDIRECT = "https://github.com/prompt/avatars.dog"

0 comments on commit 0175127

Please sign in to comment.