fix(gateway): douyinpic 图片 fetch 改 credentials omit——修复封面缓存全量 502

douyinpic CDN 恒返回 Access-Control-Allow-Origin:'*',跨站 fetch 带 credentials:'include'
按 CORS 规范必被拒(TypeError Failed to fetch),封面回填全部失败、creator_work_cover 落 0 行。
公共图片不需要 cookies,改 credentials:'omit' 后浏览器内 fetch 200,回填链路恢复。
验证:test_gateway 55 例全绿;实测 anon 浏览器 image fetch 200 image/jpeg;强制同步后
creator_work_cover 落 7/7(该账号全部作品),/works/:id/cover 正常输出 JPEG。
This commit is contained in:
2026-09-28 11:57:28 +08:00
parent c7fc67626e
commit 77e79982fa
+3 -1
View File
@@ -1547,7 +1547,9 @@ def fetch_douyin_image(self: object, alias: str, target: str) -> BrowserMediaRes
result = cdp.evaluate(
f"""(async()=>{{
try {{
const r=await fetch({json.dumps(target)},{{credentials:'include',redirect:'error'}});
// douyinpic CDN 返回 Access-Control-Allow-Origin:'*',跨站 fetch 不能带凭据,
// credentials:'include' 会直接 TypeError Failed to fetch;公共图片无需 cookies。
const r=await fetch({json.dumps(target)},{{credentials:'omit',redirect:'error'}});
if(!r.body)return {{status:r.status,content_type:r.headers.get('content-type')||'',body:'',too_large:false}};
const reader=r.body.getReader(), chunks=[]; let size=0;
for(;;){{const item=await reader.read();if(item.done)break;