Peach: Local-first video metadata scraper and media manager.
fix: 不再宣称做不到的凭据权限;输入框与按钮等高;时间按本地时区显示
Peach local maintenance0242bfc6f7b0
diff --git a/README.md b/README.mdindex e31aa4356..d06724a21 100644--- a/README.md+++ b/README.md@@ -365,8 +365,10 @@ cookie 并重定向到不含口令的干净 URL;新设备不要再复制带口写入 API:`POST /api/activity`、`/api/play`、`/api/feedback`、`/api/watch-later`、`/api/playlist`、`/api/preference`、`/api/item-tag`、`/api/batch`、`/api/trash/empty`、`/api/follow/check`、`/api/follow/status`、`/api/follow/save`、`/api/follow/source`、`/api/follow/resolve`、-`/api/follow/credential`。`resolve` 只联网发现、`credential` 只写本机 secrets 文件,两者都不碰账本,-因此不受单写者闸门管辖;凭据的值只从请求体流向磁盘(0600),不回显、不记日志、不进任何返回体。+`/api/follow/credential`。`resolve` 只联网发现、`credential` 只写 secrets 文件,两者都不碰账本,+因此不受单写者闸门管辖;凭据的值只从请求体流向磁盘,不回显、不记日志、不进任何返回体。+凭据落在**运行 Peach 的那台机器**上,不是浏览器所在的机器。**权限收紧只在 POSIX 上真的发生**:+Windows 的 `chmod` 只能拨只读位、NTFS 权限走 ACL,那里不假装收紧过,`world_readable` 也照实报未知。标签隐藏只写本地 profile 覆盖,不销毁原始来源断言;搜索历史通过 `POST /api/search-history` 共享写入账本;媒体先进入回收站,只有显式清空回收站才永久删除。除上述明确端点外,`/api/*` 返回 404。公共页面不再使用`/entity/{kind}/{name}`;内部 JSON 的 `/api/entity` 只是兼容契约,不暴露数据库路由结构。diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex ac53506fd..627675d59 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -337,11 +337,17 @@ CREDENTIAL_GUIDE: dict[str, dict] = {def w_follow_credential(contract, body) -> dict:- """保存一个来源的凭据到本机文件。+ """保存一个来源的凭据,写到**运行 Peach 的那台机器**的 secrets 目录。值只从请求体流向磁盘,**不回显、不记日志、不进任何返回体**。只接受`CREDENTIAL_GUIDE` 里声明过的 provider 和字段名——多余的字段一律拒绝,- 免得把任意内容写进 secrets 目录。文件权限设成 0600。+ 免得把任意内容写进 secrets 目录。++ **权限收紧只在 POSIX 上真的发生。** Windows 的 `os.chmod` 只能拨动只读位,+ NTFS 的权限走 ACL,落盘就是继承来的 0o666——所以那里不假装收紧过,+ `describe()` 的 `world_readable` 也照实报 `None`。要在 Windows 上真正收紧+ 得走 ACL(icacls/pywin32 断继承),那需要在那台机器上实测验证才能落地,+ 当前**未取得**,不写没验过的安全代码。"""provider = str(body.get("provider") or "")guide = CREDENTIAL_GUIDE.get(provider)@@ -367,10 +373,13 @@ def w_follow_credential(contract, body) -> dict:temporary = path.with_name(path.name + ".tmp")temporary.write_text(json.dumps(cleaned, ensure_ascii=False, indent=2) + "\n",encoding="utf-8")- os.chmod(temporary, 0o600)+ if os.name != "nt":+ os.chmod(temporary, 0o600)temporary.replace(path)# 返回的是 describe(),只有字段名,没有值。return {"ok": True, "provider": provider, "cleared": False,+ # 界面据此说明「这台机器上没有收紧文件权限」,而不是默认收紧过。+ "permissions_tightened": os.name != "nt","saved": store.describe(provider)}diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 0c28ab258..fc849189b 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -4,6 +4,8 @@不是某个文件——判据同 `tests/test_web_ui.py`。"""import json+import os+import reimport sqlite3import statimport tempfile@@ -227,7 +229,12 @@ class FollowContractTests(unittest.TestCase):path = self.root / "secrets" / "follow" / "rule34xxx.json"self.assertEqual(json.loads(path.read_text(encoding="utf-8")),{"user_id": "42", "api_key": "sekret"})- self.assertEqual(stat.S_IMODE(path.stat().st_mode), 0o600)+ if os.name == "nt":+ # Windows 的 chmod 只能拨只读位,NTFS 权限走 ACL——这里不假装收紧过。+ self.assertFalse(result["permissions_tightened"])+ else:+ self.assertTrue(result["permissions_tightened"])+ self.assertEqual(stat.S_IMODE(path.stat().st_mode), 0o600)def test_clearing_a_credential_removes_the_file(self):self._post("/api/follow/credential", {@@ -377,7 +384,15 @@ class FollowWebSourceTests(unittest.TestCase):def test_watching_lives_in_the_left_rail_and_managing_stays_in_the_manage_area(self):# 看和管是两件事,两个页面:左侧导航进「看」,管理区进「管」。- self.assertPageContains("['follow','在线追更','globe'],\n ['immerse'")+ # 断言「相邻」这件事本身,不要连换行和缩进一起写死——那种断言一改格式就红,+ # 红的原因还和它想守的契约无关。+ rail = self.page[self.page.index("const EDGE_ICONS=["):]+ rail = rail[:rail.index("];")]+ keys = re.findall(r"\['([a-z]*)'", rail)+ self.assertIn("follow", keys)+ self.assertEqual(keys[keys.index("follow") + 1], "immerse",+ "关注入口应当排在沉浸模式前面")+ self.assertPageContains("['follow','关注','globe']")self.assertPageContains("if(k==='follow'){openFollow();return}")self.assertPageContains("if(k==='follow')return path==='/follow';")self.assertPageContains("['follow','追更来源','globe']")@@ -410,8 +425,8 @@ class FollowWebSourceTests(unittest.TestCase):def test_the_first_name_lookup_warns_about_the_index_download(self):self.assertPageContains("首次按名字查要下载创作者索引,可能几十秒")- def test_the_paste_box_cannot_be_dragged_shut(self):- self.assertPageContains(".faddform textarea{min-height:82px")+ def test_the_input_and_its_button_are_the_same_height(self):+ self.assertPageContains("height:38px;min-height:38px")def test_the_manage_page_is_ordered_by_what_you_do_first(self):# 只看管理页那一段:同样的标题在别的页面上也出现过,全页搜索会命中错的那个。@@ -441,6 +456,11 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains("blocked:['接不进来'")self.assertPageContains("row.path")+ def test_the_page_says_where_the_credential_actually_lands(self):+ # 从 Mac 浏览 Windows 实例时,凭据落在 Windows 上——不能写成「本机」。+ self.assertPageContains("运行 Peach 的那台机器")+ self.assertPageContains("Windows 上不收紧文件权限")+def test_credentials_are_typed_into_the_page_not_into_a_file_by_hand(self):self.assertPageContains('data-cred-form=')self.assertPageContains("'/api/follow/credential'")@@ -462,12 +482,21 @@ class FollowWebSourceTests(unittest.TestCase):if management in watch:self.fail(f"看的那一页不应出现管理控件:{management!r}")+ def test_times_are_rendered_in_the_viewer_timezone_not_raw_utc(self):+ # 账本存 UTC;直接把那串字面量印出来,UTC+8 的人看到的每个时间都早 8 小时。+ self.assertPageContains("function localTime(iso)")+ self.assertPageContains("new Date(text)")+ self.assertPageContains("when.getHours()")+ page = self.page+ body = page[page.index("function followWhen("):page.index("function followBadges(")]+ self.assertNotIn(".replace('T',' ').slice(0,16)", body)+def test_approximate_timestamps_are_labelled_as_approximate(self):# 站点只给「1 周前」时换算值不是发布时间,界面必须照实说。self.assertPageContains("item.published_precision==='approximate'?`约 ${text}`")def test_release_variant_rows_show_when_not_a_meaningless_kind(self):- self.assertPageContains("if(!label&&group.is_release)label=(item.published_at||'').slice(5,10)")+ self.assertPageContains("if(!label&&group.is_release)label=localTime(item.published_at).slice(5,10)")def test_release_rows_show_the_reply_body_not_the_thread_title(self):self.assertPageContains("const body=group.is_release")diff --git a/web/app.css b/web/app.cssindex fccdd936b..a61cbfeef 100644--- a/web/app.css+++ b/web/app.css@@ -1182,29 +1182,38 @@ body.drawer-open .edge button{color:var(--ink-2)}.fprimary svg,.fghost svg{width:14px;height:14px;stroke:currentColor;fill:none;stroke-width:2}.fprimary:disabled,.fghost:disabled{opacity:.5;cursor:default}-.faddform{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:9px;align-items:start}-.faddform textarea{min-height:82px;max-height:340px;border:1px solid var(--border-15);- border-radius:9px;background:var(--overlay-5);color:var(--ink);padding:9px 12px;- font-size:13px;font-family:inherit;line-height:1.6;resize:vertical;+/* 输入框和按钮同高(38px = 8 上 + 20 行高 + 8 下 + 2 边框)。+ 静止一行,粘了多行才往下长——固定三行的话按钮只有它 1/3 高,看着就是没对齐。 */+.faddform{display:flex;gap:8px;align-items:flex-start}+.faddform textarea{flex:1 1 auto;min-width:0;height:38px;min-height:38px;max-height:240px;+ box-sizing:border-box;border:1px solid var(--border-15);border-radius:9px;+ background:var(--overlay-5);color:var(--ink);padding:8px 12px;+ font-size:13px;font-family:inherit;line-height:20px;resize:none;overflow-y:auto;transition:border-color .12s ease}.faddform textarea::placeholder{color:var(--muted)}.faddform textarea:focus-visible{outline:2px solid var(--tungsten);outline-offset:1px;border-color:var(--tungsten)}-.faddside{display:grid;gap:6px;min-width:96px}-.faddside button{border-radius:9px;border:1px solid var(--tungsten);background:var(--tungsten);- color:#fff;font-weight:600;padding:9px 16px;font-size:13px;cursor:pointer;+.faddform button{flex:0 0 auto;height:38px;box-sizing:border-box;border-radius:9px;+ border:1px solid var(--tungsten);background:var(--tungsten);color:#fff;font-weight:600;+ padding:0 20px;font-size:13px;cursor:pointer;transition:background-color .12s ease,scale .1s ease}-.faddside button:hover:not(:disabled){background:color-mix(in srgb,var(--tungsten) 86%,#000)}-.faddside button:active:not(:disabled){scale:.96}-.faddside button:disabled{opacity:.6;cursor:default}-.faddside [data-follow-add-state]{font-size:11px;line-height:1.5;color:var(--muted)}+.faddform button:hover:not(:disabled){background:color-mix(in srgb,var(--tungsten) 86%,#000)}+.faddform button:active:not(:disabled){scale:.96}+.faddform button:disabled{opacity:.6;cursor:default}+.fhint [data-follow-add-state]{color:var(--drop)}+.fhint [data-follow-add-state]:not(:empty){display:block;margin-bottom:4px}.fsources{list-style:none;margin:0 0 9px;padding:0;display:grid;gap:5px}.fsource{display:grid;grid-template-columns:minmax(0,1fr) auto auto auto;gap:10px;align-items:center;padding:8px 11px;border-radius:9px;background:var(--overlay-5);font-size:12.5px}.fsource b{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.fsource .mono{color:var(--muted);font-size:11px;white-space:nowrap}-.fsource .fstatus{font-size:11px;color:var(--muted);min-width:58px;text-align:right}+.fsource .fstatus{display:inline-flex;align-items:center;gap:5px;font-size:11px;+ color:var(--muted);min-width:58px}+.fsource .fstatus::before{content:'';width:6px;height:6px;border-radius:50%;+ background:var(--keep);flex:none}+.fsource.bad .fstatus::before{background:var(--drop)}+.fsource.idle .fstatus::before{background:var(--muted)}.fsource.bad{background:color-mix(in srgb,var(--drop) 8%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--drop) 30%,transparent)}.fsource.bad .fstatus{color:var(--drop)}@@ -1262,7 +1271,8 @@ body.drawer-open .edge button{color:var(--ink-2)}.faside{position:static}}@media (max-width:720px){- .faddform{grid-template-columns:minmax(0,1fr)}+ .faddform{flex-wrap:wrap}+ .faddform button{flex:1 1 100%}.fsource{grid-template-columns:minmax(0,1fr) auto}.fsource .mono:nth-of-type(2){display:none}}diff --git a/web/app.js b/web/app.jsindex 5dc425404..e4f858b20 100644--- a/web/app.js+++ b/web/app.js@@ -1199,10 +1199,23 @@ async function openQualityGoals(push=true){let followData=null,followFilter='new',followBusy=false;const FOLLOW_FILTERS=[['new','未看'],['seen','已看'],['saved','已保存'],['ignored','已忽略'],['','全部']];+/* 账本里一律存 UTC(ISO 带 Z),界面要按看的人所在时区显示。+ 原来直接把那串字面量印出来,UTC+8 的人看到的每个时间都早 8 小时。 */+function localTime(iso){+ if(!iso)return '';+ // 没有时区标记的按 UTC 解释——存进去的时候就是 UTC。+ const text=/[Zz]|[+-]\d\d:?\d\d$/.test(iso)?iso:iso+'Z';+ const when=new Date(text);+ if(isNaN(when))return String(iso).replace('T',' ').slice(0,16);+ const pad=n=>String(n).padStart(2,'0');+ return `${when.getFullYear()}-${pad(when.getMonth()+1)}-${pad(when.getDate())} `+ +`${pad(when.getHours())}:${pad(when.getMinutes())}`;+}+function followWhen(item){const raw=item.published_at||'';if(!raw)return '时间未取得';- const text=raw.replace('T',' ').slice(0,16);+ const text=localTime(raw);// 站点只给「1 周前」时换算出来的是近似值,界面必须照实说,不能冒充发布时间。return item.published_precision==='approximate'?`约 ${text}`:text;}@@ -1223,7 +1236,7 @@ function followBadges(group){把线程回复标成「main」是没有信息量的——一个线程里九条回复全是 main。 */function followVariantRow(group,item,mark){let label=mark;- if(!label&&group.is_release)label=(item.published_at||'').slice(5,10)||'动态';+ if(!label&&group.is_release)label=localTime(item.published_at).slice(5,10)||'动态';if(!label)label=item.variant_kind==='wip'?'WIP':(item.variant_label||item.variant_kind);/* 线程里九条回复的标题全是线程名,摘要才是那条动态的内容。只发了附件的回复没有正文,这时说清楚是没正文,比把线程名再印一遍强。 */@@ -1275,12 +1288,12 @@ function renderFollow(){<div class="reviewtabs">${FOLLOW_FILTERS.map(([key,label])=>`<button data-follow-filter="${key}" aria-pressed="${key===followFilter}">${label}${key?` <span class="n mono">${counts[key]||0}</span>`:''}</button>`).join('')}- <button class="fcheck" data-follow-manage>${icon('settings')}管理来源</button></div>+ <button class="fcheck" data-follow-manage>${icon('settings')}管理关注</button></div>${broken.length?`<p class="fwarn">${broken.length} 个来源上次检查失败,去- <button class="flink" data-follow-manage>管理来源</button>看原因。</p>`:''}+ <button class="flink" data-follow-manage>管理关注</button>看原因。</p>`:''}<div class="followlist">${groups.length?groups.map(followCard).join('')- :sources.length?'<p class="empty">没有符合条件的追更条目</p>'- :`<p class="empty">还没有追更来源。<button class="flink" data-follow-manage>去添加</button></p>`}</div></div>`;+ :sources.length?'<p class="empty">没有符合条件的更新</p>'+ :`<p class="empty">还没有关注任何来源。<button class="flink" data-follow-manage>去添加</button></p>`}</div></div>`;wireFollowItems();$('#stats').querySelectorAll('[data-follow-filter]').forEach(button=>button.onclick=()=>{followFilter=button.dataset.followFilter;openFollow(false)});@@ -1307,9 +1320,10 @@ async function openFollow(push=true){function followSourceRow(source){const state=source.last_status||'未检查';const bad=state==='error'||state==='unauthorized';- return `<li class="fsource${bad?' bad':''}">+ const idle=!source.last_checked_at;+ return `<li class="fsource${bad?' bad':idle?' idle':''}"><b>${esc(source.label)}</b><span class="mono">${esc(source.provider_label)}</span>- <span class="mono">${esc(source.last_checked_at?source.last_checked_at.replace('T',' ').slice(0,16):'未检查')}</span>+ <span class="mono">${esc(source.last_checked_at?localTime(source.last_checked_at):'未检查')}</span><span class="fstatus">${esc(state)}</span><button data-follow-check="${source.id}">检查</button><button class="fremove" data-follow-remove="${source.id}" title="不再追这个来源">移除</button>@@ -1360,15 +1374,13 @@ function renderFollowManage(credentials){<div class="fcardhead"><h3>添加关注</h3><button class="fghost" data-follow-view>${icon('globe')}去看更新</button></div><form class="faddform" id="followAdd">- <textarea name="lines" rows="3" required spellcheck="false"+ <textarea name="lines" rows="1" required spellcheck="false"aria-label="来源链接、名字或 id"- placeholder="每行一条,链接和名字可以混着粘"></textarea>- <div class="faddside">- <button type="submit">查找</button>- <span data-follow-add-state aria-live="polite"></span>- </div>+ placeholder="粘链接、名字或 id"></textarea>+ <button type="submit">查找</button></form>- <p class="fhint">链接直接认得;只给名字或 id 会去六个来源各查一遍,查到什么由你勾选。+ <p class="fhint"><span data-follow-add-state aria-live="polite"></span>+ 链接直接认得,名字会去六个来源各查一遍。要一次加多个就每行一条。首次按名字查要下载创作者索引,可能几十秒。</p></section><div id="followPicks"></div>@@ -1389,8 +1401,9 @@ function renderFollowManage(credentials){<section class="fcard"><div class="fcardhead"><h3>凭据</h3></div><div class="fcreds">${(credentials.providers||[]).map(followCredentialRow).join('')}</div>- <p class="fhint">凭据只留在本机,不进 Git、URL、日志或 ledger。输入框里的值直接写入- 本机文件,页面上不会再显示出来。</p>+ <p class="fhint">凭据写在<b>运行 Peach 的那台机器</b>上(不是你现在这台浏览器所在的机器),+ 不进 Git、URL、日志或 ledger。保存后页面上不会再显示出来。+ Windows 上不收紧文件权限——NTFS 走 ACL,<code>chmod</code> 在那里没有效果。</p></section></aside></div>`;wireFollowManage();@@ -1425,6 +1438,16 @@ function wireFollowItems(){function wireFollowManage(){const root=$('#stats'),form=root.querySelector('#followAdd');+ const box=form&&form.querySelector('textarea');+ /* 常见情况是粘一条,多行是例外——所以静止时就一行高,和按钮齐平;+ 真粘了多行才往下长。原来固定三行,按钮只有它 1/3 高,看着就是没对齐。 */+ if(box){+ const grow=()=>{box.style.height='auto';+ box.style.height=Math.min(box.scrollHeight,240)+'px'};+ box.addEventListener('input',grow);+ box.addEventListener('paste',()=>setTimeout(grow,0));+ grow();+ }if(form)form.onsubmit=async event=>{event.preventDefault();const state=form.querySelector('[data-follow-add-state]'),button=form.querySelector('button');@@ -1437,7 +1460,8 @@ function wireFollowManage(){try{const result=await api('/api/follow/resolve',{method:'POST',body:JSON.stringify({lines})});- state.textContent='';renderFollowPicks(result.results||[]);+ state.textContent='';if(box){box.value='';box.style.height='auto'}+ renderFollowPicks(result.results||[]);}catch(error){state.textContent=error.message||'查找失败'}finally{button.disabled=false}};@@ -2084,7 +2108,7 @@ const EDGE_ICONS=[['jav','JAV','jav'],['flagged','已标记','star'],['playlists','播放列表','list-filter'],- ['follow','在线追更','globe'],+ ['follow','关注','globe'],['immerse','沉浸模式','play'],['manage','管理','settings'],];