Files
OpenList/server/router.go

34 lines
902 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())
2020-12-24 15:21:49 +08:00
engine.Use(static.Serve("/",static.LocalFile(conf.Conf.Server.Static,false)))
engine.NoRoute(func(c *gin.Context) {
c.File(conf.Conf.Server.Static+"/index.html")
})
2021-02-04 10:02:34 +08:00
InitApiRouter(engine)
}
// init api router
func InitApiRouter(engine *gin.Engine) {
2020-12-24 15:21:49 +08:00
v2:=engine.Group("/api")
2020-12-24 01:39:45 +08:00
{
2020-12-29 13:37:58 +08:00
v2.GET("/info",controllers.Info)
v2.POST("/get",controllers.Get)
v2.POST("/list",controllers.List)
v2.POST("/search",controllers.Search)
2021-01-19 17:20:14 +08:00
v2.POST("/office_preview",controllers.OfficePreview)
2020-12-24 01:39:45 +08:00
}
2020-12-29 13:37:58 +08:00
engine.GET("/d/*file_id",controllers.Down)
engine.GET("/cache/:password",controllers.RefreshCache)
2020-12-24 01:39:45 +08:00
}