- 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 顺手格式化
117 lines
3.0 KiB
Go
117 lines
3.0 KiB
Go
package fqapi
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"fanqie/internal/algos"
|
|
"fanqie/internal/common"
|
|
)
|
|
|
|
// CreateMD5 创建MD5哈希
|
|
func CreateMD5(s string) string {
|
|
hasher := md5.New()
|
|
hasher.Write([]byte(s))
|
|
return hex.EncodeToString(hasher.Sum(nil))
|
|
}
|
|
|
|
// GorgonRequest Gorgon请求(使用签名切换器)
|
|
func GorgonRequest(urlStr string, options map[string]interface{}) (*common.ClientResponse, error) {
|
|
headers, ok := options["headers"].(map[string]string)
|
|
if !ok {
|
|
headers = make(map[string]string)
|
|
options["headers"] = headers
|
|
}
|
|
|
|
dataMD5 := ""
|
|
if body, ok := options["body"].(string); ok && body != "" {
|
|
dataMD5 = CreateMD5(body)
|
|
} else if body, ok := options["body"].([]byte); ok && len(body) > 0 {
|
|
dataMD5 = CreateMD5(string(body))
|
|
}
|
|
|
|
if dataMD5 != "" {
|
|
headers["x-ss-stub"] = dataMD5
|
|
}
|
|
|
|
// 使用签名切换器(sign2 或 sign4)生成签名
|
|
signedHeaders := algos.GlobalSignatureSwitcher.Sign(urlStr, headers)
|
|
|
|
// 更新headers
|
|
for k, v := range signedHeaders {
|
|
headers[k] = v
|
|
}
|
|
|
|
// 调用实际的HTTP请求
|
|
client := common.NewHTTPClient()
|
|
return client.Request(urlStr, options)
|
|
}
|
|
|
|
// GorgonRequestSync Gorgon同步请求(使用签名切换器)
|
|
func GorgonRequestSync(urlStr string, options map[string]interface{}) (*common.ClientResponse, error) {
|
|
headers, ok := options["headers"].(map[string]string)
|
|
if !ok {
|
|
headers = make(map[string]string)
|
|
options["headers"] = headers
|
|
}
|
|
|
|
dataMD5 := ""
|
|
if body, ok := options["body"].(string); ok && body != "" {
|
|
dataMD5 = CreateMD5(body)
|
|
} else if body, ok := options["body"].([]byte); ok && len(body) > 0 {
|
|
dataMD5 = CreateMD5(string(body))
|
|
}
|
|
|
|
if dataMD5 != "" {
|
|
headers["x-ss-stub"] = dataMD5
|
|
}
|
|
|
|
// 使用签名切换器(sign2 或 sign4)生成签名
|
|
signedHeaders := algos.GlobalSignatureSwitcher.Sign(urlStr, headers)
|
|
|
|
// 删除x-ss-stub(如果存在)
|
|
if _, exists := signedHeaders["x-ss-stub"]; exists {
|
|
delete(signedHeaders, "x-ss-stub")
|
|
}
|
|
|
|
// 更新headers
|
|
for k, v := range signedHeaders {
|
|
headers[k] = v
|
|
}
|
|
|
|
// 调用实际的HTTP请求
|
|
client := common.NewHTTPClient()
|
|
return client.Request(urlStr, options)
|
|
}
|
|
|
|
// ContentRequest Content请求(硬编码使用Sign2,不受配置影响)
|
|
func ContentRequest(urlStr string, options map[string]interface{}) (*common.ClientResponse, error) {
|
|
headers, ok := options["headers"].(map[string]string)
|
|
if !ok {
|
|
headers = make(map[string]string)
|
|
options["headers"] = headers
|
|
}
|
|
|
|
dataMD5 := ""
|
|
if body, ok := options["body"].(string); ok && body != "" {
|
|
dataMD5 = CreateMD5(body)
|
|
} else if body, ok := options["body"].([]byte); ok && len(body) > 0 {
|
|
dataMD5 = CreateMD5(string(body))
|
|
}
|
|
|
|
if dataMD5 != "" {
|
|
headers["x-ss-stub"] = dataMD5
|
|
}
|
|
|
|
// 硬编码使用 Sign2(不受配置影响)
|
|
signedHeaders := algos.Sign2Wrapper(urlStr, headers)
|
|
|
|
// 更新headers
|
|
for k, v := range signedHeaders {
|
|
headers[k] = v
|
|
}
|
|
|
|
// 调用实际的HTTP请求
|
|
client := common.NewHTTPClient()
|
|
return client.Request(urlStr, options)
|
|
}
|