Files
zzyxyz_go_api/magefile.go
zzy 429a863b76 feat(bookmark): 添加 Authorization 请求头支持
为 CORS 配置添加 `Authorization` 请求头,以支持携带认证信息的跨域请求。

feat(user-np): 改进错误信息和用户注册流程

- 在注册 VFS 服务失败时返回更详细的错误信息,包括状态码和响应体内容。
- 用户创建失败时返回具体的错误详情,并确保数据库记录被正确回滚。
- 注销用户时先尝试删除 VFS 服务中的相关资源,再执行数据库删除操作。
- 使用 `Unscoped().Delete()` 确保物理删除用户数据。

feat(vfs): 完善用户目录结构及节点创建逻辑

- 创建用户主目录 `/home/username` 及其子目录 `.Recycle_Bin`。
- 调整 `CreateVFSNode` 方法参数类型为值传递。
- 修复创建用户目录时传参不一致的问题。
- 删除用户时递归清理其在 VFS 中的所有节点,并通过代理删除关联的服务节点。

feat(mage): 新增生成 TypeScript 类型定义的任务

新增 `Gen_TS` Mage 任务用于将 OpenAPI 配置文件转换为 TypeScript 类型定义文件,
支持 `vfs`、`bookmark` 和 `user_np` 模块。
2025-09-28 12:28:22 +08:00

104 lines
2.7 KiB
Go

//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"os/exec"
// mg contains helpful utility functions, like Deps
)
//go:generate go tool oapi-codegen -config config/bookmark/client.yaml config/bookmark/bookmark.yaml
//go:generate go tool oapi-codegen -config config/bookmark/server.yaml config/bookmark/bookmark.yaml
//go:generate go tool oapi-codegen -config config/vfs/server.yaml config/vfs/vfs.yaml
//go:generate go tool oapi-codegen -config config/vfs/client.yaml config/vfs/vfs.yaml
//go:generate go tool oapi-codegen -config config/user_np/server.yaml config/user_np/user_np.yaml
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
func Build_All() error {
services := []struct {
Name string
Path string
}{
{"vfs_api", "."},
{"bookmark", "./cmd/bookmark"},
}
platforms := []struct {
OS string
Arch string
}{
{"linux", "amd64"},
{"windows", "amd64"},
}
for _, service := range services {
for _, p := range platforms {
fmt.Printf("Building service %s for %s/%s...\n", service.Name, p.OS, p.Arch)
// 设置环境变量
env := append(os.Environ(),
fmt.Sprintf("GOOS=%s", p.OS),
fmt.Sprintf("GOARCH=%s", p.Arch))
// 确定输出名称
outputName := fmt.Sprintf("./bin/%s/%s-%s-%s", p.OS, service.Name, p.OS, p.Arch)
if p.OS == "windows" {
outputName += ".exe"
}
// // 执行构建命令
// cmd := exec.Command("go", "build", "-o", outputName, service.Path)
// cmd.Env = env
// 使用 release 模式构建并显示链接信息
cmd := exec.Command("go", "build",
"-ldflags", "-s -w -extldflags -static", // 去除调试信息,减小体积
"-o", outputName,
service.Path)
cmd.Env = env
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to build %s: %w", service.Name, err)
}
}
}
return nil
}
func Gen_TS() error {
// 创建输出目录
if err := os.MkdirAll("./bin/ts", 0755); err != nil {
return fmt.Errorf("failed to create output directory: %w", err)
}
// 定义需要生成 TypeScript 类型的配置
configs := []struct {
Input string
Output string
}{
{"config/vfs/vfs.yaml", "bin/ts/vfs.ts"},
{"config/bookmark/bookmark.yaml", "bin/ts/bookmark.ts"},
{"config/user_np/user_np.yaml", "bin/ts/user_np.ts"},
}
// 为每个配置生成 TypeScript 类型文件
for _, cfg := range configs {
fmt.Printf("Generating TypeScript types for %s -> %s\n", cfg.Input, cfg.Output)
cmd := exec.Command("openapi-typescript",
cfg.Input, "--output", cfg.Output)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to generate TypeScript types for %s: %w", cfg.Input, err)
}
}
return nil
}