mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-12-02 00:46:27 +08:00
fix(site): keep multi-level site domains when adding or saving sites (#7533)
This commit is contained in:
@@ -10,11 +10,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.api.context import get_async_session, get_host_runtime
|
||||
from app.application.site.contract import SiteQueryPort, SiteStagingPort
|
||||
from app.application.site.mutation import SiteMutationCommand
|
||||
from app.application.site.protocol import site_domain
|
||||
from app.application.site.query import SiteQueryService
|
||||
|
||||
# 站点目录由外部资源加载,静态检查无法解析其动态导出。
|
||||
from app.application.site.sites import SitesHelper # pylint: disable=import-error,no-name-in-module
|
||||
from app.domain import site as site_rules
|
||||
from app.foundation import url as url_tools
|
||||
from app.runtime.events import eventmanager
|
||||
from app.schemas.types import EventType
|
||||
@@ -56,7 +56,7 @@ def get_site_mutation_command(
|
||||
unit_of_work=runtime.persistence.async_transaction(db),
|
||||
auth_level_provider=lambda: sites_helper.auth_level,
|
||||
indexer_loader=sites_helper.async_get_indexer,
|
||||
domain_extractor=site_rules.extract_domain,
|
||||
domain_extractor=site_domain,
|
||||
url_normalizer=normalize_url,
|
||||
publish_updated=_publish_site_updated,
|
||||
publish_deleted=_publish_site_deleted,
|
||||
|
||||
@@ -851,7 +851,7 @@ flowchart LR
|
||||
| 指标 | 当前值 |
|
||||
|---|---:|
|
||||
| Python 模块 | 1190 |
|
||||
| 内部导入边 | 10,439 |
|
||||
| 内部导入边 | 10,438 |
|
||||
| 非平凡 SCC | 1(29 个模块的 TMDB vendor 精确 containment) |
|
||||
| Application / Chain 具体 Adapter 直连 | 0 / 0 |
|
||||
| Direct egress | 52(精确 policy 准入,Application / Chain 均为 0;本知识 Adapter 仍复用宿主 HTTP 层) |
|
||||
|
||||
@@ -977,8 +977,8 @@
|
||||
"runtime_only": true
|
||||
}
|
||||
},
|
||||
"edge_count": 10439,
|
||||
"edge_sha256": "fb6a89a847896d271ec9aeef7cc19391950e76d9635320ae2e5fe20bb9da05c4",
|
||||
"edge_count": 10438,
|
||||
"edge_sha256": "60cb463434156efc7e471c10fcec030c28da809dd913e74a4e00477f6aa3796e",
|
||||
"edges": [
|
||||
"app -> app.foundation",
|
||||
"app -> app.foundation.environment",
|
||||
@@ -2380,9 +2380,8 @@
|
||||
"app.api.dependencies.site -> app.application.site",
|
||||
"app.api.dependencies.site -> app.application.site.contract",
|
||||
"app.api.dependencies.site -> app.application.site.mutation",
|
||||
"app.api.dependencies.site -> app.application.site.protocol",
|
||||
"app.api.dependencies.site -> app.application.site.query",
|
||||
"app.api.dependencies.site -> app.domain",
|
||||
"app.api.dependencies.site -> app.domain.site",
|
||||
"app.api.dependencies.site -> app.foundation",
|
||||
"app.api.dependencies.site -> app.foundation.url",
|
||||
"app.api.dependencies.site -> app.runtime",
|
||||
|
||||
@@ -8,7 +8,7 @@ import hmac
|
||||
import json
|
||||
from importlib import import_module
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
from Crypto.Cipher import AES
|
||||
@@ -96,6 +96,37 @@ def test_legacy_site_and_cookiecloud_use_module_domain_rules(protocol_boundary):
|
||||
assert helper._domain_resolver(".u2.dmhy.org") == "u2.dmhy.org"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_site_api_mutation_keeps_u2_and_dmhy_keys_apart(protocol_boundary, monkeypatch):
|
||||
"""
|
||||
站点接口新增和保存时使用 Module 域名规则,幼儿园不能被写成公开站动漫花园的键。
|
||||
"""
|
||||
site_dependencies = import_module("app.api.dependencies.site")
|
||||
sites_helper = SimpleNamespace(auth_level=2, async_get_indexer=AsyncMock(return_value={"name": "站点"}))
|
||||
monkeypatch.setattr(site_dependencies, "SitesHelper", lambda: sites_helper)
|
||||
repository = Mock(
|
||||
get_by_id=AsyncMock(return_value=object()),
|
||||
async_get_by_domain=AsyncMock(return_value=None),
|
||||
stage_create=AsyncMock(),
|
||||
stage_update=AsyncMock(return_value=True),
|
||||
)
|
||||
runtime = Mock()
|
||||
runtime.site.repository.return_value = repository
|
||||
runtime.persistence.async_transaction.return_value = Mock(commit=AsyncMock(), rollback=AsyncMock())
|
||||
monkeypatch.setattr(site_dependencies, "_publish_site_updated", AsyncMock())
|
||||
command = site_dependencies.get_site_mutation_command(db=Mock(), runtime=runtime)
|
||||
|
||||
assert (await command.create({"url": "https://u2.dmhy.org/torrents.php"})).success is True
|
||||
assert (await command.create({"url": "https://share.dmhy.org/"})).success is True
|
||||
assert (await command.update({"id": 1, "url": "https://u2.dmhy.org/"})).success is True
|
||||
assert (await command.update({"id": 2, "url": "https://share.dmhy.org/"})).success is True
|
||||
|
||||
created = [call.args[0].values["domain"] for call in repository.stage_create.await_args_list]
|
||||
updated = [call.args[1].values["domain"] for call in repository.stage_update.await_args_list]
|
||||
assert created == updated == ["u2.dmhy.org", "dmhy.org"]
|
||||
assert [call.args[0] for call in sites_helper.async_get_indexer.await_args_list] == ["u2.dmhy.org", "dmhy.org"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("page_url,enclosure,expected", [
|
||||
("https://totheglory.im/t/17/", "https://totheglory.im/dl/17/old", ("7", "id=17")),
|
||||
("https://totheglory.im/t/17/", "https://totheglory.im/download?id=23", ("7", "id=17")),
|
||||
|
||||
Reference in New Issue
Block a user