From 8d0568bd04b9257678f678c91ea0843c1450f46c Mon Sep 17 00:00:00 2001 From: "fish.yu" Date: Thu, 18 Apr 2024 12:04:35 +0800 Subject: [PATCH] fix: upload image failed --- lib/download.js | 7 +++++-- lib/github.js | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/download.js b/lib/download.js index 3310a29..4f9c026 100644 --- a/lib/download.js +++ b/lib/download.js @@ -140,7 +140,7 @@ class Downloader { const src = match.match(/\((.*?)\)/)[1]; console.log('image src:', src, '\n'); const imageUrl = await this.uploadImageFromUrl(cover); - body = body.replace(src, imageUrl); + mdBody = mdBody.replace(src, imageUrl); }) } // 处理脑图 @@ -165,7 +165,10 @@ class Downloader { const imageUrl = `_images/${imageName}`; // 上传到github const result = await this.gh.writeFile(imageUrl, content, { encode: false }); - console.log('uploadImageFromUrl success:', result); + console.log('uploadImageFromUrl result:', result); + if (!result.status) { + throw new Error('upload image failed:', result); + } return `https://github.com/${imageUrl}`; } diff --git a/lib/github.js b/lib/github.js index 9299d0e..2f31ada 100644 --- a/lib/github.js +++ b/lib/github.js @@ -5,9 +5,6 @@ function handler(res) { if (result) { result.status = false; result.code = res.status; - console.error(result) - } else { - console.error(res) } return result; @@ -27,6 +24,7 @@ class GitHubClient extends GitHub { const { data } = await this.repo.getContents('master', filename, true) res = { status: true, data } } catch (error) { + console.error('getContent error:', error); res = handler(error.response) } return res; @@ -38,6 +36,7 @@ class GitHubClient extends GitHub { const { data } = await this.repo.writeFile('master', name, content, `update file ${name}`, options) res = { status: true, data } } catch (error) { + console.error('writeFile error:', error); res = handler(error.response || { message: error.message }) } return res;