Files
OpenList/server/router.go

36 lines
1000 B
Go
Raw Normal View History

2020-12-24 01:39:45 +08:00
package server
2020-12-24 15:21:49 +08:00
import (
"github.com/Xhofe/alist/conf"
2020-12-29 13:37:58 +08:00
"github.com/Xhofe/alist/server/controllers"
2020-12-24 15:21:49 +08:00
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
2020-12-26 18:11:17 +08:00
log "github.com/sirupsen/logrus"
2020-12-24 15:21:49 +08:00
)
2020-12-24 01:39:45 +08:00
2021-02-04 10:02:34 +08:00
// init router
2020-12-24 01:39:45 +08:00
func InitRouter(engine *gin.Engine) {
2020-12-26 18:11:17 +08:00
log.Infof("初始化路由...")
2021-02-04 10:02:34 +08:00
engine.Use(CorsHandler())
2021-03-05 21:25:44 +08:00
engine.Use(static.Serve("/", static.LocalFile(conf.Conf.Server.Static, false)))
2020-12-24 15:21:49 +08:00
engine.NoRoute(func(c *gin.Context) {
2021-03-05 21:25:44 +08:00
c.File(conf.Conf.Server.Static + "/index.html")
2020-12-24 15:21:49 +08:00
})
2021-02-04 10:02:34 +08:00
InitApiRouter(engine)
}
// init api router
func InitApiRouter(engine *gin.Engine) {
2021-03-05 21:25:44 +08:00
apiV2 := engine.Group("/api")
2021-03-05 21:07:45 +08:00
{
2021-03-07 21:02:56 +08:00
apiV2.GET("/info", controllers.Info)
2021-03-12 18:12:56 +08:00
apiV2.POST("/get", controllers.Get)
2021-03-08 20:26:02 +08:00
apiV2.POST("/path", controllers.Path)
2021-03-07 21:02:56 +08:00
apiV2.POST("/office_preview", controllers.OfficePreview)
2021-03-07 21:51:26 +08:00
apiV2.POST("/local_search", controllers.LocalSearch)
apiV2.POST("/global_search", controllers.GlobalSearch)
2021-03-12 18:12:56 +08:00
apiV2.GET("/rebuild/*password", controllers.RebuildTree)
2021-03-05 21:07:45 +08:00
}
2021-03-08 20:26:02 +08:00
engine.GET("/d/*path", controllers.Down)
2021-03-05 21:25:44 +08:00
}