2021-10-26 14:28:37 +00:00
|
|
|
package server
|
|
|
|
|
2021-10-28 04:37:31 +00:00
|
|
|
import (
|
2021-12-07 07:56:43 +00:00
|
|
|
"github.com/Xhofe/alist/server/common"
|
|
|
|
"github.com/Xhofe/alist/server/controllers"
|
2022-01-08 14:09:27 +00:00
|
|
|
"github.com/Xhofe/alist/server/controllers/file"
|
2021-12-07 07:56:43 +00:00
|
|
|
"github.com/Xhofe/alist/server/middlewares"
|
2021-11-13 07:53:26 +00:00
|
|
|
"github.com/gin-contrib/cors"
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-10-28 04:37:31 +00:00
|
|
|
)
|
2021-10-26 14:28:37 +00:00
|
|
|
|
2021-11-13 07:53:26 +00:00
|
|
|
func InitApiRouter(r *gin.Engine) {
|
2021-10-26 14:28:37 +00:00
|
|
|
|
2021-10-28 04:37:31 +00:00
|
|
|
// TODO from settings
|
2021-11-13 07:53:26 +00:00
|
|
|
Cors(r)
|
2021-12-07 07:56:43 +00:00
|
|
|
r.GET("/d/*path", middlewares.DownCheck, controllers.Down)
|
|
|
|
r.GET("/p/*path", middlewares.DownCheck, controllers.Proxy)
|
2022-02-08 10:07:13 +00:00
|
|
|
r.GET("/favicon.ico", controllers.Favicon)
|
2022-02-16 16:06:10 +00:00
|
|
|
r.GET("/i/:data/ipa.plist", controllers.Plist)
|
2021-10-26 14:28:37 +00:00
|
|
|
|
2021-11-13 07:53:26 +00:00
|
|
|
api := r.Group("/api")
|
2021-10-29 16:35:29 +00:00
|
|
|
public := api.Group("/public")
|
2021-10-26 14:28:37 +00:00
|
|
|
{
|
2021-12-07 07:56:43 +00:00
|
|
|
path := public.Group("", middlewares.PathCheck, middlewares.CheckAccount)
|
|
|
|
path.POST("/path", controllers.Path)
|
|
|
|
path.POST("/preview", controllers.Preview)
|
2021-12-08 02:33:26 +00:00
|
|
|
|
2022-04-08 14:03:26 +00:00
|
|
|
public.POST("/search", controllers.Search)
|
|
|
|
|
2021-12-08 02:33:26 +00:00
|
|
|
//path.POST("/link",middlewares.Auth, controllers.Link)
|
2022-01-08 14:09:27 +00:00
|
|
|
public.POST("/upload", file.UploadFiles)
|
2021-12-07 07:56:43 +00:00
|
|
|
|
|
|
|
public.GET("/settings", controllers.GetSettingsPublic)
|
2021-10-26 14:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 16:35:29 +00:00
|
|
|
admin := api.Group("/admin")
|
2021-10-26 14:28:37 +00:00
|
|
|
{
|
2021-12-07 07:56:43 +00:00
|
|
|
admin.Use(middlewares.Auth)
|
2022-02-22 07:57:39 +00:00
|
|
|
admin.Any("/login", common.Login)
|
2021-12-07 07:56:43 +00:00
|
|
|
admin.GET("/settings", controllers.GetSettings)
|
|
|
|
admin.POST("/settings", controllers.SaveSettings)
|
2021-12-08 11:36:07 +00:00
|
|
|
admin.DELETE("/setting", controllers.DeleteSetting)
|
|
|
|
|
2021-12-07 07:56:43 +00:00
|
|
|
admin.POST("/account/create", controllers.CreateAccount)
|
|
|
|
admin.POST("/account/save", controllers.SaveAccount)
|
|
|
|
admin.GET("/accounts", controllers.GetAccounts)
|
|
|
|
admin.DELETE("/account", controllers.DeleteAccount)
|
|
|
|
admin.GET("/drivers", controllers.GetDrivers)
|
|
|
|
admin.GET("/clear_cache", controllers.ClearCache)
|
|
|
|
|
|
|
|
admin.GET("/metas", controllers.GetMetas)
|
|
|
|
admin.POST("/meta/create", controllers.CreateMeta)
|
|
|
|
admin.POST("/meta/save", controllers.SaveMeta)
|
|
|
|
admin.DELETE("/meta", controllers.DeleteMeta)
|
2021-12-08 02:33:26 +00:00
|
|
|
|
|
|
|
admin.POST("/link", controllers.Link)
|
2022-01-08 14:09:27 +00:00
|
|
|
admin.DELETE("/files", file.DeleteFiles)
|
2022-01-18 06:31:52 +00:00
|
|
|
admin.POST("/mkdir", file.Mkdir)
|
2022-01-18 08:13:07 +00:00
|
|
|
admin.POST("/rename", file.Rename)
|
|
|
|
admin.POST("/move", file.Move)
|
2022-01-26 06:07:51 +00:00
|
|
|
admin.POST("/copy", file.Copy)
|
2022-01-18 11:08:44 +00:00
|
|
|
admin.POST("/folder", file.Folder)
|
2022-02-23 11:16:33 +00:00
|
|
|
admin.POST("/refresh", file.RefreshFolder)
|
2021-10-26 14:28:37 +00:00
|
|
|
}
|
2021-11-27 16:12:04 +00:00
|
|
|
WebDav(r)
|
2021-12-20 15:56:17 +00:00
|
|
|
Static(r)
|
2021-11-13 07:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Cors(r *gin.Engine) {
|
|
|
|
config := cors.DefaultConfig()
|
|
|
|
config.AllowAllOrigins = true
|
2022-01-07 12:28:58 +00:00
|
|
|
config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range")
|
2021-11-13 07:53:26 +00:00
|
|
|
r.Use(cors.New(config))
|
2021-10-26 14:28:37 +00:00
|
|
|
}
|