fix: ignore expired resources

This commit is contained in:
Rogee
2024-09-09 17:39:27 +08:00
parent 6f4b72da36
commit 791198a0be
3 changed files with 217 additions and 4 deletions

View File

@@ -123,8 +123,10 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
data, err := t.saveDocument(ctx, cfg, doc)
if err != nil {
logger.Error("save document failed", zap.Error(err), zap.Int64("channel", channel.ID))
return err
if !errors.Is(err, errorx.ErrResourceExpired) {
logger.Error("save document failed", zap.Error(err), zap.Int64("channel", channel.ID))
return err
}
}
channelMessage.WithDocument(doc.GetID(), data)
}
@@ -143,8 +145,10 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok && cfg.ExportMedia {
photo := photoClass.(*tg.Photo)
if err := t.savePhoto(ctx, cfg, photo); err != nil {
logger.Error("save photo failed", zap.Error(err), zap.Int64("channel", channel.ID))
return err
if !errors.Is(err, errorx.ErrResourceExpired) {
logger.Error("save photo failed", zap.Error(err), zap.Int64("channel", channel.ID))
return err
}
}
channelMessage.WithPhoto(photo.GetID(), "jpg")
}
@@ -188,6 +192,9 @@ func (t *TClient) savePhoto(ctx context.Context, cfg *DBChannel, photo *tg.Photo
if err != nil {
os.Remove(saveTo)
logger.Error("download failed", zap.Error(err))
if strings.Contains(err.Error(), "FILE_REFERENCE_EXPIRED") {
return errorx.ErrResourceExpired
}
return err
}
@@ -266,6 +273,9 @@ func (t *TClient) saveDocument(ctx context.Context, cfg *DBChannel, doc *tg.Docu
if err != nil {
os.Remove(saveTo)
logger.Error("download failed", zap.Error(err))
if strings.Contains(err.Error(), "FILE_REFERENCE_EXPIRED") {
return ChannelMessageDocument{}, errorx.ErrResourceExpired
}
return ChannelMessageDocument{}, err
}
logger.Info("download document success", zap.String("location", saveTo), zap.Any("document", data))