2022-06-06 14:08:39 +00:00
|
|
|
package server
|
2022-06-25 12:38:02 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-25 13:34:44 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
2022-06-26 11:10:14 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/common"
|
2022-06-26 11:20:19 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/controllers"
|
2022-06-26 11:10:14 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/middlewares"
|
2022-06-25 12:38:02 +00:00
|
|
|
"github.com/gin-contrib/cors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Init(r *gin.Engine) {
|
2022-06-25 13:34:44 +00:00
|
|
|
common.SecretKey = []byte(conf.Conf.JwtSecret)
|
2022-06-25 12:38:02 +00:00
|
|
|
Cors(r)
|
2022-06-25 13:34:44 +00:00
|
|
|
|
2022-06-26 08:39:02 +00:00
|
|
|
api := r.Group("/api", middlewares.Auth)
|
2022-06-26 11:20:19 +00:00
|
|
|
api.POST("/auth/login", controllers.Login)
|
|
|
|
api.GET("/auth/current", controllers.CurrentUser)
|
2022-06-26 11:09:28 +00:00
|
|
|
|
|
|
|
admin := api.Group("/admin", middlewares.AuthAdmin)
|
|
|
|
|
|
|
|
meta := admin.Group("/meta")
|
2022-06-26 11:20:19 +00:00
|
|
|
meta.GET("/list", controllers.ListMetas)
|
|
|
|
meta.POST("/create", controllers.CreateMeta)
|
|
|
|
meta.POST("/update", controllers.UpdateMeta)
|
|
|
|
meta.POST("/delete", controllers.DeleteMeta)
|
2022-06-26 11:36:27 +00:00
|
|
|
|
|
|
|
user := admin.Group("/user")
|
|
|
|
user.GET("/list", controllers.ListUsers)
|
|
|
|
user.POST("/create", controllers.CreateUser)
|
|
|
|
user.POST("/update", controllers.UpdateUser)
|
|
|
|
user.POST("/delete", controllers.DeleteUser)
|
2022-06-26 12:00:36 +00:00
|
|
|
|
|
|
|
account := admin.Group("/account")
|
|
|
|
account.GET("/list", controllers.ListAccounts)
|
|
|
|
account.POST("/create", controllers.CreateAccount)
|
|
|
|
account.POST("/update", controllers.UpdateAccount)
|
|
|
|
account.POST("/delete", controllers.DeleteAccount)
|
2022-06-26 12:25:02 +00:00
|
|
|
|
|
|
|
driver := admin.Group("/driver")
|
|
|
|
driver.GET("/list", controllers.ListDriverItems)
|
|
|
|
driver.GET("/names", controllers.ListDriverNames)
|
|
|
|
driver.GET("/items", controllers.GetDriverItems)
|
2022-06-27 09:06:10 +00:00
|
|
|
|
|
|
|
setting := admin.Group("/setting")
|
2022-06-28 06:18:10 +00:00
|
|
|
setting.GET("/get", controllers.GetSetting)
|
2022-06-27 09:06:10 +00:00
|
|
|
setting.GET("/list", controllers.ListSettings)
|
|
|
|
setting.POST("/save", controllers.SaveSettings)
|
|
|
|
setting.POST("/delete", controllers.DeleteSetting)
|
2022-06-28 06:18:10 +00:00
|
|
|
setting.POST("/reset_token", controllers.ResetToken)
|
2022-06-27 09:06:10 +00:00
|
|
|
|
|
|
|
public := api.Group("/public")
|
|
|
|
public.GET("/settings", controllers.PublicSettings)
|
2022-06-28 06:18:10 +00:00
|
|
|
public.Any("/list", controllers.FsList)
|
2022-06-28 07:12:40 +00:00
|
|
|
public.Any("/get", controllers.FsGet)
|
2022-06-25 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Cors(r *gin.Engine) {
|
|
|
|
config := cors.DefaultConfig()
|
|
|
|
config.AllowAllOrigins = true
|
|
|
|
config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range")
|
|
|
|
r.Use(cors.New(config))
|
|
|
|
}
|