49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
var os = require("os");
|
|
|
|
// SETTINGS WebPush Configuration
|
|
const webpush = require('web-push');
|
|
|
|
const publicVapidKey = process.env.PUBLIC_VAPI_KEY;
|
|
const privateVapidKey = process.env.PRIVATE_VAPI_KEY;
|
|
webpush.setVapidDetails('mailto:' + process.env.EMAIL_FROM, publicVapidKey, privateVapidKey);
|
|
|
|
module.exports = {
|
|
getHostname: function () {
|
|
return os.hostname()
|
|
},
|
|
testing: function () {
|
|
return (process.env.TESTING_ON === '1')
|
|
},
|
|
|
|
mylog: function (...args) {
|
|
if (!this.testing())
|
|
console.log(args)
|
|
},
|
|
|
|
mylogoff: function (...args) {
|
|
// doing nothing
|
|
},
|
|
|
|
mylogshow: function (...args) {
|
|
console.log(args)
|
|
},
|
|
|
|
allfieldTodo: function () {
|
|
return ['userId', 'pos', 'category', 'descr', 'priority', 'completed', 'created_at', 'modify_at',
|
|
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'id_next', 'progress', 'modified']
|
|
},
|
|
|
|
allfieldTodoWithId: function () {
|
|
return ['_id', ...this.allfieldTodo()]
|
|
},
|
|
|
|
sendBackNotif: function (subscription, payload) {
|
|
|
|
// console.log('sendBackNotif:', subscription, payload);
|
|
// Pass object into sendNotification
|
|
webpush.sendNotification(subscription, JSON.stringify(payload)).catch(err => console.error(err));
|
|
|
|
}
|
|
|
|
};
|