Adding images to scraping data (#157)

* Fredy now supports pulling the main Image from the listing and send it together with the usual information
This commit is contained in:
Christian Kellner
2025-08-30 21:21:34 +02:00
committed by GitHub
parent da743c8279
commit f0b146fd7f
26 changed files with 1141 additions and 1135 deletions

View File

@@ -68,9 +68,29 @@ export async function refreshConfig() {
console.error('Error reading config file', error);
}
}
const RE_GT = />/g;
const RE_WEBP = /\/format\/webp/gi;
const RE_EXT = /\.(jpe?g|png|gif)(\?.*)?$/i;
const HTTPS_PREFIX = 'https://';
const normalizeImageUrl = (url) => {
if (typeof url !== 'string' || url.length === 0) return null;
let u = url.trim().replace(RE_GT, '');
if (RE_WEBP.test(u)) u = u.replace(RE_WEBP, '/format/jpg');
if (!u.startsWith(HTTPS_PREFIX)) return null;
if (!RE_EXT.test(u)) {
const jpgIdx = u.toLowerCase().lastIndexOf('.jpg');
if (jpgIdx > -1) u = u.slice(0, jpgIdx + 4);
}
return u;
};
await refreshConfig();
export { isOneOf };
export { normalizeImageUrl };
export { inDevMode };
export { nullOrEmpty };
export { duringWorkingHoursOrNotSet };