Skip to content

Commit

Permalink
add header for service worker upload api
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 16, 2024
1 parent 94bc880 commit 5267ad4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions public/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down

0 comments on commit 5267ad4

Please sign in to comment.