Peach: Local-first video metadata scraper and media manager.
refactor(processing): 独立校验服务字段与慢项跳过请求
longmeidao46bab72f8edb
diff --git a/src/peach/routes_configuration.py b/src/peach/routes_configuration.pyindex f05dd2620..4b6160001 100644--- a/src/peach/routes_configuration.py+++ b/src/peach/routes_configuration.py@@ -842,6 +842,15 @@ def _validate(body: dict[str, Any], config) -> tuple[dict[str, Any], dict[str, Aerrors["media_dirs"] = problemselse:validated["media_dirs"] = paths+ server_errors, server_values = _validate_server(body, config)+ errors.update(server_errors)+ validated.update(server_values)+ return errors, validated+++def _validate_server(body, config):+ """端口、监听范围和局域网名称按运行方式校验。"""+ errors, validated = {}, {}try:port = onboarding.validate_port(str(body.get("port", config.server.port)))if distribution.standalone():diff --git a/src/peach/web_library_processing.py b/src/peach/web_library_processing.pyindex ef6679834..b26cac11d 100644--- a/src/peach/web_library_processing.py+++ b/src/peach/web_library_processing.py@@ -65,6 +65,16 @@ def q_library_processing(contract, _args):return public_state(state)+def _request_skip(control, previous, body):+ asset_id = body.get('asset_id')+ if (isinstance(asset_id, bool) or not isinstance(asset_id, int)+ or previous.get('status') != 'running'+ or previous.get('current_asset_id') != asset_id+ or previous.get('current_action') not in ('querying_metadata', 'fetching_cover')):+ raise ValueError('当前影片已变化或不在采集外部资料,请刷新后重试')+ control.skip_current(str(body['job_id']), asset_id)++def _control_action(contract, config, body):action = body['action']if action not in ('pause', 'resume', 'set_speed', 'skip_current'):@@ -82,13 +92,7 @@ def _control_action(contract, config, body):if job_id:control.select_job(str(job_id))if action == 'skip_current':- asset_id = body.get('asset_id')- if (isinstance(asset_id, bool) or not isinstance(asset_id, int)- or previous.get('status') != 'running'- or previous.get('current_asset_id') != asset_id- or previous.get('current_action') not in ('querying_metadata', 'fetching_cover')):- raise ValueError('当前影片已变化或不在采集外部资料,请刷新后重试')- control.skip_current(str(job_id), asset_id)+ _request_skip(control, previous, body)return q_library_processing(contract, {})if action == 'set_speed':mode = valid_mode(body.get('speed_mode'))diff --git a/tests/test_configuration_sources.py b/tests/test_configuration_sources.pyindex 3bc5fa637..81e5e6a55 100644--- a/tests/test_configuration_sources.py+++ b/tests/test_configuration_sources.py@@ -16,12 +16,12 @@ class ConfigurationIsolationTests(unittest.TestCase):def test_phone_access_addresses_use_runtime_protocol_scope_and_ipv6(self):from peach.routes_configuration import network_payloadruntime = SimpleNamespace(host='0.0.0.0', port=8900, tls_enabled=True,- mdns_enabled=True, mdns_port=443, mdns_name='peach-win', mdns_address='192.168.1.8')+ mdns_enabled=True, mdns_port=443, mdns_name='peach-writer', mdns_address='192.0.2.8')request = SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(settings=runtime)),- base_url='https://peach-win.local/')+ base_url='https://peach-writer.local/')with patch('peach.distribution.standalone', return_value=False):result = network_payload(request, self.config)- self.assertEqual(result['lan_url'], 'https://peach-win.local/')+ self.assertEqual(result['lan_url'], 'https://peach-writer.local/')self.assertEqual(result['ip_url'], '')self.assertEqual(result['scope'], 'lan')self.assertFalse(result['editable'])@@ -88,6 +88,7 @@ class ConfigurationIsolationTests(unittest.TestCase):stack.enter_context(patch.object(routes, "local_only"))stack.enter_context(patch.object(routes.settings_file, "load_config", return_value=self.config))stack.enter_context(patch.object(routes, "snapshot", return_value={"media_dirs": [], "port": 8900}))+ stack.enter_context(patch.object(routes, "network_payload", return_value={"scope": "local"}))stack.enter_context(patch.object(routes, "tunnel_payload", return_value={"state": "idle"}))for key, module, name in (("push_discovery", routes, "push_discovery_payload"),("downloads", routes.web_downloads, "settings_payload")):