@rmdes/indiekit-endpoint-microsub 1.0.35 → 1.0.36
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/lib/storage/items.js +29 -0
- package/package.json +1 -1
package/lib/storage/items.js
CHANGED
|
@@ -12,6 +12,27 @@ import {
|
|
|
12
12
|
parseLimit,
|
|
13
13
|
} from "../utils/pagination.js";
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Extract image URLs from HTML content (fallback for items without explicit photos)
|
|
17
|
+
* @param {string} html - HTML content
|
|
18
|
+
* @returns {string[]} Array of image URLs
|
|
19
|
+
*/
|
|
20
|
+
function extractImagesFromHtml(html) {
|
|
21
|
+
if (!html) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const urls = [];
|
|
25
|
+
const imgRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
|
26
|
+
let match;
|
|
27
|
+
while ((match = imgRegex.exec(html)) !== null) {
|
|
28
|
+
const src = match[1];
|
|
29
|
+
if (src && !urls.includes(src)) {
|
|
30
|
+
urls.push(src);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return urls;
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
* Get items collection from application
|
|
17
38
|
* @param {object} application - Indiekit application
|
|
@@ -201,6 +222,14 @@ function transformToJf2(item, userId) {
|
|
|
201
222
|
const videos = normalizeMediaArray(item.video);
|
|
202
223
|
const audios = normalizeMediaArray(item.audio);
|
|
203
224
|
|
|
225
|
+
// Fallback: extract images from HTML content if no explicit photos
|
|
226
|
+
if (photos.length === 0 && item.content?.html) {
|
|
227
|
+
const extracted = extractImagesFromHtml(item.content.html);
|
|
228
|
+
if (extracted.length > 0) {
|
|
229
|
+
photos.push(...extracted);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
204
233
|
if (photos.length > 0) jf2.photo = photos;
|
|
205
234
|
if (videos.length > 0) jf2.video = videos;
|
|
206
235
|
if (audios.length > 0) jf2.audio = audios;
|
package/package.json
CHANGED