From 5267ad46daa41a546f94fe5303a85424e29fb1d5 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 16 Jul 2024 11:51:43 +0800 Subject: [PATCH] add header for service worker upload api --- public/serviceWorker.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/serviceWorker.js b/public/serviceWorker.js index b9b80c319ef..154f2247e9b 100644 --- a/public/serviceWorker.js +++ b/public/serviceWorker.js @@ -22,9 +22,16 @@ async function upload(request, url) { ext = file.type.split('/').pop() } const fileUrl = `${url.origin}/api/cache/${nanoid()}.${ext}` - // console.debug('file', file, fileUrl) + // console.debug('file', file, fileUrl, request) const cache = await caches.open(CHATGPT_NEXT_WEB_FILE_CACHE) - await cache.put(new Request(fileUrl), new Response(file)) + await cache.put(new Request(fileUrl), new Response(file, { + headers: { + 'content-type': file.type, + 'content-length': file.size, + 'cache-control': 'no-cache', // file already store in disk + 'server': 'ServiceWorker', + } + })) return Response.json({ code: 0, data: fileUrl }) }