From 251bc10af9c4c4bb1284ad7a262669e8f467f039 Mon Sep 17 00:00:00 2001 From: naiba Date: Sat, 7 Dec 2024 01:18:34 +0800 Subject: [PATCH] feat: v1.1 --- .github/workflows/release.yml | 11 ++++++----- cmd/dashboard/controller/controller.go | 18 +++++++++--------- cmd/dashboard/main.go | 8 +++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b20ba1..e01a2c2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,17 +29,20 @@ jobs: - uses: actions/checkout@v4 + - name: clean cache + run: | + rm -rf cmd/dashboard/*-dist + - uses: robinraju/release-downloader@v1 with: repository: nezhahq/admin-frontend - tag: v1.0.21 + tag: v1.1 fileName: dist.zip latest: true extract: true - name: prepare admin-frontend dists run: | - rm -rf cmd/dashboard/admin-dist mv dist cmd/dashboard/admin-dist - uses: robinraju/release-downloader@v1 @@ -52,20 +55,18 @@ jobs: - name: prepare admin-frontend dists run: | - rm -rf cmd/dashboard/user-dist mv dist cmd/dashboard/user-dist - uses: robinraju/release-downloader@v1 with: repository: hi2shark/nazhua - tag: v0.4.2 + tag: v0.4.3 fileName: dist.zip latest: true extract: true - name: prepare nazhua-frontend dists run: | - rm -rf cmd/dashboard/nazhua-dist mv dist cmd/dashboard/nazhua-dist - name: Fetch IPInfo GeoIP Database diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index d9695c7..6755687 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -23,7 +23,7 @@ import ( "github.com/nezhahq/nezha/service/singleton" ) -func ServeWeb(adminFrontend, userFrontend fs.FS) http.Handler { +func ServeWeb(frontendDist fs.FS) http.Handler { gin.SetMode(gin.ReleaseMode) r := gin.Default() @@ -40,12 +40,12 @@ func ServeWeb(adminFrontend, userFrontend fs.FS) http.Handler { r.Use(waf.Waf) r.Use(recordPath) - routers(r, adminFrontend, userFrontend) + routers(r, frontendDist) return r } -func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) { +func routers(r *gin.Engine, frontendDist fs.FS) { authMiddleware, err := jwt.New(initParams()) if err != nil { log.Fatal("JWT Error:" + err.Error()) @@ -133,7 +133,7 @@ func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) { auth.PATCH("/setting", commonHandler(updateConfig)) - r.NoRoute(fallbackToFrontend(adminFrontend, userFrontend)) + r.NoRoute(fallbackToFrontend(frontendDist)) } func recordPath(c *gin.Context) { @@ -212,7 +212,7 @@ func commonHandler[T any](handler handlerFunc[T]) func(*gin.Context) { } } -func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) { +func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) { checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string) bool { if _, err := os.Stat(path); err == nil { c.File(path) @@ -241,19 +241,19 @@ func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) { if strings.HasPrefix(c.Request.URL.Path, "/dashboard") { stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard") localFilePath := path.Join("admin-dist", stripPath) - if checkLocalFileOrFs(c, adminFrontend, localFilePath) { + if checkLocalFileOrFs(c, frontendDist, localFilePath) { return } - if !checkLocalFileOrFs(c, adminFrontend, "admin-dist/index.html") { + if !checkLocalFileOrFs(c, frontendDist, "admin-dist/index.html") { c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found"))) } return } localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path) - if checkLocalFileOrFs(c, userFrontend, localFilePath) { + if checkLocalFileOrFs(c, frontendDist, localFilePath) { return } - if !checkLocalFileOrFs(c, userFrontend, singleton.Conf.UserTemplate+"/index.html") { + if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.UserTemplate+"/index.html") { c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found"))) } } diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 49680fb..8c561d3 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -34,10 +34,8 @@ type DashboardCliParam struct { var ( dashboardCliParam DashboardCliParam - //go:embed admin-dist - adminFrontend embed.FS - //go:embed user-dist - userFrontend embed.FS + //go:embed *-dist + frontendDist embed.FS ) func initSystem() { @@ -125,7 +123,7 @@ func main() { singleton.NewServiceSentinel(serviceSentinelDispatchBus) grpcHandler := rpc.ServeRPC() - httpHandler := controller.ServeWeb(adminFrontend, userFrontend) + httpHandler := controller.ServeWeb(frontendDist) controller.InitUpgrader() muxHandler := newHTTPandGRPCMux(httpHandler, grpcHandler)