mirror of
https://github.com/9001/copyparty.git
synced 2026-06-18 20:22:27 -06:00
PWA: serviceworker prep / wip
This commit is contained in:
parent
3b916d415f
commit
d4c05393e5
|
|
@ -19,9 +19,9 @@
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"enctype": "multipart/form-data",
|
"enctype": "multipart/form-data",
|
||||||
"params": {
|
"params": {
|
||||||
"title": "name",
|
"title": "share",
|
||||||
"text": "description",
|
"text": "upload",
|
||||||
"url": "link",
|
"url": "/",
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"name": "files",
|
"name": "files",
|
||||||
|
|
|
||||||
|
|
@ -13,42 +13,30 @@ if ('serviceWorker' in navigator) {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
(async () => {
|
(async () => {
|
||||||
const formData = await event.request.formData();
|
const formData = await event.request.formData();
|
||||||
const link = formData.get("link") || "";
|
const files = formData.get("files") || "";
|
||||||
// Instead of the original URL `/save-bookmark/`, redirect
|
const responseUrl = '/'; // (ToDo: remember last upload dir)
|
||||||
// the user to a URL returned by the `saveBookmark()`
|
// ToDo: keep file references in clipboard
|
||||||
// function, for example, `/`.
|
// -> upload on paste
|
||||||
const responseUrl = await saveBookmark(link);
|
alert(files)
|
||||||
return Response.redirect(responseUrl, 303);
|
return Response.redirect(responseUrl, 303);
|
||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('load', async () => {
|
window.addEventListener('load', async () => {
|
||||||
try {
|
try {
|
||||||
const registration = await navigator.serviceWorker.register(
|
const registration = await navigator.serviceWorker.register("/.cpr/w/sw.js", {
|
||||||
'/service-worker.js',
|
scope: "/",
|
||||||
{ scope: '/' }
|
|
||||||
);
|
|
||||||
console.log('SW registered:', registration.scope);
|
|
||||||
|
|
||||||
// Check for waiting update
|
|
||||||
if (registration.waiting) {
|
|
||||||
notifyUserOfUpdate(registration);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen for future updates
|
|
||||||
registration.addEventListener('updatefound', () => {
|
|
||||||
const newWorker = registration.installing;
|
|
||||||
newWorker?.addEventListener('statechange', () => {
|
|
||||||
if (
|
|
||||||
newWorker.state === 'installed' &&
|
|
||||||
navigator.serviceWorker.controller
|
|
||||||
) {
|
|
||||||
notifyUserOfUpdate(registration);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
if (registration.installing) {
|
||||||
|
console.log("Service worker installing");
|
||||||
|
} else if (registration.waiting) {
|
||||||
|
console.log("Service worker installed");
|
||||||
|
} else if (registration.active) {
|
||||||
|
console.log("Service worker active");
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('SW registration failed:', error);
|
console.error(`Registration failed with ${error}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue