AI Newsletter Digest improvements: fixed QP soft line break decoding, URL extraction, and content cleaning

This commit is contained in:
Krilly
2026-03-04 13:29:22 +00:00
parent 29a98137a7
commit 57dd294675
13706 changed files with 2114953 additions and 237629 deletions

View File

@@ -0,0 +1,36 @@
const { computeAssetId, SCHEMA_VERSION } = require('./contentHash');
/**
* Format asset preview for prompt inclusion.
* Handles stringified JSON, arrays, and error cases gracefully.
*/
function formatAssetPreview(preview) {
if (!preview) return '(none)';
if (typeof preview === 'string') {
try {
const parsed = JSON.parse(preview);
if (Array.isArray(parsed) && parsed.length > 0) {
return JSON.stringify(parsed, null, 2);
}
return preview; // Keep as string if not array or empty
} catch (e) {
return preview; // Keep as string if parse fails
}
}
return JSON.stringify(preview, null, 2);
}
/**
* Validate and normalize an asset object.
* Ensures schema version and ID are present.
*/
function normalizeAsset(asset) {
if (!asset || typeof asset !== 'object') return asset;
if (!asset.schema_version) asset.schema_version = SCHEMA_VERSION;
if (!asset.asset_id) {
try { asset.asset_id = computeAssetId(asset); } catch (e) {}
}
return asset;
}
module.exports = { formatAssetPreview, normalizeAsset };