@@ -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(
|
||||||
startkey: "web_push_subscription:",
|
process.env.WEB_PUSH_SUBSCRIPTION_ID
|
||||||
endkey: "web_push_subscription:\uFFFF",
|
? {
|
||||||
include_docs: true,
|
key: process.env.WEB_PUSH_SUBSCRIPTION_ID,
|
||||||
});
|
include_docs: true,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
startkey: "web_push_subscription:",
|
||||||
|
endkey: "web_push_subscription:\uFFFF",
|
||||||
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user