Refactor(frontend): Refactor frontend using Lit

Refactor(database): use gorm+sqlite instead of bbolt
Feat: Add delete short link functionality
Fix: Load correct configuration template during meta config conversion
This commit is contained in:
2025-10-19 03:13:10 +11:00
parent 1e8a79c2d2
commit 86b74f30e7
33 changed files with 3612 additions and 1064 deletions

View File

@@ -2,46 +2,31 @@ package server
import (
"embed"
"html/template"
"log"
"net/http"
"github.com/bestnite/sub2clash/config"
"github.com/bestnite/sub2clash/constant"
"github.com/bestnite/sub2clash/server/handler"
"github.com/bestnite/sub2clash/server/middleware"
"github.com/gin-gonic/gin"
)
//go:embed static
//go:embed frontend/dist
var staticFiles embed.FS
func SetRoute(r *gin.Engine) {
tpl, err := template.ParseFS(staticFiles, "static/*")
if err != nil {
log.Fatalf("Error parsing templates: %v", err)
}
r.SetHTMLTemplate(tpl)
r.GET(
"/static/*filepath", func(c *gin.Context) {
c.FileFromFS("static/"+c.Param("filepath"), http.FS(staticFiles))
},
)
r.GET(
"/", func(c *gin.Context) {
version := constant.Version
c.HTML(
200, "index.html", gin.H{
"Version": version,
},
)
},
)
r.GET("/convert/:config", middleware.ZapLogger(), handler.ConvertHandler(config.GlobalConfig.ClashTemplate))
r.GET("/s/:hash", middleware.ZapLogger(), handler.GetRawConfHandler)
r.GET("/convert/:config", middleware.ZapLogger(), handler.ConvertHandler())
r.GET("/s/:id", middleware.ZapLogger(), handler.GetRawConfHandler)
r.POST("/short", middleware.ZapLogger(), handler.GenerateLinkHandler)
r.PUT("/short", middleware.ZapLogger(), handler.UpdateLinkHandler)
r.GET("/short", middleware.ZapLogger(), handler.GetRawConfUriHandler)
r.GET("/short/:id", middleware.ZapLogger(), handler.GetRawConfUriHandler)
r.DELETE("/short/:id", middleware.ZapLogger(), handler.DeleteShortLinkHandler)
r.GET("/", func(c *gin.Context) {
c.FileFromFS("frontend/dist/", http.FS(staticFiles))
})
r.GET(
"/assets/*filepath", func(c *gin.Context) {
c.FileFromFS("frontend/dist/assets/"+c.Param("filepath"), http.FS(staticFiles))
},
)
}