Skip to content

Commit

Permalink
fix: handle empty file name in HandleFileMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Oct 10, 2024
1 parent f9d51a6 commit 7a288e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bot
import (
"context"
"fmt"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -151,7 +152,8 @@ func HandleFileMessage(ctx context.Context, bot *telego.Bot, message telego.Mess
fileName = message.Audio.FileName
}

if fileID == "" || fileName == "" {
if fileID == "" {
logger.L.Error("File ID is empty")
ReplyMessage(message, "文件信息获取失败")
return
}
Expand Down Expand Up @@ -182,6 +184,9 @@ func HandleFileMessage(ctx context.Context, bot *telego.Bot, message telego.Mess
return
}
}
if fileName == "" {
fileName = filepath.Base(file.FilePath)
}

err = dao.AddReceivedFile(&model.ReceivedFile{
FileUniqueID: file.FileUniqueID,
Expand Down

0 comments on commit 7a288e3

Please sign in to comment.