From 85afbb89dd1ab32583b77a530f14c338fff0b29d Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Fri, 9 Jan 2026 22:11:10 +0800 Subject: ajkhfsdjhkfdsa --- frontend/main.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'frontend/main.js') 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", -- cgit v1.2.3