Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(media): 处理方式的联网闸口与媒体库字段拆成独立函数,浏览器用例跟上行内字形与紧凑档

longmeidao4717b5edb14c
diff --git a/frontend/e2e/design-settings.test.ts b/frontend/e2e/design-settings.test.ts
index 2aa3ef596..c3c660d00 100644
--- a/frontend/e2e/design-settings.test.ts
+++ b/frontend/e2e/design-settings.test.ts
@@ -386,12 +386,15 @@ describe('设计决定:设置、口味、统计与筛选玻璃', () => {
.evaluate((node) => Math.round(node.getBoundingClientRect().top));
const selected = await nav.getByRole('tab', { name: '外观与导航', exact: true }).evaluate((node) => {
const style = getComputedStyle(node), icon = getComputedStyle(node.querySelector('svg')!);
- return { face: style.backgroundColor, ring: style.boxShadow, icon: [icon.width, icon.height, icon.fill === style.color, icon.stroke] };
+ // 与文字同行的图标取 `--icon-inline`(1.2em),按所在文字字号算出应有的边长。
+ const side = (value: string) => `${Math.round(parseFloat(value) * 10) / 10}px`;
+ return { face: style.backgroundColor, ring: style.boxShadow, inline: side(String(parseFloat(style.fontSize) * 1.2)),
+ icon: [side(icon.width), side(icon.height), icon.fill === style.color, icon.stroke] };
});
assert.equal(selected.face, 'rgba(0, 0, 0, 0)', '当前项自己铺了底,滑动的那块玻璃被盖住');
assert.equal(selected.ring, 'none');
// Remix 的线条是 `fill` 画出的轮廓,全站默认的 `stroke:currentColor;fill:none` 会让它整枚消失。
- assert.deepEqual(selected.icon, ['20px', '20px', true, 'none']);
+ assert.deepEqual(selected.icon, [selected.inline, selected.inline, true, 'none']);
assert.equal(await glide(), await top('外观与导航'), '玻璃没有落在当前项上');
await nav.getByRole('tab', { name: '浏览与播放', exact: true }).hover();
diff --git a/frontend/e2e/entity-cold-skeleton.test.ts b/frontend/e2e/entity-cold-skeleton.test.ts
index 4ad434700..1c36284e7 100644
--- a/frontend/e2e/entity-cold-skeleton.test.ts
+++ b/frontend/e2e/entity-cold-skeleton.test.ts
@@ -92,7 +92,8 @@ describe('实体页冷启动等待态', () => {
const waitingControls = await controls();
const batch = waitingControls.find(control => control.selector === '[data-entity-batch]')!;
assert.deepEqual(batch.icon, { width: 16, height: 16, x: 0, y: 0 }, '换一批图标应居中且保持 16px');
- assert.equal(await root.locator('[data-entity-tags] .skeleton').first().evaluate(node => node.getBoundingClientRect().height), 30);
+ // 筛选条里的标签取紧凑档 `--control-h-compact`,骨架与真实标签同高。
+ assert.equal(await root.locator('[data-entity-tags] .skeleton').first().evaluate(node => node.getBoundingClientRect().height), 32);
assert.ok(await root.locator('[data-entity-state]').count(), '静态观看筛选尚未显示');
const ratio = () => root.locator('[style*="--skeleton-card-ratio"]').first().evaluate(node =>
Number((node as HTMLElement).style.getPropertyValue('--skeleton-card-ratio')));
diff --git a/src/peach/library_processing.py b/src/peach/library_processing.py
index 278e663bc..ea8b465ca 100644
--- a/src/peach/library_processing.py
+++ b/src/peach/library_processing.py
@@ -1839,6 +1839,29 @@ def _library_stages(config):
return stages_of
+def _people_allowed(config):
+ """有没有哪个媒体库的处理方式联网补人物图片;都没有时整轮不补人物资料、不派实体后继。"""
+ return any('people' in stages for stages in media_identity.stages_by_root(config).values())
+
+
+def _collect_allowed(remote, traffic, row, code, missing, allowed, cover_root, covered, *,
+ update, issue, answered, received, succeeded):
+ """按这一行所属媒体库的处理方式问外部来源(ADR-0116),返回 (证据条目, 新落盘的封面数)。
+
+ 关掉的联网步骤不问:不补资料时不带缺失字段,不补封面时不找封面,两样都关就整行不联网。
+ 不补人物图片的媒体库,这一行换上的封面不记进 `covered`,不因此派补头像后继。"""
+ found, covers = [], 0
+ if allowed & {'metadata', 'cover'}:
+ traffic.start_metadata(code)
+ found, covers = remote.collect(row, code, missing if 'metadata' in allowed else [], cover_root,
+ update=update, issue=issue, answered=answered, received=received,
+ fetch_cover='cover' in allowed)
+ traffic.finish_work('metadata', code, successful=succeeded())
+ if 'people' in allowed:
+ covered.append((row['id'], covers))
+ return found, covers
+
+
def _check_processing_junk(database, locations, online_roots, asset_ids, protected_ids, state, update):
"""只检查本趟可访问目录或显式选择,并把隔离与复核计数记进可恢复状态。"""
roots = [(source, root) for source, paths in locations.items() for root in paths
@@ -2542,22 +2565,15 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='co
total=completed_count + len(prepared), current_asset_id=row['id'],
current_asset_name=Path(str(row['name'] or '')).name)
target_key = f"asset:{row['id']}"
- # 媒体库处理方式关掉的联网步骤不问外部来源(ADR-0116);本地读到的证据照常保存。
- allowed = stages_of(row['path'])
- missing = ((list(COLLECTED_FIELDS) if verify_existing else _missing_fields(row, local_fields))
- if 'metadata' in allowed else [])
- found, covers = [], 0
- if allowed & {'metadata', 'cover'}:
- traffic.start_metadata(code)
- found, covers = remote.collect(row, code, missing, cover_root, update=update, issue=issue,
- answered=() if verify_existing else _answered_sources(groups, target_key, missing),
- received=lambda entries, row=row, code=code, fields=local_fields, verify=verify_existing:
- publish(row, code, fields, verify, entries),
- fetch_cover='cover' in allowed)
- traffic.finish_work('metadata', code, successful=state['issue_count'] == issues_before)
+ missing = list(COLLECTED_FIELDS) if verify_existing else _missing_fields(row, local_fields)
+ found, covers = _collect_allowed(
+ remote, traffic, row, code, missing, stages_of(row['path']), cover_root, covered,
+ update=update, issue=issue,
+ answered=() if verify_existing else _answered_sources(groups, target_key, missing),
+ received=lambda entries, row=row, code=code, fields=local_fields, verify=verify_existing:
+ publish(row, code, fields, verify, entries),
+ succeeded=lambda before=issues_before: state['issue_count'] == before)
state['covers'] += covers
- if 'people' in allowed:
- covered.append((row['id'], covers))
update(stage='保存待确认资料', current_action='writing_candidates',
current_started_at=time.time(), current_deadline_at=None)
checkpoints.queue_metadata(row, local_entries + found if local_ok else [], issues_before)
@@ -2572,7 +2588,7 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='co
summary = _finish_collection(
config, database, candidate_root, cover_root, groups, remote, asset_ids=scope_ids,
active=active, update=update, issue=issue, watermark=entity_watermark, covered=covered,
- people=any('people' in stages for stages in media_identity.stages_by_root(config).values()))
+ people=_people_allowed(config))
summary['auto_applied'] = summary.get('auto_applied', 0) + state['auto_applied']
summary['auto_rejected'] = summary.get('auto_rejected', 0) + state['auto_rejected']
finish_step('collect')
diff --git a/src/peach/media_identity.py b/src/peach/media_identity.py
index 5cc17d824..a40c5b81b 100644
--- a/src/peach/media_identity.py
+++ b/src/peach/media_identity.py
@@ -169,6 +169,23 @@ def _match_root(row, root, previous, by_path, *, windows):
return supplied or matched or str(uuid4()), old
+def _library_value(row, known, name):
+ """表单行里媒体库这一级的字段。来源色与处理方式只在设了时写进配置;表单没带的项沿用已保存的值。"""
+ value = dict(name=name, icon=str(row.get("library_icon", known.get("icon", ""))))
+ color = str(row.get("library_color", known.get("color", "")))
+ policy = str(row.get("library_policy", known.get("policy", "")))
+ if color:
+ value["color"] = color
+ if policy and policy != "auto":
+ value["policy"] = policy
+ if policy == "custom":
+ chosen = str(row.get("library_stages", known.get("stages", ""))).split(",")
+ if any(stage and stage not in STAGES for stage in chosen):
+ raise ValueError("处理步骤无效")
+ value["stages"] = ",".join(stage for stage in STAGES if stage in chosen)
+ return value
+
+
def configure_sources(config, sources, *, windows):
"""更新根目录与媒体库;既有根的来源和账本前缀保持稳定。"""
from .media_sources import cost_for
@@ -185,21 +202,7 @@ def configure_sources(config, sources, *, windows):
library_id = str(row.get("library_id") or (old or {}).get("library_id") or uuid4())
UUID(library_id)
name = str(row.get("library") or libraries.get(library_id, {}).get("name") or PureWindowsPath(root).name or root).strip()
- known = libraries.get(library_id, {})
- icon = str(row.get("library_icon", known.get("icon", "")))
- value = dict(name=name, icon=icon)
- # 来源色与处理方式只在设了时写进配置;表单没带这几项时沿用已保存的值。
- color = str(row.get("library_color", known.get("color", "")))
- policy = str(row.get("library_policy", known.get("policy", "")))
- if color:
- value["color"] = color
- if policy and policy != "auto":
- value["policy"] = policy
- if policy == "custom":
- chosen = str(row.get("library_stages", known.get("stages", ""))).split(",")
- if any(stage and stage not in STAGES for stage in chosen):
- raise ValueError("处理步骤无效")
- value["stages"] = ",".join(stage for stage in STAGES if stage in chosen)
+ value = _library_value(row, libraries.get(library_id, {}), name)
if library_id in declared_libraries and declared_libraries[library_id] != value:
raise ValueError("同一媒体库的名称、图标、来源色和处理方式必须一致")
declared_libraries[library_id] = value