初始提交:短剧库源码(含转码优化 ultrafast)

This commit is contained in:
yvan
2026-09-17 19:09:08 +08:00
commit 07dc0f1059
247 changed files with 43242 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
package app
import (
"crypto/sha256"
"fmt"
"net/http"
"strings"
"juku/internal/webui"
)
var uiHTML = webui.HTML
func webAssets() http.Handler {
tags := map[string]string{}
entries, _ := webui.Assets.ReadDir(".")
for _, entry := range entries {
if entry.IsDir() {
continue
}
body, err := webui.Assets.ReadFile(entry.Name())
if err == nil {
tags["/assets/"+entry.Name()] = fmt.Sprintf(`"%x"`, sha256.Sum256(body))
}
}
files := http.StripPrefix("/assets/", http.FileServer(http.FS(webui.Assets)))
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Cache-Control", "no-cache")
if tag := tags[request.URL.Path]; tag != "" {
writer.Header().Set("ETag", tag)
if request.Method == http.MethodGet || request.Method == http.MethodHead {
for _, candidate := range strings.Split(request.Header.Get("If-None-Match"), ",") {
candidate = strings.TrimPrefix(strings.TrimSpace(candidate), "W/")
if candidate == tag || candidate == "*" {
writer.WriteHeader(http.StatusNotModified)
return
}
}
}
}
files.ServeHTTP(writer, request)
})
}