Compare commits
3 Commits
3c8ece72cc
...
65739c9307
| Author | SHA1 | Date | |
|---|---|---|---|
| 65739c9307 | |||
| c20748aef1 | |||
| 6e323a0e4f |
@@ -34,3 +34,20 @@ func getPathFromId(id string) string {
|
||||
func getFilenameFromID(id string) string {
|
||||
return filepath.Base(id)
|
||||
}
|
||||
|
||||
func invalidateCacheForDir(ctx context.Context, path string) error {
|
||||
loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader)
|
||||
if !ok {
|
||||
return fmt.Errorf("Failed to get loader from context")
|
||||
}
|
||||
|
||||
log.Debug("Invalidate cache for dir: ", path)
|
||||
|
||||
// FIXME: only clear required ids
|
||||
loader["getFile"].ClearAll()
|
||||
loader["listObjects"].ClearAll()
|
||||
loader["getFiles"].ClearAll()
|
||||
loader["getDirs"].ClearAll()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,8 +96,39 @@ func moveMutation(ctx context.Context, src, dest string) (*File, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
invalidateCache(ctx, info.Key)
|
||||
|
||||
return &File{
|
||||
ID: info.Key,
|
||||
}, 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
|
||||
}
|
||||
|
||||
// Invalidate cache
|
||||
// TODO: check error
|
||||
invalidateCacheForDir(ctx, info.Key)
|
||||
|
||||
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{
|
||||
|
||||
Reference in New Issue
Block a user