nodebb-plugin-discord-onekite 1.1.14 → 1.1.16

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 CHANGED
@@ -1,7 +1,12 @@
1
- # nodebb-plugin-discord-onekite v1.1.4.5
1
+ # nodebb-plugin-discord-onekite v1.1.4.8
2
2
 
3
- Fixes ACP save (API route) + floating save button + toast.
3
+ ACP (NodeBB v4):
4
+ - Save button at top: "Enregistrer les paramètres"
5
+ - Uses custom API routes (GET/POST) registered with `routeHelpers.setupApiRoute`:
6
+ - GET /api/plugins/discord-onekite/settings
7
+ - POST /api/plugins/discord-onekite/settings
8
+ - Shows NodeBB toast on save
4
9
 
5
- - Adds API route via `routeHelpers.setupApiRoute` so `api.post('/admin/...')` works.
6
- - Adds floating save button bottom-right.
7
- - Shows NodeBB toast on success.
10
+ Discord:
11
+ - Embed only: clickable title (embed.url) + message excerpt in embed.description (no duplicate lines)
12
+ - Absolute URL prefix fallback to https://www.onekite.com
package/library.js CHANGED
@@ -183,6 +183,39 @@ Plugin.init = async ({ router }) => {
183
183
  controllers.renderAdminPage
184
184
  );
185
185
 
186
+ // API routes for ACP (client calls /api/plugins/discord-onekite/settings)
187
+ routeHelpers.setupApiRoute(router, 'get', '/plugins/discord-onekite/settings', [middleware.admin.checkPrivileges], async (req, res) => {
188
+ const s = await meta.settings.get(SETTINGS_KEY);
189
+ res.json({
190
+ settings: {
191
+ webhookUrl: (s && s.webhookUrl) ? String(s.webhookUrl).trim() : '',
192
+ notifyReplies: !!(s && (s.notifyReplies === true || s.notifyReplies === 'on' || s.notifyReplies === 'true')),
193
+ cids: (() => {
194
+ const v = s && s.cids;
195
+ if (!v) return [];
196
+ if (Array.isArray(v)) return v.map(String).filter(Boolean);
197
+ if (typeof v === 'string') return v.split(',').map(x => x.trim()).filter(Boolean);
198
+ return [];
199
+ })(),
200
+ },
201
+ });
202
+ });
203
+
204
+ routeHelpers.setupApiRoute(router, 'post', '/plugins/discord-onekite/settings', [middleware.admin.checkPrivileges], async (req, res) => {
205
+ try {
206
+ const payload = {
207
+ webhookUrl: req.body.webhookUrl || '',
208
+ notifyReplies: req.body.notifyReplies ? 'on' : '',
209
+ cids: req.body.cids || '',
210
+ };
211
+ await meta.settings.set(SETTINGS_KEY, payload);
212
+ res.json({ ok: true });
213
+ } catch (e) {
214
+ console.error('[discord-onekite] save failed', e);
215
+ res.status(500).json({ ok: false });
216
+ }
217
+ });
218
+
186
219
  // AJAX save endpoint for ACP (used by admin.js)
187
220
  router.post('/api/admin/plugins/discord-onekite/save',
188
221
  middleware.admin.checkPrivileges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-discord-onekite",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
@@ -10,33 +10,56 @@ define('admin/plugins/discord-onekite', ['api'], function (api) {
10
10
  return Array.from(el.selectedOptions || []).map(o => o.value);
11
11
  }
12
12
 
13
- function doSave() {
13
+ function setMultiSelectValues(selector, values) {
14
+ const el = document.querySelector(selector);
15
+ if (!el) return;
16
+ const set = new Set((values || []).map(String));
17
+ Array.from(el.options).forEach(opt => { opt.selected = set.has(String(opt.value)); });
18
+ }
19
+
20
+ async function loadSettings() {
21
+ try {
22
+ const res = await api.get('/plugins/discord-onekite/settings');
23
+ if (res && res.settings) {
24
+ $('#webhookUrl').val(res.settings.webhookUrl || '');
25
+ $('#notifyReplies').prop('checked', !!res.settings.notifyReplies);
26
+ setMultiSelectValues('#cids', res.settings.cids || []);
27
+ }
28
+ } catch (err) {
29
+ // eslint-disable-next-line no-console
30
+ console.error(err);
31
+ }
32
+ }
33
+
34
+ async function saveSettings() {
14
35
  const payload = {
15
36
  webhookUrl: String($('#webhookUrl').val() || '').trim(),
16
37
  notifyReplies: $('#notifyReplies').is(':checked'),
17
38
  cids: getMultiSelectValues('#cids'),
18
39
  };
19
40
 
20
- // `api.post('/admin/...')` -> `/api/admin/...`
21
- return api.post('/admin/plugins/discord-onekite/save', payload).then(function () {
41
+ try {
42
+ await api.post('/plugins/discord-onekite/settings', payload);
22
43
  if (window.app && typeof app.alertSuccess === 'function') {
23
44
  app.alertSuccess('Paramètres enregistrés !');
24
45
  }
25
- }).catch(function (err) {
46
+ } catch (err) {
26
47
  // eslint-disable-next-line no-console
27
48
  console.error(err);
28
49
  if (window.app && typeof app.alertError === 'function') {
29
50
  app.alertError('Erreur lors de l’enregistrement');
30
51
  }
31
- });
52
+ }
32
53
  }
33
54
 
34
55
  ACP.init = function () {
35
56
  if (!$('.discord-onekite-settings').length) return;
36
57
 
37
- $(document).off('click.discordOnekite', '#save').on('click.discordOnekite', '#save', function (e) {
58
+ loadSettings();
59
+
60
+ $('#save').off('click.discordOnekite').on('click.discordOnekite', function (e) {
38
61
  e.preventDefault();
39
- doSave();
62
+ saveSettings();
40
63
  });
41
64
  };
42
65
 
@@ -4,6 +4,7 @@
4
4
  <h4 class="mb-1">Discord Onekite</h4>
5
5
  <p class="text-muted mb-0">Notifications Discord via webhook.</p>
6
6
  </div>
7
+ <button id="save" type="button" class="btn btn-primary">Enregistrer les paramètres</button>
7
8
  </div>
8
9
 
9
10
  <form role="form" class="discord-onekite-settings">
@@ -31,8 +32,4 @@
31
32
  </p>
32
33
  </div>
33
34
  </form>
34
-
35
- <button id="save" class="btn btn-primary" style="position: fixed; right: 2rem; bottom: 2rem; z-index: 1030;">
36
- <i class="fa fa-save"></i>
37
- </button>
38
35
  </div>