liuyuqi-cnb 2 months ago
parent
commit
50d10defec
2 changed files with 62 additions and 0 deletions
  1. 37 0
      README.md
  2. 25 0
      back-go/service/service.go

+ 37 - 0
README.md

@@ -120,3 +120,40 @@ go run cmd/filecloud.go
 - [filecloud](https://github.com/yddeng/filecloud)
 - [CasaOS](https://github.com/IceWhaleTech/CasaOS)
 - [gogs](https://github.com/gogs/gogs)
+
+## 📦 打包与部署说明
+
+### 目录结构
+
+- `public/`  前端静态资源目录(Vue 打包产物)
+- `data/`    数据库存储目录(如 data/filecloud.db)
+- `conf/`    配置文件目录(如 conf/config.toml)
+
+### 前端打包部署
+
+1. 进入 `front-vue/` 目录,执行 `npm run build` 或 `yarn build`,生成静态文件到 `dist/` 目录。
+2. 将生成的静态文件复制到 `back-go/public/` 目录,或在配置文件中指定 `WebIndex` 路径。
+
+### 后端运行
+
+```bash
+cd back-go
+# 运行
+make run
+# 或直接 go run
+cd cmd && go run filecloud.go
+```
+
+### Swagger API 文档
+
+- 访问地址:http://localhost:8080/swagger/index.html
+- 可在线调试所有后端 API。
+
+### 数据库与配置
+
+- SQLite 数据库文件自动保存在 `back-go/data/filecloud.db`
+- 配置文件默认读取 `back-go/config.toml` 或通过 `-file` 参数指定
+
+---
+
+如需自定义部署、Docker 打包等,请参考本仓库的 Dockerfile 和 docker-compose.yml。

+ 25 - 0
back-go/service/service.go

@@ -10,6 +10,10 @@ import (
 	"strings"
 	"sync"
 	"time"
+	"github.com/swaggo/gin-swagger"
+	ginSwaggerFiles "github.com/swaggo/files"
+	"filecloud/docs"
+	"filecloud/internal/handler"
 )
 
 var (
@@ -23,6 +27,13 @@ func Launch() {
 	// 初始化任务队列
 	logger.Info("Task queue initialized")
 
+	// 初始化 Swagger 信息
+	docs.SwaggerInfo.Title = "FileCloud API"
+	docs.SwaggerInfo.Description = "FileCloud API documentation"
+	docs.SwaggerInfo.Version = "1.0"
+	docs.SwaggerInfo.BasePath = "/api"
+	docs.SwaggerInfo.Host = config.WebAddr
+
 	app = gin.New()
 	app.Use(gin.Logger(), gin.Recovery())
 
@@ -54,8 +65,17 @@ func Launch() {
 		app.NoRoute(func(ctx *gin.Context) {
 			ctx.File(config.WebIndex + "/index.html")
 		})
+	} else {
+		// 使用内置的 public 目录
+		app.Use(static.Serve("/", static.LocalFile("public", false)))
+		app.NoRoute(func(ctx *gin.Context) {
+			ctx.File("public/index.html")
+		})
 	}
 
+	// 注册 Swagger 路由
+	app.GET("/swagger/*any", ginSwagger.WrapHandler(ginSwaggerFiles.Handler))
+
 	initHandler(app)
 
 	port := strings.Split(config.WebAddr, ":")[1]
@@ -254,4 +274,9 @@ func initHandler(app *gin.Engine) {
 	taskHandle := new(taskHandler)
 	fileGroup := app.Group("/file")
 	fileGroup.GET("/task", WarpHandle(taskHandle.taskInfo))
+
+	// 注册文件相关 API
+	apiGroup := app.Group("/api/files")
+	apiGroup.POST("", handler.UploadFile)
+	apiGroup.GET("", handler.ListFiles)
 }