nodebb-plugin-facebook-post 1.0.0 → 1.0.2

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
@@ -29,6 +29,29 @@ const DEFAULT_SETTINGS = {
29
29
  publishInstagram: false,
30
30
  };
31
31
 
32
+
33
+ function getAuthMiddleware(mw) {
34
+ // NodeBB versions/plugins may expose different auth middleware names.
35
+ // Ensure we always pass a real callback to express.
36
+ const candidates = [
37
+ mw && mw.authenticate,
38
+ mw && mw.ensureLoggedIn,
39
+ mw && mw.requireUser,
40
+ mw && mw.checkAuth,
41
+ ].filter(fn => typeof fn === 'function');
42
+
43
+ return candidates[0] || function (req, res, next) { next(); };
44
+ }
45
+
46
+ function getCoreMiddleware(params) {
47
+ if (params && middleware) return middleware;
48
+ try {
49
+ return require.main.require('./src/middleware');
50
+ } catch {
51
+ return {};
52
+ }
53
+ }
54
+
32
55
  let redisClient = null;
33
56
 
34
57
  function bool(v) { return v === true || v === 'true' || v === 1 || v === '1' || v === 'on'; }
@@ -280,19 +303,27 @@ async function listAllGroups() {
280
303
  const Plugin = {};
281
304
 
282
305
  Plugin.init = async function (params) {
283
- appRef = params.app;
306
+ // NodeBB v4.9.x: params provides { router, middleware, meta, ... }
307
+ const { router, middleware } = params;
308
+
284
309
  meta = (params && params.meta) ? params.meta : require.main.require('./src/meta');
285
310
 
286
311
  await loadSettings();
287
312
 
288
313
  const routeHelpers = require.main.require('./src/routes/helpers');
289
- routeHelpers.setupAdminPageRoute(appRef, '/admin/plugins/facebook-post', params.middleware, [], (req, res) => {
314
+
315
+ // ACP page (clean signature: router, route, middlewares, controller)
316
+ routeHelpers.setupAdminPageRoute(router, '/admin/plugins/facebook-post', [], (req, res) => {
290
317
  res.render('admin/facebook-post', {});
291
318
  });
292
319
 
293
- appRef.get('/api/admin/plugins/facebook-post/groups', params.middleware.authenticate, async (req, res) => {
320
+ // Admin API: list groups (used by ACP UI)
321
+ routeHelpers.setupApiRoute(router, 'get', '/api/admin/plugins/facebook-post/groups', [
322
+ middleware.ensureLoggedIn,
323
+ ], async (req, res) => {
294
324
  try {
295
325
  await loadSettings();
326
+
296
327
  const ok = await ensureAdmin(req);
297
328
  if (!ok) return res.status(403).json({ error: 'forbidden' });
298
329
 
@@ -309,7 +340,10 @@ Plugin.init = async function (params) {
309
340
  }
310
341
  });
311
342
 
312
- appRef.get('/api/facebook-post/can-post', params.middleware.authenticate, async (req, res) => {
343
+ // User API: check if current user can see the composer checkbox
344
+ routeHelpers.setupApiRoute(router, 'get', '/api/facebook-post/can-post', [
345
+ middleware.ensureLoggedIn,
346
+ ], async (req, res) => {
313
347
  try {
314
348
  await loadSettings();
315
349
  if (!settings.enabled) return res.json({ allowed: false, reason: 'disabled' });
@@ -321,13 +355,18 @@ Plugin.init = async function (params) {
321
355
  }
322
356
  });
323
357
 
324
- appRef.post('/api/admin/plugins/facebook-post/mark-posted', params.middleware.authenticate, async (req, res) => {
358
+ // Admin API: worker can mark posts as posted (optional)
359
+ routeHelpers.setupApiRoute(router, 'post', '/api/admin/plugins/facebook-post/mark-posted', [
360
+ middleware.ensureLoggedIn,
361
+ ], async (req, res) => {
325
362
  try {
326
363
  await loadSettings();
364
+
327
365
  const secret = trimStr(req.body && req.body.secret);
328
366
  if (!secret || secret !== settings.workerSecret) {
329
367
  return res.status(403).json({ error: 'bad_secret' });
330
368
  }
369
+
331
370
  const ok = await ensureAdmin(req);
332
371
  if (!ok) return res.status(403).json({ error: 'forbidden' });
333
372
 
@@ -347,11 +386,23 @@ Plugin.init = async function (params) {
347
386
  }
348
387
  });
349
388
 
350
- appRef.on('nodebb:settings:reload', async (payload) => {
389
+ router.on && router.on('nodebb:settings:reload', async (payload) => {
351
390
  if (payload && payload.plugin === SETTINGS_KEY) {
352
391
  await loadSettings();
353
392
  }
354
393
  });
394
+
395
+ // Also support the legacy app event emitter (older NodeBB versions)
396
+ try {
397
+ const app = params.app;
398
+ if (app && typeof app.on === 'function') {
399
+ app.on('nodebb:settings:reload', async (payload) => {
400
+ if (payload && payload.plugin === SETTINGS_KEY) {
401
+ await loadSettings();
402
+ }
403
+ });
404
+ }
405
+ } catch {}
355
406
  };
356
407
 
357
408
  Plugin.addAdminNavigation = async function (header) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Queue-based worker to auto-post new NodeBB topics to a fixed Facebook Page and optionally Instagram (images only).",
5
5
  "main": "library.js",
6
6
  "dependencies": {
package/plugin.json CHANGED
@@ -3,7 +3,6 @@
3
3
  "name": "Facebook/Instagram Post (Worker)",
4
4
  "description": "Enqueue new NodeBB topics to a worker that posts to a fixed Facebook Page (+ optional Instagram).",
5
5
  "url": "https://example.invalid/nodebb-plugin-facebook-post",
6
- "library": "./library.js",
7
6
  "hooks": [
8
7
  {
9
8
  "hook": "static:app.load",