teldrive/api/router.go

81 lines
2.8 KiB
Go
Raw Permalink Normal View History

2023-12-03 03:47:23 +08:00
package api
import (
"github.com/gin-gonic/gin"
2024-08-31 23:50:17 +08:00
"github.com/tgdrive/teldrive/internal/cache"
"github.com/tgdrive/teldrive/internal/config"
"github.com/tgdrive/teldrive/internal/middleware"
"github.com/tgdrive/teldrive/pkg/controller"
"github.com/tgdrive/teldrive/ui"
"gorm.io/gorm"
2023-12-03 03:47:23 +08:00
)
2024-07-26 23:50:26 +08:00
func InitRouter(r *gin.Engine, c *controller.Controller, cnf *config.Config, db *gorm.DB, cache cache.Cacher) *gin.Engine {
authmiddleware := middleware.Authmiddleware(cnf.JWT.Secret, db, cache)
2023-12-03 03:47:23 +08:00
api := r.Group("/api")
{
auth := api.Group("/auth")
{
auth.GET("/session", c.GetSession)
auth.POST("/login", c.LogIn)
auth.POST("/logout", authmiddleware, c.Logout)
2023-12-03 03:47:23 +08:00
auth.GET("/ws", c.HandleMultipleLogin)
}
files := api.Group("/files")
{
files.GET("", authmiddleware, c.ListFiles)
files.POST("", authmiddleware, c.CreateFile)
files.GET(":fileID", authmiddleware, c.GetFileByID)
files.PATCH(":fileID", authmiddleware, c.UpdateFile)
2023-12-03 03:47:23 +08:00
files.HEAD(":fileID/stream/:fileName", c.GetFileStream)
files.GET(":fileID/stream/:fileName", c.GetFileStream)
2024-06-22 20:29:59 +08:00
files.HEAD(":fileID/download/:fileName", c.GetFileDownload)
files.GET(":fileID/download/:fileName", c.GetFileDownload)
files.PUT(":fileID/parts", authmiddleware, c.UpdateParts)
2024-09-15 02:00:32 +08:00
files.POST(":fileID/share", authmiddleware, c.CreateShare)
files.GET(":fileID/share", authmiddleware, c.GetShareByFileId)
files.PATCH(":fileID/share", authmiddleware, c.EditShare)
files.DELETE(":fileID/share", authmiddleware, c.DeleteShare)
2024-04-19 04:46:47 +08:00
files.GET("/category/stats", authmiddleware, c.GetCategoryStats)
files.POST("/move", authmiddleware, c.MoveFiles)
files.POST("/directories", authmiddleware, c.MakeDirectory)
files.POST("/delete", authmiddleware, c.DeleteFiles)
files.POST("/copy", authmiddleware, c.CopyFile)
files.POST("/directories/move", authmiddleware, c.MoveDirectory)
2023-12-03 03:47:23 +08:00
}
uploads := api.Group("/uploads")
{
uploads.Use(authmiddleware)
2024-04-19 04:46:47 +08:00
uploads.GET("/stats", c.UploadStats)
2024-09-15 02:00:32 +08:00
uploads.GET("/:id", c.GetUploadFileById)
uploads.POST("/:id", c.UploadFile)
uploads.DELETE("/:id", c.DeleteUploadFile)
2023-12-03 03:47:23 +08:00
}
users := api.Group("/users")
{
users.Use(authmiddleware)
2023-12-03 03:47:23 +08:00
users.GET("/profile", c.GetProfilePhoto)
2023-12-03 05:46:53 +08:00
users.GET("/stats", c.GetStats)
2023-12-03 03:47:23 +08:00
users.GET("/channels", c.ListChannels)
2024-06-11 00:16:41 +08:00
users.GET("/sessions", c.ListSessions)
2023-12-03 03:47:23 +08:00
users.PATCH("/channels", c.UpdateChannel)
users.POST("/bots", c.AddBots)
users.DELETE("/bots", c.RemoveBots)
2024-06-11 00:16:41 +08:00
users.DELETE("/sessions/:id", c.RemoveSession)
2023-12-03 03:47:23 +08:00
}
2024-09-15 02:00:32 +08:00
share := api.Group("/share")
{
share.GET("/:shareID", c.GetShareById)
share.GET("/:shareID/files", c.ListShareFiles)
share.GET("/:shareID/files/:fileID/stream/:fileName", c.StreamSharedFile)
share.GET("/:shareID/files/:fileID/download/:fileName", c.StreamSharedFile)
share.POST("/:shareID/unlock", c.ShareUnlock)
}
2023-12-03 03:47:23 +08:00
}
2023-12-03 03:51:21 +08:00
2023-12-03 03:47:23 +08:00
ui.AddRoutes(r)
return r
}