feat(weibo): 增加协作 CK 批量复制与商品图片代理
This commit is contained in:
@@ -18,6 +18,7 @@ from .client import (
|
||||
WeiboTransportError,
|
||||
extract_bind_raw_url,
|
||||
normalize_weibo_cookie,
|
||||
normalize_weibo_image_url,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -38,4 +39,5 @@ __all__ = [
|
||||
"WeiboTransportError",
|
||||
"extract_bind_raw_url",
|
||||
"normalize_weibo_cookie",
|
||||
"normalize_weibo_image_url",
|
||||
]
|
||||
|
||||
+28
-1
@@ -221,6 +221,17 @@ def normalize_weibo_cookie(raw: str) -> str:
|
||||
return "; ".join(pairs)
|
||||
|
||||
|
||||
def normalize_weibo_image_url(value: Any) -> str:
|
||||
"""把微博返回的图片地址升级为 HTTPS,避免浏览器拦截混合内容。"""
|
||||
|
||||
text = unescape(str(value or "")).strip()
|
||||
if text.startswith("//"):
|
||||
return f"https:{text}"
|
||||
if text.lower().startswith("http://"):
|
||||
return f"https://{text[7:]}"
|
||||
return text
|
||||
|
||||
|
||||
def _parse_cookie_pairs(cookie: str) -> dict[str, str]:
|
||||
pairs: dict[str, str] = {}
|
||||
for item in cookie.split(";"):
|
||||
@@ -491,7 +502,23 @@ class WeiboClient:
|
||||
"/mall/list",
|
||||
params={"F": activity, "_t": int(time.time() * 1000)},
|
||||
)
|
||||
return payload.get("data") or {}
|
||||
data = payload.get("data") or {}
|
||||
if not isinstance(data, dict):
|
||||
return {}
|
||||
goods = data.get("list")
|
||||
if not isinstance(goods, list):
|
||||
return data
|
||||
normalized_goods = []
|
||||
for item in goods:
|
||||
if not isinstance(item, dict):
|
||||
normalized_goods.append(item)
|
||||
continue
|
||||
normalized = dict(item)
|
||||
normalized["goods_image"] = normalize_weibo_image_url(
|
||||
item.get("goods_image")
|
||||
)
|
||||
normalized_goods.append(normalized)
|
||||
return {**data, "list": normalized_goods}
|
||||
|
||||
def exchange_goods(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user