58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
/**
|
|
* Web Push for category “new articles” notifications — same VAPID/SW as article/pickup push.
|
|
*/
|
|
|
|
export {
|
|
fetchPushConfiguration,
|
|
registerPushServiceWorker,
|
|
ensurePushSubscription,
|
|
isPushApiSupported,
|
|
parseSubscribedStatus,
|
|
parseSuccess,
|
|
} from "./articlePush.js";
|
|
|
|
/**
|
|
* @param {number} kKategorie
|
|
* @param {string} endpoint
|
|
*/
|
|
export async function categoryPushStatus(kKategorie, endpoint) {
|
|
const res = await fetch("/api/category/push/status", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ kKategorie, endpoint }),
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
return { ...data, httpOk: res.ok };
|
|
}
|
|
|
|
/**
|
|
* @param {number} kKategorie
|
|
* @param {PushSubscription} subscription
|
|
*/
|
|
export async function categoryPushSubscribe(kKategorie, subscription) {
|
|
const subJson = subscription.toJSON();
|
|
const res = await fetch("/api/category/push/subscribe", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
kKategorie,
|
|
subscription: subJson,
|
|
}),
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
return { ...data, httpOk: res.ok };
|
|
}
|
|
|
|
/**
|
|
* @param {string} endpoint
|
|
*/
|
|
export async function categoryPushUnsubscribe(endpoint) {
|
|
const res = await fetch("/api/category/push/unsubscribe", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ endpoint }),
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
return { ...data, httpOk: res.ok };
|
|
}
|