nodebb-plugin-facebook-post 1.0.14 → 1.0.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/library.js CHANGED
@@ -98,7 +98,7 @@ function isForumHosted(urlAbs) {
98
98
  if (!base) return false;
99
99
  try {
100
100
  return new URL(urlAbs).host === new URL(base).host;
101
- } catch {
101
+ } catch (err) {
102
102
  return false;
103
103
  }
104
104
  }
@@ -159,6 +159,11 @@ function parseAllowedGroupsList() {
159
159
  return s.split(',').map(v => v.trim()).filter(Boolean);
160
160
  }
161
161
 
162
+
163
+ function getUidFromReq(req) {
164
+ return req && (req.uid || (req.user && req.user.uid) || (req.session && req.session.uid));
165
+ }
166
+
162
167
  async function userIsAllowed(uid) {
163
168
  const allowed = parseAllowedGroupsList();
164
169
  if (!allowed.length) return false;
@@ -172,7 +177,7 @@ async function userIsAllowed(uid) {
172
177
  // eslint-disable-next-line no-await-in-loop
173
178
  const ok = await Groups.isMember(uid, groupName);
174
179
  if (ok) return true;
175
- } catch {
180
+ } catch (err) {
176
181
  // ignore
177
182
  }
178
183
  }
@@ -355,10 +360,17 @@ Plugin.init = async function (params) {
355
360
  try {
356
361
  await loadSettings();
357
362
  if (!settings.enabled) return res.json({ allowed: false, reason: 'disabled' });
358
-
359
- const ok = await userIsAllowed(req.uid);
360
- return res.json({ allowed: ok });
361
- } catch {
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 (err) {
370
+ return res.json({ allowed: false, reason: 'error' });
371
+ }
372
+ });
373
+ } catch (err) {
362
374
  return res.json({ allowed: false });
363
375
  }
364
376
  });
@@ -386,7 +398,7 @@ Plugin.init = async function (params) {
386
398
  await Posts.deletePostField(pid, 'fbQueueJobId');
387
399
  await Posts.deletePostField(pid, 'fbQueuedAt');
388
400
  return res.json({ ok: true });
389
- } catch {
401
+ } catch (err) {
390
402
  return res.status(500).json({ error: 'failed' });
391
403
  }
392
404
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
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": {
@@ -10,7 +10,7 @@
10
10
  });
11
11
  if (!res.ok) return { allowed: false };
12
12
  return await res.json();
13
- } catch {
13
+ } catch (err) {
14
14
  return { allowed: false };
15
15
  }
16
16
  }
@@ -71,7 +71,7 @@
71
71
  if (!perm.allowed) return;
72
72
 
73
73
  injectUI($composer);
74
- } catch {
74
+ } catch (err) {
75
75
  // ignore
76
76
  }
77
77
  });