Skip to content

Commit

Permalink
fix: 图片上传问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fish.yu committed Apr 17, 2024
1 parent 607f55b commit 78e01e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ class Downloader {
// 上传图片到github
const content = await downloadImage(cover);
const imageName = crypto.randomUUID() + '.' + cover.split('.').pop();
const imageUrl = `${repo_name}/_images/${imageName}`;
console.log(`download image: ${imageUrl}`);
const imageUrl = `/_images/${imageName}`;
await gh.writeFile(imageUrl, content)
mdBody = `![${title}](https://github.com${imageUrl})`
}
Expand Down
7 changes: 3 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ exports.formatDate = (date) => {

exports.downloadImage = (src) => {
return new Promise((resolve, reject) => {
axios.get(src).then((res) => {
resolve(res.data)
// const base64 = Buffer.from(res.data, 'binary').toString('base64');
// resolve(`data:image/png;base64,${base64}`)
axios.get(src, { responseType: 'arraybuffer' }).then((res) => {
const base64 = Buffer.from(res.data, 'binary').toString('base64');
resolve(`data:image/png;base64,${base64}`)
}).catch((err) => {
reject(err);
})
Expand Down

0 comments on commit 78e01e1

Please sign in to comment.