Files
chenxin 5bcc8a962e ♻️ refactor(handlers): status 与 review 页面模板化
- HTML 提取至 templates/status.html、templates/review.html(go:embed 内嵌)
- status.go 1022→271 行、review.go 1281→438 行,动态数据全部经 html/template 按上下文自动转义
- 评论循环/作者徽章/贴纸/图片条件渲染翻译为模板 range/if;emojiMap 以 template.JS 注入
- 与旧版渲染输出实测对比:22 条评论结构完全一致;差异仅为 JS 上下文安全转义(& 等)与 html/template 剥除 CSS 注释,均无功能影响
- 其余文件为 gofmt 顺手格式化
2026-09-30 00:25:09 +08:00

44 lines
1.1 KiB
Go

package handlers
import (
"fanqie/internal/fqapi"
"fmt"
"net/http"
"strconv"
"strings"
)
// HandleMangaImageProxy 处理漫画图片代理请求
func HandleMangaImageProxy(w http.ResponseWriter, r *http.Request) {
// 从URL路径提取参数: /manga/image/{itemID}/{index}
path := strings.TrimPrefix(r.URL.Path, "/manga/image/")
parts := strings.Split(path, "/")
if len(parts) != 2 {
http.Error(w, "Invalid URL format. Expected: /manga/image/{itemID}/{index}", http.StatusBadRequest)
return
}
itemID := parts[0]
index, err := strconv.Atoi(parts[1])
if err != nil {
http.Error(w, "Invalid index parameter", http.StatusBadRequest)
return
}
// 获取解密后的图片数据
imageData, mimeType, err := fqapi.HandleMangaImageProxy(itemID, index)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to get image: %s", err.Error()), http.StatusInternalServerError)
return
}
// 设置响应头
w.Header().Set("Content-Type", mimeType)
w.Header().Set("Cache-Control", "public, max-age=3600") // 缓存1小时
w.Header().Set("Content-Length", strconv.Itoa(len(imageData)))
// 返回图片数据
w.Write(imageData)
}