nodebb-plugin-facebook-post 1.0.35 → 1.0.37

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.
Files changed (2) hide show
  1. package/library.js +16 -1
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -303,10 +303,25 @@ async function postToInstagram(ctx) {
303
303
  }
304
304
  if (!childIds.length) return null;
305
305
 
306
+ // Instagram requires at least 2 children for a carousel; fall back to single image
307
+ if (childIds.length < 2) {
308
+ const singleResp = await axios.post(`${baseUrl}/media`, null, {
309
+ params: { image_url: imageUrls[0], caption, access_token: settings.fbPageAccessToken },
310
+ timeout: 20000,
311
+ });
312
+ const singleId = singleResp.data && singleResp.data.id;
313
+ if (!singleId) return null;
314
+ const pubResp = await axios.post(`${baseUrl}/media_publish`, null, {
315
+ params: { creation_id: singleId, access_token: settings.fbPageAccessToken },
316
+ timeout: 20000,
317
+ });
318
+ return pubResp.data && pubResp.data.id;
319
+ }
320
+
306
321
  const form = new URLSearchParams();
307
322
  form.append('media_type', 'CAROUSEL');
308
323
  form.append('caption', caption);
309
- childIds.forEach(id => form.append('children', id));
324
+ form.append('children', childIds.join(','));
310
325
  form.append('access_token', settings.fbPageAccessToken);
311
326
 
312
327
  const carouselResp = await axios.post(`${baseUrl}/media`, form, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
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": {