```
feat(bookmark): 添加文件夹树结构导入导出接口 新增 `/bookmarks/v1/folder/serial` 接口,支持文件夹树结构的压缩导出与解压导入。 同时完善了相关响应结构体定义,如 ImportResponse 等。 refactor(bookmark): 重命名配置文件并调整字段命名 将 `config/api.yaml` 重命名为 `config/bookmark.yaml`,并统一将 parent_path_id 字段 更名为 parent_id。此外,更新 API 鉴权头名称为 X-BookMark-Token。 feat(bookmark): 实现文件夹挂载管理功能 新增以下三个接口用于管理文件夹挂载: - GET `/bookmarks/v1/folder/{id}/mount` 获取挂载信息 - POST `/bookmarks/v1/folder/{id}/mount` 挂载文件夹 - DELETE `/bookmarks/v1/folder/{id}/mount` 取消挂载 新增相关结构体定义:MountResponse、MountInfo。 feat(vfs): 初始化虚拟文件系统 API 配置 新增 `config/vfs.yaml` 和 `config/vfs_cfg.yaml` 配置文件,定义 VFS 相关接口和代码生成规则。 接口包括文件/目录的创建、读取、更新和删除操作,并引入新的安全头 X-VFS-Token。 chore(config): 忽略 data 目录并更新生成路径 .gitignore 中新增忽略 data/ 目录。同时更新 bookmark 和 vfs 的代码生成输出路径分别为 `./gen/bookmarks/gen.go` 和 `./gen/vfs/gen.go`。 chore(deps): 引入 casbin、gopsutil 等依赖库 go.mod 中新增 casbin 权限控制、gopsutil 系统监控等相关依赖。 ```
This commit is contained in:
@ -17,6 +17,51 @@ security:
|
||||
- ApiKeyAuth: []
|
||||
|
||||
paths:
|
||||
/bookmarks/v1/folder/serial:
|
||||
get:
|
||||
summary: 导出文件夹树结构
|
||||
description: 递归导出整个文件夹树结构并压缩返回
|
||||
operationId: exportFolderTree
|
||||
tags: [folder]
|
||||
responses:
|
||||
'200':
|
||||
description: 压缩的文件夹树数据
|
||||
content:
|
||||
application/octet-stream:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
post:
|
||||
summary: 导入文件夹树结构
|
||||
description: 上传并解压文件夹树结构数据,重建文件系统
|
||||
operationId: importFolderTree
|
||||
tags: [folder]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/octet-stream:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
responses:
|
||||
'200':
|
||||
description: 导入成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ImportResponse'
|
||||
'400':
|
||||
description: 数据格式错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
/bookmarks/v1/folder:
|
||||
post:
|
||||
summary: 创建文件夹
|
||||
@ -145,6 +190,139 @@ paths:
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
/bookmarks/v1/folder/{id}/mount:
|
||||
get:
|
||||
summary: 获取文件夹挂载信息
|
||||
description: 获取指定文件夹的所有挂载信息
|
||||
operationId: getFolderMounts
|
||||
tags: [folder]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 文件夹ID
|
||||
responses:
|
||||
'200':
|
||||
description: 挂载信息列表
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/MountInfo'
|
||||
'404':
|
||||
description: 文件夹不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
post:
|
||||
summary: 挂载文件夹
|
||||
description: 将指定文件夹挂载到目标位置
|
||||
operationId: mountFolder
|
||||
tags: [folder]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 要挂载的文件夹ID
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
target_folder_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 目标文件夹ID(挂载点)
|
||||
mount_name:
|
||||
type: string
|
||||
description: 挂载后的显示名称(可选,默认使用原文件夹名)
|
||||
required:
|
||||
- target_folder_id
|
||||
responses:
|
||||
'200':
|
||||
description: 挂载成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/MountResponse'
|
||||
'400':
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'404':
|
||||
description: 文件夹不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'409':
|
||||
description: 挂载冲突(如循环挂载、重复挂载等)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
delete:
|
||||
summary: 取消挂载文件夹
|
||||
description: 取消指定文件夹的挂载关系
|
||||
operationId: unmountFolder
|
||||
tags: [folder]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 要取消挂载的文件夹ID
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
mount_point_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 挂载点ID(从哪个位置取消挂载)
|
||||
required:
|
||||
- mount_point_id
|
||||
responses:
|
||||
'200':
|
||||
description: 取消挂载成功
|
||||
'400':
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'404':
|
||||
description: 挂载关系不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
/bookmarks/v1/folder/{id}/content:
|
||||
get:
|
||||
summary: 获取文件夹的内容
|
||||
@ -324,7 +502,7 @@ components:
|
||||
ApiKeyAuth:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: X-API-Key
|
||||
name: X-BookMark-Token
|
||||
responses:
|
||||
ServerInternalError:
|
||||
description: 服务器内部错误
|
||||
@ -339,6 +517,81 @@ components:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
schemas:
|
||||
ImportResponse:
|
||||
type: object
|
||||
properties:
|
||||
imported_folders:
|
||||
type: integer
|
||||
description: 导入的文件夹数量
|
||||
imported_bookmarks:
|
||||
type: integer
|
||||
description: 导入的书签数量
|
||||
duration:
|
||||
type: string
|
||||
description: 导入耗时
|
||||
required:
|
||||
- imported_folders
|
||||
- imported_bookmarks
|
||||
- duration
|
||||
|
||||
MountResponse:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 挂载关系ID
|
||||
source_folder_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 源文件夹ID
|
||||
target_folder_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 目标文件夹ID(挂载点)
|
||||
mount_name:
|
||||
type: string
|
||||
description: 挂载显示名称
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
description: 挂载时间
|
||||
required:
|
||||
- id
|
||||
- source_folder_id
|
||||
- target_folder_id
|
||||
- mount_name
|
||||
- created_at
|
||||
|
||||
MountInfo:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 挂载关系ID
|
||||
source_folder:
|
||||
$ref: '#/components/schemas/FolderBriefResponse'
|
||||
target_folder:
|
||||
$ref: '#/components/schemas/FolderBriefResponse'
|
||||
mount_name:
|
||||
type: string
|
||||
description: 挂载显示名称
|
||||
is_mounted_here:
|
||||
type: boolean
|
||||
description: true表示此文件夹被挂载到target_folder,false表示此文件夹挂载了source_folder
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
description: 挂载时间
|
||||
required:
|
||||
- id
|
||||
- source_folder
|
||||
- target_folder
|
||||
- mount_name
|
||||
- is_mounted_here
|
||||
- created_at
|
||||
|
||||
FolderRequest:
|
||||
description: 文件夹请求结构体
|
||||
type: object
|
||||
@ -349,11 +602,11 @@ components:
|
||||
maxLength: 255
|
||||
description: 文件夹名称
|
||||
example: 测试名称
|
||||
parent_path_id:
|
||||
parent_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 父文件夹ID 若为空则自动创建在用户根目录下
|
||||
example: 1
|
||||
example: null
|
||||
required:
|
||||
- name
|
||||
|
||||
@ -376,11 +629,11 @@ components:
|
||||
description:
|
||||
type: string
|
||||
description: 书签描述
|
||||
parent_path_id:
|
||||
parent_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 父文件夹ID 若为空则自动创建在用户根目录下
|
||||
example: 1
|
||||
example: null
|
||||
required:
|
||||
- name
|
||||
|
||||
@ -395,7 +648,7 @@ components:
|
||||
name:
|
||||
type: string
|
||||
description: 文件夹名称
|
||||
parent_path_id:
|
||||
parent_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 父文件夹ID
|
||||
@ -416,7 +669,6 @@ components:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- parent_path_id
|
||||
- created_at
|
||||
- updated_at
|
||||
- sub_folder_count
|
||||
@ -442,7 +694,7 @@ components:
|
||||
description:
|
||||
type: string
|
||||
description: 书签描述
|
||||
parent_path_id:
|
||||
parent_id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: 父文件夹ID
|
||||
@ -457,7 +709,7 @@ components:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- parent_path_id
|
||||
- parent_id
|
||||
- created_at
|
||||
- updated_at
|
||||
|
6
config/bookmark_cfg.yaml
Normal file
6
config/bookmark_cfg.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
# yaml-language-server: ...
|
||||
package: api
|
||||
generate:
|
||||
gin-server: true
|
||||
models: true
|
||||
output: ./gen/bookmarks/gen.go
|
14
config/model.conf
Normal file
14
config/model.conf
Normal file
@ -0,0 +1,14 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act, eft
|
||||
|
||||
[role_definition]
|
||||
g = _, _
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
|
||||
|
||||
[matchers]
|
||||
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
|
0
config/user.yaml
Normal file
0
config/user.yaml
Normal file
199
config/vfs.yaml
Normal file
199
config/vfs.yaml
Normal file
@ -0,0 +1,199 @@
|
||||
openapi: '3.0.3'
|
||||
info:
|
||||
title: zzyxyz_vfs_api
|
||||
description: 虚拟文件系统API服务
|
||||
version: '1.0'
|
||||
servers:
|
||||
- url: http://localhost:8080/api
|
||||
description: 开发环境
|
||||
- url: https://api.zzyxyz.com/api
|
||||
description: 生产环境
|
||||
tags:
|
||||
- name: vfs
|
||||
description: 虚拟文件系统相关操作
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
|
||||
paths:
|
||||
/vfs/v1/files/{path}:
|
||||
parameters:
|
||||
- name: path
|
||||
in: path
|
||||
required: true
|
||||
description: 文件系统路径,例如 "documents/readme.txt" 或 "services/mysql.service" 或 "folder/"
|
||||
schema:
|
||||
type: string
|
||||
example: "readme.txt"
|
||||
|
||||
get:
|
||||
summary: 读取文件或列出目录
|
||||
description: 获取指定路径的文件内容或目录列表
|
||||
operationId: getVFSNode
|
||||
tags: [vfs]
|
||||
parameters:
|
||||
- name: op
|
||||
in: query
|
||||
required: false
|
||||
description: 操作类型, list表示列出目录内容, 不指定则读取文件内容
|
||||
schema:
|
||||
type: string
|
||||
enum: [list]
|
||||
responses:
|
||||
'200':
|
||||
description: 文件内容或目录列表
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- type: string
|
||||
description: 文件内容
|
||||
- type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/VFSDirectoryEntry'
|
||||
description: 目录条目列表
|
||||
|
||||
'404':
|
||||
description: 路径不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
post:
|
||||
summary: 创建文件或目录
|
||||
description: 创建文件或目录
|
||||
operationId: createVFSNode
|
||||
tags: [vfs]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
description: 文件内容(仅当type为file时有效)
|
||||
responses:
|
||||
'201':
|
||||
description: 创建成功
|
||||
'400':
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
put:
|
||||
summary: 修改文件或修改目录
|
||||
description: 修改/移动/重命名 已存在的 文件/目录
|
||||
operationId: updateVFSNode
|
||||
tags: [vfs]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
new_name:
|
||||
type: string
|
||||
description: 新名称(用于重命名)
|
||||
new_path:
|
||||
type: string
|
||||
description: 新路径(用于移动)
|
||||
content:
|
||||
type: string
|
||||
description: 新内容(用于修改文件内容)
|
||||
anyOf:
|
||||
- required: [new_name]
|
||||
- required: [new_path]
|
||||
- required: [content]
|
||||
responses:
|
||||
'200':
|
||||
description: 操作成功
|
||||
'400':
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
delete:
|
||||
summary: 删除文件或目录
|
||||
description: 删除指定路径的文件或目录
|
||||
operationId: deleteVFSNode
|
||||
tags: [vfs]
|
||||
responses:
|
||||
'204':
|
||||
description: 删除成功
|
||||
'404':
|
||||
description: 路径不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/ServerInternalError'
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
ApiKeyAuth:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: X-VFS-Token
|
||||
responses:
|
||||
ServerInternalError:
|
||||
description: 服务器内部错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
Unauthorized:
|
||||
description: 未授权
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
schemas:
|
||||
VFSDirectoryEntry:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: 条目名称
|
||||
type:
|
||||
type: string
|
||||
enum: [file, directory, service]
|
||||
description: 条目类型
|
||||
modified:
|
||||
type: string
|
||||
format: date-time
|
||||
description: 修改时间
|
||||
permissions:
|
||||
type: string
|
||||
description: 权限信息,如 "rw"
|
||||
required:
|
||||
- name
|
||||
- type
|
||||
- modified
|
||||
|
||||
Error:
|
||||
type: object
|
||||
description: 错误信息
|
||||
properties:
|
||||
errtype:
|
||||
type: string
|
||||
example: "ParameterError"
|
||||
description: 错误类型
|
||||
message:
|
||||
example: "传递的第一个参数错误"
|
||||
type: string
|
||||
description: 错误信息
|
||||
required:
|
||||
- errtype
|
||||
- message
|
@ -3,4 +3,4 @@ package: api
|
||||
generate:
|
||||
gin-server: true
|
||||
models: true
|
||||
output: ./gen/api/gen.go
|
||||
output: ./gen/vfs/gen.go
|
Reference in New Issue
Block a user