collection_cast.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package controller
  2. import (
  3. "github.com/ente-io/museum/ente"
  4. "github.com/ente-io/museum/pkg/utils/auth"
  5. "github.com/ente-io/stacktrace"
  6. "github.com/gin-contrib/requestid"
  7. "github.com/gin-gonic/gin"
  8. log "github.com/sirupsen/logrus"
  9. )
  10. func (c *CollectionController) GetCastCollection(ctx *gin.Context) (*ente.Collection, error) {
  11. castCtx := auth.GetCastCtx(ctx)
  12. collection, err := c.CollectionRepo.Get(castCtx.CollectionID)
  13. if err != nil {
  14. return nil, stacktrace.Propagate(err, "")
  15. }
  16. if collection.IsDeleted {
  17. return nil, stacktrace.Propagate(ente.ErrNotFound, "collection is deleted")
  18. }
  19. return &collection, nil
  20. }
  21. // GetCastDiff returns the changes in the collections since a timestamp, along with hasMore bool flag.
  22. func (c *CollectionController) GetCastDiff(ctx *gin.Context, sinceTime int64) ([]ente.File, bool, error) {
  23. castCtx := auth.GetCastCtx(ctx)
  24. collectionID := castCtx.CollectionID
  25. reqContextLogger := log.WithFields(log.Fields{
  26. "collection_id": collectionID,
  27. "since_time": sinceTime,
  28. "req_id": requestid.Get(ctx),
  29. })
  30. diff, hasMore, err := c.getDiff(collectionID, sinceTime, CollectionDiffLimit, reqContextLogger)
  31. if err != nil {
  32. return nil, false, stacktrace.Propagate(err, "")
  33. }
  34. // hide private metadata before returning files info in diff
  35. for idx := range diff {
  36. if diff[idx].MagicMetadata != nil {
  37. diff[idx].MagicMetadata = nil
  38. }
  39. }
  40. return diff, hasMore, nil
  41. }