feat: update transfer command to remove target path requirement and adjust usage instructions

This commit is contained in:
krau
2026-01-19 21:20:27 +08:00
parent dd0dea8cb5
commit 6990543c9f
5 changed files with 12 additions and 20 deletions

View File

@@ -2,7 +2,6 @@ package handlers
import ( import (
"fmt" "fmt"
"path"
"regexp" "regexp"
"strings" "strings"
@@ -28,7 +27,7 @@ func handleTransferCmd(ctx *ext.Context, update *ext.Update) error {
logger := log.FromContext(ctx) logger := log.FromContext(ctx)
args := strutil.ParseArgsRespectQuotes(update.EffectiveMessage.Text) args := strutil.ParseArgsRespectQuotes(update.EffectiveMessage.Text)
if len(args) < 3 { if len(args) < 2 {
ctx.Reply(update, ext.ReplyTextString(i18n.T(i18nk.BotMsgTransferUsage, nil)), nil) ctx.Reply(update, ext.ReplyTextString(i18n.T(i18nk.BotMsgTransferUsage, nil)), nil)
return dispatcher.EndGroups return dispatcher.EndGroups
} }
@@ -42,9 +41,6 @@ func handleTransferCmd(ctx *ext.Context, update *ext.Update) error {
sourceStorageName := sourceParts[0] sourceStorageName := sourceParts[0]
sourcePath := sourceParts[1] sourcePath := sourceParts[1]
// Parse target path (without storage name)
targetPath := args[2]
userID := update.GetUserChat().GetID() userID := update.GetUserChat().GetID()
// Get source storage // Get source storage
@@ -94,8 +90,8 @@ func handleTransferCmd(ctx *ext.Context, update *ext.Update) error {
// Optional filter // Optional filter
var filter *regexp.Regexp var filter *regexp.Regexp
if len(args) >= 4 { if len(args) >= 3 {
filter, err = regexp.Compile(args[3]) filter, err = regexp.Compile(args[2])
if err != nil { if err != nil {
ctx.EditMessage(update.EffectiveChat().GetID(), &tg.MessagesEditMessageRequest{ ctx.EditMessage(update.EffectiveChat().GetID(), &tg.MessagesEditMessageRequest{
ID: replied.ID, ID: replied.ID,
@@ -139,7 +135,6 @@ func handleTransferCmd(ctx *ext.Context, update *ext.Update) error {
TransferSourceStorName: sourceStorageName, TransferSourceStorName: sourceStorageName,
TransferSourcePath: sourcePath, TransferSourcePath: sourcePath,
TransferFiles: filePaths, TransferFiles: filePaths,
TransferTargetPath: targetPath,
}) })
if err != nil { if err != nil {
logger.Errorf("Failed to build storage selection keyboard: %s", err) logger.Errorf("Failed to build storage selection keyboard: %s", err)
@@ -209,7 +204,6 @@ func handleTransferCallback(ctx *ext.Context, userID int64, targetStorage storag
} }
// Build task elements for the selected files // Build task elements for the selected files
targetPath := path.Join(dirPath, data.TransferTargetPath)
elems := make([]transfer.TaskElement, 0, len(data.TransferFiles)) elems := make([]transfer.TaskElement, 0, len(data.TransferFiles))
var totalSize int64 var totalSize int64
for _, filePath := range data.TransferFiles { for _, filePath := range data.TransferFiles {
@@ -218,7 +212,7 @@ func handleTransferCallback(ctx *ext.Context, userID int64, targetStorage storag
logger.Warnf("File not found in source storage: %s", filePath) logger.Warnf("File not found in source storage: %s", filePath)
continue continue
} }
elem := transfer.NewTaskElement(sourceStorage, fileInfo, targetStorage, targetPath) elem := transfer.NewTaskElement(sourceStorage, fileInfo, targetStorage, dirPath)
elems = append(elems, *elem) elems = append(elems, *elem)
totalSize += fileInfo.Size totalSize += fileInfo.Size
} }

View File

@@ -57,7 +57,6 @@ func BuildAddSelectStorageKeyboard(stors []storage.Storage, adddata tcbdata.Add)
TransferSourceStorName: adddata.TransferSourceStorName, TransferSourceStorName: adddata.TransferSourceStorName,
TransferSourcePath: adddata.TransferSourcePath, TransferSourcePath: adddata.TransferSourcePath,
TransferFiles: adddata.TransferFiles, TransferFiles: adddata.TransferFiles,
TransferTargetPath: adddata.TransferTargetPath,
} }
dataid := xid.New().String() dataid := xid.New().String()
err := cache.Set(dataid, data) err := cache.Set(dataid, data)

View File

@@ -299,11 +299,11 @@ bot:
error_download_failed: "yt-dlp download failed: {{.Error}}" error_download_failed: "yt-dlp download failed: {{.Error}}"
transfer: transfer:
usage: | usage: |
Usage: /transfer <source_storage>:/<source_path> <target_path> [filter] Usage: /transfer <source_storage>:/<source_path> [filter]
Examples: Examples:
/transfer local1:/downloads /backup /transfer local1:/downloads
/transfer alist1:/media/photos /photos /transfer alist1:/media/photos
/transfer webdav1:/files /archive ".*\.mp4$" /transfer webdav1:/files ".*\.mp4$"
error_invalid_source: "Invalid source path format, should be: storage_name:/path" error_invalid_source: "Invalid source path format, should be: storage_name:/path"
error_invalid_target: "Invalid target path format, should be: storage_name:/path" error_invalid_target: "Invalid target path format, should be: storage_name:/path"
error_storage_not_found: "Storage '{{.StorageName}}' not found or access denied: {{.Error}}" error_storage_not_found: "Storage '{{.StorageName}}' not found or access denied: {{.Error}}"

View File

@@ -300,11 +300,11 @@ bot:
error_download_failed: "yt-dlp 下载失败: {{.Error}}" error_download_failed: "yt-dlp 下载失败: {{.Error}}"
transfer: transfer:
usage: | usage: |
用法: /transfer <source_storage>:/<source_path> <target_path> [filter] 用法: /transfer <source_storage>:/<source_path> [filter]
示例: 示例:
/transfer local1:/downloads /backup /transfer local1:/downloads
/transfer alist1:/media/photos /photos /transfer alist1:/media/photos
/transfer webdav1:/files /archive ".*\.mp4$" /transfer webdav1:/files ".*\.mp4$"
error_invalid_source: "源路径格式无效,应为: storage_name:/path" error_invalid_source: "源路径格式无效,应为: storage_name:/path"
error_invalid_target: "目标路径格式无效,应为: storage_name:/path" error_invalid_target: "目标路径格式无效,应为: storage_name:/path"
error_storage_not_found: "存储端 '{{.StorageName}}' 不存在或您无权访问: {{.Error}}" error_storage_not_found: "存储端 '{{.StorageName}}' 不存在或您无权访问: {{.Error}}"

View File

@@ -54,7 +54,6 @@ type Add struct {
TransferSourceStorName string TransferSourceStorName string
TransferSourcePath string TransferSourcePath string
TransferFiles []string // file paths relative to source storage TransferFiles []string // file paths relative to source storage
TransferTargetPath string
} }
type SetDefaultStorage struct { type SetDefaultStorage struct {