Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#5103 from ConnectAI-E/hotfix-cache-…
Browse files Browse the repository at this point in the history
…upload-image

hotfix cache upload image
  • Loading branch information
lloydzhou authored Jul 25, 2024
2 parents 00be2be + 6f0846b commit cf63619
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions public/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ self.addEventListener("install", function (event) {
);
});

function jsonify(data) {
return new Response(JSON.stringify(data), { headers: { 'content-type': 'application/json' } })
}

async function upload(request, url) {
const formData = await request.formData()
const file = formData.getAll('file')[0]
Expand All @@ -33,13 +37,13 @@ async function upload(request, url) {
'server': 'ServiceWorker',
}
}))
return Response.json({ code: 0, data: fileUrl })
return jsonify({ code: 0, data: fileUrl })
}

async function remove(request, url) {
const cache = await caches.open(CHATGPT_NEXT_WEB_FILE_CACHE)
const res = await cache.delete(request.url)
return Response.json({ code: 0 })
return jsonify({ code: 0 })
}

self.addEventListener("fetch", (e) => {
Expand Down

0 comments on commit cf63619

Please sign in to comment.