nodebb-plugin-facebook-post 1.0.13 → 1.0.15

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.
Files changed (2) hide show
  1. package/library.js +33 -3
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -135,12 +135,35 @@ function sanitizeExcerpt(text, maxLen) {
135
135
  return s.slice(0, Math.max(0, maxLen - 1)).trimEnd() + '…';
136
136
  }
137
137
 
138
+ function normalizeAllowedGroupsValue(value) {
139
+ if (!value) return '';
140
+ if (Array.isArray(value)) {
141
+ return value.map(String).map(v => v.trim()).filter(Boolean).join(',');
142
+ }
143
+ const s = String(value).trim();
144
+ if (!s) return '';
145
+ if (s.startsWith('[')) {
146
+ try {
147
+ const parsed = JSON.parse(s);
148
+ if (Array.isArray(parsed)) {
149
+ return parsed.map(String).map(v => v.trim()).filter(Boolean).join(',');
150
+ }
151
+ } catch (_) {}
152
+ }
153
+ return s;
154
+ }
155
+
138
156
  function parseAllowedGroupsList() {
139
157
  const s = trimStr(settings.allowedGroups);
140
158
  if (!s) return [];
141
159
  return s.split(',').map(v => v.trim()).filter(Boolean);
142
160
  }
143
161
 
162
+
163
+ function getUidFromReq(req) {
164
+ return req && (req.uid || (req.user && req.user.uid) || (req.session && req.session.uid));
165
+ }
166
+
144
167
  async function userIsAllowed(uid) {
145
168
  const allowed = parseAllowedGroupsList();
146
169
  if (!allowed.length) return false;
@@ -337,9 +360,16 @@ Plugin.init = async function (params) {
337
360
  try {
338
361
  await loadSettings();
339
362
  if (!settings.enabled) return res.json({ allowed: false, reason: 'disabled' });
340
-
341
- const ok = await userIsAllowed(req.uid);
342
- return res.json({ allowed: ok });
363
+ const uid = getUidFromReq(req);
364
+ if (!uid) return res.json({ allowed: false, reason: 'no_uid' });
365
+ const allowedGroups = parseAllowedGroupsList();
366
+ if (!allowedGroups.length) return res.json({ allowed: false, reason: 'no_groups_configured' });
367
+ const ok = await userIsAllowed(uid);
368
+ return res.json({ allowed: ok, reason: ok ? 'ok' : 'not_in_group' });
369
+ } catch {
370
+ return res.json({ allowed: false, reason: 'error' });
371
+ }
372
+ });
343
373
  } catch {
344
374
  return res.json({ allowed: false });
345
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Auto-post new NodeBB topics to a fixed Facebook Page (text + NodeBB uploads + place id).",
5
5
  "main": "library.js",
6
6
  "dependencies": {