mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-12-02 00:46:27 +08:00
fix(plugin): normalize nested history values from third-party market indexes (#7534)
This commit is contained in:
@@ -107,7 +107,7 @@ class PluginMetadataMapper:
|
||||
),
|
||||
None,
|
||||
)
|
||||
plugin.history = info.get("history") or {}
|
||||
plugin.history = self.normalize_history(info.get("history"))
|
||||
plugin.release = bool(info.get("release"))
|
||||
plugin.repo_url = market
|
||||
plugin.package_version = package_version
|
||||
@@ -128,6 +128,29 @@ class PluginMetadataMapper:
|
||||
self._logger.error(f"获取插件 {plugin_id} 状态出错:{error}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def normalize_history(history: Any) -> dict[str, str]:
|
||||
"""
|
||||
把市场索引的更新记录归一化为版本到文本的映射。
|
||||
|
||||
第三方索引可能把版本说明写成含 ``content`` 的嵌套对象,这里取其正文拼接为文本,
|
||||
无法得到正文的条目直接丢弃,避免错误类型进入响应模型。
|
||||
|
||||
:param history: 索引中的原始 history 字段
|
||||
:return: 仅包含字符串值的更新记录
|
||||
"""
|
||||
if not isinstance(history, dict):
|
||||
return {}
|
||||
normalized: dict[str, str] = {}
|
||||
for version, note in history.items():
|
||||
if isinstance(note, dict):
|
||||
note = note.get("content")
|
||||
if isinstance(note, list):
|
||||
note = "\n".join(str(item) for item in note)
|
||||
if isinstance(note, str):
|
||||
normalized[str(version)] = note
|
||||
return normalized
|
||||
|
||||
@staticmethod
|
||||
def normalize_label(labels: Any) -> Optional[str]:
|
||||
"""
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import warnings
|
||||
from contextlib import asynccontextmanager
|
||||
from types import SimpleNamespace
|
||||
from typing import Optional
|
||||
@@ -364,3 +365,24 @@ async def test_readme_probe_falls_back_after_proxy_error(monkeypatch: pytest.Mon
|
||||
assert len(calls) == 2
|
||||
finally:
|
||||
await transport.async_get_plugin_readme_url.cache_clear()
|
||||
|
||||
|
||||
def test_nested_history_is_normalized_to_text() -> None:
|
||||
"""
|
||||
第三方索引把 history 值写成嵌套对象时,应归一化为字符串且不触发序列化警告。
|
||||
"""
|
||||
info = {
|
||||
"name": "Demo",
|
||||
"version": "1.7.3",
|
||||
"history": {
|
||||
"v1.7.3": {"version": "1.7.3", "date": "2026-01-01", "content": ["修复A", "修复B"]},
|
||||
"v1.18.4": {"version": "1.18.4"},
|
||||
"v1.0.0": "初始版本",
|
||||
},
|
||||
}
|
||||
plugin = _mapper().map("Demo", info, REPO, [], 0, "v3")
|
||||
assert plugin is not None
|
||||
assert plugin.history == {"v1.7.3": "修复A\n修复B", "v1.0.0": "初始版本"}
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
plugin.model_dump_json()
|
||||
|
||||
Reference in New Issue
Block a user