|
@@ -10,6 +10,10 @@ import (
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
|
|
+ "github.com/swaggo/gin-swagger"
|
|
|
|
+ ginSwaggerFiles "github.com/swaggo/files"
|
|
|
|
+ "filecloud/docs"
|
|
|
|
+ "filecloud/internal/handler"
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -23,6 +27,13 @@ func Launch() {
|
|
// 初始化任务队列
|
|
// 初始化任务队列
|
|
logger.Info("Task queue initialized")
|
|
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 = gin.New()
|
|
app.Use(gin.Logger(), gin.Recovery())
|
|
app.Use(gin.Logger(), gin.Recovery())
|
|
|
|
|
|
@@ -54,8 +65,17 @@ func Launch() {
|
|
app.NoRoute(func(ctx *gin.Context) {
|
|
app.NoRoute(func(ctx *gin.Context) {
|
|
ctx.File(config.WebIndex + "/index.html")
|
|
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)
|
|
initHandler(app)
|
|
|
|
|
|
port := strings.Split(config.WebAddr, ":")[1]
|
|
port := strings.Split(config.WebAddr, ":")[1]
|
|
@@ -254,4 +274,9 @@ func initHandler(app *gin.Engine) {
|
|
taskHandle := new(taskHandler)
|
|
taskHandle := new(taskHandler)
|
|
fileGroup := app.Group("/file")
|
|
fileGroup := app.Group("/file")
|
|
fileGroup.GET("/task", WarpHandle(taskHandle.taskInfo))
|
|
fileGroup.GET("/task", WarpHandle(taskHandle.taskInfo))
|
|
|
|
+
|
|
|
|
+ // 注册文件相关 API
|
|
|
|
+ apiGroup := app.Group("/api/files")
|
|
|
|
+ apiGroup.POST("", handler.UploadFile)
|
|
|
|
+ apiGroup.GET("", handler.ListFiles)
|
|
}
|
|
}
|