nodebb-plugin-link-preview 2.1.0 → 2.1.2

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 CHANGED
@@ -130,7 +130,8 @@ async function process(content, { type, pid, tid, attachments }) {
130
130
  // Post attachments
131
131
  if (pid && Array.isArray(attachments) && attachments.length) {
132
132
  const attachmentData = await posts.attachments.getAttachments(attachments);
133
- await Promise.all(attachmentData.filter(Boolean).map(async ({ url, _type }) => {
133
+ await Promise.all(attachmentData.filter(Boolean).map(async (attachment) => {
134
+ const { url, _type } = attachment;
134
135
  const isInlineImage = new RegExp(`<img.+?src="${url}".+?>`).test(content);
135
136
  if (isInlineImage) {
136
137
  return;
@@ -142,6 +143,29 @@ async function process(content, { type, pid, tid, attachments }) {
142
143
  return;
143
144
  }
144
145
 
146
+ // ActivityPub attachments
147
+ if (attachment.hasOwnProperty('mediaType')) {
148
+ switch (true) {
149
+ case attachment.mediaType.startsWith('video/'): {
150
+ cache.set(`link-preview:${url}`, {
151
+ ...attachment,
152
+ contentType: attachment.mediaType,
153
+ mediaType: 'video',
154
+ });
155
+ break;
156
+ }
157
+
158
+ case attachment.mediaType.startsWith('image/'): {
159
+ cache.set(`link-preview:${url}`, {
160
+ ...attachment,
161
+ contentType: attachment.mediaType,
162
+ mediaType: 'image',
163
+ });
164
+ break;
165
+ }
166
+ }
167
+ }
168
+
145
169
  const type = _type || 'attachment';
146
170
  requests.set(url, { type });
147
171
  }));
@@ -237,8 +261,8 @@ async function process(content, { type, pid, tid, attachments }) {
237
261
  }
238
262
 
239
263
  content = $.html();
240
- content += attachmentHtml ? `\n\n<div class="row"><div class="col-12">${attachmentHtml}</div></div>` : '';
241
- content += placeholderHtml ? `\n\n<div class="row"><div class="col-12">${placeholderHtml}</div></div>` : '';
264
+ content += attachmentHtml ? `\n\n<div class="row"><div class="col-12 mt-3">${attachmentHtml}</div></div>` : '';
265
+ content += placeholderHtml ? `\n\n<div class="row"><div class="col-12 mt-3">${placeholderHtml}</div></div>` : '';
242
266
  return content;
243
267
  }
244
268
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nodebb-plugin-link-preview",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "nodebb-plugin-link-preview",
9
- "version": "2.1.0",
9
+ "version": "2.1.2",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "cheerio": "^1.0.0-rc.12",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-link-preview",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A starter kit for quickly creating NodeBB plugins",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  <div class="ratio ratio-16x9">
2
- <video controls>
2
+ <video controls {{{ if width }}}width="{width}"{{{ end }}} {{{ if height }}}height="{height}"{{{ end }}}>
3
3
  <source src="{url}" type="{contentType}">
4
4
  </video>
5
5
  </div>