Skip to content

Commit

Permalink
using compressImage when serviceWorker register error
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 19, 2024
1 parent a765237 commit 052004d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export function base64Image2Blob(base64Data: string, contentType: string) {
}

export function uploadImage(file: File): Promise<string> {
if (!window._SW_ENABLED) {
// if serviceWorker register error, using compressImage
return compressImage(file, 256 * 1024);
}
const body = new FormData();
body.append("file", file);
return fetch(UPLOAD_URL, {
Expand Down
1 change: 1 addition & 0 deletions public/serviceWorkerRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if ('serviceWorker' in navigator) {
registration.update().then(res => {
console.log('ServiceWorker registration update: ', res);
});
window._SW_ENABLED = true
}, function (err) {
console.error('ServiceWorker registration failed: ', err);
});
Expand Down

0 comments on commit 052004d

Please sign in to comment.