From 8b389a58d54e48c170a61403db60d09b20d11c34 Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Sun, 24 Aug 2025 11:46:12 +0800 Subject: [PATCH] fix: improve chat ID parsing in Save method and fallback to configured chat_id --- storage/telegram/telegram.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/storage/telegram/telegram.go b/storage/telegram/telegram.go index 27d31fe..ad42aba 100644 --- a/storage/telegram/telegram.go +++ b/storage/telegram/telegram.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/charmbracelet/log" "github.com/duke-git/lancet/v2/slice" "github.com/gabriel-vasile/mimetype" "github.com/gotd/td/constant" @@ -89,7 +90,13 @@ func (t *Telegram) Save(ctx context.Context, r io.Reader, storagePath string) er if len(parts) >= 2 { cid, err := tgutil.ParseChatID(tctx, parts[0]) if err != nil { - return fmt.Errorf("failed to parse chat ID: %w", err) + // id不合法时使用配置文件中的 chat_id + log.FromContext(ctx).Warnf("Failed to parse chat ID from path, using configured chat_id: %s", err) + cid = chatID + } else { + if cid > constant.MaxTDLibChannelID || cid > constant.MaxTDLibChatID || cid > constant.MaxTDLibUserID { + cid = chatID + } } chatID = cid }