nodebb-plugin-link-preview 2.1.4 → 2.1.6
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 +12 -3
- package/package-lock.json +4889 -0
- package/package.json +1 -1
- package/static/templates/partials/link-preview/html.tpl +1 -1
package/library.js
CHANGED
|
@@ -209,6 +209,7 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
209
209
|
// Start preview for cache misses, but continue for now so as to not block response
|
|
210
210
|
if (cold.size) {
|
|
211
211
|
const coldArr = Array.from(cold);
|
|
212
|
+
const failures = new Set();
|
|
212
213
|
Promise.all(coldArr.map(preview)).then(async (previews) => {
|
|
213
214
|
await Promise.all(previews.map(async (preview, idx) => {
|
|
214
215
|
if (!preview) {
|
|
@@ -236,11 +237,19 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
236
237
|
break;
|
|
237
238
|
}
|
|
238
239
|
}
|
|
240
|
+
} else if (options.type === 'attachment') {
|
|
241
|
+
// Preview failed, put back in placeholders
|
|
242
|
+
failures.add(url);
|
|
239
243
|
}
|
|
240
244
|
}));
|
|
241
245
|
|
|
246
|
+
const placeholderHtml = Array.from(failures).reduce((html, cur) => {
|
|
247
|
+
html += `<p><a href="${cur}" rel="nofollow ugc">${cur}</a></p>`;
|
|
248
|
+
return html;
|
|
249
|
+
}, '');
|
|
242
250
|
let content = $.html();
|
|
243
|
-
content += attachmentHtml ? `\n\n<div class="row">${attachmentHtml}</div>` : '';
|
|
251
|
+
content += attachmentHtml ? `\n\n<div class="row mt-3">${attachmentHtml}</div>` : '';
|
|
252
|
+
content += placeholderHtml ? `\n\n<div class="row mt-3"><div class="col-12 mt-3">${placeholderHtml}</div></div>` : '';
|
|
244
253
|
|
|
245
254
|
// bust posts cache item
|
|
246
255
|
if (pid) {
|
|
@@ -265,8 +274,8 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
content = $.html();
|
|
268
|
-
content += attachmentHtml ? `\n\n<div class="row"><div class="col-12 mt-3">${attachmentHtml}</div></div>` : '';
|
|
269
|
-
content += placeholderHtml ? `\n\n<div class="row"><div class="col-12 mt-3">${placeholderHtml}</div></div>` : '';
|
|
277
|
+
content += attachmentHtml ? `\n\n<div class="row mt-3"><div class="col-12 mt-3">${attachmentHtml}</div></div>` : '';
|
|
278
|
+
content += placeholderHtml ? `\n\n<div class="row mt-3"><div class="col-12 mt-3">${placeholderHtml}</div></div>` : '';
|
|
270
279
|
return content;
|
|
271
280
|
}
|
|
272
281
|
|