mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-01 21:50:05 +08:00
fix: add unique id to task struct to avoid duplicate file name overwrite, close #59
This commit is contained in:
@@ -117,7 +117,7 @@ func AddToQueue(ctx *ext.Context, update *ext.Update) error {
|
|||||||
if update.CallbackQuery.MsgID != record.ReplyMessageID {
|
if update.CallbackQuery.MsgID != record.ReplyMessageID {
|
||||||
record.ReplyMessageID = update.CallbackQuery.MsgID
|
record.ReplyMessageID = update.CallbackQuery.MsgID
|
||||||
if err := dao.SaveReceivedFile(record); err != nil {
|
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{
|
task = types.Task{
|
||||||
Ctx: ctx,
|
Ctx: ctx,
|
||||||
Status: types.Pending,
|
Status: types.Pending,
|
||||||
|
FileDBID: record.ID,
|
||||||
File: file,
|
File: file,
|
||||||
StorageName: storageName,
|
StorageName: storageName,
|
||||||
FileChatID: record.ChatID,
|
FileChatID: record.ChatID,
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ import (
|
|||||||
|
|
||||||
func processPendingTask(task *types.Task) error {
|
func processPendingTask(task *types.Task) error {
|
||||||
common.Log.Debugf("Start processing task: %s", task.String())
|
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() == "" {
|
if task.FileName() == "" {
|
||||||
task.File.FileName = fmt.Sprintf("%d_%d_%s", task.FileChatID, task.FileMessageID, task.File.Hash())
|
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)
|
notsupportStreamStorage, notsupportStream := taskStorage.(storage.StorageNotSupportStream)
|
||||||
cancelMarkUp := getCancelTaskMarkup(task)
|
cancelMarkUp := getCancelTaskMarkup(task)
|
||||||
|
|
||||||
if config.Cfg.Stream {
|
if config.Cfg.Stream {
|
||||||
if !notsupportStream {
|
if !notsupportStream {
|
||||||
text, entities := buildProgressMessageEntity(task, 0, task.StartTime, 0)
|
text, entities := buildProgressMessageEntity(task, 0, task.StartTime, 0)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Task struct {
|
|||||||
StorageName string
|
StorageName string
|
||||||
StoragePath string
|
StoragePath string
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
|
FileDBID uint
|
||||||
|
|
||||||
File *File
|
File *File
|
||||||
FileMessageID int
|
FileMessageID int
|
||||||
|
|||||||
Reference in New Issue
Block a user