|
@@ -14,13 +14,15 @@ async function work () {
|
|
|
const saves = [];
|
|
|
for (let {name, description, url} of resources) {
|
|
|
const [, issue, year] = name.match(/(\d+)\/(\d+)/);
|
|
|
- if (await access(`${year}.${issue}.xml`).then(() => true, () => false))
|
|
|
+ const target = `${year}.${issue}.xml`;
|
|
|
+ if (await access(target).then(() => true, () => false))
|
|
|
continue;
|
|
|
console.info(`File ${year} / ${issue}: ${description}`);
|
|
|
const xmlRaw = await fetch(url);
|
|
|
saves.push((async () => {
|
|
|
- await xmlRaw.body.pipe(createWriteStream(`${year}.${issue}.xml.download`));
|
|
|
- await rename(`${year}.${issue}.xml.download`, `${year}.${issue}.xml`);
|
|
|
+ const temporary = `${year}.${issue}.xml.download`;
|
|
|
+ await xmlRaw.body.pipe(createWriteStream(temporary));
|
|
|
+ await rename(temporary, target);
|
|
|
})());
|
|
|
}
|
|
|
await Promise.all(saves);
|