Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(follow): 增加未看时间范围

longmeidaoe977a3091cb3
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.py
index b7d2e4171..c47e7b54d 100644
--- a/src/peach/web_follow.py
+++ b/src/peach/web_follow.py
@@ -607,6 +607,11 @@ def q_follow(contract, args) -> dict:
authors = frozenset(_csv_values(args.get("author")))
providers = frozenset(_csv_values(args.get("provider")))
wanted_tags = _csv_values(args.get("tag"))
+ try:
+ unread_days = max(0, min(int(args.get("unread_days") or 0), 3650))
+ except (TypeError, ValueError):
+ unread_days = 0
+ unread_cutoff = time.time() - unread_days * 86400 if unread_days else None
credential_store = _credential_store(contract)
credential_providers = frozenset(
provider for provider in CREDENTIAL_GUIDE
@@ -663,6 +668,13 @@ def q_follow(contract, args) -> dict:
counts: dict[str, int] = {}
for item in counted:
status = str(item.status)
+ if status == "new" and unread_cutoff is not None:
+ stamp = item.published_at or item.first_seen_at
+ try:
+ if stamp and __import__('datetime').datetime.fromisoformat(str(stamp).replace('Z', '+00:00')).timestamp() < unread_cutoff:
+ continue
+ except (TypeError, ValueError, OverflowError):
+ pass
counts[status] = counts.get(status, 0) + 1
suggestions = _suggestions(contract, sources)
return {
@@ -673,6 +685,7 @@ def q_follow(contract, args) -> dict:
"suggestions": suggestions,
"groups": groups,
"counts": {status: int(counts.get(status, 0)) for status in _STATUSES},
+ "unread_days": unread_days,
"facets": facets,
# counts 是全库口径,groups 只是这一页——两个数并排显示过,看起来像自相矛盾。
"offset": offset,
diff --git a/web/app.js b/web/app.js
index 3a990c9c7..e2d81aaf5 100644
--- a/web/app.js
+++ b/web/app.js
@@ -416,6 +416,7 @@ const THEME_OPTIONS=[['system','跟随系统','monitor'],['light','浅色','sun'
const DEFAULT_SETTINGS={batchSize:60,defaultSort:'seed',sortDefaultsVersion:3,hoverDelaySeconds:5,seekSeconds:10,searchHistoryLimit:10,relatedLimit:20,javLayout:'big',javImage:'cover',followLayout:'default',peopleLayout:'big',ambientMode:true,miniplayer:true,theaterMode:false,theme:'system',groupCollapse:true,sidebarOrder:DEFAULT_SIDEBAR_ORDER};
let appSettings={...DEFAULT_SETTINGS};
try{appSettings={...DEFAULT_SETTINGS,...JSON.parse(localStorage.getItem(SETTINGS_KEY)||'{}')}}catch(_e){}
+appSettings.unreadDays=Number.isFinite(+appSettings.unreadDays)?Math.max(0,+appSettings.unreadDays):0;
const allowedSetting=(value,allowed,fallback)=>allowed.includes(value)?value:fallback;
delete appSettings.rotateMinutes;
/* 迁移只碰默认值本身:把界面上已经不存在的键换成当前键,用户主动选过的排序不动。
@@ -5834,6 +5835,7 @@ function renderFollowManage(credentials){
</section>
<section class="fsec" data-follow-workspace-panel="list">
<div class="fsechead"><h3>关注列表</h3>
+ <label class="funreadrange">未看范围<select aria-label="未看范围" data-follow-unread-days><option value="0"${appSettings.unreadDays===0?' selected':''}>全部</option><option value="7"${appSettings.unreadDays===7?' selected':''}>最近 7 天</option><option value="30"${appSettings.unreadDays===30?' selected':''}>最近 30 天</option><option value="90"${appSettings.unreadDays===90?' selected':''}>最近 90 天</option></select></label>
<span class="fmeta">${sources.length} 个来源${
counts.new?` · <b>${counts.new}</b> 条未看`:''}</span>
<span class="fmanagesort">${icon('sort')}${selectFieldHtml(FOLLOW_SORT_OPTIONS,followManageSort,
@@ -5903,7 +5905,7 @@ async function openFollowManage(push=true){
const surface=claimSurface('/follow-manage');
showManagementBody({placeholder:managementPlaceholder('/follow-manage')});
const [data,credentials,runtime]=await Promise.all([
- surfaceApi(surface,'/api/follow?limit=1'),surfaceApi(surface,'/api/follow/credentials'),
+ surfaceApi(surface,'/api/follow?limit=1&unread_days='+encodeURIComponent(appSettings.unreadDays)),surfaceApi(surface,'/api/follow/credentials'),
surfaceApi(surface,'/healthz')]);
if(!surfaceCurrent(surface))return;
followData=data;followRuntime=runtime;followCredentials=credentials;
@@ -5945,6 +5947,7 @@ function wireFollowItems(){
function wireFollowManage(creds=[]){
void wireResolveProgress();
const root=$('#stats'),form=root.querySelector('#followAdd');
+ root.querySelector('[data-follow-unread-days]')?.addEventListener('change',event=>{appSettings.unreadDays=+event.target.value||0;saveSettings();openFollowManage(false)});
wireCollapse(root,'details.fauthor','follow-author-collapse','[data-follow-author-toggle]');
root.querySelectorAll('[data-follow-author-toggle]').forEach(button=>button.onclick=event=>{
event.stopPropagation();