Spaces:
Running
Running
Download services/push.js from 4send/messenger: direct link, hf CLI and curl.
- Browser
- Download file 651 Bytes
-
https://huggingface.co/spaces/4send/messenger/resolve/main/services/push.js
- Command line
-
hf download hf://spaces/4send/messenger/services/push.js
-
curl -L -o push.js https://huggingface.co/spaces/4send/messenger/resolve/main/services/push.js
651 Bytes
| const User = require('../models/User'); | |
| const admin = require('../config/firebase'); | |
| const sendPushNotification = async (username, message) => { | |
| try { | |
| if (typeof admin.messaging !== 'function') return; | |
| const user = await User.findOne({ username }).lean(); | |
| if (!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(() => {}); | |
| } | |
| } | |
| }; | |
| module.exports = { sendPushNotification }; | |