From a50bb97ab11982274dd2af1f9dbe1f78d62be152 Mon Sep 17 00:00:00 2001 From: likeaturtle Date: Mon, 23 Feb 2026 11:11:19 +0800 Subject: [PATCH] Fixed the issue of External CDN dependencies in embedded HTML, replaced Google Fonts with the system's native font stack, and replaced FontAwesome loaded via CDN with built-in files. --- pkg/channels/websocket/channel.go | 55 ++++++++++ pkg/channels/websocket/chat.html | 96 ++++++++---------- .../websocket/static/css/fontawesome.min.css | 9 ++ .../static/webfonts/fa-brands-400.woff2 | Bin 0 -> 110088 bytes .../static/webfonts/fa-regular-400.woff2 | Bin 0 -> 18924 bytes .../static/webfonts/fa-solid-900.woff2 | Bin 0 -> 114740 bytes .../static/webfonts/fa-v4compatibility.woff2 | Bin 0 -> 4032 bytes 7 files changed, 105 insertions(+), 55 deletions(-) create mode 100644 pkg/channels/websocket/static/css/fontawesome.min.css create mode 100644 pkg/channels/websocket/static/webfonts/fa-brands-400.woff2 create mode 100644 pkg/channels/websocket/static/webfonts/fa-regular-400.woff2 create mode 100644 pkg/channels/websocket/static/webfonts/fa-solid-900.woff2 create mode 100644 pkg/channels/websocket/static/webfonts/fa-v4compatibility.woff2 diff --git a/pkg/channels/websocket/channel.go b/pkg/channels/websocket/channel.go index 1c6288b4b..29084e21f 100644 --- a/pkg/channels/websocket/channel.go +++ b/pkg/channels/websocket/channel.go @@ -27,6 +27,21 @@ var chatHTML []byte //go:embed logo.jpg var logoImage []byte +//go:embed static/css/fontawesome.min.css +var fontawesomeCSS []byte + +//go:embed static/webfonts/fa-brands-400.woff2 +var faBrandsFont []byte + +//go:embed static/webfonts/fa-regular-400.woff2 +var faRegularFont []byte + +//go:embed static/webfonts/fa-solid-900.woff2 +var faSolidFont []byte + +//go:embed static/webfonts/fa-v4compatibility.woff2 +var faV4CompatFont []byte + // clientConn wraps a WebSocket connection with a write mutex for safe concurrent writes type clientConn struct { conn *websocket.Conn @@ -290,6 +305,11 @@ func (c *Channel) Start(ctx context.Context) error { mux.HandleFunc("/ws", c.handleWebSocket) mux.HandleFunc("/", c.handleIndex) mux.HandleFunc("/assets/logo.jpg", c.handleLogo) + mux.HandleFunc("/static/css/fontawesome.min.css", c.handleFontawesomeCSS) + mux.HandleFunc("/static/webfonts/fa-brands-400.woff2", c.handleFaBrandsFont) + mux.HandleFunc("/static/webfonts/fa-regular-400.woff2", c.handleFaRegularFont) + mux.HandleFunc("/static/webfonts/fa-solid-900.woff2", c.handleFaSolidFont) + mux.HandleFunc("/static/webfonts/fa-v4compatibility.woff2", c.handleFaV4CompatFont) addr := fmt.Sprintf("%s:%d", c.config.Host, c.config.Port) c.server = &http.Server{ @@ -626,3 +646,38 @@ func (c *Channel) handleIndex(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Write(chatHTML) } + +// handleFontawesomeCSS serves the FontAwesome CSS file +func (c *Channel) handleFontawesomeCSS(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/css") + w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 1 day + w.Write(fontawesomeCSS) +} + +// handleFaBrandsFont serves the FontAwesome brands font file +func (c *Channel) handleFaBrandsFont(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "font/woff2") + w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 1 day + w.Write(faBrandsFont) +} + +// handleFaRegularFont serves the FontAwesome regular font file +func (c *Channel) handleFaRegularFont(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "font/woff2") + w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 1 day + w.Write(faRegularFont) +} + +// handleFaSolidFont serves the FontAwesome solid font file +func (c *Channel) handleFaSolidFont(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "font/woff2") + w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 1 day + w.Write(faSolidFont) +} + +// handleFaV4CompatFont serves the FontAwesome v4 compatibility font file +func (c *Channel) handleFaV4CompatFont(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "font/woff2") + w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for 1 day + w.Write(faV4CompatFont) +} diff --git a/pkg/channels/websocket/chat.html b/pkg/channels/websocket/chat.html index 2958767e0..da4f1def1 100644 --- a/pkg/channels/websocket/chat.html +++ b/pkg/channels/websocket/chat.html @@ -7,10 +7,7 @@ PicoClaw · Intelligent Conversation - - - - +