fix: issues
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user