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
43 lines
926 B
package queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/internal/session"
|
|
"git.aiterp.net/rpdata/api/model/file"
|
|
)
|
|
|
|
// FilesArgs is args for files query
|
|
type FilesArgs struct {
|
|
IncludePublic *bool
|
|
MimeTypes *[]string
|
|
}
|
|
|
|
// Files resolves the file query
|
|
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) {
|
|
user := session.FromContext(ctx).User()
|
|
author := ""
|
|
if user != nil {
|
|
author = user.ID
|
|
}
|
|
|
|
public := args.IncludePublic != nil && *args.IncludePublic == true
|
|
|
|
mimeTypes := []string(nil)
|
|
if args.MimeTypes != nil {
|
|
mimeTypes = *args.MimeTypes
|
|
}
|
|
|
|
files, err := file.List(author, 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
|
|
}
|