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.

39 lines
787 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. file, err := files.FindID(id)
  10. if err != nil {
  11. return nil, err
  12. }
  13. return &file, nil
  14. }
  15. func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) {
  16. token := auth.TokenFromContext(ctx)
  17. if filter == nil {
  18. filter = &files.Filter{}
  19. }
  20. // Only allow users to view public files that are not their own.
  21. if token != nil {
  22. if filter.Public == nil || *filter.Public == false {
  23. filter.Author = &token.UserID
  24. }
  25. } else {
  26. filter.Public = &trueValue
  27. }
  28. return files.List(filter)
  29. }
  30. var trueValue = true