Skip to content

Commit

Permalink
feat: Add error handling for failed image retrieval in bgimage.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jul 15, 2024
1 parent 4a58aec commit 51abe2e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions routes/api/v2/client/bgimage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

export const handler = {
async GET(req: Request, ctx: any) {
const userid = ctx.state.data.userid;
try {
// ./backgroundImages/にある画像すべてを取得
const dirPath = "./backgroundImages";
const result = await readRandomImageFromDir(dirPath).catch(console.error);
if(!result) {
return new Response("Internal Server Error", { status: 500 });
}
return new Response(result, {
status: 200,
headers: {
Expand Down Expand Up @@ -41,6 +44,4 @@ async function readRandomImageFromDir(dir: string) {
const randomFile = `${dir}/${files[randomIndex]}`;
const imageData = await Deno.readFile(randomFile);
return imageData;
// 画像の内容はバイナリデータとして出力されるため、ここでは内容の表示は省略
// 必要に応じて画像データを処理するコードを追加してください
}

0 comments on commit 51abe2e

Please sign in to comment.