Peach: Local-first video metadata scraper and media manager.
fix(web): 旧任务的问题列表投影进计数,失败时保留发起入口
longmeidao58fbf1b59b5b
diff --git a/frontend/src/islands/library-processing.tsx b/frontend/src/islands/library-processing.tsxindex 3e68a38dd..6d627ea20 100644--- a/frontend/src/islands/library-processing.tsx+++ b/frontend/src/islands/library-processing.tsx@@ -101,7 +101,7 @@ export function LibraryProcessing({ data, error, toast, onComplete, mode, monito<footer class="geist-fieldset-footer" data-geist-fieldset-footer><a class="geist-button" href="/scraping">采集来源</a>{!!state.candidates && <a class="geist-button" href="/review">复核资料</a>}- {state.status !== 'failed' && <button ref={button} type="button" class="geist-button primary" onClick={start}>扫描并补全资料</button>}+ {(state.status !== 'failed' || !retryable) && <button ref={button} type="button" class="geist-button primary" onClick={start}>扫描并补全资料</button>}</footer></section><div class="library-processing-outcome" aria-live="polite">diff --git a/frontend/test/library-processing.test.tsx b/frontend/test/library-processing.test.tsxindex 1ea5d6e6d..57b546ffc 100644--- a/frontend/test/library-processing.test.tsx+++ b/frontend/test/library-processing.test.tsx@@ -61,11 +61,20 @@ it('失败时列出问题总数并只提交失败项重试', async () => {await act(async()=>{render(h(LibraryProcessing,{data,error:'',toast:vi.fn()}),host)});expect(host.textContent).toContain('共 23 项问题,以下为前 1 项');expect(host.textContent).toContain('重试未完成项');+ expect(host.querySelector('.geist-fieldset-footer .geist-button.primary')).toBeNull();await act(async()=>{host.querySelector<HTMLButtonElement>('[data-note-action]')!.click();await new Promise(resolve=>setTimeout(resolve,0));});const post=calls.find(call=>call.init?.method==='POST');expect(post).toBeTruthy();expect(JSON.parse(String(post!.init!.body))).toEqual({job_id:'one',retry:[7,8]});});+it('失败项都不可重试时仍能重新发起整批任务', async () => {+ host=document.createElement('div');document.body.append(host);+ const data={status:'failed',job_id:'one',error:'1 项需要处理',issue_count:1,+ issue_preview:[{asset_id:1,message:'未识别到番号'}],retryable_asset_ids:[]};+ await act(async()=>{render(h(LibraryProcessing,{data,error:'',toast:vi.fn()}),host)});+ expect(host.querySelector('[data-note-action]')).toBeNull();+ expect(host.querySelector('.geist-fieldset-footer .geist-button.primary')?.textContent).toBe('扫描并补全资料');+});it('首页从空闲发现后台任务,完成后收起并在卸载后停止查询', async () => {vi.useFakeTimers();let status='running';diff --git a/src/peach/library_processing.py b/src/peach/library_processing.pyindex 315b1861c..aeda23822 100644--- a/src/peach/library_processing.py+++ b/src/peach/library_processing.py@@ -103,11 +103,19 @@ def _save(path, payload):def decorate(state, *, now=None):- """给运行中的状态副本补上等待时长与「长时间没有进展」标记。+ """把状态投影成当前契约,并给运行中的副本补上等待时长与「长时间没有进展」标记。- 只改这一次读取的副本:GET 不会把任务改成失败,慢与卡死由人判断。+ 旧状态文件把完整问题存在 `issues` 数组里;投影只留计数与前 20 条预览,+ 其余照旧可读,也不把上千条问题重新塞回每次轮询的响应。读取只改副本,+ GET 不会把任务改成失败,慢与卡死由人判断。"""state = dict(state)+ legacy = state.pop('issues', None)+ if legacy and 'issue_count' not in state:+ state['issue_count'] = len(legacy)+ state['issue_preview'] = [dict(asset_id=row.get('asset_id'), message=str(row.get('message') or ''))+ for row in legacy[:ISSUE_PREVIEW_LIMIT]]+ state['issues_truncated'] = len(legacy) > ISSUE_PREVIEW_LIMITif state.get('status') != 'running':return statenow = time.time() if now is None else nowdiff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.pyindex ae9e64242..a89dd958d 100644--- a/tests/test_metadata_library.py+++ b/tests/test_metadata_library.py@@ -263,6 +263,15 @@ class LibraryWatchdogTests(unittest.TestCase):self.assertFalse(within['stalled'])self.assertTrue(expired['stalled'])+ def test_legacy_issue_list_projects_into_count_and_preview(self):+ legacy = [{'asset_id': index, 'message': '未识别到番号'} for index in range(1, 26)]+ state = decorate({'status': 'failed', 'job_id': 'old', 'issues': legacy})+ self.assertNotIn('issues', state)+ self.assertEqual(state['issue_count'], 25)+ self.assertEqual(len(state['issue_preview']), 20)+ self.assertEqual(state['issue_preview'][0], {'asset_id': 1, 'message': '未识别到番号'})+ self.assertTrue(state['issues_truncated'])+@unittest.skipUnless(os.name == 'nt', '真实声明根使用 Windows 盘符')def test_deadline_skips_one_asset_and_keeps_processing(self):from peach.jav_cover_fetch import DeadlineExceededdiff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex 8f3b8f9b1..83658d622 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -743,7 +743,7 @@ function mt({ data: e, error: t, toast: n, onComplete: r, mode: i, monitor: a, phref: "/review",children: "复核资料"}),- s.status !== "failed" && /* @__PURE__ */ J("button", {+ (s.status !== "failed" || !A) && /* @__PURE__ */ J("button", {ref: C,type: "button",class: "geist-button primary",