nodebb-plugin-facebook-post 1.0.21 → 1.0.23
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 +56 -11
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -339,44 +339,89 @@ Plugin.addAdminNavigation = async function (header) {
|
|
|
339
339
|
};
|
|
340
340
|
|
|
341
341
|
Plugin.onPostCreate = async function (hookData) {
|
|
342
|
+
const winston = require.main.require('winston');
|
|
342
343
|
try {
|
|
343
|
-
if (!hookData?.post || !hookData?.data)
|
|
344
|
+
if (!hookData?.post || !hookData?.data) {
|
|
345
|
+
winston.info('[facebook-post] onPostCreate: hookData manquant (post ou data absent)');
|
|
346
|
+
return hookData;
|
|
347
|
+
}
|
|
344
348
|
hookData.post.fbPostEnabled = bool(hookData.data.fbPostEnabled);
|
|
345
349
|
const fbPlaceId = trimStr(hookData.data.fbPlaceId);
|
|
346
350
|
if (fbPlaceId) hookData.post.fbPlaceId = fbPlaceId;
|
|
347
|
-
|
|
348
|
-
|
|
351
|
+
winston.info(`[facebook-post] onPostCreate: pid=${hookData.post.pid} fbPostEnabled=${hookData.post.fbPostEnabled} fbPlaceId=${hookData.post.fbPlaceId || '(none)'}`);
|
|
352
|
+
} catch (e) {
|
|
353
|
+
winston.error(`[facebook-post] onPostCreate erreur: ${e?.message || e}`);
|
|
349
354
|
}
|
|
350
355
|
return hookData;
|
|
351
356
|
};
|
|
352
357
|
|
|
353
358
|
Plugin.onPostSave = async function (hookData) {
|
|
354
359
|
const winston = require.main.require('winston');
|
|
360
|
+
winston.info('[facebook-post] onPostSave: hook déclenché');
|
|
355
361
|
try {
|
|
356
362
|
await loadSettings();
|
|
357
|
-
|
|
363
|
+
winston.info(`[facebook-post] onPostSave: settings.enabled=${settings.enabled} fbPageId=${settings.fbPageId ? 'défini' : 'MANQUANT'} fbPageAccessToken=${settings.fbPageAccessToken ? 'défini' : 'MANQUANT'}`);
|
|
358
364
|
|
|
359
|
-
|
|
360
|
-
|
|
365
|
+
if (!settings.enabled) {
|
|
366
|
+
winston.info('[facebook-post] onPostSave: abandon — plugin désactivé dans les paramètres');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
361
369
|
|
|
362
|
-
const
|
|
363
|
-
|
|
370
|
+
const rawPost = hookData && hookData.post ? hookData.post : hookData;
|
|
371
|
+
winston.info(`[facebook-post] onPostSave: données brutes reçues — pid=${rawPost?.pid} fbPostEnabled=${rawPost?.fbPostEnabled}`);
|
|
372
|
+
|
|
373
|
+
const ctx = await getPostContext(rawPost);
|
|
374
|
+
if (!ctx) {
|
|
375
|
+
winston.warn('[facebook-post] onPostSave: abandon — impossible de récupérer le contexte du post (pid invalide ?)');
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
winston.info(`[facebook-post] onPostSave: contexte récupéré — pid=${ctx.post.pid} tid=${ctx.topic.tid} cid=${ctx.topic.cid} uid=${ctx.user.uid} isMainPost=${ctx.post.isMainPost} index=${ctx.post.index} reputation=${ctx.user.reputation}`);
|
|
364
379
|
|
|
365
|
-
|
|
380
|
+
const allowed = await userIsAllowed(ctx.post.uid);
|
|
381
|
+
if (!allowed) {
|
|
382
|
+
const groups = parseAllowedGroupsList();
|
|
383
|
+
winston.info(`[facebook-post] onPostSave: abandon — uid=${ctx.post.uid} n'est pas dans les groupes autorisés: [${groups.join(', ')}]`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
winston.info(`[facebook-post] onPostSave: uid=${ctx.post.uid} autorisé par les groupes`);
|
|
387
|
+
|
|
388
|
+
const process = shouldProcessPost(ctx);
|
|
389
|
+
if (!process) {
|
|
390
|
+
const isFirstPost = (ctx.post.isMainPost === true) || (ctx.post.index === 0);
|
|
391
|
+
const fbEnabled = bool(ctx.post.fbPostEnabled);
|
|
392
|
+
const repOk = (ctx.user.reputation || 0) >= settings.minimumReputation;
|
|
393
|
+
const whitelist = parseCsvInts(settings.categoriesWhitelist);
|
|
394
|
+
const catOk = whitelist.length === 0 || whitelist.includes(parseInt(ctx.topic.cid, 10));
|
|
395
|
+
winston.info(`[facebook-post] onPostSave: abandon — shouldProcessPost=false. Détail: isFirstPost=${isFirstPost} fbPostEnabled=${fbEnabled} reputationOk=${repOk}(${ctx.user.reputation}>=${settings.minimumReputation}) categoryOk=${catOk}(cid=${ctx.topic.cid} whitelist=[${whitelist}])`);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
winston.info('[facebook-post] onPostSave: shouldProcessPost=true, publication en cours…');
|
|
366
399
|
|
|
367
400
|
const Posts = require.main.require('./src/posts');
|
|
368
401
|
|
|
369
402
|
const already = await Posts.getPostField(ctx.post.pid, 'fbPostedId');
|
|
370
|
-
if (already)
|
|
403
|
+
if (already) {
|
|
404
|
+
winston.info(`[facebook-post] onPostSave: abandon — déjà publié (fbPostedId=${already})`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const imageUrls = extractImageUrlsFromContent(ctx.post.content || '').filter(isForumHosted);
|
|
409
|
+
winston.info(`[facebook-post] onPostSave: images hébergées sur le forum trouvées: ${imageUrls.length} [${imageUrls.join(', ')}]`);
|
|
371
410
|
|
|
372
411
|
const fbId = await postToFacebook(ctx);
|
|
373
412
|
if (fbId) {
|
|
374
413
|
await Posts.setPostField(ctx.post.pid, 'fbPostedId', fbId);
|
|
375
414
|
await Posts.setPostField(ctx.post.pid, 'fbPostedAt', Date.now());
|
|
415
|
+
winston.info(`[facebook-post] onPostSave: publication réussie — fbId=${fbId} pid=${ctx.post.pid}`);
|
|
416
|
+
} else {
|
|
417
|
+
winston.warn('[facebook-post] onPostSave: postToFacebook a retourné un fbId vide (pas d\'erreur levée)');
|
|
376
418
|
}
|
|
377
419
|
} catch (e) {
|
|
378
420
|
const detail = e?.response ? JSON.stringify(e.response.data) : (e?.message || e);
|
|
379
|
-
winston.error(`[facebook-post]
|
|
421
|
+
winston.error(`[facebook-post] onPostSave: ERREUR: ${detail}`);
|
|
422
|
+
if (e?.response?.config?.url) {
|
|
423
|
+
winston.error(`[facebook-post] onPostSave: URL appelée: ${e.response.config.url} — status: ${e.response.status}`);
|
|
424
|
+
}
|
|
380
425
|
}
|
|
381
426
|
};
|
|
382
427
|
|
package/package.json
CHANGED