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-07-01 08:53:01 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/message"
|
2022-06-26 11:10:14 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/common"
|
2022-07-11 09:12:50 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/handles"
|
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-30 14:41:55 +00:00
|
|
|
WebDav(r)
|
2022-06-25 13:34:44 +00:00
|
|
|
|
2022-07-11 09:12:50 +00:00
|
|
|
r.GET("/d/*path", middlewares.Down, handles.Down)
|
|
|
|
r.GET("/p/*path", middlewares.Down, handles.Proxy)
|
2022-06-28 10:00:11 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
api := r.Group("/api")
|
|
|
|
auth := api.Group("", middlewares.Auth)
|
2022-07-07 06:19:24 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
api.POST("/auth/login", handles.Login)
|
2022-07-23 12:49:16 +00:00
|
|
|
auth.GET("/me", handles.CurrentUser)
|
|
|
|
auth.POST("/me/update", handles.UpdateCurrent)
|
2022-06-26 11:09:28 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
// no need auth
|
|
|
|
public := api.Group("/public")
|
|
|
|
public.Any("/settings", handles.PublicSettings)
|
|
|
|
|
|
|
|
fs(auth.Group("/fs"))
|
|
|
|
admin(auth.Group("/admin", middlewares.AuthAdmin))
|
|
|
|
}
|
2022-06-26 11:09:28 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
func admin(g *gin.RouterGroup) {
|
|
|
|
meta := g.Group("/meta")
|
2022-07-11 09:12:50 +00:00
|
|
|
meta.GET("/list", handles.ListMetas)
|
2022-07-27 09:41:25 +00:00
|
|
|
meta.GET("/get", handles.GetMeta)
|
2022-07-11 09:12:50 +00:00
|
|
|
meta.POST("/create", handles.CreateMeta)
|
|
|
|
meta.POST("/update", handles.UpdateMeta)
|
|
|
|
meta.POST("/delete", handles.DeleteMeta)
|
2022-06-26 11:36:27 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
user := g.Group("/user")
|
2022-07-11 09:12:50 +00:00
|
|
|
user.GET("/list", handles.ListUsers)
|
2022-07-27 09:41:25 +00:00
|
|
|
user.GET("/get", handles.GetUser)
|
2022-07-11 09:12:50 +00:00
|
|
|
user.POST("/create", handles.CreateUser)
|
|
|
|
user.POST("/update", handles.UpdateUser)
|
|
|
|
user.POST("/delete", handles.DeleteUser)
|
2022-06-26 12:00:36 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
storage := g.Group("/storage")
|
2022-07-11 09:12:50 +00:00
|
|
|
storage.GET("/list", handles.ListStorages)
|
2022-07-18 15:02:14 +00:00
|
|
|
storage.GET("/get", handles.GetStorage)
|
2022-07-11 09:12:50 +00:00
|
|
|
storage.POST("/create", handles.CreateStorage)
|
|
|
|
storage.POST("/update", handles.UpdateStorage)
|
|
|
|
storage.POST("/delete", handles.DeleteStorage)
|
2022-06-26 12:25:02 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
driver := g.Group("/driver")
|
2022-07-11 09:12:50 +00:00
|
|
|
driver.GET("/list", handles.ListDriverItems)
|
|
|
|
driver.GET("/names", handles.ListDriverNames)
|
|
|
|
driver.GET("/items", handles.GetDriverItems)
|
2022-06-27 09:06:10 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
setting := g.Group("/setting")
|
2022-07-11 09:12:50 +00:00
|
|
|
setting.GET("/get", handles.GetSetting)
|
|
|
|
setting.GET("/list", handles.ListSettings)
|
|
|
|
setting.POST("/save", handles.SaveSettings)
|
|
|
|
setting.POST("/delete", handles.DeleteSetting)
|
|
|
|
setting.POST("/reset_token", handles.ResetToken)
|
|
|
|
setting.POST("/set_aria2", handles.SetAria2)
|
2022-06-27 09:06:10 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
task := g.Group("/task")
|
2022-07-11 09:12:50 +00:00
|
|
|
task.GET("/down/undone", handles.UndoneDownTask)
|
|
|
|
task.GET("/down/done", handles.DoneDownTask)
|
|
|
|
task.POST("/down/cancel", handles.CancelDownTask)
|
2022-07-31 13:42:01 +00:00
|
|
|
task.POST("/down/delete", handles.DeleteDownTask)
|
2022-07-31 13:21:54 +00:00
|
|
|
task.POST("/down/clear_done", handles.ClearDoneDownTasks)
|
2022-07-11 09:12:50 +00:00
|
|
|
task.GET("/transfer/undone", handles.UndoneTransferTask)
|
|
|
|
task.GET("/transfer/done", handles.DoneTransferTask)
|
|
|
|
task.POST("/transfer/cancel", handles.CancelTransferTask)
|
2022-07-31 13:42:01 +00:00
|
|
|
task.POST("/transfer/delete", handles.DeleteTransferTask)
|
2022-07-31 13:21:54 +00:00
|
|
|
task.POST("/transfer/clear_done", handles.ClearDoneTransferTasks)
|
2022-07-11 09:12:50 +00:00
|
|
|
task.GET("/upload/undone", handles.UndoneUploadTask)
|
|
|
|
task.GET("/upload/done", handles.DoneUploadTask)
|
|
|
|
task.POST("/upload/cancel", handles.CancelUploadTask)
|
2022-07-31 13:42:01 +00:00
|
|
|
task.POST("/upload/delete", handles.DeleteUploadTask)
|
2022-07-31 13:21:54 +00:00
|
|
|
task.POST("/upload/clear_done", handles.ClearDoneUploadTasks)
|
2022-07-11 09:12:50 +00:00
|
|
|
task.GET("/copy/undone", handles.UndoneCopyTask)
|
|
|
|
task.GET("/copy/done", handles.DoneCopyTask)
|
|
|
|
task.POST("/copy/cancel", handles.CancelCopyTask)
|
2022-07-31 13:42:01 +00:00
|
|
|
task.POST("/copy/delete", handles.DeleteCopyTask)
|
2022-07-31 13:21:54 +00:00
|
|
|
task.POST("/copy/clear_done", handles.ClearDoneCopyTasks)
|
2022-06-29 10:36:14 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
ms := g.Group("/message")
|
2022-07-01 08:53:01 +00:00
|
|
|
ms.GET("/get", message.PostInstance.GetHandle)
|
|
|
|
ms.POST("/send", message.PostInstance.SendHandle)
|
2022-07-23 12:42:12 +00:00
|
|
|
}
|
2022-07-01 08:53:01 +00:00
|
|
|
|
2022-07-23 12:42:12 +00:00
|
|
|
func fs(g *gin.RouterGroup) {
|
|
|
|
g.Any("/list", handles.FsList)
|
|
|
|
g.Any("/get", handles.FsGet)
|
|
|
|
g.Any("/dirs", handles.FsDirs)
|
|
|
|
g.POST("/mkdir", handles.FsMkdir)
|
|
|
|
g.POST("/rename", handles.FsRename)
|
|
|
|
g.POST("/move", handles.FsMove)
|
|
|
|
g.POST("/copy", handles.FsCopy)
|
|
|
|
g.POST("/remove", handles.FsRemove)
|
|
|
|
g.POST("/put", handles.FsPut)
|
|
|
|
g.POST("/link", middlewares.AuthAdmin, handles.Link)
|
|
|
|
g.POST("/add_aria2", handles.AddAria2)
|
2022-06-25 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Cors(r *gin.Engine) {
|
|
|
|
config := cors.DefaultConfig()
|
|
|
|
config.AllowAllOrigins = true
|
2022-07-01 09:11:22 +00:00
|
|
|
config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range", "File-Path", "As-Task")
|
2022-06-25 12:38:02 +00:00
|
|
|
r.Use(cors.New(config))
|
|
|
|
}
|