file.go 897 B

12345678910111213141516171819202122232425262728
  1. package access
  2. import (
  3. "github.com/ente-io/museum/ente"
  4. enteArray "github.com/ente-io/museum/pkg/utils/array"
  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. type VerifyFileOwnershipParams struct {
  11. // userID of the user trying to fetch the controller
  12. ActorUserId int64
  13. FileIDs []int64
  14. }
  15. // VerifyFileOwnership will return error if given fileIDs are not valid or don't belong to the ownerID
  16. func (c controllerImpl) VerifyFileOwnership(ctx *gin.Context, req *VerifyFileOwnershipParams) error {
  17. if enteArray.ContainsDuplicateInInt64Array(req.FileIDs) {
  18. return stacktrace.Propagate(ente.ErrBadRequest, "duplicate fileIDs")
  19. }
  20. ownerID := req.ActorUserId
  21. logger := log.WithFields(log.Fields{
  22. "req_id": requestid.Get(ctx),
  23. })
  24. return c.FileRepo.VerifyFileOwner(ctx, req.FileIDs, ownerID, logger)
  25. }