package api import ( "context" "errors" creator "git.ipao.vip/rogee/creator-hub/internal/creator" "github.com/sirupsen/logrus" ) type eventCoverFiles interface { GetPlatformWorkCover(string, string) (string, error) SavePlatformWorkCover(string, string, string, []byte) error } // Cover failures are per-event results: preserve the notification, expose the // failure on its cover, and retry when the platform returns the notice again. func cacheListenerWorkCovers(ctx context.Context, files eventCoverFiles, fetch func(context.Context, string) (string, []byte, error), items []creator.ListenerDelivery) { for i := range items { n := items[i].Notice if n == nil || n.WorkID == "" || n.WorkAuthorUID == "" || n.WorkCoverURL == "" { continue } _, err := files.GetPlatformWorkCover(n.WorkAuthorUID, n.WorkID) if errors.Is(err, creator.ErrNotFound) { var contentType string var data []byte contentType, data, err = fetch(ctx, n.WorkCoverURL) if err == nil { err = files.SavePlatformWorkCover(n.WorkAuthorUID, n.WorkID, contentType, data) } } n.WorkCoverError = "" if err != nil { n.WorkCoverError = err.Error() logrus.WithError(err).WithFields(logrus.Fields{"event_key": n.EventKey, "work_key": n.WorkID, "author_uid": n.WorkAuthorUID}).Error("notification cover cache failed") } } }