nodebb-plugin-facebook-post 1.0.22 → 1.0.24
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 +19 -15
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -167,7 +167,7 @@ function shouldProcessPost(ctx) {
|
|
|
167
167
|
if (!settings.enabled) return false;
|
|
168
168
|
if (!settings.fbPageId || !settings.fbPageAccessToken) return false;
|
|
169
169
|
|
|
170
|
-
const isFirstPost = (ctx.post.isMainPost === true) || (ctx.post.index === 0);
|
|
170
|
+
const isFirstPost = (ctx.post.isMainPost === true) || (ctx.post.index === 0) || (String(ctx.post.pid) === String(ctx.topic.mainPid));
|
|
171
171
|
if (!isFirstPost) return false;
|
|
172
172
|
|
|
173
173
|
if (!bool(ctx.post.fbPostEnabled)) return false;
|
|
@@ -342,13 +342,13 @@ Plugin.onPostCreate = async function (hookData) {
|
|
|
342
342
|
const winston = require.main.require('winston');
|
|
343
343
|
try {
|
|
344
344
|
if (!hookData?.post || !hookData?.data) {
|
|
345
|
-
winston.
|
|
345
|
+
winston.info('[facebook-post] onPostCreate: hookData manquant (post ou data absent)');
|
|
346
346
|
return hookData;
|
|
347
347
|
}
|
|
348
348
|
hookData.post.fbPostEnabled = bool(hookData.data.fbPostEnabled);
|
|
349
349
|
const fbPlaceId = trimStr(hookData.data.fbPlaceId);
|
|
350
350
|
if (fbPlaceId) hookData.post.fbPlaceId = fbPlaceId;
|
|
351
|
-
winston.
|
|
351
|
+
winston.info(`[facebook-post] onPostCreate: pid=${hookData.post.pid} fbPostEnabled=${hookData.post.fbPostEnabled} fbPlaceId=${hookData.post.fbPlaceId || '(none)'}`);
|
|
352
352
|
} catch (e) {
|
|
353
353
|
winston.error(`[facebook-post] onPostCreate erreur: ${e?.message || e}`);
|
|
354
354
|
}
|
|
@@ -357,57 +357,61 @@ Plugin.onPostCreate = async function (hookData) {
|
|
|
357
357
|
|
|
358
358
|
Plugin.onPostSave = async function (hookData) {
|
|
359
359
|
const winston = require.main.require('winston');
|
|
360
|
-
winston.
|
|
360
|
+
winston.info('[facebook-post] onPostSave: hook déclenché');
|
|
361
361
|
try {
|
|
362
362
|
await loadSettings();
|
|
363
|
-
winston.
|
|
363
|
+
winston.info(`[facebook-post] onPostSave: settings.enabled=${settings.enabled} fbPageId=${settings.fbPageId ? 'défini' : 'MANQUANT'} fbPageAccessToken=${settings.fbPageAccessToken ? 'défini' : 'MANQUANT'}`);
|
|
364
364
|
|
|
365
365
|
if (!settings.enabled) {
|
|
366
|
-
winston.
|
|
366
|
+
winston.info('[facebook-post] onPostSave: abandon — plugin désactivé dans les paramètres');
|
|
367
367
|
return;
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
const rawPost = hookData && hookData.post ? hookData.post : hookData;
|
|
371
|
-
winston.
|
|
371
|
+
winston.info(`[facebook-post] onPostSave: données brutes reçues — pid=${rawPost?.pid} fbPostEnabled=${rawPost?.fbPostEnabled}`);
|
|
372
372
|
|
|
373
373
|
const ctx = await getPostContext(rawPost);
|
|
374
374
|
if (!ctx) {
|
|
375
375
|
winston.warn('[facebook-post] onPostSave: abandon — impossible de récupérer le contexte du post (pid invalide ?)');
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
|
|
379
|
+
// Restore ephemeral fields set by onPostCreate (not persisted to DB)
|
|
380
|
+
ctx.post.fbPostEnabled = rawPost.fbPostEnabled;
|
|
381
|
+
if (rawPost.fbPlaceId) ctx.post.fbPlaceId = rawPost.fbPlaceId;
|
|
382
|
+
|
|
383
|
+
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} mainPid=${ctx.topic.mainPid} reputation=${ctx.user.reputation}`);
|
|
379
384
|
|
|
380
385
|
const allowed = await userIsAllowed(ctx.post.uid);
|
|
381
386
|
if (!allowed) {
|
|
382
387
|
const groups = parseAllowedGroupsList();
|
|
383
|
-
winston.
|
|
388
|
+
winston.info(`[facebook-post] onPostSave: abandon — uid=${ctx.post.uid} n'est pas dans les groupes autorisés: [${groups.join(', ')}]`);
|
|
384
389
|
return;
|
|
385
390
|
}
|
|
386
|
-
winston.
|
|
391
|
+
winston.info(`[facebook-post] onPostSave: uid=${ctx.post.uid} autorisé par les groupes`);
|
|
387
392
|
|
|
388
393
|
const process = shouldProcessPost(ctx);
|
|
389
394
|
if (!process) {
|
|
390
|
-
// Log détaillé de la raison du refus
|
|
391
395
|
const isFirstPost = (ctx.post.isMainPost === true) || (ctx.post.index === 0);
|
|
392
396
|
const fbEnabled = bool(ctx.post.fbPostEnabled);
|
|
393
397
|
const repOk = (ctx.user.reputation || 0) >= settings.minimumReputation;
|
|
394
398
|
const whitelist = parseCsvInts(settings.categoriesWhitelist);
|
|
395
399
|
const catOk = whitelist.length === 0 || whitelist.includes(parseInt(ctx.topic.cid, 10));
|
|
396
|
-
winston.
|
|
400
|
+
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}])`);
|
|
397
401
|
return;
|
|
398
402
|
}
|
|
399
|
-
winston.
|
|
403
|
+
winston.info('[facebook-post] onPostSave: shouldProcessPost=true, publication en cours…');
|
|
400
404
|
|
|
401
405
|
const Posts = require.main.require('./src/posts');
|
|
402
406
|
|
|
403
407
|
const already = await Posts.getPostField(ctx.post.pid, 'fbPostedId');
|
|
404
408
|
if (already) {
|
|
405
|
-
winston.
|
|
409
|
+
winston.info(`[facebook-post] onPostSave: abandon — déjà publié (fbPostedId=${already})`);
|
|
406
410
|
return;
|
|
407
411
|
}
|
|
408
412
|
|
|
409
413
|
const imageUrls = extractImageUrlsFromContent(ctx.post.content || '').filter(isForumHosted);
|
|
410
|
-
winston.
|
|
414
|
+
winston.info(`[facebook-post] onPostSave: images hébergées sur le forum trouvées: ${imageUrls.length} [${imageUrls.join(', ')}]`);
|
|
411
415
|
|
|
412
416
|
const fbId = await postToFacebook(ctx);
|
|
413
417
|
if (fbId) {
|
package/package.json
CHANGED