mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-18 10:33:11 +02:00
Move web-push-config endpoint to config.js
This commit is contained in:
parent
9e0687e142
commit
e8139ad655
7 changed files with 11 additions and 57 deletions
web/src/app
|
@ -8,7 +8,6 @@ import {
|
|||
topicUrlJsonPollWithSince,
|
||||
topicUrlWebPushSubscribe,
|
||||
topicUrlWebPushUnsubscribe,
|
||||
webPushConfigUrl,
|
||||
} from "./utils";
|
||||
import userManager from "./UserManager";
|
||||
import { fetchOrThrow } from "./errors";
|
||||
|
@ -117,27 +116,8 @@ class Api {
|
|||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<{ public_key: string } | undefined>}
|
||||
*/
|
||||
async getWebPushConfig(baseUrl) {
|
||||
const response = await fetch(webPushConfigUrl(baseUrl));
|
||||
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
if (response.status === 404) {
|
||||
// web push is not enabled
|
||||
return undefined;
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
|
||||
async subscribeWebPush(baseUrl, topic, browserSubscription) {
|
||||
const user = await userManager.get(baseUrl);
|
||||
|
||||
const url = topicUrlWebPushSubscribe(baseUrl, topic);
|
||||
console.log(`[Api] Sending Web Push Subscription ${url}`);
|
||||
|
||||
|
@ -163,7 +143,9 @@ class Api {
|
|||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: maybeWithAuth({}, user),
|
||||
body: JSON.stringify({ endpoint: subscription.webPushEndpoint }),
|
||||
body: JSON.stringify({
|
||||
endpoint: subscription.webPushEndpoint
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue