Skip to content

Commit f3df3d0

Browse files
authored
Fixbug no file exist check (#12)
* feat: when network is weak, try run toMarkdown() * feat: file exist check * code clear * add console log * add ;
1 parent f938354 commit f3df3d0

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

dist/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -48996,14 +48996,14 @@ const {
4899648996
const {
4899748997
gatherInputs,
4899848998
inputExistCheck,
48999+
fileExistCheck,
4899949000
getRouteAddr,
4900049001
haveRouterAddrmd,
4900149002
HTMLtoMarkdown
4900249003
} = __nccwpck_require__(7677);
4900349004

4900449005
// cd ./news-translation
4900549006
// You can run `node script\toMarkdown\index.js URL<String>`(URL is the URL of the article).
49006-
4900749007
(async function toMarkdown() {
4900849008
try {
4900949009
const input = gatherInputs();
@@ -49019,6 +49019,10 @@ const {
4901949019
const articleFileName = await haveRouterAddrmd(articleChildRouter);
4902049020
const htmlString = await (await nodeFetch(URL, options)).text();
4902149021
const articleText = await HTMLtoMarkdown(htmlString);
49022+
49023+
if (await fileExistCheck(input.markDownFilePath + articleFileName)) {
49024+
return Promise.reject("file has exist");
49025+
}
4902249026

4902349027
await fs.writeFile(
4902449028
input.markDownFilePath + articleFileName,
@@ -49028,8 +49032,8 @@ const {
4902849032
}
4902949033
);
4903049034
} catch (error) {
49031-
console.log('ERR:', error);
49032-
process.exitCode = 1;
49035+
console.log('ERR:', error);
49036+
process.exitCode = 1;
4903349037
}
4903449038
})();
4903549039

@@ -49120,6 +49124,13 @@ exports.inputExistCheck = (input) =>
4912049124
input.newsLink ? resolve(input.newsLink) : reject(Err_DontGetNewsLink);
4912149125
});
4912249126

49127+
49128+
//fileExitCheck in the path.
49129+
exports.fileExistCheck = (path) =>
49130+
new Promise((resolve, reject) => {
49131+
fs.existsSync(path)? resolve(true) : reject(false);
49132+
});
49133+
4912349134
// Check the input parameters, and get the routing address of the article.
4912449135
// - 原文网址:[原文标题](https://www.freecodecamp.org/news/xxxxxxx/
4912549136
exports.getRouteAddr = (URL) =>

src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const {
88
const {
99
gatherInputs,
1010
inputExistCheck,
11+
fileExistCheck,
1112
getRouteAddr,
1213
haveRouterAddrmd,
1314
HTMLtoMarkdown
1415
} = require('./utilities.js');
1516

1617
// cd ./news-translation
1718
// You can run `node script\toMarkdown\index.js URL<String>`(URL is the URL of the article).
18-
1919
(async function toMarkdown() {
2020
try {
2121
const input = gatherInputs();
@@ -31,6 +31,10 @@ const {
3131
const articleFileName = await haveRouterAddrmd(articleChildRouter);
3232
const htmlString = await (await nodeFetch(URL, options)).text();
3333
const articleText = await HTMLtoMarkdown(htmlString);
34+
35+
if (await fileExistCheck(input.markDownFilePath + articleFileName)) {
36+
return Promise.reject("file has exist");
37+
}
3438

3539
await fs.writeFile(
3640
input.markDownFilePath + articleFileName,
@@ -40,7 +44,7 @@ const {
4044
}
4145
);
4246
} catch (error) {
43-
console.log('ERR:', error);
44-
process.exitCode = 1;
47+
console.log('ERR:', error);
48+
process.exitCode = 1;
4549
}
4650
})();

src/utilities.js

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ exports.inputExistCheck = (input) =>
4444
input.newsLink ? resolve(input.newsLink) : reject(Err_DontGetNewsLink);
4545
});
4646

47+
48+
//fileExitCheck in the path.
49+
exports.fileExistCheck = (path) =>
50+
new Promise((resolve, reject) => {
51+
fs.existsSync(path)? resolve(true) : reject(false);
52+
});
53+
4754
// Check the input parameters, and get the routing address of the article.
4855
// - 原文网址:[原文标题](https://www.freecodecamp.org/news/xxxxxxx/
4956
exports.getRouteAddr = (URL) =>

0 commit comments

Comments
 (0)