43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"dashboard/pkg/jwt"
|
|
"dashboard/routes"
|
|
"dashboard/settings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type FileRoute struct {
|
|
cjwt *jwt.Jwt
|
|
}
|
|
|
|
func NewFileRoute(jwtC settings.JwtConfig) *FileRoute {
|
|
res := new(FileRoute)
|
|
res.cjwt = jwt.New(jwt.WithSalt(jwtC.Salt), jwt.WithExpire(time.Duration(jwtC.Expire)*time.Second))
|
|
return res
|
|
}
|
|
|
|
func (f *FileRoute) AddRoute(r *gin.Engine) {
|
|
// 静态文件服务
|
|
r.Static("/static", "./static")
|
|
r.StaticFile("/", "./static/index.html")
|
|
|
|
r.GET("login", LoginPage)
|
|
|
|
r.POST("/api/login", routes.ErrWapper(UserSignInHandler(f.cjwt)))
|
|
r.POST("/api/logout", UserLogOutHandler)
|
|
|
|
g1 := r.Group("/api")
|
|
g1.Use(routes.ErrWapper(routes.GinJwtAuthor(f.cjwt)))
|
|
{
|
|
g1.GET("/system-info", routes.ErrWapper(SystemInfoHandle))
|
|
g1.POST("/upload", routes.ErrWapper(FileUploadHandle))
|
|
g1.GET("/files", routes.ErrWapper(FileListHandle))
|
|
g1.GET("/download", routes.ErrWapper(FileDownloadHandle))
|
|
}
|
|
|
|
r.GET("/ws/terminal", routes.ErrWapper(routes.GinJwtAuthor(f.cjwt)), routes.ErrWapper(TerminalHandle()))
|
|
}
|