arreglar sistema de varios tipos de target

This commit is contained in:
Cat /dev/Nulo 2023-12-09 17:10:10 -03:00
parent bbfec73b48
commit 37756fbf3c

View file

@ -30,19 +30,19 @@ let urls = process.argv.slice(2);
if (urls.length < 1) { if (urls.length < 1) {
urls = targetsPorDefecto; urls = targetsPorDefecto;
} }
/** @typedef {{type: "data.json" | "ckan"; url: string;}} Target */ /** @typedef {{type: "datajson" | "ckan"; url: string;}} Target */
/** @type {Target[]} */ /** @type {Target[]} */
const targets = urls.map((url) => { const targets = urls.map((url) => {
if (url.startsWith("datajson+")) { if (url.startsWith("datajson+")) {
return { type: "data.json", url: url.slice("datajson+".length) }; return { type: "datajson", url: url.slice("datajson+".length) };
} else if (url.startsWith("ckan+")) { } else if (url.startsWith("ckan+")) {
return { type: "ckan", url: url.slice("ckan+".length) }; return { type: "ckan", url: url.slice("ckan+".length) };
} else return { type: "data.json", url }; } else return { type: "datajson", url };
}); });
for (const target of targets) for (const target of targets)
downloadFromData(target).catch((error) => downloadFromData(target).catch((error) =>
console.error(`${target} FALLÓ CON`, error) console.error(`${target.type}+${target.url} FALLÓ CON`, error)
); );
/** /**
@ -53,7 +53,7 @@ async function downloadFromData(target) {
let json; let json;
if (target.type === "ckan") { if (target.type === "ckan") {
json = await generateDataJsonFromCkan(target.url); json = await generateDataJsonFromCkan(target.url);
} else if (target.type === "data.json") { } else if (target.type === "datajson") {
const jsonRes = await fetch(target.url); const jsonRes = await fetch(target.url);
json = await jsonRes.json(); json = await jsonRes.json();
} }