Skip to content

Commit 444c2e2

Browse files
committed
URL regex error fix
1 parent c33ef91 commit 444c2e2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crawler/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Crawler {
7171
try {
7272
response = await axios.post(this.__grahpqlURL, PostQuery(this.username, url_slug));
7373
} catch (e) {
74-
console.error(`⚠️ 벨로그에서 글을 가져오는데 실패했습니다. \n error = ${e}`);
74+
console.error(`⚠️ 벨로그에서 글을 가져오는데 실패했습니다. \n error = ${e} url = ${url_slug}`);
7575
process.exit(1);
7676
}
7777

@@ -92,12 +92,14 @@ class Crawler {
9292
}
9393

9494
async getImage(body) {
95-
const regex = /!\[[^\]]*\]\((?<filename>.*?)(?=\"|\))(?<optionalpart>\".*\")?\)/g;
96-
95+
const regex = /!\[[^\]]*\]\((.*?.png|.jpeg|.jpg|.webp|.svg|.gif|.tiff)\s*("(?:.*[^"])")?\s*\)|!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g;
96+
9797
body = body.replace(regex, (_, url) => {
98+
if (!url) return;
99+
98100
const filename = url.replace(/\/\s*$/,'').split('/').slice(-2).join('-').trim();
99101
const path = join('backup', 'images', decodeURI(filename));
100-
102+
101103
axios({
102104
method: 'get',
103105
url: encodeURI(decodeURI(url)),
@@ -111,6 +113,7 @@ class Crawler {
111113

112114
return body;
113115
}
116+
114117
};
115118

116119
module.exports = Crawler;

0 commit comments

Comments
 (0)