nodebb-plugin-web-push 0.7.7 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/controllers.js +6 -4
- package/lib/subscriptions.js +1 -1
- package/library.js +15 -15
- package/package.json +8 -9
- package/public/lib/settings.js +5 -5
- package/test/index.js +1 -1
- package/package-lock.json +0 -4059
package/lib/controllers.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const user =
|
|
3
|
+
const user = nodebb.require('./src/user');
|
|
4
|
+
const helpers = nodebb.require('./src/controllers/helpers');
|
|
4
5
|
|
|
5
6
|
const subscriptions = require('./subscriptions');
|
|
6
7
|
|
|
7
|
-
const helpers = require.main.require('./src/controllers/helpers');
|
|
8
|
-
|
|
9
8
|
const Controllers = module.exports;
|
|
10
9
|
|
|
11
10
|
Controllers.renderSettings = async function (req, res) {
|
|
@@ -21,7 +20,10 @@ Controllers.renderSettings = async function (req, res) {
|
|
|
21
20
|
const payload = {
|
|
22
21
|
...res.locals.userData,
|
|
23
22
|
title: '[[web-push:profile.label]]',
|
|
24
|
-
breadcrumbs: helpers.buildBreadcrumbs([
|
|
23
|
+
breadcrumbs: helpers.buildBreadcrumbs([
|
|
24
|
+
{ text: username, url: `/user/${userslug}` },
|
|
25
|
+
{ text: '[[web-push:profile.label]]' },
|
|
26
|
+
]),
|
|
25
27
|
count,
|
|
26
28
|
};
|
|
27
29
|
|
package/lib/subscriptions.js
CHANGED
package/library.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const nconf = require.main.require('nconf');
|
|
4
|
-
const winston = require.main.require('winston');
|
|
5
3
|
const webPush = require('web-push');
|
|
6
4
|
const validator = require('validator');
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
6
|
+
const nconf = nodebb.require('nconf');
|
|
7
|
+
const winston = nodebb.require('winston');
|
|
8
|
+
|
|
9
|
+
const db = nodebb.require('./src/database');
|
|
10
|
+
const user = nodebb.require('./src/user');
|
|
11
|
+
const meta = nodebb.require('./src/meta');
|
|
12
|
+
const utils = nodebb.require('./src/utils');
|
|
13
|
+
const translator = nodebb.require('./src/translator');
|
|
14
|
+
const notifications = nodebb.require('./src/notifications');
|
|
15
|
+
|
|
16
|
+
const routeHelpers = nodebb.require('./src/routes/helpers');
|
|
14
17
|
|
|
15
18
|
const controllers = require('./lib/controllers');
|
|
16
19
|
const subscriptions = require('./lib/subscriptions');
|
|
17
20
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const plugin = {};
|
|
21
|
+
const plugin = module.exports;
|
|
21
22
|
|
|
22
23
|
plugin.init = async (params) => {
|
|
23
24
|
const { router, middleware/* , controllers */ } = params;
|
|
@@ -104,7 +105,8 @@ plugin.addRoutes = async ({ router, middleware, helpers }) => {
|
|
|
104
105
|
const payload = await constructPayload({
|
|
105
106
|
nid: utils.generateUUID(),
|
|
106
107
|
bodyShort: 'Test notification',
|
|
107
|
-
|
|
108
|
+
// test notification shouln't show any html chars
|
|
109
|
+
bodyLong: 'This is a <bdi>test</bid> message sent from <strong>NodeBB</strong>',
|
|
108
110
|
path: `/me/web-push`,
|
|
109
111
|
}, req.uid, userLang);
|
|
110
112
|
await webPush.sendNotification(subscription, JSON.stringify(payload));
|
|
@@ -217,7 +219,7 @@ async function constructPayload(notification, uid, lang) {
|
|
|
217
219
|
const { nid, mergeId, bodyShort, bodyLong, path } = notification;
|
|
218
220
|
|
|
219
221
|
let [title, body] = await translator.translateKeys([bodyShort, bodyLong], lang);
|
|
220
|
-
([title, body] = [title, body].map(str =>
|
|
222
|
+
([title, body] = [title, body].map(str => utils.stripHTMLTags(utils.decodeHTMLEntities(str))));
|
|
221
223
|
title = `${dir === 'rtl' ? '\u200f' : '\u200e'}${title}`;
|
|
222
224
|
const tag = mergeId || nid;
|
|
223
225
|
const url = `${nconf.get('url')}${path}`;
|
|
@@ -247,5 +249,3 @@ async function constructPayload(notification, uid, lang) {
|
|
|
247
249
|
data: { url, icon, badge },
|
|
248
250
|
};
|
|
249
251
|
}
|
|
250
|
-
|
|
251
|
-
module.exports = plugin;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-web-push",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.7.9",
|
|
4
|
+
"description": "A plugin for adding native push notifications to NodeBB via the Web Push API.",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -35,16 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"readmeFilename": "README.md",
|
|
37
37
|
"nbbpm": {
|
|
38
|
-
"compatibility": "^4.
|
|
38
|
+
"compatibility": "^4.12.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@commitlint/cli": "
|
|
42
|
-
"@commitlint/config-angular": "
|
|
43
|
-
"eslint": "^10.0.
|
|
44
|
-
"eslint-config-nodebb": "^2.0.
|
|
45
|
-
"eslint-plugin-import": "^2.31.0",
|
|
41
|
+
"@commitlint/cli": "21.0.2",
|
|
42
|
+
"@commitlint/config-angular": "21.0.2",
|
|
43
|
+
"@eslint/js": "^10.0.1",
|
|
44
|
+
"eslint-config-nodebb": "^2.0.2",
|
|
46
45
|
"husky": "9.1.7",
|
|
47
|
-
"lint-staged": "
|
|
46
|
+
"lint-staged": "17.0.8"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
50
49
|
"validator": "^13.12.0",
|
package/public/lib/settings.js
CHANGED
|
@@ -83,15 +83,15 @@ export async function init() {
|
|
|
83
83
|
// as value for applicationServerKey in pushManager.subscribe yet
|
|
84
84
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=802280
|
|
85
85
|
function urlBase64ToUint8Array(base64String) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
|
87
|
+
const base64 = (base64String + padding)
|
|
88
88
|
.replace(/-/g, '+')
|
|
89
89
|
.replace(/_/g, '/');
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const rawData = window.atob(base64);
|
|
92
|
+
const outputArray = new Uint8Array(rawData.length);
|
|
93
93
|
|
|
94
|
-
for (
|
|
94
|
+
for (let i = 0; i < rawData.length; ++i) {
|
|
95
95
|
outputArray[i] = rawData.charCodeAt(i);
|
|
96
96
|
}
|
|
97
97
|
return outputArray;
|
package/test/index.js
CHANGED