nodebb-plugin-facebook-post 1.0.30 → 1.0.31

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 +19 -2
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -73,16 +73,33 @@ function absolutizeUrl(url) {
73
73
  return `${base}/${url}`;
74
74
  }
75
75
 
76
+ function getApexDomain(hostname) {
77
+ const parts = hostname.split('.');
78
+ return parts.length <= 2 ? hostname : parts.slice(-2).join('.');
79
+ }
80
+
76
81
  function isForumHosted(urlAbs) {
77
82
  const base = getForumBaseUrl();
78
83
  if (!base) return false;
79
84
  try {
80
- return new URL(urlAbs).host === new URL(base).host;
85
+ const imgHost = new URL(urlAbs).host;
86
+ const forumHost = new URL(base).host;
87
+ return imgHost === forumHost || getApexDomain(imgHost) === getApexDomain(forumHost);
81
88
  } catch {
82
89
  return false;
83
90
  }
84
91
  }
85
92
 
93
+ function decodeHtmlEntities(str) {
94
+ return str
95
+ .replace(/&amp;/g, '&')
96
+ .replace(/&lt;/g, '<')
97
+ .replace(/&gt;/g, '>')
98
+ .replace(/&quot;/g, '"')
99
+ .replace(/&#x([0-9a-fA-F]+);/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
100
+ .replace(/&#(\d+);/g, (_, dec) => String.fromCharCode(Number(dec)));
101
+ }
102
+
86
103
  function extractImageUrlsFromContent(rawContent) {
87
104
  const urls = new Set();
88
105
  if (!rawContent) return [];
@@ -212,7 +229,7 @@ async function publishFeedPost({ message, link, photoIds }) {
212
229
 
213
230
  async function postToFacebook(ctx) {
214
231
  const rawContent = ctx.post.content || '';
215
- const topicTitle = ctx.topic.title || 'Nouveau sujet';
232
+ const topicTitle = decodeHtmlEntities(ctx.topic.title || 'Nouveau sujet');
216
233
  const author = ctx.user.username || 'Quelqu\u2019un';
217
234
  const link = ctx.topicUrlAbs;
218
235
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
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": {