diff --git a/dist/index.js b/dist/index.js index 9af268d..1cc7951 100644 --- a/dist/index.js +++ b/dist/index.js @@ -48996,6 +48996,7 @@ const { const { gatherInputs, inputExistCheck, + fileExistCheck, getRouteAddr, haveRouterAddrmd, HTMLtoMarkdown @@ -49003,7 +49004,6 @@ const { // cd ./news-translation // You can run `node script\toMarkdown\index.js URL`(URL is the URL of the article). - (async function toMarkdown() { try { const input = gatherInputs(); @@ -49019,6 +49019,10 @@ const { const articleFileName = await haveRouterAddrmd(articleChildRouter); const htmlString = await (await nodeFetch(URL, options)).text(); const articleText = await HTMLtoMarkdown(htmlString); + + if (await fileExistCheck(input.markDownFilePath + articleFileName)) { + return Promise.reject("file has exist"); + } await fs.writeFile( input.markDownFilePath + articleFileName, @@ -49028,8 +49032,8 @@ const { } ); } catch (error) { - console.log('ERR:', error); - process.exitCode = 1; + console.log('ERR:', error); + process.exitCode = 1; } })(); @@ -49120,6 +49124,13 @@ exports.inputExistCheck = (input) => input.newsLink ? resolve(input.newsLink) : reject(Err_DontGetNewsLink); }); + +//fileExitCheck in the path. +exports.fileExistCheck = (path) => + new Promise((resolve, reject) => { + fs.existsSync(path)? resolve(true) : reject(false); + }); + // Check the input parameters, and get the routing address of the article. // - 原文网址:[原文标题](https://www.freecodecamp.org/news/xxxxxxx/ exports.getRouteAddr = (URL) => diff --git a/src/index.js b/src/index.js index 4aa70d2..f22b518 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ const { const { gatherInputs, inputExistCheck, + fileExistCheck, getRouteAddr, haveRouterAddrmd, HTMLtoMarkdown @@ -15,7 +16,6 @@ const { // cd ./news-translation // You can run `node script\toMarkdown\index.js URL`(URL is the URL of the article). - (async function toMarkdown() { try { const input = gatherInputs(); @@ -31,6 +31,10 @@ const { const articleFileName = await haveRouterAddrmd(articleChildRouter); const htmlString = await (await nodeFetch(URL, options)).text(); const articleText = await HTMLtoMarkdown(htmlString); + + if (await fileExistCheck(input.markDownFilePath + articleFileName)) { + return Promise.reject("file has exist"); + } await fs.writeFile( input.markDownFilePath + articleFileName, @@ -40,7 +44,7 @@ const { } ); } catch (error) { - console.log('ERR:', error); - process.exitCode = 1; + console.log('ERR:', error); + process.exitCode = 1; } })(); diff --git a/src/utilities.js b/src/utilities.js index 30a71ca..eaefb73 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -44,6 +44,13 @@ exports.inputExistCheck = (input) => input.newsLink ? resolve(input.newsLink) : reject(Err_DontGetNewsLink); }); + +//fileExitCheck in the path. +exports.fileExistCheck = (path) => + new Promise((resolve, reject) => { + fs.existsSync(path)? resolve(true) : reject(false); + }); + // Check the input parameters, and get the routing address of the article. // - 原文网址:[原文标题](https://www.freecodecamp.org/news/xxxxxxx/ exports.getRouteAddr = (URL) =>