feat(backend): handle processing errors and add PWA routes
- Block file downloads and previews with a 424 StatusFailedDependency if file processing failed or the box has issues. - Register routes for `/service-worker.js` and `/share-target` to support PWA features. - Update README.md with an AI usage disclosure.
This commit is contained in:
43
backend/static/js/02-pwa.js
Normal file
43
backend/static/js/02-pwa.js
Normal file
@@ -0,0 +1,43 @@
|
||||
(function () {
|
||||
let installPrompt = null;
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/service-worker.js").catch(() => {
|
||||
/* Service workers are progressive enhancement here. */
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("beforeinstallprompt", (event) => {
|
||||
const button = document.querySelector("[data-install-pwa]");
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
installPrompt = event;
|
||||
button.hidden = false;
|
||||
button.addEventListener("click", async () => {
|
||||
if (!installPrompt) {
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
try {
|
||||
await installPrompt.prompt();
|
||||
await installPrompt.userChoice;
|
||||
} finally {
|
||||
installPrompt = null;
|
||||
button.hidden = true;
|
||||
button.disabled = false;
|
||||
}
|
||||
}, { once: true });
|
||||
});
|
||||
|
||||
window.addEventListener("appinstalled", () => {
|
||||
const button = document.querySelector("[data-install-pwa]");
|
||||
if (button) {
|
||||
button.hidden = true;
|
||||
}
|
||||
installPrompt = null;
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user