diff options
| author | altaf-creator <dev@altafcreator.com> | 2026-01-09 22:11:10 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2026-01-09 22:11:10 +0800 |
| commit | 85afbb89dd1ab32583b77a530f14c338fff0b29d (patch) | |
| tree | 21c75713c6ef9b0cc8d8591d5686e8a97fb949c6 /frontend/main.js | |
| parent | 36a1e21e3d85fd1faa70a60b1515826a551d2e28 (diff) | |
ajkhfsdjhkfdsa
Diffstat (limited to 'frontend/main.js')
| -rw-r--r-- | frontend/main.js | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/frontend/main.js b/frontend/main.js index d92d4ad..3f5c4c4 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -22,23 +22,33 @@ async function subscribe() { return; } + console.log(await Notification.requestPermission()); + const registration = await navigator.serviceWorker.ready; - const subscription = await registration.pushManager.subscribe({ - userVisibleOnly: true, - applicationServerKey: urlBase64ToUint8Array(PUBLIC_VAPID_KEY), - }); - console.log(subscription); - alert(subscription); + try { + const subscription = await registration.pushManager.subscribe({ + userVisibleOnly: true, + applicationServerKey: urlBase64ToUint8Array(PUBLIC_VAPID_KEY), + }); + console.log(subscription); + } catch (e) { + console.log("ERR in regis, ", e); + return false; + } - await fetch(`${API_URL}/notifsubscribe`, { + console.log("sw regis pass, write to db"); + + const db_reply = await fetch(`${API_URL}/notifsubscribe`, { method: 'POST', credentials: "include", body: JSON.stringify(subscription), headers: { "Content-Type": "application/json", }, - }) + }); + + return db_reply.status == 2000; } /// copied from somewhere @@ -108,6 +118,8 @@ async function start() { // --- information loading + cookie setting (from server) async function information(urlParam = null) { + const urlCookie = await cookieStore.get("last_used_url"); + const response = await fetch(`${API_URL}/info`, { credentials: "include", method: "POST", |
