CI / Lint & TypeCheck (push) Canceled after 0s
CI / Test (push) Canceled after 0s
CI / Tauri Foundation Acceptance (push) Canceled after 0s
CI / Build (macos-latest) (push) Canceled after 0s
CI / Build (ubuntu-latest) (push) Canceled after 0s
CI / Build (windows-latest) (push) Canceled after 0s
- apps/server:Gin embed 官网 + /docs + /health + /download(无操作 API) - run.sh 重写 web/gui 场景;.gitignore 排除 server 二进制与挂载的安装包 - README/AGENTS/CLAUDE 同步「浏览器只看官网、操作走桌面」的产品形态说明 - 终端视口背景变量与全宽终端边缘 hairline 修正(serial/terminal/i18n 微调)
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
// Package site 提供产品官网(嵌入 HTML/CSS/JS)。
|
|
package site
|
|
|
|
import (
|
|
"embed"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
//go:embed template.html assets
|
|
var files embed.FS
|
|
|
|
type Handler struct {
|
|
html string
|
|
}
|
|
|
|
func New() *Handler {
|
|
raw, err := files.ReadFile("template.html")
|
|
if err != nil {
|
|
panic("site: template.html 缺失: " + err.Error())
|
|
}
|
|
return &Handler{html: string(raw)}
|
|
}
|
|
|
|
func (h *Handler) Register(r *gin.Engine) {
|
|
r.GET("/", h.Page)
|
|
r.GET("/home", h.Page)
|
|
r.GET("/index.html", h.Page)
|
|
r.GET("/site/assets/*file", h.Asset)
|
|
}
|
|
|
|
func (h *Handler) Page(c *gin.Context) {
|
|
c.Header("Content-Type", "text/html; charset=utf-8")
|
|
c.Header("Cache-Control", "no-cache")
|
|
_, _ = c.Writer.WriteString(h.html)
|
|
}
|
|
|
|
func (h *Handler) Asset(c *gin.Context) {
|
|
name := strings.TrimPrefix(c.Param("file"), "/")
|
|
if strings.Contains(name, "..") {
|
|
c.Status(http.StatusBadRequest)
|
|
return
|
|
}
|
|
data, err := files.ReadFile("assets/" + name)
|
|
if err != nil {
|
|
c.Status(http.StatusNotFound)
|
|
return
|
|
}
|
|
switch {
|
|
case strings.HasSuffix(name, ".css"):
|
|
c.Header("Content-Type", "text/css; charset=utf-8")
|
|
case strings.HasSuffix(name, ".js"):
|
|
c.Header("Content-Type", "application/javascript; charset=utf-8")
|
|
case strings.HasSuffix(name, ".svg"):
|
|
c.Header("Content-Type", "image/svg+xml")
|
|
default:
|
|
c.Header("Content-Type", "application/octet-stream")
|
|
}
|
|
c.Header("Cache-Control", "public, max-age=3600")
|
|
c.Data(http.StatusOK, "", data)
|
|
}
|