allow sending push to unanswered publishers;
comment dangerous admin functions
This commit is contained in:
@ -33,19 +33,21 @@ const Notification = async (req, res) => {
|
||||
select: { pushSubscription: true }
|
||||
});
|
||||
subs = Array.isArray(publisher.pushSubscription) ? publisher.pushSubscription.length : (publisher.pushSubscription ? 1 : 0);
|
||||
res.send({ subs })
|
||||
res.end()
|
||||
return
|
||||
} else {
|
||||
// send the public key in the response headers
|
||||
//res.setHeader('Content-Type', 'text/plain')
|
||||
res.send({ pk: process.env.NEXT_PUBLIC_WEB_PUSH_PUBLIC_KEY, subs })
|
||||
res.end()
|
||||
}
|
||||
// send the public key in the response headers
|
||||
//res.setHeader('Content-Type', 'text/plain')
|
||||
res.send({ pk: process.env.NEXT_PUBLIC_WEB_PUSH_PUBLIC_KEY, subs })
|
||||
res.end()
|
||||
}
|
||||
if (req.method == 'PUT') {
|
||||
// store the subscription object in the database
|
||||
// publisher.pushSubscription = subscription
|
||||
const prisma = common.getPrismaClient();
|
||||
const { subscription, id } = req.body
|
||||
const { subscription, id, name } = req.body
|
||||
const publisher = await prisma.publisher.findUnique({
|
||||
where: { id },
|
||||
select: { pushSubscription: true }
|
||||
@ -105,14 +107,19 @@ const Notification = async (req, res) => {
|
||||
|
||||
|
||||
if (req.method == 'POST') {//title = "ССС", message = "Ще получите уведомление по този начин.")
|
||||
const { subscription, id, broadcast, title = 'ССОМ', message = 'Ще получавате уведомления така.', actions } = req.body
|
||||
const { subscription, id, ids, broadcast, title = 'ССОМ', message = 'Ще получавате уведомления така.', actions } = req.body
|
||||
if (broadcast) {
|
||||
await broadcastPush(title, message, actions)
|
||||
res.statusCode = 200
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
else if (id) {
|
||||
} else if (ids && ids.length) {
|
||||
console.log('Sending push notifications to publishers ', ids);
|
||||
await Promise.all(ids.map(_id => sendPush(_id, title, message, actions)));
|
||||
res.statusCode = 200;
|
||||
res.end();
|
||||
return;
|
||||
} else if (id) {
|
||||
console.log('Sending push notification to publisher ', id)
|
||||
await sendPush(id, title, message, actions)
|
||||
res.statusCode = 200
|
||||
|
Reference in New Issue
Block a user