feat: 添加常量 TempDir 并更新文件下载逻辑以支持跳过已存在文件的选项

This commit is contained in:
lixiangwuxian
2025-04-12 21:16:58 +08:00
parent b49b780da2
commit 7ba0f74b49
7 changed files with 20 additions and 13 deletions

View File

@@ -3,7 +3,6 @@ package scoresaber
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"sync"
@@ -211,12 +210,15 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
go func(songHash string) {
defer wg.Done()
//文件存在则跳过
if _, err := os.Stat(util.GetResizedIamgePathByOrgPath(util.GenTempFilePath(songHash + ".jpeg"))); err == nil {
// if _, err := os.Stat(util.GetResizedIamgePathByOrgPath(util.GenTempFilePath(songHash + ".jpeg"))); err == nil {
// return
// }
filePath, err := util.DownloadFile(coverImageMap[songHash], constants.TempDir, true)
if err != nil {
log.Printf("下载图片失败: %v", err)
return
}
util.DownloadFile(coverImageMap[songHash], util.GenTempFilePath(songHash+".jpeg"))
newPath, err := util.ResizeImageByMaxHeight(util.GenTempFilePath(songHash+".jpeg"), 20)
os.Remove(util.GenTempFilePath(songHash + ".jpeg"))
newPath, err := util.ResizeImageByMaxHeight(filePath, 20)
if err != nil {
log.Printf("缩放图片失败: %v", err)
}
@@ -228,7 +230,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
imageMsg := message.ImageMessage{
Type: "image",
Data: message.ImageMessageData{
File: util.GetResizedIamgePathByOrgPath(util.GenTempFilePath(record.SongHash + ".jpeg")),
File: coverImageMap[record.SongHash],
},
}
scoreMsg += imageMsg.ToCQString() + record.ToString() + "\n"