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.
|
|
package queries
import ( "context"
"git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/model/file" )
// FilesArgs is args for files query
type FilesArgs struct { Filter *struct { Public *bool MimeTypes *[]string } }
// Files resolves the file query
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) { filter := args.Filter token := auth.TokenFromContext(ctx)
author := "" if token != nil { author = token.UserID }
mimeTypes := []string(nil) if filter.MimeTypes != nil { mimeTypes = *filter.MimeTypes }
files, err := file.List(author, filter.Public, mimeTypes) if err != nil { return nil, err }
resolvers := make([]*types.FileResolver, len(files)) for i := range files { resolvers[i] = &types.FileResolver{F: files[i]} }
return resolvers, nil }
|