Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 同步导航代次并清理 Application 菜单与覆盖页资源

longmeidaob48d8edae4b6
diff --git a/docs/STATUS.md b/docs/STATUS.md
index ae8559e27..9b57e5844 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -2,7 +2,7 @@
最后核验:2026-10-10
-状态查 `/healthz`;[待办](PRODUCT_BACKLOG.md)、[复用清单](REUSE.md)、[长期约定](HANDOFF.md)。
+查 `/healthz`;[待办](PRODUCT_BACKLOG.md)、[复用清单](REUSE.md)、[长期约定](HANDOFF.md)。
## 运行态
@@ -14,27 +14,27 @@
- JAV 头像 816 张,38 张水印待复核;17 位档案、253 张头像候选、2 张官方封面。
- 「整理」(ADR-0039)支持预览、执行、回滚;英文视频名分词 169 条。
- 产地是独立维度、JAV 是其投影:`region` 空时按厂牌、创作者、番号逐层推断,不落库;韩国 MIB 不算 JAV。
-- Windows 托盘自动恢复;`restart_windows_tray.py --source` 重启。代码与数据在内置盘,媒体在外置盘。
+- Windows 托盘自动恢复,重启用 `restart_windows_tray.py --source`;代码与数据在内置盘,媒体在外置盘。
- 托盘须普通权限启动:提权令牌看不到 CloudDrive 的 `A:`/`B:`,误报脱盘。
-- Windows:80 跳转 HTTPS,LAN:443;`peach-win`、`0.37.0`。10-10 重启,CA、健康及前端产物通过。
-- 主界面入口为 `peach-app.js/css`,登录与配置页使用独立的 `peach-pages.js/css`;Application 管理路由树与资源生命周期,应用域控制器保留原生宿主适配。
-- `/healthz` 报 `configurable=true`;配置与选目录共用本机连接判据,托盘管理 HTTPS 地址、端口及配置重载。
-- 首启与配置页列缺失依赖(CloudDrive、挂载驱动、FFmpeg/ffprobe、OpenSSL);Windows 已认出 CloudDrive 与 WinFsp。
-- 文件检查覆盖本地与网盘,来源等分、共用确认弹层;CloudDrive 分档建议首启与配置页共用。
-- 访问密码未开,局域网匿名可读;可选密码首启可跳过,配置页可改可关,登录可记住设备。
+- Windows:80 跳 HTTPS,LAN:443;`peach-win`、`0.37.0`。10-10 重启,CA、健康、前端产物通过。
+- 主界面 `peach-app.js/css`,登录、配置页 `peach-pages.js/css`;Application 管理路由与资源,域控制器适配原生宿主。
+- `/healthz` 报 `configurable=true`;配置与选目录共用连接判据,托盘管理 HTTPS 地址、端口及重载。
+- 首启、配置页列缺失依赖(CloudDrive、挂载驱动、FFmpeg/ffprobe、OpenSSL);Windows 识别 CloudDrive、WinFsp。
+- 文件检查含本地与网盘,来源等分、共用确认弹层;CloudDrive 分档建议首启与配置页共用。
+- 访问密码未开,局域网匿名可读;首启可跳过密码,配置页可改可关,登录可记住设备。
- macOS 是 reader,代码与 `peach-data` 在内置盘;`peach.local` 经 8900/8443 和 pf 提供 80/443,GET 正常、写入回 409。
-- 两端各用本机 CA,私钥与凭据不跨机;代码走 Git、账本单写者复制、图片走 Syncthing;本机坐标见 `<数据根>/config.toml`。
+- 两端各用本机 CA,私钥与凭据不跨机;代码用 Git、账本单写者复制、图片用 Syncthing;坐标见 `<数据根>/config.toml`。
- Windows ledger `0045`,资源 80,209 行;字幕 195 行(孤立 19),175 部带字幕轨;R 盘暂缓。
-- Mac ledger 经授权从共享副本拉取,恢复 `in-sync`;`sources` 在内置盘,`archive`、`tools` 可指向外置盘。
-- Windows doctor、诊断页通过 CA 核验;本地目录缺失,115/PikPak 可读取;密码未开、历史失败为警告。
-- Python 3.14,下限 3.12;CI 同测 3.12 与 3.14。Windows FFmpeg/ffprobe 在 `peach-data/tools/ffmpeg`,macOS 走 PATH。
-- amane 桥(ADR-0048)代码在 `tools/amane-bridge/`,venv 在 `peach-data/tools/amane-bridge/.venv`,供番号查询。
-- 发行名 `peach`、目录名 `peach-app`。macOS 按待办「待执行的操作」第 26 条处理后重启菜单栏:无口令的 `peach serve --host 0.0.0.0` 拒绝启动。
-- 扫描与采集 120 秒无进展预警;资料 90 秒、封面 240 秒超时可重试;见 `state/library-processing-<job_id>.issues.jsonl`。
-- 口味、复核、关注等聚合按账本版本号与文件版本缓存;补女优资料后继每轮存量至多 16 条。
-- 实体种子(ADR-0075)由扫描结算的 `seed-import` 后继导入,只填空、换旧种子行;不一致与重复身份在 `generated/seed-landing.csv`。
+- Mac ledger 使用已授权共享副本,`in-sync`;`sources` 在内置盘,`archive`、`tools` 可在外置盘。
+- Windows doctor、诊断页通过 CA;本地目录缺失,115/PikPak 可读;密码未开、历史失败为警告。
+- Python 3.14(下限 3.12,CI 测两版);Windows FFmpeg/ffprobe 在 `peach-data/tools/ffmpeg`,macOS 走 PATH。
+- amane 桥(ADR-0048)供番号查询;代码 `tools/amane-bridge/`,venv `peach-data/tools/amane-bridge/.venv`。
+- 发行名 `peach`、目录名 `peach-app`。macOS 按待办第 26 条处理后重启菜单栏;无口令的 `peach serve --host 0.0.0.0` 拒绝启动。
+- 扫描、采集 120 秒无进展预警;资料 90 秒、封面 240 秒超时可重试;见 `state/library-processing-<job_id>.issues.jsonl`。
+- 口味、复核、关注等聚合按账本与文件版本缓存;女优资料后继每轮存量至多 16 条。
+- 实体种子(ADR-0075)由扫描结算后继 `seed-import` 导入,只填空、换旧种子行;冲突与重复身份在 `generated/seed-landing.csv`。
- 推送发现开:本地 watch 加 CloudDrive 云端前缀 `/115open→B:`、`/Pikpak→A:`;关注每 60 分钟轮询;自动更新关闭。
-- Cloudflare 公网入口默认关,配置页启停,须先设访问密码;临时链接只写状态文件,命名隧道限源码环境、令牌只存设置文件;整站 `noindex` 加 `/robots.txt`。
+- Cloudflare 公网入口默认关,配置页启停前须设密码;临时链接写状态文件,命名隧道限源码部署、令牌存设置文件;整站 `noindex` 与 `/robots.txt`。
- FC2PPV-DB、JAVten 与被拦时的 minnano-av 经本机 Chrome 取页(ADR-0065),profile 在 `secrets/browser/`,免贴 Cookie。
## 批处理进度
diff --git a/frontend/e2e/index-people.test.ts b/frontend/e2e/index-people.test.ts
index 79f9cf61f..278c4182f 100644
--- a/frontend/e2e/index-people.test.ts
+++ b/frontend/e2e/index-people.test.ts
@@ -35,12 +35,12 @@ describe('本地与在线艺人共用名册布局', () => {
const page = await context.newPage();
let release!: () => void;
const gate = new Promise<void>(resolve => { release = resolve });
- await page.route('**/dist/peach-app.js*', async route => {
+ await page.route(url => url.pathname === '/api/index' || url.pathname === '/api/follow/authors', async route => {
await gate;
await route.continue();
});
try {
- // 主模块落地前直接验收 HTML 骨架;DOMContentLoaded 要等这份模块执行。
+ // 主模块先铺索引骨架,首屏数据暂缓;标题行与名册入口在等待时已经完整可见。
await page.goto(requiredEnv('PEACH_E2E_ORIGIN') + path, { waitUntil: 'commit' });
await page.locator('#index [data-skeleton]').first().waitFor();
assert.equal(await page.locator('#index [role="tablist"]').count(), 1);
diff --git a/frontend/src/application/composition.js b/frontend/src/application/composition.js
index 429aaa8ba..0f2ea1229 100644
--- a/frontend/src/application/composition.js
+++ b/frontend/src/application/composition.js
@@ -162,7 +162,8 @@ compositionState.routing = false;
applicationEffects.own(peachHistory.listen(navigation=>{
/* 取齐前地址仍在源页:任何非覆盖历史变化(包括同地址 POP)都撤回这一趟,晚到的包或响应不能再开舞台。 */
if(navigationState.queueOpenRequest&&navigation.seq!==navigationState.queueOpenRequest.seq&&!isOverlayPath(navigation.location.pathname))disposeStage(false);
- if(compositionState.routing&&!navigation.claimed)queueMicrotask(syncRouteChrome);
+ // 历史通知内先同步页面代次,再由路由元素的微任务领取取数代次。
+ if(compositionState.routing&&!navigation.claimed)syncRouteChrome();
}));
loadRouter(compositionState.shellActions).catch(error=>console.error('客户端导航装载失败',error));
mountManageHeader();
diff --git a/frontend/src/react/application.tsx b/frontend/src/react/application.tsx
index c13f53dda..8150b1901 100644
--- a/frontend/src/react/application.tsx
+++ b/frontend/src/react/application.tsx
@@ -6,6 +6,7 @@ import { initializeApplication } from '../application/initialize.js';
import { connectApplication, disposeApplicationResidents } from './application-residents';
import { renewApplicationEffects, type ApplicationEffects } from '../application/effects';
import { initMiddleTruncate } from '../ui-kit/middle-truncate';
+import { closeAnchoredMenu } from '../ui-kit/anchored-menu';
import { queryClient } from '../query';
import { releaseHoverPreviews } from '../card-art';
import { releaseAllManagedRoutes } from '../history';
@@ -30,6 +31,7 @@ function acquireResources(): ApplicationResources {
effects.own(() => { releaseHoverPreviews(); void queryClient.cancelQueries(); });
effects.own(disposeApplicationResidents);
effects.own(releaseAllManagedRoutes);
+ effects.own(closeAnchoredMenu);
}
resources.owners += 1;
resources.effects.resume();
diff --git a/frontend/src/react/router/pages/overlay.tsx b/frontend/src/react/router/pages/overlay.tsx
index 1774abc8e..ad7e30b76 100644
--- a/frontend/src/react/router/pages/overlay.tsx
+++ b/frontend/src/react/router/pages/overlay.tsx
@@ -14,8 +14,8 @@
* 目录网格(目录元素),关注详情只让出 `#stats`(`FollowDetailGround`),不画列表。
*
* 打开、收起与让位都排进微任务:路由根在历史变化的同一次调用里同步提交,壳打开舞台要同步画,在提交阶段里画会
- * 出 flushSync 告警。壳在路由根之前订阅历史,它的标题与侧栏那一轮排在前面。 */
-import { useContext, useEffect, useRef, useSyncExternalStore, type ReactNode } from 'react';
+ * 出 flushSync 告警。历史通知同步更新壳的标题与侧栏,页面取数随后领取当前代次。 */
+import { useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore, type ReactNode } from 'react';
import {
adoptOverlayState, bootEntry, clearOverlayBackground, isOverlayPath, overlayTarget, peachHistory, type OverlayPath,
@@ -69,6 +69,8 @@ export function useRouteOpen(run: (boot: boolean) => void, claimedOpens = false)
/* 一条覆盖地址的元素:挂上按地址打开那一条,卸下去处不再是覆盖地址就收起舞台(正在放的视频照旧进小窗)。 */
function OverlayOpen() {
const actions = useContext(ShellActionsContext);
+ const latestActions = useRef(actions);
+ useLayoutEffect(() => { latestActions.current = actions }, [actions]);
useRouteOpen((boot) => {
const target = overlayTarget(peachHistory.navigation.location.pathname);
if (!actions || !target) return;
@@ -78,7 +80,7 @@ function OverlayOpen() {
}, true);
useEffect(() => () => {
queueMicrotask(() => {
- if (!isOverlayPath(peachHistory.navigation.location.pathname)) actions?.closeStage();
+ if (!isOverlayPath(peachHistory.navigation.location.pathname)) latestActions.current?.closeStage();
});
}, []);
return null;
diff --git a/frontend/test/react/application.test.tsx b/frontend/test/react/application.test.tsx
index e2029c1c7..c8afa3075 100644
--- a/frontend/test/react/application.test.tsx
+++ b/frontend/test/react/application.test.tsx
@@ -19,14 +19,27 @@ afterEach(async () => {
});
async function load() {
- const [app, residents, effects, shell] = await Promise.all([
+ const [app, residents, effects, shell, menus] = await Promise.all([
import('../../src/react/application'), import('../../src/react/application-residents'),
- import('../../src/application/effects'), import('../../src/shell'),
+ import('../../src/application/effects'), import('../../src/shell'), import('../../src/ui-kit/anchored-menu'),
]);
- return { ...app, residents, effects, shell };
+ return { ...app, residents, effects, shell, menus };
}
function host() { const node = document.createElement('div'); document.body.append(node); return node; }
+function openNativeMenu(menus: Awaited<ReturnType<typeof load>>['menus']) {
+ const mount = document.createElement('div'), toggle = document.createElement('button'), menu = document.createElement('div');
+ menu.hidden = true; mount.append(toggle, menu); document.body.append(mount);
+ const add = vi.spyOn(window, 'addEventListener'), start = add.mock.calls.length;
+ const measure = vi.spyOn(toggle, 'getBoundingClientRect');
+ const control = menus.wireAnchoredMenu(mount, toggle, menu); control.setOpen(true);
+ const installed = add.mock.calls.slice(start);
+ const resize = installed.find(([type]) => type === 'resize')?.[1];
+ const scroll = installed.find(([type]) => type === 'scroll')?.[1];
+ expect(resize).toBeDefined(); expect(scroll).toBeDefined();
+ return { control, toggle, measure, resize, scroll };
+}
+
function actions(): ShellActions {
return {
openItem: vi.fn(), openEntity: vi.fn(), openTag: vi.fn(), openTasteSignal: vi.fn(), navigate: vi.fn(),
@@ -58,6 +71,8 @@ it('同宿主重复挂载沿用实际 Application,一次后退只打开一次
it('实际卸载后立即重挂同宿主重新初始化,旧资源信号已取消', async () => {
const r = await load(), node = host();
+ const remove = vi.spyOn(window, 'removeEventListener'), menus: ReturnType<typeof openNativeMenu>[] = [];
+ boot.initialize.mockImplementation(() => { menus.push(openNativeMenu(r.menus)); });
let first!: Root, second!: Root, oldSignal!: AbortSignal;
await act(async () => {
first = r.mountApplication(node); oldSignal = r.effects.applicationEffects.signal;
@@ -65,21 +80,43 @@ it('实际卸载后立即重挂同宿主重新初始化,旧资源信号已取
});
roots.add(second); expect(second).not.toBe(first);
expect(boot.initialize).toHaveBeenCalledTimes(2); expect(oldSignal.aborted).toBe(true);
+ const [oldMenu, newMenu] = menus;
+ expect(oldMenu!.control.isOpen()).toBe(false); expect(oldMenu!.toggle.getAttribute('aria-expanded')).toBe('false');
+ expect(remove.mock.calls.filter(([type, callback]) => type === 'resize' && callback === oldMenu!.resize)).toHaveLength(1);
+ expect(remove.mock.calls.filter(([type, callback, capture]) => type === 'scroll' && callback === oldMenu!.scroll && capture === true)).toHaveLength(1);
+ expect(newMenu!.control.isOpen()).toBe(true);
+ const oldMeasurements = oldMenu!.measure.mock.calls.length, newMeasurements = newMenu!.measure.mock.calls.length;
+ window.dispatchEvent(new Event('resize'));
+ expect(oldMenu!.measure.mock.calls.length).toBe(oldMeasurements);
+ expect(newMenu!.measure.mock.calls.length).toBe(newMeasurements + 1);
+ await act(async () => { second.unmount(); }); roots.delete(second);
+ expect(newMenu!.control.isOpen()).toBe(false);
+ expect(remove.mock.calls.filter(([type, callback]) => type === 'resize' && callback === newMenu!.resize)).toHaveLength(1);
+ expect(remove.mock.calls.filter(([type, callback, capture]) => type === 'scroll' && callback === newMenu!.scroll && capture === true)).toHaveLength(1);
});
it('StrictMode 诊断重取仅初始化一次,最终卸载移除监听和调度', async () => {
vi.useFakeTimers();
const r = await load(), node = host(), heard = vi.fn(), timer = vi.fn();
+ const remove = vi.spyOn(window, 'removeEventListener');
+ let menu!: ReturnType<typeof openNativeMenu>;
let signal!: AbortSignal;
boot.initialize.mockImplementation(() => {
const effects = r.effects.applicationEffects; signal = effects.signal;
effects.listen(document, 'application-probe', heard); effects.delay(timer, 100);
+ menu = openNativeMenu(r.menus);
});
const root = createRoot(node); roots.add(root);
await act(async () => { root.render(<StrictMode><r.Application /></StrictMode>); });
expect(boot.initialize).toHaveBeenCalledTimes(1);
+ expect(menu.control.isOpen()).toBe(true);
+ expect(remove.mock.calls.filter(([type, callback]) => type === 'resize' && callback === menu.resize)).toHaveLength(0);
+ expect(remove.mock.calls.filter(([type, callback]) => type === 'scroll' && callback === menu.scroll)).toHaveLength(0);
document.dispatchEvent(new Event('application-probe')); expect(heard).toHaveBeenCalledTimes(1);
await act(async () => { root.unmount(); }); roots.delete(root);
document.dispatchEvent(new Event('application-probe')); vi.runAllTimers();
expect(heard).toHaveBeenCalledTimes(1); expect(timer).not.toHaveBeenCalled(); expect(signal.aborted).toBe(true);
+ expect(menu.control.isOpen()).toBe(false); expect(menu.toggle.getAttribute('aria-expanded')).toBe('false');
+ expect(remove.mock.calls.filter(([type, callback]) => type === 'resize' && callback === menu.resize)).toHaveLength(1);
+ expect(remove.mock.calls.filter(([type, callback, capture]) => type === 'scroll' && callback === menu.scroll && capture === true)).toHaveLength(1);
});
diff --git a/frontend/test/react/pages/overlay.test.tsx b/frontend/test/react/pages/overlay.test.tsx
index aa1c33f36..ccb918f6b 100644
--- a/frontend/test/react/pages/overlay.test.tsx
+++ b/frontend/test/react/pages/overlay.test.tsx
@@ -97,6 +97,22 @@ const over = (pathname: string, overlay: 'item' | 'follow' = 'item', search = ''
({ backgroundLocation: { pathname, search }, overlay });
const entry = (state: unknown, key = 'x') => ({ usr: state, key, idx: 1 });
+it('启动覆盖元素在应用动作就绪后打开,离开详情用当前动作关闭舞台', async () => {
+ const r = await load('/item/7');
+ const { actions, opened } = shellActions(r);
+ const root = createRoot(document.createElement('div'));
+ unmounts.push(() => root.unmount());
+ await act(async () => { root.render(<r.RouterRoot />) });
+ await settle();
+ expect(actions.openOverlay).not.toHaveBeenCalled();
+ await act(async () => { root.render(<r.RouterRoot actions={actions} />) });
+ await start(r);
+ expect(opened.map(one => one.target)).toEqual([{ kind: 'item', id: 7 }]);
+ await act(async () => { r.peachHistory.push('/performers/name') });
+ await settle();
+ expect(actions.closeStage).toHaveBeenCalledTimes(1);
+});
+
it('后退前进落到覆盖地址上接上背景并打开;没有请求的认领条目只同步地址;关掉时背景页不重挂', async () => {
const r = await load('/nowhere');
const { actions, opened } = shellActions(r);
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 49b5bb801..18e8e1891 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -5,7 +5,6 @@
"""
import json
import os
-import re
import stat
import tempfile
import threading
diff --git a/web/dist/peach-app.js b/web/dist/peach-app.js
index 4fd8f2b07..5328a307e 100644
--- a/web/dist/peach-app.js
+++ b/web/dist/peach-app.js
@@ -88970,13 +88970,15 @@ function Q8(e, t = !1) {
}, [n]);
}
function v9e() {
- let e = (0, b.useContext)(e5);
- return Q8((t) => {
+ let e = (0, b.useContext)(e5), t = (0, b.useRef)(e);
+ return (0, b.useLayoutEffect)(() => {
+ t.current = e;
+ }, [e]), Q8((t) => {
let n = $7e(q8.navigation.location.pathname);
e && n && (E8(), t || t9e(q8.navigation.location.state), e.openOverlay(n));
}, !0), (0, b.useEffect)(() => () => {
queueMicrotask(() => {
- S8(q8.navigation.location.pathname) || e?.closeStage();
+ S8(q8.navigation.location.pathname) || t.current?.closeStage();
});
}, []), null;
}
@@ -94903,7 +94905,7 @@ function Zat() {
}
}
}, U9.routing = !1, Z5.own(q8.listen((e) => {
- Q.queueOpenRequest && e.seq !== Q.queueOpenRequest.seq && !S8(e.location.pathname) && b9(!1), U9.routing && !e.claimed && queueMicrotask(k9);
+ Q.queueOpenRequest && e.seq !== Q.queueOpenRequest.seq && !S8(e.location.pathname) && b9(!1), U9.routing && !e.claimed && k9();
})), Ltt(U9.shellActions).catch((e) => console.error("客户端导航装载失败", e)), cit(), Nrt(), R7(), Promise.all([
h9(),
oit(),
@@ -95257,7 +95259,7 @@ function fot() {
owners: 0
}, e.own(uot(document)), e.own(() => {
qs(), V.cancelQueries();
- }), e.own(Rtt), e.own(u9e);
+ }), e.own(Rtt), e.own(u9e), e.own(Ra);
}
return Z9.owners += 1, Z9.effects.resume(), Z9;
}