🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
This commit is contained in:
commit
6981148727
107 files changed
+12463
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fanqie/internal/fqapi"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HandleMangaImageProxy 处理漫画图片代理请求
|
||||
func HandleMangaImageProxy(w http.ResponseWriter, r *http.Request) {
|
||||
// 从URL路径提取参数: /manga/image/{itemID}/{index}
|
||||
path := strings.TrimPrefix(r.URL.Path, "/manga/image/")
|
||||
parts := strings.Split(path, "/")
|
||||
|
||||
if len(parts) != 2 {
|
||||
http.Error(w, "Invalid URL format. Expected: /manga/image/{itemID}/{index}", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
itemID := parts[0]
|
||||
index, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid index parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取解密后的图片数据
|
||||
imageData, mimeType, err := fqapi.HandleMangaImageProxy(itemID, index)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Failed to get image: %s", err.Error()), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置响应头
|
||||
w.Header().Set("Content-Type", mimeType)
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600") // 缓存1小时
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(imageData)))
|
||||
|
||||
// 返回图片数据
|
||||
w.Write(imageData)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user