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.
45 lines
907 B
45 lines
907 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 {
|
|
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
|
|
user := session.FromContext(ctx).User()
|
|
|
|
author := ""
|
|
if user != nil {
|
|
author = user.ID
|
|
}
|
|
|
|
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
|
|
}
|