Skip to content

下载图片报错了 #15

Closed Answered by Chilfish
HayashiKaori asked this question in Q&A
Feb 28, 2024 · 4 comments · 9 replies
Discussion options

You must be logged in to vote

看起来是因为这个图片的链接无法访问导致的,我忘了加这个判断😹

你可以手动修改一下 download.mjs 这个代码中第22行到28行的函数为下面这样。应该就会显示下载失败的原因,而不会直接退出了

async function download_file(url, file_path) {
  const headers = { Referer: referer }
  try {
    const res = await fetch(url, { headers })
    const buffer = await res.arrayBuffer()
    writeFileSync(file_path, Buffer.from(buffer))
  }
  catch (e) {
    console.error(`下载失败:${url},原因:${e.cause || e.message}`)
  }
}

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
9 replies
@HayashiKaori
Comment options

@HayashiKaori
Comment options

@HayashiKaori
Comment options

@Chilfish
Comment options

@HayashiKaori
Comment options

Answer selected by Chilfish
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working
2 participants