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 系统监控等相关依赖。 ```
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Bookmark 书签结构体
|
|
type Bookmark struct {
|
|
ID int64 `json:"id" gorm:"primaryKey"`
|
|
Name string `json:"name" gorm:"not null;index;size:255"`
|
|
Link *string `json:"link" gorm:"type:url"`
|
|
Detail *string `json:"detail" gorm:"type:text"`
|
|
Description *string `json:"description" gorm:"type:text"`
|
|
ParentID int64 `json:"parent_id" gorm:"not null;index"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
}
|
|
|
|
// Folder 文件夹结构体
|
|
type Folder struct {
|
|
ID int64 `json:"id" gorm:"primaryKey"`
|
|
Name string `json:"name" gorm:"not null;index;size:255"`
|
|
ParentID *int64 `json:"parent_id" gorm:"index"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
}
|
|
|
|
// IsValidParent 检查父文件夹ID是否有效
|
|
func (f *Folder) IsValidParent(db *gorm.DB, parentID int64) bool {
|
|
// 检查父文件夹是否存在且未被删除
|
|
if err := db.Where("id = ?", parentID).First(&Folder{}).Error; err != nil {
|
|
return false
|
|
}
|
|
|
|
// 防止循环引用(不能将文件夹设置为自己的子文件夹)
|
|
if parentID == f.ID {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// IsValidParent 检查书签的父文件夹ID是否有效
|
|
func (b *Bookmark) IsValidParent(db *gorm.DB, parentID int64) bool {
|
|
// 检查父文件夹是否存在且未被删除
|
|
if err := db.Where("id = ?", parentID).First(&Folder{}).Error; err != nil {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|