From 548b9109eb6f66b94426dcaf4b540bed61697793 Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 2 Sep 2024 19:12:39 +0800 Subject: [PATCH] fix: issues --- .vscode/launch.json | 10 +++++--- internal/client_channel.go | 49 +++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c1028b5..ea2420b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,9 +12,13 @@ "program": "${workspaceFolder}/main.go", "args": [ "export", - "--alias", - "yunpanshare", - // "--history", + // https://t.me/yunpanshare/26640 + // "--alias", "yunpanshare", + // https://t.me/Aliyun_4K_Movies/26640 + // "--alias", "Aliyun_4K_Movies", + // https://t.me/abskoop/8501 + "--alias", "abskoop", + "--history", ] } ] diff --git a/internal/client_channel.go b/internal/client_channel.go index a479a2e..c9264f7 100644 --- a/internal/client_channel.go +++ b/internal/client_channel.go @@ -61,29 +61,40 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann channelMessage.WithMessage(msg.GetMessage()) if mediaClass, ok := msg.GetMedia(); ok { - if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok { - photo := photoClass.(*tg.Photo) - - thumbSize := "" - if len(photo.Sizes) > 1 { - thumbSize = photo.Sizes[len(photo.Sizes)-1].GetType() + switch mediaClass.(type) { + case *tg.MessageMediaDocument: + if doc, ok := mediaClass.(*tg.MessageMediaDocument).GetDocument(); ok { + t.logger.Warn("document", zap.String("file_name", doc.String())) } + return + case *tg.MessageMediaWebPage: + t.logger.Warn("web_page", zap.String("url", mediaClass.(*tg.MessageMediaWebPage).GetWebpage().String())) + return + case *tg.MessageMediaPhoto: + if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok { + photo := photoClass.(*tg.Photo) - location := &tg.InputPhotoFileLocation{ - ID: photo.GetID(), - AccessHash: photo.GetAccessHash(), - FileReference: photo.GetFileReference(), - ThumbSize: thumbSize, - } + thumbSize := "" + if len(photo.Sizes) > 1 { + thumbSize = photo.Sizes[len(photo.Sizes)-1].GetType() + } - saveTo := cfg.Asset(photo.GetID(), "jpg") - _, err := downloader.Download(t.Client.API(), location).ToPath(ctx, saveTo) - if err != nil { - t.logger.Error("download failed", zap.Error(err)) - return + location := &tg.InputPhotoFileLocation{ + ID: photo.GetID(), + AccessHash: photo.GetAccessHash(), + FileReference: photo.GetFileReference(), + ThumbSize: thumbSize, + } + + saveTo := cfg.Asset(photo.GetID(), "jpg") + _, err := downloader.Download(t.Client.API(), location).ToPath(ctx, saveTo) + if err != nil { + t.logger.Error("download failed", zap.Error(err)) + return + } + channelMessage.WithPhoto(photo.GetID(), "jpg") + t.logger.Info("download photo success", zap.String("location", saveTo)) } - channelMessage.WithPhoto(photo.GetID(), "jpg") - t.logger.Info("download photo success", zap.String("location", saveTo)) } } })