Skip to content

Commit

Permalink
先存储再发布
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed May 14, 2024
1 parent bca06bc commit bb1e89f
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions fetcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func PostAndCreateArtwork(ctx context.Context, artwork *types.Artwork, bot *tele
Logger.Debugf("Artwork %s is deleted", artwork.Title)
return errors.ErrArtworkDeleted
}
for i, picture := range artwork.Pictures {
info, err := storage.SavePicture(artwork, picture)
if err != nil {
Logger.Errorf("saving picture %s: %s", picture.Original, err)
return fmt.Errorf("saving picture %s: %w", picture.Original, err)
}
artwork.Pictures[i].StorageInfo = info
}
messages, err := telegram.PostArtwork(telegram.Bot, artwork)
if err != nil {
return fmt.Errorf("posting artwork [%s](%s): %w", artwork.Title, artwork.SourceURL, err)
Expand All @@ -51,21 +59,6 @@ func PostAndCreateArtwork(ctx context.Context, artwork *types.Artwork, bot *tele
}
}

for i, picture := range artwork.Pictures {
info, err := storage.SavePicture(artwork, picture)
if err != nil {
Logger.Errorf("saving picture %s: %s", picture.Original, err)
if telegram.Bot.DeleteMessages(&telego.DeleteMessagesParams{
ChatID: telegram.ChannelChatID,
MessageIDs: telegram.GetMessageIDs(messages),
}) != nil {
Logger.Errorf("deleting messages: %s", err)
}
return fmt.Errorf("saving picture %s: %w", picture.Original, err)
}
artwork.Pictures[i].StorageInfo = info
}

_, err = service.CreateArtwork(ctx, artwork)
if err != nil {
go func() {
Expand Down

0 comments on commit bb1e89f

Please sign in to comment.