Peach: Local-first video metadata scraper and media manager.
fix: keep follow context around detail gallery
longmeidao3f216bcd62f8
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 4027f6c21..c39f6a927 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -937,7 +937,7 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains("if(path==='/follow-manage'){await openFollowManage(false);return}")self.assertPageContains(- "if(parts[0]==='follow'&&parts[1]==='item'&&/^\\d+$/.test(parts[2]||'')){await openFollowDetail(+parts[2],false);return}")+ "await openFollow(false,true);await openFollowDetail(+parts[2],false)")self.assertPageContains("api(`/api/follow?item=${encodeURIComponent(id)}`)")self.assertPageContains(".then(async()=>{buildEdge();wireAllDrag();await restoreRoute();scheduleStickySurfaces()})")@@ -1275,6 +1275,17 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains("imageDots.length&&(e.key==='ArrowLeft'||e.key==='ArrowRight')")self.assertPageContains("openFollowDetail(item.id,false,+index,true)")self.assertPageContains(".followimagedots button[aria-current=\"true\"]")+ self.assertPageContains("function alignFollowImageControls()")+ self.assertPageContains("const renderedWidth=Math.min(box.width,box.height*ratio)")+ self.assertPageContains("--follow-image-arrow-inset")++ def test_follow_detail_keeps_filter_context_and_clears_initial_loading(self):+ self.assertPageContains("async function openFollow(push=true,renderForDetail=false)")+ self.assertPageContains("if(location.pathname!=='/follow'&&!renderForDetail)return")+ self.assertPageContains("await openFollow(false,true);await openFollowDetail(+parts[2],false)")+ self.assertPageContains("const followList=$('#stats').querySelector('.followlist')")+ self.assertPageContains("if(followList)followList.before($('#stage'))")+ self.assertPageContains("if(stage.parentElement!==main)main.insertBefore(stage,combo)")def test_follow_filters_put_all_first_and_sources_are_icon_only(self):self.assertPageContains("const FOLLOW_FILTERS=[['','全部'],['new','未看']")diff --git a/web/app.css b/web/app.cssindex 3f3704733..17cd4525d 100644--- a/web/app.css+++ b/web/app.css@@ -1297,7 +1297,7 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.fstate{flex:1 1 100%;font-size:var(--fs-xs);color:var(--drop)}.fvkind{display:inline-block;max-width:120px;margin-right:6px;padding:1px 7px;border-radius:var(--badge-radius);overflow:hidden;text-overflow:ellipsis;vertical-align:-2px;background:var(--overlay-5);color:var(--muted);font-size:var(--fs-xs);font-style:normal}.fvkind.wip{color:var(--meter)}.fvkind.alt{color:var(--tungsten)}-.followdetailmedia{min-height:min(62vh,640px)}.followdetailposter{position:relative;z-index:1;display:block;width:100%;height:100%;max-height:76vh;object-fit:contain;background:#000}.followimagearrow{position:absolute;z-index:4;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:46px;height:46px;border:1px solid rgba(255,255,255,.24);border-radius:50%;background:rgba(0,0,0,.56);color:#fff;cursor:pointer;backdrop-filter:blur(10px)}.followimagearrow:hover{background:rgba(255,255,255,.18)}.followimagearrow.prev{left:16px}.followimagearrow.next{right:16px}.followimagearrow svg{width:25px;height:25px;stroke:currentColor;fill:none}.followimagedots{position:absolute;z-index:4;left:50%;bottom:18px;transform:translateX(-50%);display:flex;align-items:center;justify-content:center;gap:8px;max-width:calc(100% - 120px);padding:8px 11px;border-radius:14px;background:rgba(0,0,0,.5);overflow:hidden}.followimagedots button{flex:none;width:8px;height:8px;padding:0;border:0;border-radius:50%;background:rgba(255,255,255,.42);cursor:pointer}.followimagedots button[aria-current="true"]{width:20px;border-radius:5px;background:#fff}+.followdetailmedia{--follow-image-arrow-inset:16px;min-height:min(62vh,640px)}.followdetailposter{position:relative;z-index:1;display:block;width:100%;height:100%;max-height:76vh;object-fit:contain;background:#000}.followimagearrow{position:absolute;z-index:4;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:46px;height:46px;border:1px solid rgba(255,255,255,.24);border-radius:50%;background:rgba(0,0,0,.56);color:#fff;cursor:pointer;backdrop-filter:blur(10px)}.followimagearrow:hover{background:rgba(255,255,255,.18)}.followimagearrow.prev{left:var(--follow-image-arrow-inset)}.followimagearrow.next{right:var(--follow-image-arrow-inset)}.followimagearrow svg{width:25px;height:25px;stroke:currentColor;fill:none}.followimagedots{position:absolute;z-index:4;left:50%;bottom:18px;transform:translateX(-50%);display:flex;align-items:center;justify-content:center;gap:8px;max-width:calc(100% - 120px);padding:8px 11px;border-radius:14px;background:rgba(0,0,0,.5);overflow:hidden}.followimagedots button{flex:none;width:8px;height:8px;padding:0;border:0;border-radius:50%;background:rgba(255,255,255,.42);cursor:pointer}.followimagedots button[aria-current="true"]{width:20px;border-radius:5px;background:#fff}.followdetailplaceholder{display:grid;place-items:center;gap:10px;color:var(--muted)}.followdetailplaceholder .ficon{width:34px;height:34px;margin:0}.followdetailtitle{display:flex;gap:5px;align-items:flex-start;margin-bottom:8px}.followdetailtitle .stitle{width:auto;max-width:calc(100% - 35px);margin:0}.followdetailtitle .followorigin{flex:none;width:30px;height:30px;margin:0;display:grid;place-items:center;border-radius:7px}.followdetailtitle .followorigin:hover{background:var(--hover)}.followdetailidentity{display:flex;align-items:center;gap:10px;margin:2px 0 12px}.followdetailidentity .mav{flex:none}.followdetailidentity b,.followdetailidentity span{display:block}.followdetailidentity>div>span{margin-top:3px;color:var(--muted);font-size:var(--fs-xs)}@@ -1305,7 +1305,7 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.fnote.followmedianote{margin:18px 0 8px}.followresources{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 16px}.followresources a{display:inline-flex;align-items:center;gap:7px;height:34px;padding:0 11px;border:1px solid var(--border-15);border-radius:7px;color:var(--ink-2);text-decoration:none}.followresources a:hover{border-color:var(--tungsten);color:var(--ink);text-decoration:none}.followresources svg{width:15px;height:15px;stroke:currentColor;fill:none}.followdetailactions{margin-top:2px}.followdetailactions button:disabled{opacity:.45;cursor:default}.followorigin{display:inline-flex;align-items:center;gap:7px;width:max-content;margin-top:auto;color:var(--muted);text-decoration:none}.followorigin svg{width:16px;height:16px;stroke:currentColor;fill:none}.followorigin:hover{color:var(--ink);text-decoration:none}@media (max-width:640px){.followhead{align-items:center}.follow .fcheck{height:36px;padding:0 13px}.followauthors{margin-right:-12px;padding-top:3px}.followfilters{margin-right:-12px;padding-right:12px}- .followimagearrow{width:42px;height:42px}.followimagearrow.prev{left:10px}.followimagearrow.next{right:10px}.followimagedots{bottom:12px}+ .followdetailmedia{--follow-image-arrow-inset:10px}.followimagearrow{width:42px;height:42px}.followimagedots{bottom:12px}}/* ── 关注管理页 ──diff --git a/web/app.js b/web/app.jsindex 15c66a5fb..c965b8e7d 100644--- a/web/app.js+++ b/web/app.js@@ -269,6 +269,10 @@ function cancelStreamSession(session){}function disposeStage(push=false){const stage=$('#stage');+ // 关注详情会把舞台插到头像和筛选条之后。离开详情前先放回 main 的固定槽位,+ // 否则下一次重绘 #stats 会连同 #stage 一起删掉,后续所有详情都打不开。+ const main=$('#main'),combo=$('#combo');+ if(stage.parentElement!==main)main.insertBefore(stage,combo);if(detailStatsTimer){clearInterval(detailStatsTimer);detailStatsTimer=null}if(detailNetTimer){clearInterval(detailNetTimer);detailNetTimer=null}if(detailNetHideTimer){clearTimeout(detailNetHideTimer);detailNetHideTimer=null}@@ -1613,6 +1617,10 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=falsconst tags=(item.tags||[]).map(tag=>followTagChip(item,tag,'button')).join('');const author=followAuthorName(authorSources)||item.author||item.source_label||'作者未取得';const postedBy=item.author&&foldName(item.author)!==foldName(author)?item.author:'';+ // 关注列表的头像与筛选就是详情的上文;舞台放在筛选和卡片网格之间,+ // 不再占用 main 最顶部、把用户从原来的筛选上下文里切走。+ const followList=$('#stats').querySelector('.followlist');+ if(followList)followList.before($('#stage'));$('#stage').hidden=false;document.body.classList.add('detail-open');$('#stage').innerHTML=`<div class="sgrid followdetailgrid${collection||embeddedQueue?' mixgrid':''}"><div class="vwrap followdetailmedia"><button class="closestage" id="closeStage" title="关闭" aria-label="关闭">${icon('x')}</button>${media}${imageControls}</div>@@ -1665,7 +1673,28 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=falsitem.status=button.dataset.followDetailStatus;$('#stage').querySelectorAll('[data-follow-detail-status]').forEach(control=>control.setAttribute('aria-pressed',String(control.dataset.followDetailStatus===item.status)))}));- $('#stage').scrollIntoView({block:'start',behavior:'smooth'});+ alignFollowImageControls();+ ($('#stats').querySelector('.followhead')||$('#stage')).scrollIntoView({block:'start',behavior:'smooth'});+}++/* object-fit:contain 后图片左右黑边会随图片比例和窗口改变。箭头应位于黑边的视觉中心,+ 不能永远贴容器边缘;黑边太窄时才退回原来的安全内边距。 */+function alignFollowImageControls(){+ const frame=$('#stage:not([hidden]) .followdetailmedia');+ const image=frame?.querySelector('.followdetailposter');+ const arrow=frame?.querySelector('.followimagearrow');+ if(!frame||!image||!arrow)return;+ const align=()=>{+ if(!image.naturalWidth||!image.naturalHeight)return;+ const box=frame.getBoundingClientRect(),ratio=image.naturalWidth/image.naturalHeight;+ const renderedWidth=Math.min(box.width,box.height*ratio);+ const gutter=Math.max(0,(box.width-renderedWidth)/2);+ const fallback=matchMedia('(max-width:640px)').matches?10:16;+ const inset=gutter>=arrow.offsetWidth+fallback*2?(gutter-arrow.offsetWidth)/2:fallback;+ frame.style.setProperty('--follow-image-arrow-inset',`${Math.round(inset)}px`);+ };+ if(image.complete)requestAnimationFrame(align);+ else image.addEventListener('load',align,{once:true});}function wireFollowDetail(root){@@ -1879,7 +1908,7 @@ function wireFollowOlder(){};}-async function openFollow(push=true){+async function openFollow(push=true,renderForDetail=false){releaseHoverPreviews();disposeStage(false);document.body.classList.remove('entity-open','index-open');if(push)route('/follow');@@ -1889,9 +1918,9 @@ async function openFollow(push=true){$('#managebar').hidden=true;$('#manageTitle').hidden=true;buildEdge();$('#stats').innerHTML='<div class="follow"><p class="empty">正在读取…</p></div>';followData=await api(`/api/follow?limit=300${followFilter?`&status=${followFilter}`:''}`);- if(location.pathname!=='/follow')return;+ if(location.pathname!=='/follow'&&!renderForDetail)return;renderFollow();- window.scrollTo({top:0,behavior:'smooth'});+ if(!renderForDetail)window.scrollTo({top:0,behavior:'smooth'});}/* ── 管的那一页 ── */@@ -3334,7 +3363,7 @@ window.addEventListener('scroll',()=>{releaseHoverPreviews();clearTimeout(scrollT); scrollT=setTimeout(()=>{window.__scrolling=false},180);},{passive:true});-window.addEventListener('resize',scheduleStickySurfaces,{passive:true});+window.addEventListener('resize',()=>{scheduleStickySurfaces();alignFollowImageControls()},{passive:true});/* 只在真正进入 72 px 图标栏时展开;内容区左缘不再设隐形热区。 */$('#edge').addEventListener('mouseleave',()=>clearTimeout(edgeT));@@ -4291,7 +4320,8 @@ async function restoreRoute(){if(parts[0]==='mix'&&/^\d+$/.test(parts[1]||'')&&/^\d+$/.test(parts[2]||'')){await openMix(+parts[1],+parts[2],false);return}if(parts[0]==='parts'&&/^\d+$/.test(parts[1]||'')&&/^\d+$/.test(parts[2]||'')){await openParts(+parts[1],+parts[2],false);return}if(parts[0]==='item'&&/^\d+$/.test(parts[1]||'')){await openItem(+parts[1],false);return}- if(parts[0]==='follow'&&parts[1]==='item'&&/^\d+$/.test(parts[2]||'')){await openFollowDetail(+parts[2],false);return}+ if(parts[0]==='follow'&&parts[1]==='item'&&/^\d+$/.test(parts[2]||'')){+ await openFollow(false,true);await openFollowDetail(+parts[2],false);return}const entityKind=ROUTE_ENTITIES[parts[0]];if(entityKind&&parts.length>=2){await openEntity(entityKind,parts.slice(1).join('/'),false);return}if(path==='/performers'||path==='/creators'||path==='/tags'){