add generate-keys
Main daploy / deploy (push) Successful in 41s

This commit is contained in:
2024-11-24 13:02:27 +02:00
parent c724ab1028
commit 2cd8bf62a9
2 changed files with 30 additions and 10 deletions
@@ -1,5 +1,14 @@
import webpush from 'web-push'; import webpush from "web-push";
import PouchDB from "./PouchDB.js";
const vapidKeys = webpush.generateVAPIDKeys(); const vapidKeys = webpush.generateVAPIDKeys();
console.log(vapidKeys) await new PouchDB(`${process.env.API_URL}/server_settings`, {
skip_setup: true,
}).put({
_id: "server_settings:message_delivery_method_web_push:vapid",
vapid: {
subject: process.env.VAPID_SUBJECT,
keys: vapidKeys,
},
});
@@ -37,16 +37,27 @@ const notification = {
const { rows } = await new PouchDB( const { rows } = await new PouchDB(
`${process.env.API_URL}/web_push_subscriptions`, `${process.env.API_URL}/web_push_subscriptions`,
{ skip_setup: true }, { skip_setup: true },
).allDocs({ ).allDocs(
process.env.WEB_PUSH_SUBSCRIPTION_ID
? {
key: process.env.WEB_PUSH_SUBSCRIPTION_ID,
include_docs: true,
}
: {
startkey: "web_push_subscription:", startkey: "web_push_subscription:",
endkey: "web_push_subscription:\uFFFF", endkey: "web_push_subscription:\uFFFF",
include_docs: true, include_docs: true,
}); },
);
await Promise.allSettled( await Promise.allSettled(
rows.map(({ doc }) => rows.map(async ({ doc }) => {
webpush.sendNotification(doc.subscription, JSON.stringify(notification)), await webpush.sendNotification(
), doc.subscription,
JSON.stringify(notification),
);
console.log("sent ", doc._id);
}),
); );
// issues: // issues: