nodebb-plugin-link-preview 2.0.4 → 2.0.5
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 +8 -12
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -14,9 +14,7 @@ const { isURL } = require('validator');
|
|
|
14
14
|
const meta = require.main.require('./src/meta');
|
|
15
15
|
const cache = require.main.require('./src/cache');
|
|
16
16
|
const posts = require.main.require('./src/posts');
|
|
17
|
-
const topics = require.main.require('./src/topics');
|
|
18
17
|
const websockets = require.main.require('./src/socket.io');
|
|
19
|
-
const postsCache = require.main.require('./src/posts/cache');
|
|
20
18
|
|
|
21
19
|
const controllers = require('./lib/controllers');
|
|
22
20
|
|
|
@@ -82,7 +80,7 @@ async function preview(url) {
|
|
|
82
80
|
});
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
async function process(content, { type, pid, tid }) {
|
|
83
|
+
async function process(content, { type, pid, tid, attachments }) {
|
|
86
84
|
const inlineTypes = ['default', 'activitypub.article'];
|
|
87
85
|
const processInline = inlineTypes.includes(type);
|
|
88
86
|
const { embedHtml, embedImage, embedAudio, embedVideo } = await meta.settings.get('link-preview');
|
|
@@ -91,11 +89,9 @@ async function process(content, { type, pid, tid }) {
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
const requests = new Map();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const attachments = await posts.attachments.get(pid);
|
|
98
|
-
attachments.forEach(({ url, _type }) => {
|
|
92
|
+
if (pid && Array.isArray(attachments) && attachments.length) {
|
|
93
|
+
const attachmentData = await posts.attachments.getAttachments(attachments);
|
|
94
|
+
attachmentData.filter(Boolean).forEach(({ url, _type }) => {
|
|
99
95
|
const type = _type || 'attachment';
|
|
100
96
|
requests.set(url, { type });
|
|
101
97
|
});
|
|
@@ -199,11 +195,11 @@ async function process(content, { type, pid, tid }) {
|
|
|
199
195
|
content += attachmentHtml ? `\n\n<div class="row">${attachmentHtml}</div>` : '';
|
|
200
196
|
|
|
201
197
|
// bust posts cache item
|
|
202
|
-
if (pid
|
|
198
|
+
if (pid) {
|
|
203
199
|
posts.clearCachedPost(pid);
|
|
204
200
|
|
|
205
201
|
// fire post edit event with mocked data
|
|
206
|
-
if (tid
|
|
202
|
+
if (tid) {
|
|
207
203
|
websockets.in(`topic_${tid}`).emit('event:post_edited', {
|
|
208
204
|
post: {
|
|
209
205
|
tid,
|
|
@@ -300,9 +296,9 @@ plugin.onParse = async (payload) => {
|
|
|
300
296
|
const type = 'default';
|
|
301
297
|
payload = await process(payload, { type });
|
|
302
298
|
} else if (payload && payload.postData && payload.postData.content) { // post
|
|
303
|
-
const { content, pid, tid } = payload.postData;
|
|
299
|
+
const { content, pid, tid, attachments } = payload.postData;
|
|
304
300
|
const { type } = payload;
|
|
305
|
-
payload.postData.content = await process(content, { type, pid, tid });
|
|
301
|
+
payload.postData.content = await process(content, { type, pid, tid, attachments });
|
|
306
302
|
}
|
|
307
303
|
|
|
308
304
|
return payload;
|