e2af482cc9
- Implement FileHandler with CRUD operations for files/directories - Add FileService with business logic and SHA-256 hashing - Create LocalStorage backend for filesystem persistence - Add database repository with pagination and name uniqueness constraints - Configure max upload size in storage settings - Include comprehensive tests for all layers
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/dhao2001/mygo/internal/app"
|
|
"github.com/dhao2001/mygo/internal/handler"
|
|
"github.com/dhao2001/mygo/internal/middleware"
|
|
)
|
|
|
|
func setupProtectedRoutes(rg *gin.RouterGroup, webApp *app.WebApp) {
|
|
jwtSecret := []byte(webApp.Config.JWT.Secret)
|
|
accountHandler := handler.NewAccountHandler(webApp.AuthService)
|
|
fileHandler := handler.NewFileHandler(webApp.FileService)
|
|
|
|
rg.Use(middleware.AuthRequired(jwtSecret))
|
|
|
|
account := rg.Group("/account")
|
|
{
|
|
account.GET("", accountHandler.GetAccount)
|
|
|
|
passkeys := account.Group("/passkeys")
|
|
{
|
|
passkeys.GET("", accountHandler.ListPasskeys)
|
|
passkeys.POST("", accountHandler.CreatePasskey)
|
|
passkeys.DELETE("/:id", accountHandler.RevokePasskey)
|
|
}
|
|
}
|
|
|
|
files := rg.Group("/files")
|
|
{
|
|
files.GET("", fileHandler.List)
|
|
files.POST("", fileHandler.Upload)
|
|
files.GET("/:id", fileHandler.Get)
|
|
files.GET("/:id/content", fileHandler.Download)
|
|
files.PUT("/:id", fileHandler.Update)
|
|
files.DELETE("/:id", fileHandler.Delete)
|
|
}
|
|
}
|