- 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 顺手格式化
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package fqapi
|
|
|
|
import (
|
|
"fanqie/internal/common"
|
|
"fmt"
|
|
)
|
|
|
|
var categoryFrontLogger = common.NewLogger("category_front", "INFO", "")
|
|
|
|
// HandleCategoryFront 处理获取分类列表,分类列表短缓存 10 分钟
|
|
func HandleCategoryFront(tab interface{}) (string, error) {
|
|
return withCache(fmt.Sprintf("category_front_%v", tab), 600, func() (string, error) {
|
|
return fetchCategoryFront(tab)
|
|
})
|
|
}
|
|
|
|
func fetchCategoryFront(tab interface{}) (string, error) {
|
|
tabInt := ParseIntParam(tab, 0)
|
|
|
|
reqURL := BuildURL(
|
|
"https://reading.snssdk.com/reading/bookapi/new_category/front/v/",
|
|
fmt.Sprintf("new_category_tab=%d", tabInt),
|
|
fmt.Sprintf("update_version_code=%s", "58932"),
|
|
"distinct_style=1",
|
|
)
|
|
|
|
resp, err := GorgonRequest(reqURL, map[string]interface{}{
|
|
"method": "GET",
|
|
"headers": map[string]string{
|
|
"User-Agent": "com.dragon.read",
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
categoryFrontLogger.Error(fmt.Sprintf("获取分类列表失败: %v", err))
|
|
return BuildErrorResponse("请求失败"), err
|
|
}
|
|
|
|
respJSON, err := resp.JSON()
|
|
if err != nil {
|
|
return BuildErrorResponse("解析响应失败"), err
|
|
}
|
|
|
|
if code, ok := respJSON["code"].(float64); ok && code == 0 {
|
|
return resp.Text, nil
|
|
}
|
|
|
|
return BuildErrorResponse("获取失败"), nil
|
|
}
|