feat: 添加同步进度显示和中文界面支持

refactor: 重构同步引擎以支持进度跟踪
style: 更新前端界面为中文
docs: 更新README为中文文档
This commit is contained in:
panw
2026-04-01 10:43:51 +08:00
parent 34944518f0
commit 5eff309a9f
13 changed files with 469 additions and 154 deletions

25
main.go
View File

@@ -101,16 +101,25 @@ func runServer(cfg *config.Config, engine *sync.Engine) error {
// Serve embedded frontend
distFS, err := fs.Sub(webFS, "web/dist")
if err == nil {
// Serve assets
r.StaticFS("/assets", http.FS(distFS))
// SPA fallback - serve index.html for non-API routes
fileServer := http.FileServer(http.FS(distFS))
r.NoRoute(func(c *gin.Context) {
if !strings.HasPrefix(c.Request.URL.Path, "/api") {
data, _ := webFS.ReadFile("web/dist/index.html")
c.Data(http.StatusOK, "text/html; charset=utf-8", data)
} else {
if strings.HasPrefix(c.Request.URL.Path, "/api") {
c.JSON(http.StatusNotFound, gin.H{"error": "Not found"})
return
}
// Try to serve static file first
name := strings.TrimPrefix(c.Request.URL.Path, "/")
if name != "" {
f, err := distFS.Open(name)
if err == nil {
f.Close()
fileServer.ServeHTTP(c.Writer, c.Request)
return
}
}
// SPA fallback - serve index.html
data, _ := webFS.ReadFile("web/dist/index.html")
c.Data(http.StatusOK, "text/html; charset=utf-8", data)
})
}
@@ -124,10 +133,10 @@ func runServer(cfg *config.Config, engine *sync.Engine) error {
protected.GET("/settings", handler.HandleGetSettings)
protected.PUT("/settings", handler.HandleUpdateSettings)
protected.GET("/servers", handler.HandleListServers)
protected.POST("/servers/test", handler.HandleTestConnection)
protected.POST("/servers", handler.HandleCreateServer)
protected.PUT("/servers/:id", handler.HandleUpdateServer)
protected.DELETE("/servers/:id", handler.HandleDeleteServer)
protected.POST("/servers/:id/test", handler.HandleTestConnection)
protected.GET("/servers/:id/repos", handler.HandleListRepos)
protected.POST("/servers/:id/discover", handler.HandleDiscoverRepos)
protected.POST("/servers/:id/sync", handler.HandleSyncServer(engine))