refactor: 更新 downloadImageToLocal 函数,使用 UUID 生成临时文件名以避免文件名冲突
This commit is contained in:
parent
b9dabbfcb4
commit
d6d02ae681
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
"git.lxtend.com/qqbot/util"
|
"git.lxtend.com/qqbot/util"
|
||||||
"github.com/fogleman/gg"
|
"github.com/fogleman/gg"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/nfnt/resize"
|
"github.com/nfnt/resize"
|
||||||
"golang.org/x/image/font/opentype"
|
"golang.org/x/image/font/opentype"
|
||||||
)
|
)
|
||||||
@ -455,7 +456,9 @@ func downloadImageToLocal(url string) (string, error) {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// 生成临时文件
|
// 生成临时文件
|
||||||
tmpFile, err := os.CreateTemp("", "avatar_*.jpg")
|
// tmpFile, err := os.CreateTemp("", "avatar_*.jpg")
|
||||||
|
uuid := uuid.New().String()
|
||||||
|
tmpFile, err := os.Create(util.GenTempFilePath(uuid + ".jpg"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -694,7 +697,7 @@ func GenBs50(ssID string, outputPath string) error {
|
|||||||
B50Songs: songs,
|
B50Songs: songs,
|
||||||
Country: ssUser.Country,
|
Country: ssUser.Country,
|
||||||
}
|
}
|
||||||
if err = generateB50Image(player, outputPath, "/resources/font.ttf"); err != nil {
|
if err = generateB50Image(player, outputPath, "/resource/font.ttf"); err != nil {
|
||||||
return fmt.Errorf("生成 B50 图片失败: %v", err)
|
return fmt.Errorf("生成 B50 图片失败: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user