nodebb-plugin-discord-onekite 1.0.8 → 1.0.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/README.md +1 -5
- package/lib/controllers.js +32 -9
- package/library.js +19 -2
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/templates/admin/plugins/discord-onekite.tpl +12 -3
package/README.md
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
1
|
+
Debug build v1.0.7
|
package/lib/controllers.js
CHANGED
|
@@ -12,15 +12,28 @@ function normalizeCids(v) {
|
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
async function getCategoriesDebug(uid) {
|
|
16
|
+
const result = { method: 'getCategoriesByPrivilege', count: 0, error: null, sample: [] };
|
|
17
|
+
|
|
18
|
+
const cats = await new Promise((resolve) => {
|
|
19
|
+
try {
|
|
20
|
+
categories.getCategoriesByPrivilege('categories:cid', uid || 0, 'read', (err, categoriesData) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
result.error = err.message || String(err);
|
|
23
|
+
return resolve([]);
|
|
24
|
+
}
|
|
25
|
+
if (!Array.isArray(categoriesData)) return resolve([]);
|
|
26
|
+
resolve(categoriesData.filter(Boolean));
|
|
27
|
+
});
|
|
28
|
+
} catch (e) {
|
|
29
|
+
result.error = e.message || String(e);
|
|
30
|
+
resolve([]);
|
|
31
|
+
}
|
|
23
32
|
});
|
|
33
|
+
|
|
34
|
+
result.count = cats.length;
|
|
35
|
+
result.sample = cats.slice(0, 5).map(c => ({ cid: c.cid, name: c.name }));
|
|
36
|
+
return { cats, result };
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
const controllers = {};
|
|
@@ -29,7 +42,7 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
29
42
|
const settings = await meta.settings.get(SETTINGS_KEY);
|
|
30
43
|
const savedCids = normalizeCids(settings && settings.cids);
|
|
31
44
|
|
|
32
|
-
const cats = await
|
|
45
|
+
const { cats, result } = await getCategoriesDebug(req.uid);
|
|
33
46
|
const categoriesForTpl = (cats || [])
|
|
34
47
|
.filter(c => c && typeof c.cid !== 'undefined' && c.name)
|
|
35
48
|
.map(c => ({
|
|
@@ -39,9 +52,19 @@ controllers.renderAdminPage = async function (req, res) {
|
|
|
39
52
|
}))
|
|
40
53
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
41
54
|
|
|
55
|
+
const debug = {
|
|
56
|
+
uid: req.uid,
|
|
57
|
+
relative_path: meta.config && meta.config.relative_path,
|
|
58
|
+
url: meta.config && meta.config.url,
|
|
59
|
+
categories: result,
|
|
60
|
+
savedCidsCount: savedCids.length,
|
|
61
|
+
now: new Date().toISOString(),
|
|
62
|
+
};
|
|
63
|
+
|
|
42
64
|
res.render('admin/plugins/discord-onekite', {
|
|
43
65
|
settings: settings || {},
|
|
44
66
|
categories: categoriesForTpl,
|
|
67
|
+
debug: JSON.stringify(debug, null, 2),
|
|
45
68
|
});
|
|
46
69
|
};
|
|
47
70
|
|
package/library.js
CHANGED
|
@@ -75,6 +75,8 @@ async function buildTopicEmbed({ tid, pid, type }) {
|
|
|
75
75
|
const Plugin = {};
|
|
76
76
|
|
|
77
77
|
Plugin.init = async ({ router }) => {
|
|
78
|
+
console.log('[discord-onekite] init hook fired');
|
|
79
|
+
|
|
78
80
|
routeHelpers.setupAdminPageRoute(
|
|
79
81
|
router,
|
|
80
82
|
'/admin/plugins/discord-onekite',
|
|
@@ -82,7 +84,6 @@ Plugin.init = async ({ router }) => {
|
|
|
82
84
|
controllers.renderAdminPage
|
|
83
85
|
);
|
|
84
86
|
|
|
85
|
-
// POST save - keep it very simple and redirect to the canonical path
|
|
86
87
|
router.post('/admin/plugins/discord-onekite/save',
|
|
87
88
|
middleware.admin.checkPrivileges,
|
|
88
89
|
async (req, res) => {
|
|
@@ -93,19 +94,35 @@ Plugin.init = async ({ router }) => {
|
|
|
93
94
|
cids: req.body.cids || '',
|
|
94
95
|
};
|
|
95
96
|
await meta.settings.set(SETTINGS_KEY, payload);
|
|
97
|
+
console.log('[discord-onekite] settings saved');
|
|
96
98
|
} catch (e) {
|
|
97
99
|
console.error('[discord-onekite] save failed', e);
|
|
98
100
|
}
|
|
99
101
|
res.redirect('/admin/plugins/discord-onekite');
|
|
100
102
|
}
|
|
101
103
|
);
|
|
104
|
+
|
|
105
|
+
router.get('/admin/plugins/discord-onekite/ping',
|
|
106
|
+
middleware.admin.checkPrivileges,
|
|
107
|
+
(req, res) => {
|
|
108
|
+
res.json({
|
|
109
|
+
ok: true,
|
|
110
|
+
plugin: 'nodebb-plugin-discord-onekite',
|
|
111
|
+
version: '1.0.7',
|
|
112
|
+
uid: req.uid,
|
|
113
|
+
relative_path: meta.config && meta.config.relative_path,
|
|
114
|
+
url: meta.config && meta.config.url,
|
|
115
|
+
time: new Date().toISOString(),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
);
|
|
102
119
|
};
|
|
103
120
|
|
|
104
121
|
Plugin.addAdminNavigation = (header) => {
|
|
105
122
|
header.plugins.push({
|
|
106
123
|
route: '/plugins/discord-onekite',
|
|
107
124
|
icon: 'fa-bell',
|
|
108
|
-
name: 'Discord Onekite',
|
|
125
|
+
name: 'Discord Onekite (Debug)',
|
|
109
126
|
});
|
|
110
127
|
return header;
|
|
111
128
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-discord-onekite",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Discord webhook notifier for Onekite (NodeBB v4.x only) - debug build",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "nodebb-plugin-discord-onekite",
|
|
3
3
|
"name": "Discord Onekite Notifier",
|
|
4
|
-
"description": "Notifie Discord via webhook
|
|
4
|
+
"description": "Notifie Discord via webhook (v4.x). Version debug (ACP server-side).",
|
|
5
5
|
"library": "./library.js",
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="acp-page-container">
|
|
2
|
-
<h4>Discord Onekite</h4>
|
|
2
|
+
<h4>Discord Onekite (Debug)</h4>
|
|
3
3
|
<p class="text-muted">
|
|
4
|
-
|
|
4
|
+
Cette page est en rendu serveur et inclut des informations de debug.
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<form role="form" method="post" action="/admin/plugins/discord-onekite/save">
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<div class="form-check mb-3">
|
|
16
16
|
<input class="form-check-input" type="checkbox" id="notifyReplies" name="notifyReplies" <!-- IF settings.notifyReplies -->checked<!-- ENDIF settings.notifyReplies -->>
|
|
17
17
|
<label class="form-check-label" for="notifyReplies">
|
|
18
|
-
Notifier aussi les réponses
|
|
18
|
+
Notifier aussi les réponses
|
|
19
19
|
</label>
|
|
20
20
|
</div>
|
|
21
21
|
|
|
@@ -33,4 +33,13 @@
|
|
|
33
33
|
|
|
34
34
|
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
|
35
35
|
</form>
|
|
36
|
+
|
|
37
|
+
<hr />
|
|
38
|
+
|
|
39
|
+
<h5>Debug</h5>
|
|
40
|
+
<pre style="white-space: pre-wrap;">{debug}</pre>
|
|
41
|
+
<p>
|
|
42
|
+
Endpoint de test (doit répondre JSON) :
|
|
43
|
+
<code>/admin/plugins/discord-onekite/ping</code>
|
|
44
|
+
</p>
|
|
36
45
|
</div>
|