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.

43 lines
926 B

  1. package queries
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/internal/session"
  6. "git.aiterp.net/rpdata/api/model/file"
  7. )
  8. // FilesArgs is args for files query
  9. type FilesArgs struct {
  10. IncludePublic *bool
  11. MimeTypes *[]string
  12. }
  13. // Files resolves the file query
  14. func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) {
  15. user := session.FromContext(ctx).User()
  16. author := ""
  17. if user != nil {
  18. author = user.ID
  19. }
  20. public := args.IncludePublic != nil && *args.IncludePublic == true
  21. mimeTypes := []string(nil)
  22. if args.MimeTypes != nil {
  23. mimeTypes = *args.MimeTypes
  24. }
  25. files, err := file.List(author, public, mimeTypes)
  26. if err != nil {
  27. return nil, err
  28. }
  29. resolvers := make([]*types.FileResolver, len(files))
  30. for i := range files {
  31. resolvers[i] = &types.FileResolver{F: files[i]}
  32. }
  33. return resolvers, nil
  34. }