From 585f9f596fce6166e44dd32ae9712a72e05ce194 Mon Sep 17 00:00:00 2001 From: MarSeventh <1193267292@qq.com> Date: Wed, 11 Sep 2024 13:25:12 +0800 Subject: [PATCH] add notice when picture has been deleted --- functions/api/manage/delete/[id].js | 2 -- functions/file/[id].js | 5 ++++- functions/upload.js | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/functions/api/manage/delete/[id].js b/functions/api/manage/delete/[id].js index 80b5725a..8d75b096 100644 --- a/functions/api/manage/delete/[id].js +++ b/functions/api/manage/delete/[id].js @@ -8,8 +8,6 @@ export async function onRequest(context) { next, // used for middleware or to fetch assets data, // arbitrary space for passing data between middlewares } = context; - console.log(env) - console.log(params.id) await env.img_url.delete(params.id); const info = JSON.stringify(params.id); return new Response(info); diff --git a/functions/file/[id].js b/functions/file/[id].js index 0582994e..1eb14acd 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -35,7 +35,7 @@ export async function onRequest(context) { // Contents of context object } const imgRecord = await env.img_url.getWithMetadata(params.id); // 图片是否存在 - if (imgRecord === null) { + if (imgRecord === null || imgRecord?.metadata === null) { return new Response('Error: Image not found', { status: 404 }); } @@ -49,6 +49,9 @@ export async function onRequest(context) { // Contents of context object const fileType = imgRecord.metadata?.FileType || 'image/jpeg'; const response = await getFileContent(request, imgRecord, TgFileID, env, url); + if (response === null) { + return new Response('Error: Failed to fetch image', { status: 500 }); + } try { const headers = new Headers(response.headers); diff --git a/functions/upload.js b/functions/upload.js index 45526992..24962c0b 100644 --- a/functions/upload.js +++ b/functions/upload.js @@ -153,8 +153,6 @@ export async function onRequestPost(context) { // Contents of context object ); } const time = new Date().getTime(); - // const src = clonedRes[0].src; - // const id = src.split('/').pop(); const id = fileInfo.file_id; const fullId = id + '.' + fileExt; const apikey = env.ModerateContentApiKey;