fix: 将52号接口范围限定为GPU worker
撤回52号网关路由、图片字段改名和mock改动,gateway目录恢复a3fddbb。worker保持base64和null响应,更新接口说明和回归测试。 验证:worker API、IP限制与网关兼容性共54项测试通过。
This commit is contained in:
@@ -208,8 +208,6 @@ async def index():
|
||||
"if3_hair_grow_b": "/static/test_interface3.html",
|
||||
"if4_features": "/static/test_interface4.html",
|
||||
"if5_hairline": "/static/test_interface5.html",
|
||||
"if52_hairline": "/static/test_interface52.html",
|
||||
"if52_compare": "/static/test_interface52_compare.html",
|
||||
"if6_measure_v2": "/static/test_interface6.html",
|
||||
"if7_hair_grow_v2": "/static/test_interface7.html",
|
||||
"if9_head_mask": "/static/test_interface9.html",
|
||||
@@ -593,12 +591,6 @@ async def hairline_generate(request: Request):
|
||||
return await _proxy(request, "/api/v1/hairline/generate")
|
||||
|
||||
|
||||
@app.post("/api/v1/hairline/generate-52", tags=["人脸分析"])
|
||||
async def hairline_generate_52(request: Request):
|
||||
"""接口52:新高度规则、扶正裁切与发际线生成"""
|
||||
return await _proxy(request, "/api/v1/hairline/generate-52")
|
||||
|
||||
|
||||
@app.post("/api/v1/hair/grow-v2", tags=["生发"])
|
||||
async def hair_grow_v2(request: Request):
|
||||
"""接口7:C端生发 v2(add_hair2 工作流)"""
|
||||
|
||||
+3
-15
@@ -88,8 +88,6 @@ def rewrite_base64_to_url(
|
||||
obj: Any,
|
||||
public_base_url: str,
|
||||
static_dir: str,
|
||||
*,
|
||||
rewrite_null_images: bool = False,
|
||||
) -> Any:
|
||||
"""递归遍历响应 JSON,将所有 *_base64 字段改写为 *_url。
|
||||
|
||||
@@ -97,16 +95,10 @@ def rewrite_base64_to_url(
|
||||
- 支持 data: URI 和原始 base64 两种格式
|
||||
- 解码 base64 → 保存到 static_dir/{uuid}.png
|
||||
- 删除 *_base64 字段,新增 *_url 字段指向公网 URL
|
||||
- 接口52显式开启 rewrite_null_images,空图片也返回 *_url: null;旧接口保持原空字段
|
||||
"""
|
||||
if isinstance(obj, dict):
|
||||
new_dict: Dict[str, Any] = {}
|
||||
for key, value in obj.items():
|
||||
if rewrite_null_images and key.endswith("_base64") and value is None:
|
||||
# Deprecated/optional image fields must keep their external
|
||||
# *_url names even when no image is generated.
|
||||
new_dict[key[:-7] + "_url"] = None
|
||||
continue
|
||||
if key.endswith("_base64") and isinstance(value, str):
|
||||
img_bytes = _decode_base64_value(value)
|
||||
if img_bytes is not None:
|
||||
@@ -126,12 +118,10 @@ def rewrite_base64_to_url(
|
||||
logger.warning("字段 %s 的值无法解码为图片,保留", key)
|
||||
new_dict[key] = value
|
||||
else:
|
||||
new_dict[key] = rewrite_base64_to_url(
|
||||
value, public_base_url, static_dir, rewrite_null_images=rewrite_null_images)
|
||||
new_dict[key] = rewrite_base64_to_url(value, public_base_url, static_dir)
|
||||
return new_dict
|
||||
elif isinstance(obj, list):
|
||||
return [rewrite_base64_to_url(item, public_base_url, static_dir,
|
||||
rewrite_null_images=rewrite_null_images) for item in obj]
|
||||
return [rewrite_base64_to_url(item, public_base_url, static_dir) for item in obj]
|
||||
else:
|
||||
return obj
|
||||
|
||||
@@ -258,9 +248,7 @@ async def proxy_request(request: Request, path: str) -> JSONResponse:
|
||||
)
|
||||
|
||||
# 递归改写 base64 图片字段
|
||||
rewritten = rewrite_base64_to_url(
|
||||
worker_json, public_base_url, static_dir,
|
||||
rewrite_null_images=path == "/api/v1/hairline/generate-52")
|
||||
rewritten = rewrite_base64_to_url(worker_json, public_base_url, static_dir)
|
||||
|
||||
return JSONResponse(
|
||||
status_code=resp.status_code,
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
- POST /api/v1/hair/grow-b → mock 响应
|
||||
- POST /api/v1/face/features → mock 响应
|
||||
- POST /api/v1/hairline/generate → mock 响应
|
||||
- POST /api/v1/hairline/generate-52 → 新规则 mock 响应
|
||||
|
||||
鉴权:校验 X-Internal-Token 头,不匹配返回 401。
|
||||
并发模拟:可通过 ?delay=N 让接口 sleep N 秒(默认 1)。
|
||||
@@ -214,7 +213,6 @@ def create_app(port: int, password: str) -> FastAPI:
|
||||
|
||||
# --- 接口5 ---
|
||||
@app.post("/api/v1/hairline/generate")
|
||||
@app.post("/api/v1/hairline/generate-52")
|
||||
async def hairline_generate(
|
||||
request: Request,
|
||||
x_internal_token: Optional[str] = Header(default=None),
|
||||
@@ -247,14 +245,6 @@ def create_app(port: int, password: str) -> FastAPI:
|
||||
],
|
||||
"best_hairline_center_point": {"x": 540, "y": 430},
|
||||
}
|
||||
if request.url.path.endswith("generate-52"):
|
||||
for item in data["hairline_images"]:
|
||||
item["image_high_base64"] = None
|
||||
item["image_low_base64"] = None
|
||||
data.update(high_hairline_center_point=None, low_hairline_center_point=None,
|
||||
face_measure=None, framing=None, height_rule=None,
|
||||
guide_landmarks={}, input_image_base64=_png, original_image_base64=_png,
|
||||
coordinate_space="original_image", width=1, height=1)
|
||||
return mock_ok(data, delay=delay)
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user