nodebb-plugin-facebook-post 1.0.21 → 1.0.22
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 +57 -11
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -339,44 +339,90 @@ 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.verbose('[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.verbose(`[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.verbose('[facebook-post] onPostSave: hook déclenché');
|
|
355
361
|
try {
|
|
356
362
|
await loadSettings();
|
|
357
|
-
|
|
363
|
+
winston.verbose(`[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.verbose('[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.verbose(`[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.verbose(`[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.verbose(`[facebook-post] onPostSave: abandon — uid=${ctx.post.uid} n'est pas dans les groupes autorisés: [${groups.join(', ')}]`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
winston.verbose(`[facebook-post] onPostSave: uid=${ctx.post.uid} autorisé par les groupes`);
|
|
387
|
+
|
|
388
|
+
const process = shouldProcessPost(ctx);
|
|
389
|
+
if (!process) {
|
|
390
|
+
// Log détaillé de la raison du refus
|
|
391
|
+
const isFirstPost = (ctx.post.isMainPost === true) || (ctx.post.index === 0);
|
|
392
|
+
const fbEnabled = bool(ctx.post.fbPostEnabled);
|
|
393
|
+
const repOk = (ctx.user.reputation || 0) >= settings.minimumReputation;
|
|
394
|
+
const whitelist = parseCsvInts(settings.categoriesWhitelist);
|
|
395
|
+
const catOk = whitelist.length === 0 || whitelist.includes(parseInt(ctx.topic.cid, 10));
|
|
396
|
+
winston.verbose(`[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
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
winston.verbose('[facebook-post] onPostSave: shouldProcessPost=true, publication en cours…');
|
|
366
400
|
|
|
367
401
|
const Posts = require.main.require('./src/posts');
|
|
368
402
|
|
|
369
403
|
const already = await Posts.getPostField(ctx.post.pid, 'fbPostedId');
|
|
370
|
-
if (already)
|
|
404
|
+
if (already) {
|
|
405
|
+
winston.verbose(`[facebook-post] onPostSave: abandon — déjà publié (fbPostedId=${already})`);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const imageUrls = extractImageUrlsFromContent(ctx.post.content || '').filter(isForumHosted);
|
|
410
|
+
winston.verbose(`[facebook-post] onPostSave: images hébergées sur le forum trouvées: ${imageUrls.length} [${imageUrls.join(', ')}]`);
|
|
371
411
|
|
|
372
412
|
const fbId = await postToFacebook(ctx);
|
|
373
413
|
if (fbId) {
|
|
374
414
|
await Posts.setPostField(ctx.post.pid, 'fbPostedId', fbId);
|
|
375
415
|
await Posts.setPostField(ctx.post.pid, 'fbPostedAt', Date.now());
|
|
416
|
+
winston.info(`[facebook-post] onPostSave: publication réussie — fbId=${fbId} pid=${ctx.post.pid}`);
|
|
417
|
+
} else {
|
|
418
|
+
winston.warn('[facebook-post] onPostSave: postToFacebook a retourné un fbId vide (pas d\'erreur levée)');
|
|
376
419
|
}
|
|
377
420
|
} catch (e) {
|
|
378
421
|
const detail = e?.response ? JSON.stringify(e.response.data) : (e?.message || e);
|
|
379
|
-
winston.error(`[facebook-post]
|
|
422
|
+
winston.error(`[facebook-post] onPostSave: ERREUR: ${detail}`);
|
|
423
|
+
if (e?.response?.config?.url) {
|
|
424
|
+
winston.error(`[facebook-post] onPostSave: URL appelée: ${e.response.config.url} — status: ${e.response.status}`);
|
|
425
|
+
}
|
|
380
426
|
}
|
|
381
427
|
};
|
|
382
428
|
|
package/package.json
CHANGED