From 25ad9befa0ecd4c59890aaf8213b867eb4c81cbb Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Sun, 24 Aug 2025 11:38:44 +0800 Subject: [PATCH] feat: add ForceFile option to TelegramStorageConfig and update Save method --- config/storage/telegram.go | 1 + storage/telegram/telegram.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/storage/telegram.go b/config/storage/telegram.go index 8487235..37a2208 100644 --- a/config/storage/telegram.go +++ b/config/storage/telegram.go @@ -9,6 +9,7 @@ import ( type TelegramStorageConfig struct { BaseConfig ChatID int64 `toml:"chat_id" mapstructure:"chat_id" json:"chat_id"` + ForceFile bool `toml:"force_file" mapstructure:"force_file" json:"force_file"` RateLimit int `toml:"rate_limit" mapstructure:"rate_limit" json:"rate_limit"` RateBurst int `toml:"rate_burst" mapstructure:"rate_burst" json:"rate_burst"` } diff --git a/storage/telegram/telegram.go b/storage/telegram/telegram.go index 5dc7258..27d31fe 100644 --- a/storage/telegram/telegram.go +++ b/storage/telegram/telegram.go @@ -80,7 +80,7 @@ func (t *Telegram) Save(ctx context.Context, r io.Reader, storagePath string) er // ==1, 视作只有文件名, 存储到配置文件中的 chat_id // ==2, parts[0]: 视作要存储到的 chat_id, parts[1]: filename - parts := slice.Compact(strings.SplitN(strings.TrimPrefix(storagePath, "/"), "/", 4)) + parts := slice.Compact(strings.Split(strings.TrimPrefix(storagePath, "/"), "/")) filename := "" chatID := t.config.ChatID if len(parts) >= 1 { @@ -136,7 +136,7 @@ func (t *Telegram) Save(ctx context.Context, r io.Reader, storagePath string) er caption := styling.Plain(filename) docb := message.UploadedDocument(file, caption). Filename(filename). - ForceFile(false). + ForceFile(t.config.ForceFile). MIME(mtype.String()) var media message.MediaOption = docb