56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package fqapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fanqie/internal/common"
|
|
"fmt"
|
|
)
|
|
|
|
var detailLogger = common.NewLogger("detail", "INFO", "")
|
|
|
|
// HandleGetDetail 处理获取书籍详情
|
|
func HandleGetDetail(bookID string) (string, error) {
|
|
if bookID == "" {
|
|
return BuildErrorResponse("需要参数 book_id"), nil
|
|
}
|
|
|
|
// 构建URL
|
|
reqURL := BuildURL("https://reading.snssdk.com/reading/bookapi/detail/v/", "book_id="+bookID)
|
|
|
|
resp, err := GorgonRequest(reqURL, map[string]interface{}{
|
|
"method": "GET",
|
|
"headers": map[string]string{
|
|
"User-Agent": "com.dragon.read",
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
detailLogger.Error(fmt.Sprintf("获取详情请求失败: %v", err))
|
|
return BuildErrorResponse("获取详情请求失败"), err
|
|
}
|
|
|
|
respJSON, err := resp.JSON()
|
|
if err != nil {
|
|
detailLogger.Error(fmt.Sprintf("解析响应失败: %v", err))
|
|
return BuildErrorResponse("解析响应失败"), err
|
|
}
|
|
|
|
if code, ok := respJSON["code"].(float64); ok && code == 0 {
|
|
// 删除content字段
|
|
if data, ok := respJSON["data"].(map[string]interface{}); ok {
|
|
delete(data, "content")
|
|
}
|
|
|
|
// 重新序列化
|
|
resultBytes, err := json.Marshal(respJSON)
|
|
if err != nil {
|
|
return BuildErrorResponse("序列化失败"), err
|
|
}
|
|
|
|
return string(resultBytes), nil
|
|
}
|
|
|
|
return BuildErrorResponse("获取失败"), nil
|
|
}
|
|
|