nodebb-plugin-discord-onekite 1.0.6 → 1.0.7
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/README.md +4 -7
- package/lib/controllers.js +8 -15
- package/library.js +2 -6
- package/package.json +1 -1
- package/templates/admin/plugins/discord-onekite.tpl +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
# nodebb-plugin-discord-onekite — v1.0.
|
|
1
|
+
# nodebb-plugin-discord-onekite — v1.0.6
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- Categories are rendered server-side.
|
|
7
|
-
- Settings are saved via a normal POST form submit.
|
|
8
|
-
- CSRF token is provided via `{config.csrf_token}`.
|
|
3
|
+
Fixes:
|
|
4
|
+
- Form action/redirect no longer uses `{config.relative_path}` (was rendering as `undefined` on your install).
|
|
5
|
+
- Categories are fetched server-side via `categories.getCategoriesByPrivilege('categories:cid', uid, 'read', ...)` (returns category objects). citeturn0search10
|
package/lib/controllers.js
CHANGED
|
@@ -12,21 +12,14 @@ function normalizeCids(v) {
|
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async function
|
|
16
|
-
//
|
|
17
|
-
//
|
|
15
|
+
async function getReadableCategories(uid) {
|
|
16
|
+
// NodeBB core uses this helper to get categories for a user by privilege.
|
|
17
|
+
// It returns an array of category objects (cid, name, slug, ...). citeturn0search10
|
|
18
18
|
return await new Promise((resolve) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (err2 || !Array.isArray(data)) return resolve([]);
|
|
24
|
-
resolve(data);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
} catch (e) {
|
|
28
|
-
resolve([]);
|
|
29
|
-
}
|
|
19
|
+
categories.getCategoriesByPrivilege('categories:cid', uid || 0, 'read', (err, categoriesData) => {
|
|
20
|
+
if (err || !Array.isArray(categoriesData)) return resolve([]);
|
|
21
|
+
resolve(categoriesData.filter(Boolean));
|
|
22
|
+
});
|
|
30
23
|
});
|
|
31
24
|
}
|
|
32
25
|
|
|
@@ -36,7 +29,7 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
36
29
|
const settings = await meta.settings.get(SETTINGS_KEY);
|
|
37
30
|
const savedCids = normalizeCids(settings && settings.cids);
|
|
38
31
|
|
|
39
|
-
const cats = await
|
|
32
|
+
const cats = await getReadableCategories(req.uid);
|
|
40
33
|
const categoriesForTpl = (cats || [])
|
|
41
34
|
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
42
35
|
.map(c => ({
|
package/library.js
CHANGED
|
@@ -75,7 +75,6 @@ async function buildTopicEmbed({ tid, pid, type }) {
|
|
|
75
75
|
const Plugin = {};
|
|
76
76
|
|
|
77
77
|
Plugin.init = async ({ router }) => {
|
|
78
|
-
// GET admin page
|
|
79
78
|
routeHelpers.setupAdminPageRoute(
|
|
80
79
|
router,
|
|
81
80
|
'/admin/plugins/discord-onekite',
|
|
@@ -83,8 +82,7 @@ Plugin.init = async ({ router }) => {
|
|
|
83
82
|
controllers.renderAdminPage
|
|
84
83
|
);
|
|
85
84
|
|
|
86
|
-
// POST save
|
|
87
|
-
// Protect via admin middleware; CSRF is checked globally by NodeBB when _csrf is present.
|
|
85
|
+
// POST save - keep it very simple and redirect to the canonical path
|
|
88
86
|
router.post('/admin/plugins/discord-onekite/save',
|
|
89
87
|
middleware.admin.checkPrivileges,
|
|
90
88
|
async (req, res) => {
|
|
@@ -92,15 +90,13 @@ Plugin.init = async ({ router }) => {
|
|
|
92
90
|
const payload = {
|
|
93
91
|
webhookUrl: req.body.webhookUrl || '',
|
|
94
92
|
notifyReplies: req.body.notifyReplies ? 'on' : '',
|
|
95
|
-
// multiple select may come as string or array
|
|
96
93
|
cids: req.body.cids || '',
|
|
97
94
|
};
|
|
98
95
|
await meta.settings.set(SETTINGS_KEY, payload);
|
|
99
96
|
} catch (e) {
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
97
|
console.error('[discord-onekite] save failed', e);
|
|
102
98
|
}
|
|
103
|
-
res.redirect(
|
|
99
|
+
res.redirect('/admin/plugins/discord-onekite');
|
|
104
100
|
}
|
|
105
101
|
);
|
|
106
102
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
2
|
<h4>Discord Onekite</h4>
|
|
3
3
|
<p class="text-muted">
|
|
4
|
-
Notifications Discord via webhook (
|
|
4
|
+
Notifications Discord via webhook (page ACP en rendu serveur).
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
<form role="form" method="post" action="
|
|
7
|
+
<form role="form" method="post" action="/admin/plugins/discord-onekite/save">
|
|
8
8
|
<input type="hidden" name="_csrf" value="{config.csrf_token}" />
|
|
9
9
|
|
|
10
10
|
<div class="mb-3">
|