Spaces:
Running
Running
Update server.js
Browse files21 unmodified lines22232425262728293031323334353637383940414243380 unmodified lines4244254264274284294303584 unmodified lines4015401640174018401940204021402221 unmodified linestry {if (process.env.FIREBASE_SERVICE_ACCOUNT) {let raw = process.env.FIREBASE_SERVICE_ACCOUNT;try {const serviceAccount = JSON.parse(raw);admin.initializeApp({credential: admin.credential.cert(serviceAccount)});} catch (parseErr) {const fixed = raw.replace(/\\n/g, '\n');const serviceAccount = JSON.parse(fixed);admin.initializeApp({credential: admin.credential.cert(serviceAccount)});}}} catch (err) {console.error('Firebase Admin init failed:', err.message);}const SECURE_SALT = process.env.SECURE_SALT;380 unmodified linesif (!user || !user.pushToken) return;await admin.messaging().send({ ...message, token: user.pushToken });} catch (err) {console.error(`Push to ${username} failed:`, err.code || err.message);if (err.code === 'messaging/registration-token-not-registered') {await User.updateOne({ username }, { $unset: { pushToken: 1 } }).catch(() => {});}3584 unmodified linesawait sendPushNotification(u.username, {notification: { title: st('У вас есть непрочитанные сообщения', 'ru'), body: `${st('Непрочитанных сообщений:', 'ru')} ${unreadMsgs.length}` },android: { notification: { channelId: '4send_channel', priority: 'high', sound: 'default', icon: '/ico.png', tag: 'unread_reminder' } },apns: { payload: { aps: { sound: 'default', badge: unreadMsgs.length, 'thread-id': 'unread_reminder' } } },webpush: { notification: { icon: '/ico.png', badge: '/ico.png', tag: 'unread_reminder' } }});}}21 unmodified lines222324252627282930313233380 unmodified lines4144154164174184193584 unmodified lines400440054006400740084009401021 unmodified linestry {if (process.env.FIREBASE_SERVICE_ACCOUNT) {const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);admin.initializeApp({credential: admin.credential.cert(serviceAccount)});}} catch (err) {}const SECURE_SALT = process.env.SECURE_SALT;380 unmodified linesif (!user || !user.pushToken) return;await admin.messaging().send({ ...message, token: user.pushToken });} catch (err) {if (err.code === 'messaging/registration-token-not-registered') {await User.updateOne({ username }, { $unset: { pushToken: 1 } }).catch(() => {});}3584 unmodified linesawait sendPushNotification(u.username, {notification: { title: st('У вас есть непрочитанные сообщения', 'ru'), body: `${st('Непрочитанных сообщений:', 'ru')} ${unreadMsgs.length}` },android: { notification: { channelId: '4send_channel', priority: 'high', sound: 'default', icon: '/ico.png', tag: 'unread_reminder' } },apns: { payload: { aps: { sound: 'default', badge: unreadMsgs.length, 'thread-id': 'unread_reminder' } } }});}}
server.js+5-17