♻️ 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
+17
-18
@@ -144,10 +144,10 @@ func decodeVideoModelAsJSON(videoModelStr string) interface{} {
|
||||
// 解析失败,返回空对象
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
|
||||
|
||||
// 构建精简的返回结果,只包含关键字段
|
||||
result := make(map[string]interface{})
|
||||
|
||||
|
||||
// 提取关键字段
|
||||
if videoID, ok := videoModel["video_id"].(string); ok {
|
||||
result["video_id"] = videoID
|
||||
@@ -158,16 +158,16 @@ func decodeVideoModelAsJSON(videoModelStr string) interface{} {
|
||||
if posterURL, ok := videoModel["poster_url"].(string); ok {
|
||||
result["poster_url"] = posterURL
|
||||
}
|
||||
|
||||
|
||||
// 处理 video_list
|
||||
if videoList, ok := videoModel["video_list"].(map[string]interface{}); ok {
|
||||
processedVideoList := make(map[string]interface{})
|
||||
|
||||
|
||||
for quality, qualityData := range videoList {
|
||||
if qualityMap, ok := qualityData.(map[string]interface{}); ok {
|
||||
// 只保留关键字段
|
||||
qualityInfo := make(map[string]interface{})
|
||||
|
||||
|
||||
if definition, ok := qualityMap["definition"].(string); ok {
|
||||
qualityInfo["definition"] = definition
|
||||
}
|
||||
@@ -189,39 +189,39 @@ func decodeVideoModelAsJSON(videoModelStr string) interface{} {
|
||||
if fps, ok := qualityMap["fps"].(float64); ok {
|
||||
qualityInfo["fps"] = int(fps)
|
||||
}
|
||||
|
||||
|
||||
// 解码 main_url
|
||||
if mainURL, ok := qualityMap["main_url"].(string); ok {
|
||||
if decoded, err := base64.StdEncoding.DecodeString(mainURL); err == nil {
|
||||
qualityInfo["main_url"] = string(decoded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 解码 backup_url_1
|
||||
if backupURL, ok := qualityMap["backup_url_1"].(string); ok {
|
||||
if decoded, err := base64.StdEncoding.DecodeString(backupURL); err == nil {
|
||||
qualityInfo["backup_url_1"] = string(decoded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
processedVideoList[quality] = qualityInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result["video_list"] = processedVideoList
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// formatDuration 将秒数转换为可读的时间格式
|
||||
func formatDuration(seconds float64) string {
|
||||
totalSeconds := int(math.Round(seconds))
|
||||
|
||||
|
||||
hours := totalSeconds / 3600
|
||||
minutes := (totalSeconds % 3600) / 60
|
||||
secs := totalSeconds % 60
|
||||
|
||||
|
||||
if hours > 0 {
|
||||
return fmt.Sprintf("%d小时%d分%d秒", hours, minutes, secs)
|
||||
} else if minutes > 0 {
|
||||
@@ -236,17 +236,17 @@ func formatFileSize(bytes float64) string {
|
||||
if bytes < unit {
|
||||
return fmt.Sprintf("%.0f B", bytes)
|
||||
}
|
||||
|
||||
|
||||
kb := bytes / unit
|
||||
if kb < unit {
|
||||
return fmt.Sprintf("%.2f KB", kb)
|
||||
}
|
||||
|
||||
|
||||
mb := kb / unit
|
||||
if mb < unit {
|
||||
return fmt.Sprintf("%.2f MB", mb)
|
||||
}
|
||||
|
||||
|
||||
gb := mb / unit
|
||||
return fmt.Sprintf("%.2f GB", gb)
|
||||
}
|
||||
@@ -255,12 +255,11 @@ func formatFileSize(bytes float64) string {
|
||||
func formatBitrate(bitrate float64) string {
|
||||
const unit = 1000.0
|
||||
kbps := bitrate / unit
|
||||
|
||||
|
||||
if kbps < unit {
|
||||
return fmt.Sprintf("%.0f Kbps", kbps)
|
||||
}
|
||||
|
||||
|
||||
mbps := kbps / unit
|
||||
return fmt.Sprintf("%.2f Mbps", mbps)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user