♻️ 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 顺手格式化
This commit is contained in:
1 parent
ad6d28fd85
commit
5bcc8a962e
29 files changed
+1267
-2893
No files matched your search
@@ -20,9 +20,9 @@ func HandleContent(w http.ResponseWriter, r *http.Request) {
|
||||
itemID := params["item_id"]
|
||||
|
||||
// 获取URL参数(支持动态覆盖配置)
|
||||
textMode := r.URL.Query().Get("text_mode") // 1=纯文本模式
|
||||
imageMode := r.URL.Query().Get("image_mode") // 0=移除图片, 1=保留图片
|
||||
reviewParam := r.URL.Query().Get("review") // 1=启用段评, 0=禁用段评
|
||||
textMode := r.URL.Query().Get("text_mode") // 1=纯文本模式
|
||||
imageMode := r.URL.Query().Get("image_mode") // 0=移除图片, 1=保留图片
|
||||
reviewParam := r.URL.Query().Get("review") // 1=启用段评, 0=禁用段评
|
||||
|
||||
result, err := fqapi.HandleGetContent(itemID, textMode, imageMode)
|
||||
if err != nil {
|
||||
@@ -103,19 +103,19 @@ func addReviewToContent(jsonResult, itemID string, r *http.Request) string {
|
||||
if err := fqapi.ParseJSON([]byte(jsonResult), &resultData); err != nil {
|
||||
return jsonResult
|
||||
}
|
||||
|
||||
|
||||
// 获取 data 字段
|
||||
data, ok := resultData["data"].(map[string]interface{})
|
||||
if !ok {
|
||||
return jsonResult
|
||||
}
|
||||
|
||||
|
||||
// 获取 content 字段
|
||||
content, ok := data["content"].(string)
|
||||
if !ok || content == "" {
|
||||
return jsonResult
|
||||
}
|
||||
|
||||
|
||||
// 从响应数据中提取 book_id (data.novel_data.book_id)
|
||||
bookID := ""
|
||||
if novelData, ok := data["novel_data"].(map[string]interface{}); ok {
|
||||
@@ -125,7 +125,7 @@ func addReviewToContent(jsonResult, itemID string, r *http.Request) string {
|
||||
bookID = fmt.Sprintf("%.0f", bookIDVal)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取基础 URL
|
||||
cfg := config.GetConfig()
|
||||
baseURL := ""
|
||||
@@ -136,7 +136,7 @@ func addReviewToContent(jsonResult, itemID string, r *http.Request) string {
|
||||
}
|
||||
port := cfg.Server.Port
|
||||
scheme := "http"
|
||||
|
||||
|
||||
// 检查是否来自外部请求
|
||||
if r.Host != "" {
|
||||
baseURL = scheme + "://" + r.Host
|
||||
@@ -144,24 +144,23 @@ func addReviewToContent(jsonResult, itemID string, r *http.Request) string {
|
||||
baseURL = scheme + "://" + host + ":" + port
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 生成带段评标记的内容
|
||||
newContent, err := fqapi.GenerateParagraphsWithComments(itemID, bookID, content, baseURL)
|
||||
if err != nil {
|
||||
// 如果失败,返回原始内容
|
||||
return jsonResult
|
||||
}
|
||||
|
||||
|
||||
// 替换 content 字段
|
||||
data["content"] = newContent
|
||||
resultData["data"] = data
|
||||
|
||||
|
||||
// 重新序列化为 JSON
|
||||
newJSON, err := fqapi.ToJSON(resultData)
|
||||
if err != nil {
|
||||
return jsonResult
|
||||
}
|
||||
|
||||
|
||||
return newJSON
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user