Herby Vojčík 4 years ago
parent
commit
be04249228
1 changed files with 5 additions and 3 deletions
  1. 5 3
      index.js

+ 5 - 3
index.js

@@ -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);