Peach: Local-first video metadata scraper and media manager.
fix: derive runtime network and system disk state
longmeidao4d7c734c8c9b
diff --git a/src/peach/tray.py b/src/peach/tray.pyindex 85990d4e8..4a499ce5d 100644--- a/src/peach/tray.py+++ b/src/peach/tray.py@@ -29,7 +29,6 @@ from .versioning import VersionManagerLOGGER = logging.getLogger(__name__)-DEFAULT_LAN_ADDRESS = "192.168.50.162"#: macOS 菜单栏项拉起的端口。80/443 在 macOS 上要 root,开发机不该为一个菜单栏图标#: 去要管理员权限;本机 CA 的那套 TLS 材料也是给 Windows 生产实例签的。MACOS_PORT = 8900@@ -383,7 +382,7 @@ def build_service_specs() -> tuple[ServiceSpec, ...]:if sys.platform == "darwin":return build_macos_service_specs()- address = lan_address or os.environ.get("PEACH_LAN_ADDRESS", DEFAULT_LAN_ADDRESS)+ address = lan_address or os.environ.get("PEACH_LAN_ADDRESS") or lan_ipv4()peach = str(_peach_executable())cert_dir = Path(tls_dir) if tls_dir is not None else SECRETS_DIR / "tls"ca = cert_dir / "peach-local-ca.crt"diff --git a/src/peach/web_contract.py b/src/peach/web_contract.pyindex 20466b574..66bb63b04 100644--- a/src/peach/web_contract.py+++ b/src/peach/web_contract.py@@ -28,6 +28,7 @@ from .entities import (upsert_asset_entity,)from .media import remap_managed_path+from .platform import system_volumefrom .web_logic import (DUPLICATE_FLOOR_SECONDS,DUPLICATE_TOLERANCE,@@ -891,9 +892,12 @@ def q_stats(contract: WebContract):c.close()try:import shutil- du = shutil.disk_usage("C:" + chr(92))- out["disk_c"] = {"free": du.free, "total": du.total}+ volume = system_volume()+ du = shutil.disk_usage(volume)+ out["system_disk"] = {"root": str(volume), "free": du.free, "total": du.total}+ out["disk_c"] = out["system_disk"] # 0.6.x 客户端兼容别名except Exception:+ out["system_disk"] = Noneout["disk_c"] = Nonereturn outdiff --git a/tests/test_rm_web.py b/tests/test_rm_web.pyindex 002e857c6..cb8ea8758 100644--- a/tests/test_rm_web.py+++ b/tests/test_rm_web.py@@ -192,6 +192,15 @@ class WebDataTests(unittest.TestCase):self.assertEqual(stats["tag_cov"], 2)self.assertIn("审核标签", {row["k"] for row in stats["top_tags"]})+ def test_stats_use_the_platform_system_volume_and_keep_the_old_alias(self):+ usage = type("Usage", (), {"free": 20, "total": 100})+ with mock.patch.object(rm_web, "system_volume", return_value=Path("X:/")), mock.patch(+ "shutil.disk_usage", return_value=usage,+ ):+ stats = rm_web.q_stats(self.contract)+ self.assertEqual(stats["system_disk"], {"root": "X:\\", "free": 20, "total": 100})+ self.assertIs(stats["disk_c"], stats["system_disk"])+def test_items_support_duration_range(self):result = rm_web.q_items(self.contract, {"dur_min": "90", "dur_max": "110", "limit": "10"},diff --git a/tests/test_tray.py b/tests/test_tray.pyindex 952ccf3d8..eaa831744 100644--- a/tests/test_tray.py+++ b/tests/test_tray.py@@ -55,12 +55,25 @@ class TrayTests(unittest.TestCase):tls_dir = Path(directory)for name in ("peach-local-ca.crt", "peach.crt", "peach.key"):(tls_dir / name).write_text("test-only", encoding="utf-8")- specs = build_service_specs(tls_dir=tls_dir)+ specs = build_service_specs(lan_address="192.0.2.10", tls_dir=tls_dir)owners = [spec for spec in specs if "--no-ledger-sync" not in spec.command]self.assertEqual(owners, [])for spec in specs:self.assertIn("--no-ledger-sync", spec.command)+ def test_windows_service_address_uses_the_current_route_when_not_configured(self):+ with tempfile.TemporaryDirectory() as directory:+ tls_dir = Path(directory)+ for name in ("peach-local-ca.crt", "peach.crt", "peach.key"):+ (tls_dir / name).write_text("test-only", encoding="utf-8")+ with patch.dict(os.environ, {}, clear=False), patch(+ "peach.tray.lan_ipv4", return_value="192.0.2.55",+ ):+ os.environ.pop("PEACH_LAN_ADDRESS", None)+ specs = build_service_specs(tls_dir=tls_dir)+ commands = [item for spec in specs for item in spec.command]+ self.assertIn("192.0.2.55", commands)+@patch("peach.tray.LOG_DIR")def test_start_and_stop_only_owned_service(self, log_dir):with tempfile.TemporaryDirectory() as directory:diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex dd7ba3d8d..f4ae71591 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -473,6 +473,7 @@ class WebUiSourceTests(unittest.TestCase):self.assertPageContains(".stats{padding:8px 0 42px}")self.assertPageContains(".review{padding:8px 0 42px}")self.assertPageLacks("max-width:1440px")+ self.assertPageContains("card('系统盘', d.system_disk")def test_returning_home_from_any_surface_moves_the_highlight(self):"""点回首页时路径还停在 /review 之类上,navOn('') 仍然为假,高亮不切换。"""diff --git a/web/app.js b/web/app.jsindex d8174f1a1..c880065e7 100644--- a/web/app.js+++ b/web/app.js@@ -853,9 +853,9 @@ async function openStats(push=true){+kv('回收站', cs.trash.toLocaleString()))}${card('标签来源', d.tag_source.map(t=>kv(t.k, t.n.toLocaleString(), t.assets.toLocaleString()+' 个视频')).join(''))}- ${card('C 盘', d.disk_c- ? kv('可用', gb(d.disk_c.free), pct(d.disk_c.free,d.disk_c.total)+'%')- +bar(d.disk_c.free,d.disk_c.total)+ ${card('系统盘', d.system_disk+ ? kv('可用', gb(d.system_disk.free), pct(d.system_disk.free,d.system_disk.total)+'%')+ +bar(d.system_disk.free,d.system_disk.total)+`<div class="bigsub">CloudDrive 的块缓存会长在这里,低于 40 GB 抽帧任务会拒绝启动</div>`: '—')}</div>