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

View File

@@ -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))
}
}
})