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

文件名比对不通过导致的Time Out超时问题 #17

Open
whoami-xu opened this issue Apr 25, 2024 · 0 comments
Open

文件名比对不通过导致的Time Out超时问题 #17

whoami-xu opened this issue Apr 25, 2024 · 0 comments

Comments

@whoami-xu
Copy link

whoami-xu commented Apr 25, 2024

文件名比对不通过导致的Time Out问题

语雀导出Markdown时以文章名作为文件名,但不可避免有文章名中出现了特殊字符而不能作为文件名的情况,因此语雀会使用下划线‘_’替代特殊字符。然而在该项目export.js源文件waitForDownload函数里,参数mdname是将特殊字符用空格替代了的文件名字符串,参数filename是下载时语雀使用下划线替代的字符串,因此filename和mdname的比较不通过。最终,waitForDownload函数则因为文件名不一致找不到想要的文件,三次重试以后导致Time Out。

一个简单的解决方式是将文件名中的符号字符都过滤掉,只保留中英文字符和数字,这样比较不容易出错。(你说:“我就喜欢拿标点符号做文件名咋办?” 那这方法不行,我没辙了,自己摸索语雀文件名替换规则一个个换吧)

打过补丁的代码waitForDownload函数代码如下:

async function waitForDownload(rootPath, book, mdname, started = false) {
    const timeout = 10000; // 10s timeout
    let filteredMdname = mdname.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g, "");
    return new Promise((resolve, reject) => {
        // console.log(`======> watch ${rootPath} ${mdname}.md`)
        const watcher = fs.watch(rootPath, (eventType, filename) => {
            // console.log(`watch ${rootPath} ${eventType} ${filename}, want ${mdname}.md, filtered ${filteredMdname}`)
            // if (eventType === 'rename' && filename === `${mdname}.md.crdownload` && !started) {
            //     console.log("Downloading document " + book + "/" + mdname)
            //     started = true
            // }
            if (eventType === 'rename' && filename.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g, "") === `${filteredMdname}mdcrdownload` && !started) {
                console.log("Downloading document " + book + "/" + mdname)
                started = true
            }

            if (eventType === 'rename' && filename.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g, "") === `${filteredMdname}md` && started) {
                watcher.close();
                resolve(filename);
            }
        });

        setTimeout(() => {
            watcher.close();
            reject(new Error('Download timed out'));
        }, timeout);
    });
}

不能下载表格类笔记导致的Time Out问题

有些笔记是表格的形式,而导出的方式只能是Excel。downloadFile函数的url链接是无效的。


最后建议可以在downloadFile函数里记录下载失败的文件,并在exportMarkDownFiles函数最后打印出来。这样可以照着失败列表手动下载文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant