@@ -37,16 +37,27 @@ const notification = {
|
||||
const { rows } = await new PouchDB(
|
||||
`${process.env.API_URL}/web_push_subscriptions`,
|
||||
{ skip_setup: true },
|
||||
).allDocs({
|
||||
startkey: "web_push_subscription:",
|
||||
endkey: "web_push_subscription:\uFFFF",
|
||||
include_docs: true,
|
||||
});
|
||||
).allDocs(
|
||||
process.env.WEB_PUSH_SUBSCRIPTION_ID
|
||||
? {
|
||||
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(
|
||||
rows.map(({ doc }) =>
|
||||
webpush.sendNotification(doc.subscription, JSON.stringify(notification)),
|
||||
),
|
||||
rows.map(async ({ doc }) => {
|
||||
await webpush.sendNotification(
|
||||
doc.subscription,
|
||||
JSON.stringify(notification),
|
||||
);
|
||||
console.log("sent ", doc._id);
|
||||
}),
|
||||
);
|
||||
|
||||
// issues:
|
||||
|
||||
Reference in New Issue
Block a user