From f9be8a0a31649961a674661024d399b88415e152 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 16 Oct 2026 15:55:09 +0800 Subject: [PATCH] Add recording upload queue and verified local space reclamation dashboard --- RELEASE-v0.1.44.md | 7 ++ app.py | 6 +- baidu.py | 20 +++-- frontend/src/components/FamilyLocations.vue | 2 +- frontend/src/components/UploadTasks.vue | 60 +++++++++++++++ frontend/src/components/Workspace.vue | 3 +- frontend/src/composables/upload-tasks.mjs | 17 +++++ recording_archive.py | 73 +++++++++++++++++-- test_recording_archive.py | 67 ++++++++++++++++- test_upload_tasks.js | 19 +++++ web/app.js | 2 +- web/ui/assets/index-CKCKLCNa.js | 5 -- ...{index-COdFa75p.css => index-DSPHROV4.css} | 2 +- web/ui/assets/index-gjn_aJcE.js | 5 ++ web/ui/index.html | 4 +- 15 files changed, 267 insertions(+), 25 deletions(-) create mode 100644 frontend/src/components/UploadTasks.vue create mode 100644 frontend/src/composables/upload-tasks.mjs create mode 100644 test_upload_tasks.js delete mode 100644 web/ui/assets/index-CKCKLCNa.js rename web/ui/assets/{index-COdFa75p.css => index-DSPHROV4.css} (98%) create mode 100644 web/ui/assets/index-gjn_aJcE.js diff --git a/RELEASE-v0.1.44.md b/RELEASE-v0.1.44.md index 2d9fb37..aa028fc 100644 --- a/RELEASE-v0.1.44.md +++ b/RELEASE-v0.1.44.md @@ -32,3 +32,10 @@ - 修复 TP-Link 不接受 RTSP 地址中用户信息造成的黑屏,凭据改由原生播放器认证选项传入。电视设备状态以硬件心跳和本屏实际播放状态为准;路由状态区分电视本地探测和服务器探测。 新增 `recording_archive` 与 `location_shares` 表。部署硬容量分区需要主机管理员执行 `ops/recording-volume.py`,服务使用非特权用户;不能仅在网页填写容量数字就宣称已有硬限制。 + +## 上传任务面板 + +- 平台存储页增加按家庭、摄像机、任务状态筛选的分页队列,五秒更新,后台页停止轮询。展示片段文件、录制时间、大小、上传分片进度、完整回读校验进度、错误和下一次重试时间。 +- 显示待传容量、已归档容量、今日及累计已删除录像文件大小、当前磁盘可用空间。累计清理量仅在确认本机删除后落库,云端到期清理不重置累计值。 +- 超级管理员可重试队首失败任务,不跳过时间顺序;同时查看数据库备份近期上传结果。个人记事照片、语音等手工上传仍在各自录入页展示进度,不计入录像释放量。 +- 修复百度 OAuth 以 HTTP 400 返回授权失效时被误报为网络错误的问题;对提前失效的访问令牌刷新一次,刷新凭据失效时明确要求重新授权。 diff --git a/app.py b/app.py index 9c7ecaf..3b20196 100644 --- a/app.py +++ b/app.py @@ -505,7 +505,7 @@ def storage_watch(): spool_free = shutil.disk_usage(RECORDINGS).free free_gb, used_gb = usage.free / 1e9, used / 1e9 reason = ('临时录像区的硬容量限制尚未就绪' if not hard_ready else - '旧录像正在上传,等待腾出新片段容量' if legacy_used+hard_bytes > policy['maxGB']*1e9 else + '旧录像等待上传并清理,暂停新片段录制' if legacy_used+hard_bytes > policy['maxGB']*1e9 else '临时录像区接近容量上限,等待上传释放空间' if spool_free < 256*1024**2 else '磁盘可用空间不足' if free_gb < policy['reserveGB'] else '') with LOCK: @@ -767,6 +767,8 @@ class Handler(BaseHTTPRequestHandler): elif path == '/api/backups/run': self.require_admin() self.answer(BACKUPS.start()) + elif path == '/api/uploads/recordings/retry': + self.require_admin(); self.answer(ARCHIVE.retry(self.user)) elif path == '/api/account/password': result = ACCOUNTS.change_password(data, self.user) self.answer(result, cookie='vision=; Path=/; Max-Age=0; HttpOnly; SameSite=Strict') @@ -1063,6 +1065,8 @@ class Handler(BaseHTTPRequestHandler): elif path == '/api/backups': self.require_admin() self.answer(BACKUPS.status()) + elif path == '/api/uploads/recordings': + self.require_admin(); self.answer(ARCHIVE.tasks(self.user,query)) elif path == '/api/households/cover': home = get_object('households', query.get('id')) if not home or self.user['role'] != 'admin' and home['id'] != HOUSEHOLDS.scope(self.user): diff --git a/baidu.py b/baidu.py index 7817fd2..8422178 100644 --- a/baidu.py +++ b/baidu.py @@ -147,7 +147,13 @@ class Baidu: if body is not None: headers['Content-Type'] = content_type or 'application/x-www-form-urlencoded' req = urllib.request.Request(address, body, headers) try: - with urllib.request.build_opener(NoRedirect()).open(req, timeout=40) as response: + try: + response = urllib.request.build_opener(NoRedirect()).open(req, timeout=40) + except urllib.error.HTTPError as error: + # OAuth reports invalid_grant in a JSON HTTP 400 body. Preserve + # that machine code without exposing the credential-bearing URL. + response = error + with response: payload = response.read(2*1024*1024+1) if len(payload) > 2*1024*1024: raise ValueError() value = json.loads(payload) @@ -162,6 +168,8 @@ class Baidu: error.reauthorize = True raise error raise self.a.Problem('网盘操作未完成('+code+'),请检查应用权限、目录及网盘容量', 502) + if getattr(response,'status',200) >= 400: + raise self.a.Problem('百度网盘服务暂不可用,请稍后重试',502) return value def token_response(self, c, **fields): @@ -309,15 +317,16 @@ class Baidu: while block := stream.read(BLOCK): hashes.append(hashlib.md5(block).hexdigest()) if not hashes: raise self.a.Problem('空文件不能上传') pre = self.prepare(remote, size, hashes) - if pre.get('existing'): return pre['existing'] + if pre.get('existing'): + progress(len(hashes),len(hashes));return pre['existing'] needed = pre.get('block_list', list(range(len(hashes)))) if any(type(i) is not int or not 0 <= i < len(hashes) for i in needed): raise self.a.Problem('网盘分片索引不正确', 502) with local.open('rb') as stream: - for i in needed: + for done,i in enumerate(needed,1): stream.seek(i*BLOCK) self.send_block(remote, pre['uploadid'], i, stream.read(BLOCK), hashes[i]) - progress(i+1, len(hashes)) + progress(len(hashes)-len(needed)+done, len(hashes)) return self.complete(dict(remotePath=remote, size=size, uploadId=pre['uploadid'], hashes=hashes)) def open_file(self, key, item, byte_range=''): @@ -339,7 +348,7 @@ class Baidu: def verify_backup(self, remote, fs_id, size, digest): return self.verify_file(remote, fs_id, size, digest) - def verify_file(self, remote, fs_id, size, digest): + def verify_file(self, remote, fs_id, size, digest, progress=lambda n,total:None): """Read back into a small memory buffer before allowing retention deletion.""" sha = hashlib.sha256(); received = 0 with self.open_file('shared', dict(remotePath=remote, fsId=str(fs_id))) as response: @@ -347,6 +356,7 @@ class Baidu: received += len(chunk) if received > size: raise self.a.Problem('云端文件大小不符,未清理本地文件', 502) sha.update(chunk) + progress(received,size) if received != size or sha.hexdigest() != digest: raise self.a.Problem('云端文件校验不一致,未清理本地文件', 502) diff --git a/frontend/src/components/FamilyLocations.vue b/frontend/src/components/FamilyLocations.vue index fa81753..fee6250 100644 --- a/frontend/src/components/FamilyLocations.vue +++ b/frontend/src/components/FamilyLocations.vue @@ -23,7 +23,7 @@ async function action(name){if(busy.value)return;busy.value=true;error.value=''; try{const value=await bridge().api('/api/locations',{action:name,consent:consent.value,days:days.value});if(e!==epoch)return;code.value=value.code||'';expires.value=value.expires||0;if(name==='stop')consent.value=false;clearTimeout(timer);await load()} catch(err){if(e===epoch)error.value=err.message}finally{if(e===epoch)busy.value=false} } -watch(()=>[active.value,snapshot.value.state.familyId,snapshot.value.session],()=>{epoch++;clearTimeout(timer);result.value=null;code.value='';selected.value='';consent.value=false;busy.value=false;if(active.value)load()},{immediate:true}) +watch([active,()=>snapshot.value.state.familyId,()=>snapshot.value.session],()=>{epoch++;clearTimeout(timer);result.value=null;code.value='';selected.value='';consent.value=false;busy.value=false;if(active.value)load()},{immediate:true}) onBeforeUnmount(()=>{epoch++;clearTimeout(timer)})