fix: issues

This commit is contained in:
Rogee
2024-09-02 19:12:39 +08:00
parent 6d0f4e888a
commit 548b9109eb
2 changed files with 37 additions and 22 deletions

10
.vscode/launch.json vendored
View File

@@ -12,9 +12,13 @@
"program": "${workspaceFolder}/main.go", "program": "${workspaceFolder}/main.go",
"args": [ "args": [
"export", "export",
"--alias", // https://t.me/yunpanshare/26640
"yunpanshare", // "--alias", "yunpanshare",
// "--history", // https://t.me/Aliyun_4K_Movies/26640
// "--alias", "Aliyun_4K_Movies",
// https://t.me/abskoop/8501
"--alias", "abskoop",
"--history",
] ]
} }
] ]

View File

@@ -61,29 +61,40 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
channelMessage.WithMessage(msg.GetMessage()) channelMessage.WithMessage(msg.GetMessage())
if mediaClass, ok := msg.GetMedia(); ok { if mediaClass, ok := msg.GetMedia(); ok {
if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok { switch mediaClass.(type) {
photo := photoClass.(*tg.Photo) case *tg.MessageMediaDocument:
if doc, ok := mediaClass.(*tg.MessageMediaDocument).GetDocument(); ok {
thumbSize := "" t.logger.Warn("document", zap.String("file_name", doc.String()))
if len(photo.Sizes) > 1 {
thumbSize = photo.Sizes[len(photo.Sizes)-1].GetType()
} }
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{ thumbSize := ""
ID: photo.GetID(), if len(photo.Sizes) > 1 {
AccessHash: photo.GetAccessHash(), thumbSize = photo.Sizes[len(photo.Sizes)-1].GetType()
FileReference: photo.GetFileReference(), }
ThumbSize: thumbSize,
}
saveTo := cfg.Asset(photo.GetID(), "jpg") location := &tg.InputPhotoFileLocation{
_, err := downloader.Download(t.Client.API(), location).ToPath(ctx, saveTo) ID: photo.GetID(),
if err != nil { AccessHash: photo.GetAccessHash(),
t.logger.Error("download failed", zap.Error(err)) FileReference: photo.GetFileReference(),
return 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))
} }
} }
}) })