mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-20 10:04:08 +00:00
Make DELETE endpoint, add different UI description
This commit is contained in:
parent
eb220544a3
commit
58992fc795
5 changed files with 47 additions and 16 deletions
|
@ -115,14 +115,13 @@ class Api {
|
|||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
|
||||
async updateWebPushSubscriptions(topics, pushSubscription) {
|
||||
async updateWebPush(pushSubscription, topics) {
|
||||
const user = await userManager.get(config.base_url);
|
||||
const url = accountWebPushUrl(config.base_url);
|
||||
console.log(`[Api] Sending Web Push Subscriptions`, { url, topics, endpoint: pushSubscription.endpoint });
|
||||
console.log(`[Api] Sending Web Push Subscriptions`, { pushSubscription });
|
||||
console.log(`[Api] Updating Web Push subscription`, { url, topics, endpoint: pushSubscription.endpoint });
|
||||
const serializedSubscription = JSON.parse(JSON.stringify(pushSubscription)); // Ugh ... https://stackoverflow.com/a/40525434/1440785
|
||||
await fetchOrThrow(url, {
|
||||
method: "PUT",
|
||||
method: "POST",
|
||||
headers: maybeWithAuth({}, user),
|
||||
body: JSON.stringify({
|
||||
endpoint: serializedSubscription.endpoint,
|
||||
|
@ -132,6 +131,20 @@ class Api {
|
|||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async deleteWebPush(pushSubscription) {
|
||||
const user = await userManager.get(config.base_url);
|
||||
const url = accountWebPushUrl(config.base_url);
|
||||
console.log(`[Api] Deleting Web Push subscription`, { url, endpoint: pushSubscription.endpoint });
|
||||
await fetchOrThrow(url, {
|
||||
method: "DELETE",
|
||||
headers: maybeWithAuth({}, user),
|
||||
body: JSON.stringify({
|
||||
endpoint: pushSubscription.endpoint
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const api = new Api();
|
||||
|
|
|
@ -119,7 +119,12 @@ class SubscriptionManager {
|
|||
return;
|
||||
}
|
||||
|
||||
await api.updateWebPushSubscriptions(topics, browserSubscription);
|
||||
if (topics.length > 0) {
|
||||
await api.updateWebPush(browserSubscription, topics);
|
||||
} else {
|
||||
await api.deleteWebPush(browserSubscription);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async updateState(subscriptionId, state) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue