Escape backslashes, drop embed.go, fix CPU counts

Frontend: escape backslashes as well as pipe characters when building Markdown table cells in scan-results-export to avoid breaking table formatting for values containing backslashes.

Remove home/internal/static/embed.go which provided the embedded dist FS and SPA handler (file deleted).

Backend: tighten error handling in home/internal/system/stats.go by capturing the physical CPU count error separately and only setting cachedCPU values when both logical and physical counts succeeded; also removed an unused comment line. These changes prevent incorrect CPU metadata from being cached when one of the syscalls fails.
This commit is contained in:
hhftechnologies 2026-04-04 04:51:20 +05:30
parent e7ed5f0286
commit a6a2505d6e
3 changed files with 3 additions and 74 deletions

View file

@ -72,7 +72,7 @@ export function ScanResultsExport({ result }: ScanResultsExportProps) {
`| CVE ID | Severity | Package | Installed | Fixed In |`,
`|--------|----------|---------|-----------|----------|`,
...result.vulnerabilities.map((v) => {
const ep = (s: string) => s.replace(/\|/g, "\\|");
const ep = (s: string) => s.replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
return `| ${ep(v.id)} | ${ep(v.severity)} | ${ep(v.package)} | ${ep(v.installed_version)} | ${ep(v.fixed_version || "-")} |`;
}),
];

View file

@ -1,70 +0,0 @@
package static
import (
"embed"
"io"
"io/fs"
"net/http"
"path"
"strings"
"time"
)
//go:embed dist/*
var distFS embed.FS
// GetFileSystem returns the embedded filesystem with the dist directory as root
func GetFileSystem() (http.FileSystem, error) {
// Strip the "dist" prefix so files are served from root
fsys, err := fs.Sub(distFS, "dist")
if err != nil {
return nil, err
}
return http.FS(fsys), nil
}
// SPAHandler wraps a http.FileServer to serve index.html for SPA routes
type SPAHandler struct {
staticFS http.FileSystem
fileServer http.Handler
}
func NewSPAHandler(staticFS http.FileSystem) *SPAHandler {
return &SPAHandler{
staticFS: staticFS,
fileServer: http.FileServer(staticFS),
}
}
func (h *SPAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
upath := r.URL.Path
if !strings.HasPrefix(upath, "/") {
upath = "/" + upath
}
upath = path.Clean(upath)
f, err := h.staticFS.Open(upath)
if err == nil {
f.Close()
h.fileServer.ServeHTTP(w, r)
return
}
indexPath := path.Join(upath, "index.html")
f, err = h.staticFS.Open(indexPath)
if err == nil {
f.Close()
h.fileServer.ServeHTTP(w, r)
return
}
// Fall back to index.html for SPA routing (client-side routing)
indexFile, err := h.staticFS.Open("/index.html")
if err != nil {
http.NotFound(w, r)
return
}
defer indexFile.Close()
http.ServeContent(w, r, "index.html", time.Time{}, indexFile.(io.ReadSeeker))
}

View file

@ -70,7 +70,6 @@ func GetStats(ctx context.Context) (*SystemStats, error) {
// Note: 0 interval returns immediate value since last call, which might be 0 on first call
// For a dashboard, we usually want the average over the last second, but that blocks.
// A better approach for an API is to return the value since last call or just immediate.
// Let's use a very short interval for responsiveness, or 0.
cpuPercents, err := cpu.PercentWithContext(ctx, 0, false)
if err != nil {
return nil, err
@ -84,8 +83,8 @@ func GetStats(ctx context.Context) (*SystemStats, error) {
cachedCPUMutex.Lock()
if cachedCPULogical == 0 {
logical, err := cpu.CountsWithContext(ctx, true)
physical, _ := cpu.CountsWithContext(ctx, false)
if err == nil && logical > 0 {
physical, errPhys := cpu.CountsWithContext(ctx, false)
if err == nil && errPhys == nil && logical > 0 {
cachedCPULogical = logical
cachedCPUPhysical = physical
}