Skip to content

Commit

Permalink
feat: 为图片渲染失败添加兜底
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmingming committed Oct 27, 2024
1 parent 78e99e5 commit 650ad60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/command/generate/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,14 @@ class GenerateCustomer extends Base {

let imageBuffer = fs.readFileSync(imgUri)

let size = await imageSize.imageSize(imageBuffer)
let { width, height } = size
let size: { width: number | undefined, height: number | undefined } = { width: 0, height: 0 }
try {
size = await imageSize.imageSize(imageBuffer)
} catch (e) {
this.log(`第${weiboIndex}/${weiboDayRecord.configList.length}条微博, ${imgUri}图片宽高解析失败, 为非法文件, 自动跳过&自动删除图片`)
fs.unlinkSync(imgUri)
}
let { width = 0, height = 0 } = size
if (!width || width <= 0 || !height || height <= 0) {
this.log(`第${weiboIndex}/${weiboDayRecord.configList.length}条微博截图捕获失败, 自动跳过`)
continue
Expand Down

0 comments on commit 650ad60

Please sign in to comment.