Forked from vadimfedenko/analyze-images
src / multiImageArgs.ts
// Only decode an explicitly JSON-encoded list. Never guess separators or paths.
export function parseMultiImageNames(value: unknown): {images: string[]} | {error: string; receivedType: string} {
let decoded = value;
if (typeof value === "string") {
if (value.length > 32768) return {error:"imageNames exceeds the supported argument size.",receivedType:"string"};
try {decoded=JSON.parse(value);} catch {return {error:"imageNames is a string, not a JSON array. Send an actual array of 2–4 exact image paths. Comma/newline-separated names and single-quoted lists are not interpreted.",receivedType:"string"};}
}
const receivedType = decoded === null ? "null" : Array.isArray(decoded) ? "array" : typeof decoded;
if (!Array.isArray(decoded) || decoded.length < 2 || decoded.length > 4 || !decoded.every(item=>typeof item === "string" && item.trim().length > 0)) {
return {error:"imageNames must be a JSON array containing 2–4 nonempty image-path strings. No paths will be added, split or guessed.",receivedType};
}
return {images:decoded};
}