Skip to content

Commit

Permalink
fix: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sosweetham committed May 8, 2024
1 parent e4bb78f commit e1bc9f7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/src/controllers/server-banner.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const serverBannerController = new Elysia()
if (await serverBannerBucket.checkAssetExists(params.id)) {
const lastModified = await serverBannerBucket.getAssetLastModified(params.id)
if (Date.now() - lastModified.valueOf() > 24 * 60 * 60 * 1000) {
guildedServerProfileScrape(params.id, 'banner')
(async () => guildedServerProfileScrape(params.id, 'banner'))().catch((e) => console.error(e))
}
const banner = await serverBannerBucket.getAsset(params.id)
return new Response(await streamToBuffer(banner), { headers: { 'Content-Type': 'image/webp' } })
Expand Down
2 changes: 1 addition & 1 deletion app/src/controllers/server-icon.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const serverIconController = new Elysia()
if (await serverIconBucket.checkAssetExists(params.id)) {
const lastModified = await serverIconBucket.getAssetLastModified(params.id)
if (Date.now() - lastModified.valueOf() > 24 * 60 * 60 * 1000) {
guildedServerProfileScrape(params.id, 'icon')
(async () => guildedServerProfileScrape(params.id, 'icon'))().catch((e) => console.error(e))
}
const avatar = await serverIconBucket.getAsset(params.id)
const res = new Response(await streamToBuffer(avatar), { headers: { 'Content-Type': 'image/webp' } })
Expand Down
3 changes: 1 addition & 2 deletions app/src/controllers/user-avatar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const userAvatarController = new Elysia()
console.log('User avatar exists')
const lastModified = await userAvatarBucket.getAssetLastModified(params.id)
if (Date.now() - lastModified.valueOf() > 24 * 60 * 60 * 1000) {
console.log('User avatar is older than 24 hours')
guildedUserProfileScrape(params.id, 'avatar')
(async () => guildedUserProfileScrape(params.id, 'avatar'))().catch((e) => console.error(e))
}
console.log('Sending cached avatar')
const avatar = await userAvatarBucket.getAsset(params.id)
Expand Down
2 changes: 1 addition & 1 deletion app/src/controllers/user-banner.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const userBannerController = new Elysia()
if (await userBannerBucket.checkAssetExists(params.id)) {
const lastModified = await userBannerBucket.getAssetLastModified(params.id)
if (Date.now() - lastModified.valueOf() > 24 * 60 * 60 * 1000) {
guildedUserProfileScrape(params.id, 'banner')
(async () => guildedUserProfileScrape(params.id, 'banner'))().catch((e) => console.error(e))
}
const banner = await userBannerBucket.getAsset(params.id)
return new Response(await streamToBuffer(banner), { headers: { 'Content-Type': 'image/webp' } })
Expand Down
4 changes: 2 additions & 2 deletions app/src/libs/guilded-scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const guildedUserProfileScrape: (id: string, getElement: 'avatar' | 'bann
}),
keepalive: false
})).json()
if (!signed) {
if (!signed || !signed.urlSignatures || !signed.urlSignatures[0] || !signed.urlSignatures[0].url) {
return new Error('Failed to sign URL')
}
const signedSrc = signed.urlSignatures[0].url
Expand Down Expand Up @@ -56,7 +56,7 @@ export const guildedServerProfileScrape: (id: string, getElement: 'icon' | 'bann
}),
keepalive: false
})).json()
if (!signed) {
if (!signed || !signed.urlSignatures || !signed.urlSignatures[0] || !signed.urlSignatures[0].url) {
return new Error('Failed to sign URL')
}
const signedSrc = signed.urlSignatures[0].url
Expand Down

0 comments on commit e1bc9f7

Please sign in to comment.