mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-28 10:41:25 +08:00
feat: rename file only when storagePath exists
This commit is contained in:
@@ -27,13 +27,7 @@ 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)
|
||||
}
|
||||
common.Log.Infof("Start processing task: %s", task.String())
|
||||
|
||||
if task.FileName() == "" {
|
||||
task.File.FileName = fmt.Sprintf("%d_%d_%s", task.FileChatID, task.FileMessageID, task.File.Hash())
|
||||
|
||||
31
core/rule.go
31
core/rule.go
@@ -26,23 +26,30 @@ func getStorageAndPathForTask(task *types.Task) (storage.Storage, string, error)
|
||||
return nil, "", err
|
||||
}
|
||||
storagePath := taskStorage.JoinStoragePath(*task)
|
||||
if !user.ApplyRule || user.Rules == nil {
|
||||
return taskStorage, storagePath, nil
|
||||
}
|
||||
|
||||
var ruleTaskStorage storage.Storage
|
||||
var ruleStoragePath string
|
||||
for _, rule := range user.Rules {
|
||||
matchStorage, matchStoragePath := applyRule(&rule, *task)
|
||||
if matchStorage != nil && matchStoragePath != "" {
|
||||
ruleTaskStorage = matchStorage
|
||||
ruleStoragePath = matchStoragePath
|
||||
if user.ApplyRule && user.Rules != nil {
|
||||
for _, rule := range user.Rules {
|
||||
matchStorage, matchStoragePath := applyRule(&rule, *task)
|
||||
if matchStorage != nil && matchStoragePath != "" {
|
||||
ruleTaskStorage = matchStorage
|
||||
ruleStoragePath = matchStoragePath
|
||||
common.Log.Debugf("Rule matched: %s, %s", ruleTaskStorage.Name(), ruleStoragePath)
|
||||
return ruleTaskStorage, ruleStoragePath, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if ruleStoragePath == "" || ruleTaskStorage == nil {
|
||||
return taskStorage, storagePath, nil
|
||||
|
||||
if taskStorage.Exists(task.Ctx, storagePath) {
|
||||
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)
|
||||
task.StoragePath = task.File.FileName
|
||||
storagePath = taskStorage.JoinStoragePath(*task)
|
||||
}
|
||||
common.Log.Debugf("Rule matched: %s, %s", ruleTaskStorage.Name(), ruleStoragePath)
|
||||
return ruleTaskStorage, ruleStoragePath, nil
|
||||
|
||||
return taskStorage, storagePath, nil
|
||||
}
|
||||
|
||||
func applyRule(rule *dao.Rule, task types.Task) (storage.Storage, string) {
|
||||
|
||||
Reference in New Issue
Block a user