fix: add unique id to task struct to avoid duplicate file name overwrite, close #59

This commit is contained in:
krau
2025-05-09 08:58:30 +08:00
parent 488d709d85
commit ed99a37831
3 changed files with 11 additions and 1 deletions

View File

@@ -117,7 +117,7 @@ func AddToQueue(ctx *ext.Context, update *ext.Update) error {
if update.CallbackQuery.MsgID != record.ReplyMessageID {
record.ReplyMessageID = update.CallbackQuery.MsgID
if err := dao.SaveReceivedFile(record); err != nil {
common.Log.Errorf("更新接收的文件失败: %s", err)
common.Log.Errorf("更新记录失败: %s", err)
}
}
@@ -169,6 +169,7 @@ func AddToQueue(ctx *ext.Context, update *ext.Update) error {
task = types.Task{
Ctx: ctx,
Status: types.Pending,
FileDBID: record.ID,
File: file,
StorageName: storageName,
FileChatID: record.ChatID,

View File

@@ -27,6 +27,13 @@ import (
func processPendingTask(task *types.Task) error {
common.Log.Debugf("Start processing task: %s", task.String())
if task.FileName() != "" && !task.IsTelegraph && task.File.FileSize != 0 && task.FileDBID != 0 {
ext := path.Ext(task.FileName())
name := task.FileName()[:len(task.FileName())-len(ext)]
task.File.FileName = fmt.Sprintf("%s_%d%s", name, task.FileDBID, ext)
}
if task.FileName() == "" {
task.File.FileName = fmt.Sprintf("%d_%d_%s", task.FileChatID, task.FileMessageID, task.File.Hash())
}
@@ -60,6 +67,7 @@ func processPendingTask(task *types.Task) error {
notsupportStreamStorage, notsupportStream := taskStorage.(storage.StorageNotSupportStream)
cancelMarkUp := getCancelTaskMarkup(task)
if config.Cfg.Stream {
if !notsupportStream {
text, entities := buildProgressMessageEntity(task, 0, task.StartTime, 0)

View File

@@ -20,6 +20,7 @@ type Task struct {
StorageName string
StoragePath string
StartTime time.Time
FileDBID uint
File *File
FileMessageID int