GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
722 B

  1. package queries
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/internal/auth"
  5. "git.aiterp.net/rpdata/api/models"
  6. "git.aiterp.net/rpdata/api/models/files"
  7. )
  8. func (r *resolver) File(ctx context.Context, id string) (models.File, error) {
  9. return files.FindID(id)
  10. }
  11. func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) {
  12. token := auth.TokenFromContext(ctx)
  13. if filter == nil {
  14. filter = &files.Filter{}
  15. }
  16. // Only allow users to view public files that are not their own.
  17. if token != nil {
  18. if filter.Public == nil || *filter.Public == false {
  19. filter.Author = &token.UserID
  20. }
  21. } else {
  22. filter.Public = &trueValue
  23. }
  24. return files.List(filter)
  25. }
  26. var trueValue = true