/**
* Timeline item storage operations
* @module storage/items
*/
import { ObjectId } from "mongodb";
import {
buildPaginationQuery,
buildPaginationSort,
generatePagingCursors,
parseLimit,
} from "../utils/pagination.js";
/**
* Extract image URLs from HTML content (fallback for items without explicit photos)
* @param {string} html - HTML content
* @returns {string[]} Array of image URLs
*/
function extractImagesFromHtml(html) {
if (!html) {
return [];
}
const urls = [];
const imgRegex = /
]+src=["']([^"']+)["'][^>]*>/gi;
let match;
while ((match = imgRegex.exec(html)) !== null) {
const src = match[1];
if (src && !urls.includes(src)) {
urls.push(src);
}
}
return urls;
}
/**
* Get items collection from application
* @param {object} application - Indiekit application
* @returns {object} MongoDB collection
*/
function getCollection(application) {
return application.collections.get("microsub_items");
}
/**
* Add an item to a channel
* @param {object} application - Indiekit application
* @param {object} data - Item data
* @param {ObjectId} data.channelId - Channel ObjectId
* @param {ObjectId} data.feedId - Feed ObjectId
* @param {string} data.uid - Unique item identifier
* @param {object} data.item - jf2 item data
* @returns {Promise