Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixbug no file exist check #12

Merged

Conversation

luojiyin1987
Copy link
Collaborator

@luojiyin1987 luojiyin1987 commented May 6, 2022

Checklist(清单):

  • I have read freeCodeCamp's contribution guidelines(我已经阅读 freeCodeCamp 贡献指南).
  • My pull request has a descriptive title (not a vague title like Update index.md)(我的 pull request 有一个详细的标题,而不是像“添加 index.md 文件这样的粗略标题”。)
  • My pull request targets the main branch of this repo.(我的 pull rewuest 基于本仓库 main 分支修改。)

Closes #11

@luojiyin1987
Copy link
Collaborator Author

@stevending1st
在文件 utilies.js 文件中 haveRouterAddrmd 函数可以检查文件是否存在, 但 Path_ArticleFolder_R 变量 未初始化,给具体的值。 所以我写个 fileExistCheck 函数

@stevending1st stevending1st merged commit f3df3d0 into freeCodeCamp-China:main May 8, 2022
@luojiyin1987
Copy link
Collaborator Author

luojiyin1987 commented May 12, 2022

fileExistCheck 返回的 false 将被 try catch 先捕捉到,直接先运行错误处理逻辑, 退出爬虫,造成爬虫失败。

逻辑将改为 这是不是新增爬虫(没文件是新增爬虫, 有文件则不是)。 #15

从原来的回调 ,变成这种 await promise相关结合,还是不太习惯。

@@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async 函数里可以用同步的思维写

throw new Error('file has exist');

Comment on lines +49 to +52
exports.fileExistCheck = (path) =>
new Promise((resolve, reject) => {
fs.existsSync(path)? resolve(true) : reject(false);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要什么东西都封装成 Promise 异步的……

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我只是看到里面代码大部分是这样的, 就想保持语法风格的统一。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我只是看到里面代码大部分是这样的, 就想保持语法风格的统一。

不能形式大于内容,过多异步也拖性能。

@TechQuery TechQuery added the bug Something isn't working label May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在执行爬虫前,因为没检查文件是否存在, 导致原文件被覆盖
3 participants