added createDir mutation
This commit is contained in:
parent
6e323a0e4f
commit
c20748aef1
@ -103,3 +103,28 @@ func moveMutation(ctx context.Context, src, dest string) (*File, error) {
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func createDirectory(ctx context.Context, path string) (*Directory, error) {
|
||||
s3Client, ok := ctx.Value("s3Client").(*minio.Client)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Failed to get s3Client from context")
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path += "/"
|
||||
}
|
||||
|
||||
info, err := s3Client.PutObject(ctx, bucketName, path, strings.NewReader(""), 0, minio.PutObjectOptions{
|
||||
ContentType: "application/x-directory",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Directory{
|
||||
ID: info.Key,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
@ -146,6 +146,24 @@ func graphqlSchema() (graphql.Schema, error) {
|
||||
return moveMutation(p.Context, src, dest)
|
||||
},
|
||||
},
|
||||
"createDir": &graphql.Field{
|
||||
Type: graphql.NewNonNull(graphqlDirType),
|
||||
Args: graphql.FieldConfigArgument{
|
||||
"path": &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.ID),
|
||||
},
|
||||
},
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
path, ok := p.Args["path"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Failed to parse args")
|
||||
}
|
||||
|
||||
log.Debug("mutation 'createDir': ", path)
|
||||
|
||||
return createDirectory(p.Context, path)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rootQuery := graphql.ObjectConfig{
|
||||
|
Loading…
Reference in New Issue
Block a user