Peach: Local-first video metadata scraper and media manager.
fix(avatars): 拒绝封面覆盖人像并校验取景源尺寸
longmeidao5a5307fa631a
diff --git a/docs/PRODUCT_BACKLOG.md b/docs/PRODUCT_BACKLOG.mdindex b445a7588..9c8065166 100644--- a/docs/PRODUCT_BACKLOG.md+++ b/docs/PRODUCT_BACKLOG.md@@ -97,4 +97,4 @@2026-09-06 核对 wish-promotion.jp 已是其他内容站,不能作为现官网。15 条现官网链接使用共用 Chrome UA 重查,13 条返回 200;Cruse Group 证书链与 Prime Agency TLS 连接仍未取得。32. `install_entity_links.py` 的可达性门槛按「非 200 就跳过」执行,而同文件的 `is_gone()` 明确写着 403/5xx/连接错误不能当「页面没了」。首批 703 条里 137 条因此没装,其中 31 条 twitter.com、23 条 t-powers.co.jp。把跳过分成「确证没了」和「这次没取到」两档:后者留进待复查队列,配合 `rediscover_entity_links.py` 对 t-powers/nax-pro/mines-pro 这些已经搬家的域名上溯找新锚,再装一次。33. 托盘自重建被测试记录门槛卡住:2026-09-05 22:54 托盘为 0.8.5 起的那次「同步开发进度」全量 3181 个用例全绿,`scripts/test_runner.py` 却因验证前后主检出的内容或依赖快照不一致判本次记录无效、退出码 1,托盘按测试失败处理,没有打包也没有换 EXE,并且同一 HEAD 不再重试;同一时段两次 `auto` 记录也是空的 `validated`。第二次(23:14 起,HEAD 5a4b37f8)跑到一半,协调者于 23:17:42 把 0.8.6 合进了同一个主检出,全量因此 6 个用例失败、记录再次无效;失败用例名未取得,第三次尝试一开始就把日志覆盖了。机制已确认:托盘在主检出跑全量,`integrate` 的 `integration.lock` 与全量的 `full-suite.lock` 互不排斥,任何一次集成都会改掉正在验证的树。要做三件事:集成前等主检出里正在跑的全量结束(或让两把锁互斥),并把「记录无效」和「用例失败」在退出码或输出上分开,让托盘对前者重试而不是放弃;托盘的日志只写 stderr,没有落盘,22:43 那次托盘连同两个服务一起消失的原因也因此未取得,给托盘补一份 `logs/tray.log`。现场:线上服务 0.8.5 正常,托盘 EXE 仍是 21:08 打的 0.8.1,`pyproject.toml` 与 `windows_update.py` 的改动没进 EXE。-34. 封面来源头像逐条复核:78 张仍来自 `cover-fallback`,清单位于 `attic/reviews/20260906-portrait-agency/remaining-cover-avatars.csv`。封面关联单一演员不构成人脸身份核验,采集器只生成候选,不自动安装。日向真凛缓存为 SSIS-135 封面,印刷署名与别名一致,独立官方人像来源仍待补齐。+34. 封面来源头像逐条复核:37 张仍来自 `cover-fallback`,完整初始清单位于 `attic/reviews/20260906-portrait-agency/remaining-cover-avatars.csv`。41 张被封面覆盖的 Gfriends 人像已从备份恢复,包括日向真凛,恢复记录见同目录 `cover-restore-result.json`。采集器将封面保留为未验证候选,安装函数拒绝把封面写成人物头像。diff --git a/frontend/src/islands.ts b/frontend/src/islands.tsindex 5579dfa8c..b43c9a395 100644--- a/frontend/src/islands.ts+++ b/frontend/src/islands.ts@@ -29,7 +29,7 @@ import type { ScrapingData, ScrapingProps } from './islands/scraping';* 怎么写一个 store 见 `./state/index.ts` 和 `docs/FRONTEND.md`。 */export { refreshStore, storeNames } from './state';export { watchJob, followJobProgress } from './jobs';-export { nativeImageFit } from './native-image';+export { nativeImageFit, matchesFaceSource } from './native-image';export { entitySkeletonHtml } from './entity-skeleton';export { syncSidebarSurface, sidebarTagCounts, sidebarHasCatalogContent } from './sidebar';export { cleanupSkeletonHtml, cloudLocations, cloudPreferenceLocations, tasteHistoryGuideHtml, wireTasteHistoryGuide, TASTE_GUIDE_KEY } from './management';diff --git a/frontend/src/native-image.ts b/frontend/src/native-image.tsindex 99f49b8d8..0a8a005a1 100644--- a/frontend/src/native-image.ts+++ b/frontend/src/native-image.ts@@ -1,3 +1,8 @@+/** 焦点只适用于生成它的源图尺寸,缓存中的另一张图不得借用。 */+export function matchesFaceSource(width: number, height: number, sourceWidth: number, sourceHeight: number) {+ return width > 0 && height > 0 && width === sourceWidth && height === sourceHeight;+}+/** 64 px 以下的头像属于小图标;大图和 70 px 紧凑头像按源像素判断是否补底。 */export function nativeImageFit(width: number, height: number, frameWidth: number, frameHeight: number, dpr = 1) {const density = Number.isFinite(dpr) && dpr > 0 ? dpr : 1;diff --git a/frontend/test/native-image.test.ts b/frontend/test/native-image.test.tsindex 27879cf32..c8cb7e639 100644--- a/frontend/test/native-image.test.ts+++ b/frontend/test/native-image.test.ts@@ -1,5 +1,11 @@import { describe, expect, it } from 'vitest';-import { nativeImageFit } from '../src/native-image';+import { nativeImageFit, matchesFaceSource } from '../src/native-image';++it('544×724 的旧人像不能使用 2184×1468 封面的焦点', () => {+ expect(matchesFaceSource(544, 724, 2184, 1468)).toBe(false);+ expect(matchesFaceSource(544, 724, 544, 724)).toBe(true);+ expect(matchesFaceSource(0, 0, 0, 0)).toBe(false);+});describe('头像和标识的小图补底', () => {it('大框中的低分辨率图片按原尺寸居中', () => {diff --git a/scripts/harvest_social_avatars.py b/scripts/harvest_social_avatars.pyindex 848074b29..0be54a6e2 100644--- a/scripts/harvest_social_avatars.py+++ b/scripts/harvest_social_avatars.py@@ -755,6 +755,8 @@ def outranks_incumbent(winner: dict, incumbent: dict | None) -> bool:def install_avatar(avatar_dir: Path, kind: str, entity_id: int, winner: dict) -> Path:"""赢家直接落盘到 /entity-image 真正读的目录,带 .ct、provenance 与取景 sidecar。"""+ if source_tier(winner) == COVER_TIER:+ raise ValueError("作品封面只作为候选留档,不安装为人物头像")destination = avatar_dir / f"{kind}-{entity_id}.img"avatar_dir.mkdir(parents=True, exist_ok=True)data = winner["object_path"].read_bytes()diff --git a/tests/test_social_avatar_harvest.py b/tests/test_social_avatar_harvest.pyindex ce3717cc8..25f3409e7 100644--- a/tests/test_social_avatar_harvest.py+++ b/tests/test_social_avatar_harvest.py@@ -471,6 +471,18 @@ class InstallGateTests(unittest.TestCase):root, jpeg(400, 400, (9, 9, 9)), None))self.assertFalse((root / "performer-1.face.json").exists())+ def test_cover_candidates_cannot_overwrite_an_installed_portrait(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp).resolve()+ original = jpeg(544, 724)+ self.install(root, "performer-1.img", original, self.record(544, 724, 234))+ candidate = self.winner(root, jpeg(2184, 1468), self.record(2184, 1468, 234))+ candidate["provider"] = "cover-fallback"+ with self.assertRaisesRegex(ValueError, "作品封面"):+ self.module.install_avatar(root, "performer", 1, candidate)+ self.assertEqual((root / "performer-1.img").read_bytes(), original)+ self.assertEqual(json.loads((root / "performer-1.face.json").read_text())["px"], [544, 724])+def test_a_missing_face_model_records_the_reason_instead_of_raising(self):"""下不到 ONNX 不该把「今天没网」变成「所有人都没有头像」。"""from peach.avatar_face import FaceProbediff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 141bd6593..ba91536ce 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -4541,6 +4541,8 @@ class WebUiSourceTests(unittest.TestCase):def test_portrait_pixels_do_not_size_the_face_frame(self):self.assertPageContains(".entityportrait img{position:absolute;inset:0;grid-area:auto;")+ self.assertPageContains("if(!matchesFaceSource(img.naturalWidth,img.naturalHeight,imgW,imgH)){")+ self.assertPageContains("img.style.objectPosition='50% 50%';")def test_the_agency_page_gets_the_same_loading_skeleton(self):self.assertPageContains("performers|creators|studios|agencies")diff --git a/web/app.js b/web/app.jsindex abc49d426..196c66c61 100644--- a/web/app.js+++ b/web/app.js@@ -6,7 +6,7 @@ import { matchRoute, routeLabel } from './js/routes.js';import { initMiddleTruncate } from './js/middle-truncate.js';import { tagLabel } from './js/tags.js';import { syncSidebarSurface, sidebarTagCounts, sidebarHasCatalogContent, cleanupSkeletonHtml, cloudLocations, cloudPreferenceLocations, tasteHistoryGuideHtml, wireTasteHistoryGuide, TASTE_GUIDE_KEY } from './dist/peach-ui.js';-import { nativeImageFit, entitySkeletonHtml } from './dist/peach-ui.js';+import { nativeImageFit, matchesFaceSource, entitySkeletonHtml } from './dist/peach-ui.js';import {attachOverlayScrollbar, breadcrumbHtml, checkboxHtml, closeAnchoredMenu, confirmModal, emptyStateHtml, fieldsetTitle,fillSkeletonTier, fitSkeleton, iconSwitchHtml, indexSkeletonHtml, loadingDotsHtml,@@ -1884,6 +1884,10 @@ function avatarFrame(img){return;}const [cx,cy,faceW,imgW,imgH]=String(img.dataset.facebox).split(' ').map(Number);+ if(!matchesFaceSource(img.naturalWidth,img.naturalHeight,imgW,imgH)){+ img.style.objectPosition='50% 50%';+ return;+ }const frame=faceFrame({cx,cy,faceW,imgW,imgH},{w:rect.width,h:rect.height},window.devicePixelRatio||1);// 放不大就一个字都不写:留下的是 CSS 里那份几何,`object-position` 照旧生效。diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex 33d3944ad..6a83e10b0 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -1710,7 +1710,10 @@ async function Zt(e) {}//#endregion//#region src/native-image.ts-function Qt(e, t, n, r, i = 1) {+function Qt(e, t, n, r) {+ return e > 0 && t > 0 && e === n && t === r;+}+function $t(e, t, n, r, i = 1) {let a = Number.isFinite(i) && i > 0 ? i : 1;e /= a, t /= a;let o = [@@ -1727,7 +1730,7 @@ function Qt(e, t, n, r, i = 1) {}//#endregion//#region src/entity-skeleton.ts-function $t(e, t) {+function en(e, t) {return `<section data-skeleton="entity/${e}" role="status" aria-label="正在读取资料"><span class="sr-only">正在读取资料</span><div aria-hidden="true"><div class="entityhero"><div class="entityportrait ${e === "studio" || e === "agency" ? "square " : ""}skeleton"></div>@@ -1739,7 +1742,7 @@ function $t(e, t) {}//#endregion//#region src/sidebar.ts-function en(e) {+function tn(e) {return ["/","/unseen",@@ -1749,23 +1752,23 @@ function en(e) {"/junk-files"].includes(e) || /^\/(item|mix|parts|editions)\//.test(e) || /^\/playlists\/\d+\/\d+$/.test(e) || /^\/(performers|studios|creators|series|agencies)\/.+/.test(e);}-function tn(e, t) {+function nn(e, t) {return e.dataset.surface === t && e.querySelector(".dnav") ? !1 : (e.dataset.surface = t, e.replaceChildren(), !0);}-function nn(e) {+function rn(e) {let t = /* @__PURE__ */ new Map();for (let n of e) for (let e of new Set(n.tags || [])) t.set(e, (t.get(e) || 0) + 1);return [...t].sort((e, t) => t[1] - e[1]).slice(0, 30);}//#endregion//#region src/management.ts-function rn(e) {+function an(e) {return e.filter((e) => ["115", "pikpak"].includes(e.location) && (e.roots === void 0 || e.roots.length > 0)).map((e) => e.location);}-function an(e, t) {+function on(e, t) {return t.filter((t) => e.some((e) => e.location === t));}-function on() {+function sn() {return `<div class="cleanuppage" data-skeleton="cleanup" aria-busy="true" aria-label="正在读取数据管理状态"><div class="cleanupgrid">${[[@@ -1811,7 +1814,7 @@ function on() {<footer class="geist-fieldset-footer" data-geist-fieldset-footer><button type="button"${r === 3 ? " class=\"danger\"" : ""} disabled>${r === 3 ? "<svg aria-hidden=\"true\"><use href=\"#i-trash\"></use></svg><span>" + t + "</span>" : t}</button></footer></section>`).join("")}</div></div>`;}-function sn(e, t = !1, n = !1) {+function cn(e, t = !1, n = !1) {if (t || n) return "";let r = "<svg aria-hidden=\"true\"><use href=\"#i-external-link\"></use></svg>";return `<details class="taste-history-guide"${e ? " open" : ""}>@@ -1825,16 +1828,16 @@ function sn(e, t = !1, n = !1) {<button type="button" class="taste-guide-skip">跳过</button></div></details>`;}-var cn = "peach-taste-guide-dismissed";-function ln(e, t) {+var ln = "peach-taste-guide-dismissed";+function un(e, t) {let n = e.querySelector(".taste-history-guide");n?.querySelector(".taste-guide-skip")?.addEventListener("click", () => {- t.setItem(cn, "1"), n.remove();+ t.setItem(ln, "1"), n.remove();});}//#endregion//#region src/islands.ts-var un = {+var dn = {scraping: {load: Gt,component: Jt@@ -1847,11 +1850,11 @@ var un = {load: Xe,component: nt}-}, dn = () => Object.keys(un), $ = /* @__PURE__ */ new Map();-async function fn(e, t, n, r = {}) {- let i = un[e];+}, fn = () => Object.keys(dn), $ = /* @__PURE__ */ new Map();+async function pn(e, t, n, r = {}) {+ let i = dn[e];if (!i) throw Error(`未注册的 island:${String(e)}`);- pn(t);+ mn(t);let a = {controller: new AbortController(),painted: !1@@ -1882,9 +1885,9 @@ async function fn(e, t, n, r = {}) {};xe(te(i.component, s), t);}-function pn(e) {+function mn(e) {let t = $.get(e);t && (t.controller.abort(), $.delete(e), t.painted && xe(null, e));}//#endregion-export { cn as TASTE_GUIDE_KEY, on as cleanupSkeletonHtml, rn as cloudLocations, an as cloudPreferenceLocations, $t as entitySkeletonHtml, Wt as followJobProgress, dn as islandNames, fn as mountIsland, Qt as nativeImageFit, Zt as refreshStore, en as sidebarHasCatalogContent, nn as sidebarTagCounts, Xt as storeNames, tn as syncSidebarSurface, sn as tasteHistoryGuideHtml, pn as unmountIsland, Ut as watchJob, ln as wireTasteHistoryGuide };+export { ln as TASTE_GUIDE_KEY, sn as cleanupSkeletonHtml, an as cloudLocations, on as cloudPreferenceLocations, en as entitySkeletonHtml, Wt as followJobProgress, fn as islandNames, Qt as matchesFaceSource, pn as mountIsland, $t as nativeImageFit, Zt as refreshStore, tn as sidebarHasCatalogContent, rn as sidebarTagCounts, Xt as storeNames, nn as syncSidebarSurface, cn as tasteHistoryGuideHtml, mn as unmountIsland, Ut as watchJob, un as wireTasteHistoryGuide };