mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-22 16:50:38 +08:00
Merge pull request #204 from Rain-kl/feat/save-strategy
新增功能: 重名文件时选择保存策略 - 重命名,覆盖,跳过
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package ctxkey
|
||||
|
||||
// ENUM(content-length)
|
||||
// ENUM(content-length, overwrite-existing)
|
||||
//
|
||||
//go:generate go-enum --values --names --flag --nocase --noprefix
|
||||
type ContextKey string
|
||||
|
||||
@@ -14,12 +14,15 @@ import (
|
||||
const (
|
||||
// ContentLength is a ContextKey of type content-length.
|
||||
ContentLength ContextKey = "content-length"
|
||||
// OverwriteExisting is a ContextKey of type overwrite-existing.
|
||||
OverwriteExisting ContextKey = "overwrite-existing"
|
||||
)
|
||||
|
||||
var ErrInvalidContextKey = fmt.Errorf("not a valid ContextKey, try [%s]", strings.Join(_ContextKeyNames, ", "))
|
||||
|
||||
var _ContextKeyNames = []string{
|
||||
string(ContentLength),
|
||||
string(OverwriteExisting),
|
||||
}
|
||||
|
||||
// ContextKeyNames returns a list of possible string values of ContextKey.
|
||||
@@ -33,6 +36,7 @@ func ContextKeyNames() []string {
|
||||
func ContextKeyValues() []ContextKey {
|
||||
return []ContextKey{
|
||||
ContentLength,
|
||||
OverwriteExisting,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +53,8 @@ func (x ContextKey) IsValid() bool {
|
||||
}
|
||||
|
||||
var _ContextKeyValue = map[string]ContextKey{
|
||||
"content-length": ContentLength,
|
||||
"content-length": ContentLength,
|
||||
"overwrite-existing": OverwriteExisting,
|
||||
}
|
||||
|
||||
// ParseContextKey attempts to convert a string to a ContextKey.
|
||||
|
||||
@@ -14,6 +14,31 @@ const (
|
||||
TypeCancel = "cancel"
|
||||
)
|
||||
|
||||
const (
|
||||
ConflictStrategyRename = "rename"
|
||||
ConflictStrategyAsk = "ask"
|
||||
ConflictStrategyOverwrite = "overwrite"
|
||||
ConflictStrategySkip = "skip"
|
||||
)
|
||||
|
||||
func ConflictStrategyValues() []string {
|
||||
return []string{
|
||||
ConflictStrategyRename,
|
||||
ConflictStrategyAsk,
|
||||
ConflictStrategyOverwrite,
|
||||
ConflictStrategySkip,
|
||||
}
|
||||
}
|
||||
|
||||
func IsConflictStrategy(strategy string) bool {
|
||||
for _, value := range ConflictStrategyValues() {
|
||||
if strategy == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// type TaskDataTGFiles struct {
|
||||
// Files []tfile.TGFileMessage
|
||||
// AsBatch bool
|
||||
@@ -34,6 +59,8 @@ type Add struct {
|
||||
SelectedStorName string
|
||||
DirID uint
|
||||
SettedDir bool
|
||||
SelectedDirPath string
|
||||
ConflictStrategy string
|
||||
// tfiles
|
||||
Files []tfile.TGFileMessage
|
||||
AsBatch bool
|
||||
|
||||
Reference in New Issue
Block a user