bugfixing
This commit is contained in:
parent
3abc95e904
commit
d0111d91d8
@ -13,20 +13,20 @@ webPush.setVapidDetails(
|
|||||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||||
const { pb, apiKey } = locals;
|
const { pb, apiKey } = locals;
|
||||||
// Extract 'url' from the request body
|
// Extract 'url' from the request body
|
||||||
const { title, body, key, url } = await request?.json();
|
const { title, body, key, url, userId } = await request?.json();
|
||||||
|
|
||||||
if (apiKey !== key) {
|
if (apiKey !== key) {
|
||||||
return new Response(JSON.stringify({ success: false, error: 'Invalid API key' }), { status: 401 });
|
return new Response(JSON.stringify({ success: false, error: 'Invalid API key' }), { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const subscriptions = await pb.collection('pushSubscription').getFullList({ sort: '-created' });
|
const subscriptions = await pb.collection('pushSubscription').getFullList({ filter: `user="${userId}"`, sort: '-created' });
|
||||||
|
|
||||||
if (!subscriptions.length) {
|
if (!subscriptions.length) {
|
||||||
return new Response(JSON.stringify({ success: false, error: 'No subscriptions found' }), { status: 404 });
|
return new Response(JSON.stringify({ success: false, error: 'No subscriptions found' }), { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendNotifications = subscriptions.map(async (subRecord) => {
|
const sendNotifications = subscriptions?.map(async (subRecord) => {
|
||||||
try {
|
try {
|
||||||
const subscriptionData = subRecord.subscription?.subscription;
|
const subscriptionData = subRecord.subscription?.subscription;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user