Skip to content

Commit

Permalink
fix: upload image failed
Browse files Browse the repository at this point in the history
  • Loading branch information
fish.yu committed Apr 18, 2024
1 parent 30c5585 commit 8d0568b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
}
// 处理脑图
Expand All @@ -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}`;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8d0568b

Please sign in to comment.