Simplify admin publishing pipeline

This commit is contained in:
yarnom 2026-06-03 18:18:50 +08:00
parent 13e7e4026d
commit 9186801c7f
37 changed files with 750 additions and 3367 deletions

View file

@ -46,6 +46,33 @@ func serveAdminFile(c *gin.Context, adminDir string) bool {
return true
}
func serveSiteFile(c *gin.Context, staticDir string) bool {
if strings.TrimSpace(staticDir) == "" {
return false
}
requested := strings.TrimPrefix(c.Request.URL.Path, "/")
if requested == "" {
requested = "index.html"
}
cleaned := filepath.Clean(requested)
if cleaned == "." || strings.HasPrefix(cleaned, "..") || filepath.IsAbs(cleaned) {
return false
}
path := filepath.Join(staticDir, cleaned)
info, err := os.Stat(path)
if err == nil && info.IsDir() {
path = filepath.Join(path, "index.html")
info, err = os.Stat(path)
}
if err != nil || info.IsDir() {
return false
}
http.ServeFile(c.Writer, c.Request, path)
return true
}
func rewriteAdminBase(page []byte) []byte {
return []byte(strings.Replace(string(page), `<base href="/">`, `<base href="/admin/">`, 1))
}