Skip to content

Commit

Permalink
fallback user image を都度読み込みに修正
Browse files Browse the repository at this point in the history
  • Loading branch information
YutaUra committed Nov 23, 2023
1 parent 3381e1a commit be81d58
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions webapp/node/src/handlers/livecomment-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getLivecommentsHandler = [
const livecommentResponse = await fillLivecommentResponse(
conn,
livecomment,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)
livecommnetResponses.push(livecommentResponse)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export const postLivecommentHandler = [
tip: body.tip,
created_at: now,
},
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down Expand Up @@ -253,7 +253,7 @@ export const reportLivecommentHandler = [
livecomment_id: livecommentId,
created_at: now,
},
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down
12 changes: 6 additions & 6 deletions webapp/node/src/handlers/livestream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const reserveLivestreamHandler = [
start_at: body.start_at,
end_at: body.end_at,
},
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down Expand Up @@ -206,7 +206,7 @@ export const searchLivestreamsHandler = async (
const livestreamResponse = await fillLivestreamResponse(
conn,
livestream,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)
livestreamResponses.push(livestreamResponse)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ export const getMyLivestreamsHandler = [
const livestreamResponse = await fillLivestreamResponse(
conn,
livestream,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

livestreamResponses.push(livestreamResponse)
Expand Down Expand Up @@ -295,7 +295,7 @@ export const getUserLivestreamsHandler = [
const livestreamResponse = await fillLivestreamResponse(
conn,
livestream,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

livestreamResponses.push(livestreamResponse)
Expand Down Expand Up @@ -412,7 +412,7 @@ export const getLivestreamHandler = [
const livestreamResponse = await fillLivestreamResponse(
conn,
livestream,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down Expand Up @@ -465,7 +465,7 @@ export const getLivecommentReportsHandler = [
const report = await fillLivecommentReportResponse(
conn,
livecommentReport,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)
reportResponses.push(report)
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/node/src/handlers/reaction-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getReactionsHandler = [
const reactionResponse = await fillReactionResponse(
conn,
reaction,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

reactionResponses.push(reactionResponse)
Expand Down Expand Up @@ -98,7 +98,7 @@ export const postReactionHandler = [
livestream_id: livestreamId,
created_at: now,
},
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down
8 changes: 4 additions & 4 deletions webapp/node/src/handlers/user-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getIconHandler = [
.catch(throwErrorWith('failed to get icon'))
if (!icon) {
await conn.rollback()
return c.body(await c.get('runtime').fallbackUserIcon, 200, {
return c.body(await c.get('runtime').fallbackUserIcon(), 200, {
'Content-Type': 'image/jpeg',
})
}
Expand Down Expand Up @@ -119,7 +119,7 @@ export const getMeHandler = [
const response = await fillUserResponse(
conn,
user,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down Expand Up @@ -195,7 +195,7 @@ export const registerHandler = async (
display_name: body.display_name,
description: body.description,
},
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down Expand Up @@ -289,7 +289,7 @@ export const getUserHandler = [
const response = await fillUserResponse(
conn,
user,
await c.get('runtime').fallbackUserIcon,
await c.get('runtime').fallbackUserIcon(),
)

await conn.commit().catch(throwErrorWith('failed to commit'))
Expand Down
9 changes: 4 additions & 5 deletions webapp/node/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ const runtime = {
hashPassword: async (password: string) => hash(password, 4),
comparePassword: async (password: string, hash: string) =>
compare(password, hash),
// eslint-disable-next-line unicorn/prefer-module, unicorn/prefer-top-level-await
fallbackUserIcon: readFile(join(__dirname, '../../img/NoImage.jpg')).then(
(v) => {
fallbackUserIcon: () =>
// eslint-disable-next-line unicorn/prefer-module, unicorn/prefer-top-level-await
readFile(join(__dirname, '../../img/NoImage.jpg')).then((v) => {
const buf = v.buffer
if (buf instanceof ArrayBuffer) {
return buf
} else {
throw new TypeError(`NoImage.jpg should be ArrayBuffer, but ${buf}`)
}
},
),
}),
} satisfies Runtime

const pool = createPool({
Expand Down
2 changes: 1 addition & 1 deletion webapp/node/src/types/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Runtime {
exec: (cmd: string[]) => Promise<{ stdout: string; stderr: string }>
hashPassword: (password: string) => Promise<string>
comparePassword: (password: string, hash: string) => Promise<boolean>
fallbackUserIcon: Promise<Readonly<ArrayBuffer>>
fallbackUserIcon: () => Promise<Readonly<ArrayBuffer>>
}

export interface ApplicationRuntime extends Runtime {
Expand Down

0 comments on commit be81d58

Please sign in to comment.