feat(vfs): 增强虚拟文件系统删除和查询功能

- 新增递归删除目录及子项的功能,支持 recursive 和 force 操作模式
- 支持通过路径获取文件或目录内容,并完善参数说明和示例
- 完善 VFS API 文档,包括操作模式、权限描述和响应内容
- 优化 GetVFSNode 方法,改为通过 ID 查询节点信息
- 修复部分路径和权限检查的逻辑注释
This commit is contained in:
zzy
2025-09-27 22:23:30 +08:00
parent cf47ef66c3
commit a3033bbf67
5 changed files with 178 additions and 38 deletions

View File

@ -99,29 +99,51 @@ func (v *VfsImpl) DeleteVFSNode(ctx context.Context, request api.DeleteVFSNodeRe
}, nil
}
case models.VfsNodeTypeDirectory:
// 检查目录是否为空
children, err := v.vfs.GetChildren(node.ID)
if err != nil {
return api.DeleteVFSNode500JSONResponse{
ServerInternalErrorJSONResponse: api.ServerInternalErrorJSONResponse{
Errtype: api.ErrorErrtypeInternalServerError,
Message: "Failed to get directory children: " + err.Error(),
},
}, nil
}
if len(children) != 0 {
return api.DeleteVFSNode400JSONResponse{
ParameterErrorJSONResponse: api.ParameterErrorJSONResponse{
Errtype: api.ErrorErrtypeConflictError,
Message: "Directory is not empty",
},
}, nil
if request.Params.Op != nil && *request.Params.Op == api.Recursive {
if sericeIDs, err := v.vfs.DeleteNodeRecursively(node.ID); err != nil {
return api.DeleteVFSNode500JSONResponse{
ServerInternalErrorJSONResponse: api.ServerInternalErrorJSONResponse{
Errtype: api.ErrorErrtypeInternalServerError,
Message: "Failed to delete node: " + err.Error(),
},
}, nil
} else {
for _, serviceID := range sericeIDs {
// 对于服务类型节点,通过代理删除
_, err := v.StrictProxy2Service(http.MethodDelete, nil, v.vfs.GetVFSNode(serviceID))
if err != nil {
return api.DeleteVFSNode500JSONResponse{
ServerInternalErrorJSONResponse: api.ServerInternalErrorJSONResponse{
Errtype: api.ErrorErrtypeServiceProxyError,
Message: err.Error(),
},
}, nil
}
}
return api.DeleteVFSNode204Response{}, nil
}
} else {
// 检查目录是否为空
children, err := v.vfs.GetChildren(node.ID)
if err != nil {
return api.DeleteVFSNode500JSONResponse{
ServerInternalErrorJSONResponse: api.ServerInternalErrorJSONResponse{
Errtype: api.ErrorErrtypeInternalServerError,
Message: "Failed to get directory children: " + err.Error(),
},
}, nil
}
if len(children) != 0 {
return api.DeleteVFSNode400JSONResponse{
ParameterErrorJSONResponse: api.ParameterErrorJSONResponse{
Errtype: api.ErrorErrtypeConflictError,
Message: "Directory is not empty",
},
}, nil
}
}
case models.VfsNodeTypeFile:
// TODO
// 文件类型节点可以直接删除
fallthrough
default:
return api.DeleteVFSNode400JSONResponse{
ParameterErrorJSONResponse: api.ParameterErrorJSONResponse{