mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-28 11:46:42 +08:00
feat: support custom storage path in filename
This commit is contained in:
+1
-1
@@ -63,7 +63,7 @@ SaveAny Bot - 转存你的 Telegram 文件
|
|||||||
/help - 显示帮助
|
/help - 显示帮助
|
||||||
/silent - 静默模式
|
/silent - 静默模式
|
||||||
/storage - 设置默认存储位置
|
/storage - 设置默认存储位置
|
||||||
/save - 保存文件
|
/save [自定义文件名] - 保存文件
|
||||||
|
|
||||||
静默模式: 开启后 Bot 直接保存到收到的文件到默认位置, 不再询问
|
静默模式: 开启后 Bot 直接保存到收到的文件到默认位置, 不再询问
|
||||||
`
|
`
|
||||||
|
|||||||
+9
-2
@@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/celestix/gotgproto/ext"
|
"github.com/celestix/gotgproto/ext"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
"github.com/gotd/td/tg"
|
"github.com/gotd/td/tg"
|
||||||
"github.com/krau/SaveAny-Bot/bot"
|
"github.com/krau/SaveAny-Bot/bot"
|
||||||
"github.com/krau/SaveAny-Bot/config"
|
"github.com/krau/SaveAny-Bot/config"
|
||||||
@@ -20,7 +21,14 @@ import (
|
|||||||
|
|
||||||
func processPendingTask(task *types.Task) error {
|
func processPendingTask(task *types.Task) error {
|
||||||
logger.L.Debugf("Start processing task: %s", task.String())
|
logger.L.Debugf("Start processing task: %s", task.String())
|
||||||
os.MkdirAll(config.Cfg.Temp.BasePath, os.ModePerm)
|
destPath := filepath.Join(config.Cfg.Temp.BasePath, task.FileName())
|
||||||
|
absDestPath, err := filepath.Abs(destPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to get absolute path: %w", err)
|
||||||
|
}
|
||||||
|
if err := fileutil.CreateDir(filepath.Dir(absDestPath)); err != nil {
|
||||||
|
return fmt.Errorf("Failed to create directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
ctx := task.Ctx.(*ext.Context)
|
ctx := task.Ctx.(*ext.Context)
|
||||||
ctx.EditMessage(task.ChatID, &tg.MessagesEditMessageRequest{
|
ctx.EditMessage(task.ChatID, &tg.MessagesEditMessageRequest{
|
||||||
@@ -28,7 +36,6 @@ func processPendingTask(task *types.Task) error {
|
|||||||
ID: task.ReplyMessageID,
|
ID: task.ReplyMessageID,
|
||||||
})
|
})
|
||||||
|
|
||||||
destPath := filepath.Join(config.Cfg.Temp.BasePath, task.File.FileName)
|
|
||||||
if task.StoragePath == "" {
|
if task.StoragePath == "" {
|
||||||
task.StoragePath = task.File.FileName
|
task.StoragePath = task.File.FileName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,13 @@ func (l *Local) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
|
func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
|
||||||
return fileutil.CopyFile(filePath, filepath.Join(config.Cfg.Storage.Local.BasePath, storagePath))
|
storagePath = filepath.Join(config.Cfg.Storage.Local.BasePath, storagePath)
|
||||||
|
absPath, err := filepath.Abs(storagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := fileutil.CreateDir(filepath.Dir(absPath)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fileutil.CopyFile(filePath, storagePath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user