- 新增 /rank 免签名榜单接口(多域名容错)、/bookshelf 与 /read-history(sessionid 登录态,书架支持分组过滤) - 搜索重写:翻页透传上游 passback/search_id/next_offset/corrected_query 并按 book_id 去重,15~20 位纯数字关键词直查详情(ID 直搜) - 删除 /login/check 登录校验端点(login.go、路由与文档同步移除,sessionid 说明改为直接供书架/历史使用) - 正文链路重构:singleflight 合并同章节并发回源防击穿,缓存与解析解耦统一在出口处理,decodeContentBody 按 crypt_status 分支并兜底 500003 明文 - 缓存层:SQL 持久层 TTL 与业务 TTL 解耦(不可变内容过期后由 SQL 回填),动态短缓存只走 Redis,withCache 合并并发 miss - 密钥池:KeyTs 随正文请求上传降低密钥不匹配重试,密钥超 24 小时异步刷新并防刷新风暴,last_used_at 批量落库 - 签名补 X-Helios(与 X-Ladon 同值,对齐书源实现);设备注册版本号统一走 ClientVersionCode/Name - 分类 landing 透传新版标签 selected_items;multi-detail 批量详情供书架/历史复用 - README 与 openapi.yaml 补充新接口文档
128 lines
3.3 KiB
Go
128 lines
3.3 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))
|
|
}
|
|
|
|
// setCommonHeaders 注入番茄客户端通用请求头(与签名头不冲突,对齐书源实现降低风控特征)
|
|
func setCommonHeaders(headers map[string]string) {
|
|
if _, ok := headers["x-tt-store-region"]; ok {
|
|
return
|
|
}
|
|
headers["x-tt-store-region"] = "cn-zj"
|
|
headers["x-tt-store-region-src"] = "did"
|
|
headers["sdk-version"] = "2"
|
|
}
|
|
|
|
// 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
|
|
}
|
|
setCommonHeaders(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
|
|
}
|
|
setCommonHeaders(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(如果存在)
|
|
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
|
|
}
|
|
setCommonHeaders(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)
|
|
}
|