chore: 初始提交 - 移除所有硬编码凭据,统一从环境变量读取

This commit is contained in:
yangxiangyuan
2026-06-11 17:10:58 +08:00
commit c223c79b36
1699 changed files with 313940 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+73
View File
@@ -0,0 +1,73 @@
;(function(){
var of = window.fetch
window.fetch = function(u, o){ o = o || {}; if (!o.credentials) o.credentials = 'include'; return of(u, o) }
function ensureOverlay(){
var el = document.getElementById('authOverlay')
if (el) return el
el = document.createElement('div')
el.id = 'authOverlay'
el.style.position = 'fixed'
el.style.left = '0'
el.style.top = '0'
el.style.width = '100%'
el.style.height = '100%'
el.style.background = 'rgba(0,0,0,0.6)'
el.style.display = 'none'
el.style.alignItems = 'center'
el.style.justifyContent = 'center'
el.style.zIndex = '9999'
var box = document.createElement('div')
box.style.background = '#fff'
box.style.borderRadius = '8px'
box.style.padding = '16px'
box.style.boxShadow = '0 6px 24px rgba(0,0,0,0.25)'
box.style.minWidth = '280px'
var t = document.createElement('div')
t.textContent = '鉴权失败'
t.style.fontSize = '18px'
t.style.marginBottom = '8px'
var b = document.createElement('button')
b.id = 'btnRecheck'
b.textContent = '重新校验'
b.style.padding = '8px 12px'
b.style.border = '1px solid #999'
b.style.borderRadius = '4px'
b.style.background = '#f7f7f7'
box.appendChild(t); box.appendChild(b)
el.appendChild(box)
document.body.appendChild(el)
return el
}
function show(){
ensureOverlay().style.display = 'flex'
var main = document.querySelector('.container')
if (main) main.style.display = 'none'
}
function hide(){
var el = ensureOverlay()
el.style.display = 'none'
var main = document.querySelector('.container')
if (main) main.style.display = 'block'
}
function removeTokenFromUrl(){
var q = location.search || ''
if (q.indexOf('token=') >= 0) {
var sp = new URLSearchParams(q)
sp.delete('token')
var nu = location.pathname + (sp.toString() ? ('?' + sp.toString()) : '') + location.hash
history.replaceState(null, '', nu)
}
}
function handshake(){ return fetch('/api/psc/auth/handshake').then(function(r){ if(!r.ok) throw 0 }) }
function start(cfg){
if (!cfg || !cfg.enableCookieAuth) return
var params = new URLSearchParams(location.search||'')
var tk = params.get('token')
var p = tk ? fetch('/api/psc/auth/token?token=' + encodeURIComponent(tk)).then(function(r){ if(r.ok) removeTokenFromUrl() }).catch(function(){}) : Promise.resolve()
p.then(function(){ handshake().then(function(){ hide() }).catch(function(){ show() }) })
var btn = document.getElementById('btnRecheck')
if (btn) btn.onclick = function(){ handshake().then(function(){ hide() }).catch(function(){ show() }) }
}
function loadCfg(){ return fetch('auth_config.json').then(function(r){ return r.json() }).catch(function(){ return { enableCookieAuth: true } }) }
document.addEventListener('DOMContentLoaded', function(){ loadCfg().then(start) })
})()
+9
View File
@@ -0,0 +1,9 @@
{
"_comment": "PSC 工具(密码安全中心等)的前端鉴权配置",
"enableCookieAuth_comment": "true:启用基于 JWT cookie 的鉴权;false:关闭(通常仅限开发环境)",
"enableCookieAuth": false,
"cookieName_comment": "PSC 使用的 JWT cookie 名称",
"cookieName": "TRAE-PSC_jwt",
"max_age_days_comment": "JWT cookie 的最大有效天数(1~365)",
"max_age_days": 30
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

+238
View File
@@ -0,0 +1,238 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TRAE-AI 个人私有安全网盘</title>
<link rel="icon" href="psc.svg" type="image/svg+xml" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="header">
<h1>🔒 TRAE-AI 个人私有安全网盘</h1>
<div class="header-info" id="statusTop"></div>
</div>
<div class="main-content">
<div id="setup" class="auth-section">
<h2>🔑 系统初始化</h2>
<div class="form-group">
<label class="form-label" for="baseCode">基础密码</label>
<input id="baseCode" placeholder="请输入基础密码" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-base" data-tip="用于初始化或重置主密码的基础口令" />
</div>
<div class="form-group">
<label class="form-label" for="newMaster">18位身份证号</label>
<input id="newMaster" placeholder="请设置新的身份证号" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-master-new" data-tip="设置新的身份证号,用于加密存储与分享" />
</div>
<button id="btnSetup" class="primary-btn">🚀 初始化系统</button>
<div class="notice" style="margin-top: 16px; color: var(--text-tertiary); font-size: 13px;">
本系统采用身份证实名制验证,确保数据安全。我们仅验证身份证格式,不采集其他个人信息。
</div>
</div>
<div id="login" class="auth-section hidden">
<h2>🔐 登录网盘</h2>
<div class="form-group">
<label class="form-label" for="master">18位身份证号</label>
<input id="master" placeholder="请输入您的身份证号" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-master" data-tip="登录所需的身份证号" />
</div>
<button id="btnLogin" class="primary-btn">🔓 登录</button>
<div class="notice" style="margin-top: 16px; color: var(--text-tertiary); font-size: 13px;">
本系统采用身份证实名制验证,确保数据安全。我们仅验证身份证格式,不采集其他个人信息。
</div>
</div>
<div id="dashboard" class="hidden">
<div class="toolbar">
<div class="toolbar-group">
<input type="file" id="fileInput" multiple data-tip="选择一个或多个文件进行上传" />
<select id="sizeRange">
<option value="lt1" selected>📁 1G以内</option>
<option value="1to10">📦 1G到10G</option>
<option value="gt10">🚚 10G以上</option>
</select>
<button id="btnUpload" data-tip="开始上传所选文件">📤 上传</button>
</div>
<div class="toolbar-group">
<button id="btnRefresh" data-tip="重新加载当前目录文件列表">🔄 刷新</button>
<button id="btnLogout" data-tip="退出登录并清理本地令牌">🚪 退出</button>
<button id="btnOpenSettings" class="hidden" data-tip="打开主密码重置等设置">⚙️ 设置</button>
<button id="btnOpenLogs" class="hidden" data-tip="查看操作日志">📋 日志</button>
</div>
</div>
<div class="toolbar" style="background: var(--background-tertiary);">
<div class="toolbar-group">
<span style="color: var(--text-secondary);">📂 当前目录:</span>
<span id="curDir" style="font-weight: 500;">/</span>
<button id="btnUp" data-tip="回到上一级目录">⬆️ 上一级</button>
<input id="newDirName" placeholder="新建文件夹名" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-newdir" data-tip="输入新文件夹的名称" style="width: 200px;" />
<button id="btnNewDir" data-tip="在当前目录创建新文件夹">📁 新建文件夹</button>
</div>
</div>
<div id="status"></div>
<!-- 上传进度条 -->
<div id="uploadProgress" class="hidden" style="margin: 16px 0;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<span id="uploadFileName" style="font-weight: 500; color: var(--text-primary);"></span>
<span id="uploadProgressText" style="color: var(--text-secondary); font-size: 14px;"></span>
</div>
<div style="width: 100%; height: 8px; background: var(--background-tertiary); border-radius: 4px; overflow: hidden;">
<div id="uploadProgressBar" style="width: 0%; height: 100%; background: linear-gradient(90deg, var(--primary-color), var(--primary-hover)); transition: width 0.3s ease; border-radius: 4px;"></div>
</div>
</div>
<!-- 空状态模板 -->
<div id="emptyState" class="empty-state hidden">
<div class="empty-state-icon">📁</div>
<h3>当前目录为空</h3>
<p>请上传文件或创建文件夹来开始使用您的网盘</p>
</div>
<table id="fileTable" class="hidden">
<thead>
<tr>
<th>📄 名称</th>
<th>🔍 类型</th>
<th>💾 大小</th>
<th>⏰ 最后修改</th>
<th>📊 状态</th>
<th>⚡ 操作</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="pwdModal" class="modal hidden">
<div class="modal-content">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">输入</h3><button id="btnClosePwd" class="icon-btn" data-tip="关闭">❌</button></div>
<div id="pwdPromptText" style="margin-bottom:8px">请输入18位身份证号</div>
<input id="pwdInput" placeholder="18位身份证号" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-op-pwd" />
<div style="margin-top:8px"><button id="btnPwdOk">确定</button> <button id="btnPwdCancel">取消</button></div>
</div>
</div>
<div id="captchaModal" class="modal hidden">
<div class="modal-content" style="width:360px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">身份验证</h3><button id="capClose" class="icon-btn" data-tip="关闭">❌</button></div>
<div style="text-align:center;margin-bottom:8px">拖动滑块,使图像角度为正</div>
<div id="capBox" style="width:240px;height:240px;margin:0 auto;position:relative;border-radius:50%;overflow:hidden;background:radial-gradient(circle at 120px 120px,#eef,#dde)">
<div id="capInner" style="position:absolute;left:0;top:0;width:240px;height:240px;border-radius:50%;clip-path:circle(85px at 120px 140px);transform-origin:120px 140px;background:radial-gradient(circle at 120px 120px,#eef,#dde)"></div>
</div>
<input id="capSlider" type="range" min="0" max="359" value="0" style="width:100%;margin-top:8px" />
<div style="margin-top:8px"><button id="capOk">验证并继续</button> <button id="capCancel">取消</button></div>
</div>
</div>
<div id="shareCreateModal" class="modal hidden">
<div class="modal-content">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">创建分享</h3><button id="btnCloseCreateShare" class="icon-btn" data-tip="关闭">❌</button></div>
<div>有效期:</div>
<div class="chips">
<span class="chip" data-days="1">1天</span>
<span class="chip" data-days="7">7天</span>
<span class="chip active" data-days="30">30天</span>
<span class="chip" data-days="365">365天</span>
<span class="chip" data-days="0">永久有效</span>
</div>
<input id="shareCreatePwd" placeholder="提取码" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-share-pwd" data-tip="设置分享提取码,用于对方验证" />
<div id="shareMasterWrap" style="margin-top:8px; display:block">
<input id="shareMaster" placeholder="18位身份证号(用于生成分享)" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-share-master" data-tip="当前未登录身份证号时,需手动输入用于生成分享" />
</div>
<label style="display:block;margin-top:8px"><input type="checkbox" id="shareAutoFill" /> 分享链接自动填写提取码(存在泄露风险)</label>
<div style="margin-top:12px; display:flex; gap:8px; align-items:center">
<button id="btnCopyShareLink" data-tip="生成分享并复制链接">复制链接</button>
<button id="btnGenQr" data-tip="生成分享并显示二维码">生成二维码</button>
</div>
<div id="shareLinkOutput" class="out"></div>
<div class="qr"><img id="shareQrImg" style="max-width:220px; display:none" /></div>
</div>
</div>
<div id="sliceModal" class="modal hidden">
<div class="modal-content" style="min-width:380px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">文件切片</h3><button id="btnSliceClose" class="icon-btn" data-tip="关闭">❌</button></div>
<div>文件:<span id="sliceFileName"></span></div>
<div style="margin-top:8px">分卷大小(MB):<input id="sliceSize" type="number" min="1" max="2048" value="100" style="width:120px" /></div>
<div id="sliceInfo" style="margin-top:8px"></div>
<div style="margin-top:8px"><button id="btnSliceStart">切片</button> <button id="btnSliceReslice">重新切片</button></div>
<div style="margin-top:12px;border-top:1px solid #eee;padding-top:8px">
<div>分卷列表:</div>
<div id="sliceList"></div>
</div>
</div>
</div>
<div id="resetModal" class="modal hidden">
<div class="modal-content">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">重置登录密码</h3><button id="btnCloseReset" class="icon-btn" data-tip="关闭设置">❌</button></div>
<input id="resetBase" placeholder="基础密码" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-reset-base" data-tip="基础密码" title="基础密码" />
<input id="resetMaster" placeholder="新的登录密码" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-reset-master" data-tip="新的登录密码" />
<div style="margin-top:8px"><button id="btnResetMaster">重置</button></div>
<div style="margin-top:16px;border-top:1px dashed #ccc;padding-top:12px">
<h3 style="margin:4px 0">初始化清空密钥</h3>
<div style="color:#333;margin:4px 0">仅管理员执行一次,用于启用战时清空功能</div>
<input id="setupWipeCode1" placeholder="密钥一" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-wipe-setup-1" />
<input id="setupWipeCode2" placeholder="密钥二" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-wipe-setup-2" />
<div style="margin-top:8px"><button id="btnSetupWipe">初始化清空密钥</button></div>
</div>
<div style="margin-top:16px;border-top:1px dashed #ccc;padding-top:12px">
<h3 style="margin:4px 0">清空所有数据</h3>
<div style="color:#c00;margin:4px 0">危险操作:将删除所有文件、分享、日志与索引</div>
<input id="wipeCode1" placeholder="密钥一" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-wipe1" />
<input id="wipeCode2" placeholder="密钥二" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-wipe2" />
<div style="margin-top:8px"><button id="btnWipeAll">清空所有数据</button></div>
</div>
</div>
</div>
<div id="genericModal" class="modal hidden">
<div class="modal-content" style="max-width: 400px; min-width: 300px;">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
<h3 id="genericModalTitle" style="margin:0; font-size: 16px; color: var(--text-primary);">提示</h3>
<button id="btnGenericClose" class="icon-btn" data-tip="关闭">❌</button>
</div>
<div id="genericModalMessage" style="margin-bottom:16px; color: var(--text-secondary); line-height: 1.5; font-size: 14px;"></div>
<div id="genericModalInputWrap" style="margin-bottom:16px; display:none;">
<input id="genericModalInput" type="text" autocomplete="off" spellcheck="false" style="width: 100%;" />
</div>
<div style="display:flex;justify-content:flex-end;gap:8px;margin-top:24px;">
<button id="btnGenericCancel" style="background:var(--background-tertiary); color:var(--text-secondary); border:none; padding:8px 16px; border-radius:var(--border-radius-md); cursor:pointer; font-weight:500;">取消</button>
<button id="btnGenericOk" class="primary-btn" style="padding:8px 16px; border-radius:var(--border-radius-md); width:auto;">确定</button>
</div>
</div>
</div>
<div id="logsModal" class="modal hidden">
<div class="modal-content">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px"><h3 style="margin:0">操作日志</h3><button id="btnCloseLogs" class="icon-btn" data-tip="关闭">❌</button></div>
<div style="display:flex;gap:8px;align-items:center;margin-bottom:8px" class="logs-toolbar">
<input id="logsFrom" type="datetime-local" />
<input id="logsTo" type="datetime-local" />
<select id="logsCategory"><option value="">全部</option><option value="file">文件</option><option value="dir">目录</option><option value="share">分享</option></select>
<input id="logsPageSize" type="number" min="10" max="100000" value="200" style="width:100px" />
<button id="btnFetchLogs">查询</button>
<button id="btnExportLogs">导出CSV</button>
<div><button id="btnLogsPrev">上一页</button> <button id="btnLogsNext">下一页</button> <span id="logsPageInfo"></span></div>
</div>
<div id="logsTableWrap">
<table id="logsTable">
<thead><tr><th>时间</th><th>类型</th><th>详情</th></tr></thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
<script src="auth.js"></script>
<script src="app.js"></script>
<script>
// 若服务端已启用本地二维码生成,则无需外部库;否则回退使用 CDN
(function(){
fetch('/share/qr?url=data:&size=10').then(r=>{
if(!r.ok) throw new Error('qr_offline_unavailable')
}).catch(()=>{
var s=document.createElement('script'); s.src='https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js'; document.body.appendChild(s)
})
})()
</script>
</body>
</html>
+41
View File
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Yang's 网盘</title>
<link rel="icon" href="psc.svg" type="image/svg+xml" />
<style>
body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;margin:0;padding:0;color:#111}
.container{max-width:800px;margin:24px auto;padding:0 16px}
h1{font-size:24px;margin:0 0 12px}
#statusTop{color:#666;margin-bottom:16px}
input{padding:8px;border:1px solid #ccc;border-radius:4px}
button{padding:8px 12px;border:1px solid #999;border-radius:4px;background:#f7f7f7}
.debugbox{white-space:pre-wrap;border:1px dashed #ccc;border-radius:4px;padding:8px;min-height:120px;margin-top:8px;color:#333}
</style>
<script>
let lines=[]
function log(){ const t=new Date().toISOString(); const msg=[t].concat([].slice.call(arguments)).join(' '); lines.push(msg); if(lines.length>200) lines.shift(); const el=document.getElementById('debugBottom'); if(el) el.textContent=lines.join('\n') }
function setStatus(t){ const s=document.getElementById('status'); if(s) s.textContent=t; const top=document.getElementById('statusTop'); if(top) top.textContent='后端: ' + location.origin + ' | ' + t; try{ log('status', t) }catch{} }
async function calcMasterFp(s){ const material = await window.crypto.subtle.importKey('raw', new TextEncoder().encode(s), 'PBKDF2', false, ['deriveBits']); const bits = await window.crypto.subtle.deriveBits({ name:'PBKDF2', hash:'SHA-256', salt: new TextEncoder().encode('local-fp'), iterations:120000 }, material, 256); const b = new Uint8Array(bits); return btoa(String.fromCharCode(...b)) }
function init(){ log('app.loaded'); log('backend.origin', location.origin); log('initUi.start'); const btn=document.getElementById('btnLogin'); const inp=document.getElementById('master'); btn.onclick=async function(){ const v=(inp.value||'').trim(); if(!v){ setStatus('请输入18位身份证号'); return } try{ log('login.skip_format_check'); log('login.req', 'id.len', v.length); const r = await fetch('/api/psc/auth/login/plain', { method:'POST', headers:{ 'Content-Type':'application/json' }, body: JSON.stringify({ master_password: v }) }); let j=null; try{ j=await r.json() }catch{}; log('login.status', r.status); log('login.json', JSON.stringify(j)); if(r.ok && j && j.token){ try{ localStorage.setItem('tk_plain', j.token) }catch{}; try{ const fp = await calcMasterFp(v); localStorage.setItem('mfp', fp) }catch{}; setStatus('登录成功,正在跳转...'); setTimeout(()=>{ location.href='index.html' }, 300) } else { if(j && j.error==='not_setup'){ setStatus('未初始化,请先设置登录密码'); return } if(j && j.error==='unauthorized'){ setStatus('身份证号不准确'); return } setStatus('登录失败') } } catch(e){ setStatus('网络错误,登录失败') } }; const cp=document.getElementById('btnCopyDebugBottom'); cp.onclick=async function(){ try{ await navigator.clipboard.writeText((document.getElementById('debugBottom')?.textContent)||''); setStatus('调试信息已复制') } catch{ setStatus('请手动复制调试信息') } } }
window.addEventListener('DOMContentLoaded', init)
</script>
</head>
<body>
<div class="container">
<h1>Yang's 网盘</h1>
<div id="statusTop"></div>
<div id="login">
<h2>登录</h2>
<input id="master" placeholder="18位身份证号" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" />
<button id="btnLogin">登录</button>
<div style="margin:6px 0"><button id="btnCopyDebugBottom">复制调试信息</button></div>
<div id="status" style="margin-top:8px"></div>
<div id="debugBottom" class="debugbox"></div>
</div>
</div>
<script src="auth.js"></script>
</body>
</html>
+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<text y=".9em" font-size="90">💾</text>
</svg>

After

Width:  |  Height:  |  Size: 113 B

+29
View File
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>分享下载</title>
<link rel="icon" href="/tools/psc/psc.svg" type="image/svg+xml" />
<link rel="stylesheet" href="/tools/psc/style.css" />
</head>
<body class="share-page">
<div class="container">
<h2>分享下载</h2>
<div class="row">
<input id="sharePwd" type="password" placeholder="分享密码" autocomplete="off" autocapitalize="off" spellcheck="false" name="no-save-share-open" />
<button id="btnOpen">打开</button>
</div>
<div id="status"></div>
<div id="info" class="hidden">
<div>文件:<span id="fname"></span></div>
<div>大小:<span id="fsize"></span></div>
<div class="row row-actions">
<button id="btnDownload">下载</button>
</div>
</div>
</div>
<script src="/tools/psc/share.js"></script>
</body>
</html>
+104
View File
@@ -0,0 +1,104 @@
function g(id){return document.getElementById(id)}
function status(t){g('status').textContent=t}
const params = new URLSearchParams(location.search)
const shareId = params.get('id') || location.pathname.split('/').filter(Boolean).pop()
const pAuto = params.get('p')
let meta=null
let fileKey=null
let sdebug=[]
function slog(){ const t=new Date().toISOString(); const msg=[t].concat([].slice.call(arguments)).join(' '); sdebug.push(msg); if(sdebug.length>200) sdebug.shift(); const el=g('shareDebug'); if(el) el.textContent=sdebug.join('\n') }
const CLIENT_VER = 'sharejs-2025-11-25-02'
slog('client.ver', CLIENT_VER)
slog('share.id', shareId)
slog('location', location.href)
async function deriveShareKey(pwd, salt){
const material = await crypto.subtle.importKey('raw', new TextEncoder().encode(pwd), 'PBKDF2', false, ['deriveKey'])
return crypto.subtle.deriveKey({ name:'PBKDF2', hash:'SHA-256', salt, iterations:200000 }, material, { name:'AES-GCM', length:256 }, false, ['encrypt','decrypt'])
}
async function unwrapFileKey(wrappedB64, shareKey, ivB64){
const iv = new Uint8Array([...atob(ivB64)].map(c=>c.charCodeAt(0)))
const ct = new Uint8Array([...atob(wrappedB64)].map(c=>c.charCodeAt(0)))
const pt = await crypto.subtle.decrypt({ name:'AES-GCM', iv }, shareKey, ct)
return new Uint8Array(pt)
}
async function deriveFileKeyFromBytes(bytes){
return crypto.subtle.importKey('raw', bytes, { name:'AES-GCM', length:256 }, false, ['decrypt'])
}
async function ivForChunk(saltBytes, index){
const data = new Uint8Array(saltBytes.length+4)
data.set(saltBytes,0)
data.set(new Uint8Array([index>>>24,(index>>>16)&255,(index>>>8)&255,index&255]), saltBytes.length)
const d = await crypto.subtle.digest('SHA-256', data)
return new Uint8Array(d).slice(0,12)
}
async function openShare(){
const pwd = g('sharePwd').value
slog('open.pwd', pwd)
if(!pwd){status('请输入分享密码');return}
status('验证中...')
const started = performance.now()
const r = await fetch(`/api/psc/share/${shareId}/init`, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ password: pwd }) })
let j=null
try { j = await r.json() } catch(e){ j={ error:'bad_json' } }
slog('open.status', r.status); slog('open.json', JSON.stringify(j)); if(j && j.error) slog('open.json.error', j.error)
if(j && j.expected) slog('open.hash.expected', j.expected)
if(j && j.actual) slog('open.hash.actual', j.actual)
if(j && j.shareSaltB64) slog('open.shareSaltB64.len', (j.shareSaltB64||'').length)
slog('open.ms', (performance.now()-started).toFixed(2))
if(!r.ok){ status('密码错误或分享不存在'); return }
meta = j
g('fname').textContent = j.name
g('fsize').textContent = (j.size/1048576).toFixed(2)+' MB'
const shareSalt = new Uint8Array([...atob(j.shareSaltB64)].map(c=>c.charCodeAt(0)))
const sKey = await deriveShareKey(pwd, shareSalt)
const fkBytes = await unwrapFileKey(j.wrappedKeyB64, sKey, j.ivB64)
fileKey = await deriveFileKeyFromBytes(fkBytes)
const fkHash = new Uint8Array(await crypto.subtle.digest('SHA-256', fkBytes))
slog('fk.hash', btoa(String.fromCharCode(...fkHash)))
slog('meta.fileId', j.fileId)
slog('meta.chunkCount', j.chunkCount)
slog('unwrap.len', fkBytes.length)
g('info').classList.remove('hidden')
status('验证通过')
}
async function download(){
if(!meta || !fileKey){ await openShare(); if(!meta || !fileKey){ status('请先验证分享'); return } }
status('开始下载')
const fileSalt = new Uint8Array([...atob(meta.fileSalt)].map(c=>c.charCodeAt(0)))
const chunks = new Array(meta.chunkCount)
let active=0, next=0, processed=0
const maxParallel=4
async function runOne(i){
try {
active++
slog('dl.req', i)
const r = await fetch(`/api/psc/share/${shareId}/chunk?index=${i}`)
slog('dl.http', r.status)
if(!r.ok){ throw new Error('http '+r.status) }
const buf = new Uint8Array(await r.arrayBuffer())
slog('dl.buf.len', buf.length)
const iv = await ivForChunk(fileSalt,i)
slog('dl.iv.b64', btoa(String.fromCharCode(...iv)))
const pt = new Uint8Array(await crypto.subtle.decrypt({ name:'AES-GCM', iv }, fileKey, buf))
chunks[i]=pt; processed+=pt.length; status(`已下载 ${(processed/meta.size*100).toFixed(2)}%`)
slog('dl.ok', i, pt.length)
} catch(e){ slog('dl.err', i, e && (e.message||String(e))); status('分片下载失败') }
finally { active--; schedule() }
}
function schedule(){
slog('dl.schedule', 'active', active, 'next', next)
while(active<maxParallel && next<meta.chunkCount){ runOne(next); next++ }
if(active===0 && next>=meta.chunkCount){ finish() }
}
function finish(){
const out=new Uint8Array(meta.size); let off=0; for(let i=0;i<meta.chunkCount;i++){ out.set(chunks[i],off); off+=chunks[i].length }
slog('dl.finish.size', out.length)
const blob=new Blob([out]); const a=document.createElement('a'); a.href=URL.createObjectURL(blob); a.download=meta.name; a.target='_blank'; a.click(); setTimeout(()=>URL.revokeObjectURL(a.href), 30000); status('下载完成')
}
schedule()
}
g('btnOpen').onclick=openShare
g('btnDownload').onclick=download
if(pAuto){ g('sharePwd').value = pAuto; slog('auto.p', pAuto); openShare() }
const btnCopy = document.getElementById('btnCopyShareDebug'); if(btnCopy){ btnCopy.onclick = async()=>{ try{ await navigator.clipboard.writeText((g('shareDebug')?.textContent)||''); status('调试信息已复制') } catch{ status('请手动复制调试信息') } } }
document.addEventListener('visibilitychange', ()=>{ if(document.visibilityState==='visible'){ const inputs = Array.from(document.querySelectorAll('input,textarea')); inputs.forEach(el=>{ if(el.type==='checkbox' || el.type==='radio'){ el.checked=false } else { el.value='' } }) } })
+606
View File
@@ -0,0 +1,606 @@
/* 简约扁平化风格 - 现代化网盘系统 */
:root {
--primary-color: #1677ff;
--primary-hover: #4096ff;
--success-color: #52c41a;
--warning-color: #faad14;
--error-color: #ff4d4f;
--text-primary: #262626;
--text-secondary: #595959;
--text-tertiary: #8c8c8c;
--border-color: #d9d9d9;
--background-primary: #ffffff;
--background-secondary: #fafafa;
--background-tertiary: #f5f5f5;
--shadow-light: 0 2px 8px rgba(0, 0, 0, 0.06);
--shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.12);
--shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.15);
--border-radius-sm: 6px;
--border-radius-md: 8px;
--border-radius-lg: 12px;
--transition-fast: 0.2s ease;
--transition-normal: 0.3s ease;
}
* {
box-sizing: border-box;
}
body {
font-family: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
margin: 0;
background: linear-gradient(135deg, #f0f2f5 0%, #e6f7ff 100%);
min-height: 100vh;
color: var(--text-primary);
}
.container {
max-width: 1200px;
margin: 0 auto;
background: var(--background-primary);
border-radius: var(--border-radius-lg);
box-shadow: var(--shadow-medium);
overflow: hidden;
min-height: calc(100vh - 40px);
margin-top: 20px;
margin-bottom: 20px;
}
/* 头部样式 */
.header {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
color: white;
padding: 24px 32px;
display: flex;
justify-content: space-between;
align-items: center;
}
.header h1 {
margin: 0;
font-size: 28px;
font-weight: 600;
letter-spacing: -0.5px;
}
.header-info {
font-size: 14px;
opacity: 0.9;
}
/* 主要内容区域 */
.main-content {
padding: 32px;
}
/* 登录/初始化区域 */
.auth-section {
max-width: 400px;
margin: 60px auto;
text-align: center;
}
.auth-section h2 {
color: var(--text-primary);
font-size: 24px;
margin-bottom: 24px;
font-weight: 600;
}
/* 表单控件样式 */
.form-group {
margin-bottom: 20px;
text-align: left;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: var(--text-secondary);
font-size: 14px;
}
input, select, button {
transition: all var(--transition-fast);
border: 1px solid var(--border-color);
border-radius: var(--border-radius-sm);
padding: 12px 16px;
font-size: 14px;
outline: none;
width: 100%;
margin-bottom: 12px;
}
input:focus, select:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.1);
transform: translateY(-1px);
}
/* 按钮样式 */
button {
background: var(--primary-color);
color: white;
border: none;
cursor: pointer;
font-weight: 500;
letter-spacing: 0.5px;
text-transform: uppercase;
font-size: 14px;
padding: 14px 24px;
border-radius: var(--border-radius-md);
transition: all var(--transition-fast);
position: relative;
overflow: hidden;
}
button:hover {
background: var(--primary-hover);
transform: translateY(-2px);
box-shadow: var(--shadow-medium);
}
button:active {
transform: translateY(0);
}
button:disabled {
background: var(--text-tertiary);
cursor: not-allowed;
transform: none;
}
/* 工具条样式 */
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
padding: 20px;
background: var(--background-secondary);
border-radius: var(--border-radius-md);
flex-wrap: wrap;
gap: 16px;
}
.toolbar-group {
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
}
.toolbar input, .toolbar select, .toolbar button {
width: auto;
margin-bottom: 0;
}
/* 文件表格样式 */
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
margin-top: 0;
background: var(--background-primary);
border-radius: var(--border-radius-md);
overflow: hidden;
box-shadow: var(--shadow-light);
}
th {
background: var(--background-secondary);
padding: 16px 12px;
text-align: left;
font-weight: 600;
color: var(--text-secondary);
font-size: 14px;
border-bottom: 1px solid var(--border-color);
}
td {
padding: 16px 12px;
border-bottom: 1px solid var(--border-color);
transition: background-color var(--transition-fast);
}
tr:hover td {
background: var(--background-tertiary);
}
tr:last-child td {
border-bottom: none;
}
.tooltip { position: absolute; background: rgba(0,0,0,0.75); color: #fff; font-size: 12px; padding: 6px 8px; border-radius: 6px; pointer-events: none; box-shadow: var(--shadow-light); z-index: 10001 }
.tooltip.hidden { display: none }
td button { width: auto; display: inline-flex; align-items: center; justify-content: center; padding: 6px 8px; margin: 2px }
button.icon-btn { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px }
.share-page .container {
max-width: 560px;
min-height: auto;
}
.share-page .main-content {
padding: 20px;
}
.share-page h2 {
margin: 0 0 12px 0;
font-size: 20px;
}
.share-page input, .share-page button {
font-size: 14px;
padding: 10px 12px;
margin-bottom: 10px;
text-transform: none;
letter-spacing: 0;
}
.share-page .row {
display: flex;
gap: 10px;
align-items: center;
}
.share-page .row input {
flex: 1;
margin-bottom: 0;
}
.share-page .row button {
width: auto;
margin-bottom: 0;
padding-left: 14px;
padding-right: 14px;
}
.share-page #info {
margin-top: 12px;
}
.share-page #info > div {
margin: 8px 0;
}
.share-page .row-actions {
justify-content: flex-end;
}
/* 隐藏类 */
.hidden { display: none }
/* 状态提示 */
#status {
margin: 16px 0;
padding: 12px 16px;
border-radius: var(--border-radius-sm);
background: var(--background-secondary);
color: var(--text-secondary);
font-size: 14px;
}
#statusTop {
background: var(--background-secondary);
padding: 8px 32px;
font-size: 12px;
color: var(--text-tertiary);
border-bottom: 1px solid var(--border-color);
}
/* 模态框样式 */
.modal {
position: fixed;
left: 0; top: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
backdrop-filter: blur(4px);
}
.modal.hidden { display: none }
.modal-content {
background: var(--background-primary);
padding: 24px;
border-radius: var(--border-radius-lg);
min-width: 400px;
max-width: 90vw;
max-height: 80vh;
overflow: auto;
box-shadow: var(--shadow-heavy);
animation: modalSlideIn 0.3s ease;
}
@keyframes modalSlideIn {
from {
opacity: 0;
transform: translateY(-20px) scale(0.95);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
/* 其他组件样式 */
.chips {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin: 16px 0;
}
.chip {
padding: 8px 16px;
border: 1px solid var(--border-color);
border-radius: 20px;
cursor: pointer;
user-select: none;
transition: all var(--transition-fast);
font-size: 14px;
}
.chip:hover {
border-color: var(--primary-color);
color: var(--primary-color);
}
.chip.active {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
/* 加载动画 */
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-top: 2px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-right: 8px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* 按钮悬停动画 */
button:hover {
background: var(--primary-hover);
transform: translateY(-2px);
box-shadow: var(--shadow-medium);
}
button:active {
transform: translateY(0);
}
/* 文件项悬停效果 */
.file-item:hover {
background: var(--background-tertiary);
transform: translateX(4px);
transition: all var(--transition-fast);
}
/* 进度条动画 */
.progress-bar {
transition: width 0.3s ease;
background: linear-gradient(90deg, var(--primary-color), var(--primary-hover));
}
/* 淡入淡出动画 */
.fade-in {
animation: fadeIn 0.3s ease;
}
.fade-out {
animation: fadeOut 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(-10px); }
}
/* 卡片悬停效果 */
.card {
transition: all var(--transition-fast);
cursor: pointer;
}
.card:hover {
transform: translateY(-4px);
box-shadow: var(--shadow-heavy);
}
/* 空状态样式 */
.empty-state {
text-align: center;
padding: 60px 20px;
color: var(--text-tertiary);
}
.empty-state-icon {
font-size: 64px;
margin-bottom: 16px;
opacity: 0.3;
}
.empty-state h3 {
margin: 0 0 8px 0;
font-size: 18px;
font-weight: 500;
}
.empty-state p {
margin: 0;
font-size: 14px;
}
/* 移动端响应式 */
@media (max-width: 768px) {
.container {
margin: 0;
border-radius: 0;
min-height: 100vh;
box-shadow: none;
}
.header {
padding: 16px 20px;
flex-direction: column;
gap: 8px;
text-align: center;
}
.header h1 {
font-size: 24px;
}
.main-content {
padding: 16px;
}
.auth-section {
margin: 40px auto;
max-width: 100%;
}
.toolbar {
flex-direction: column;
align-items: stretch;
gap: 12px;
padding: 16px;
}
.toolbar-group {
justify-content: center;
flex-wrap: wrap;
}
.toolbar input, .toolbar select, .toolbar button {
width: 100%;
margin-bottom: 8px;
}
.modal-content {
min-width: 90vw;
padding: 16px;
margin: 16px;
}
table {
font-size: 14px;
display: block;
overflow-x: auto;
}
th, td {
padding: 12px 8px;
white-space: nowrap;
}
/* 移动端按钮优化 */
button {
padding: 16px 20px;
font-size: 16px; /* 防止iOS缩放 */
}
input, select {
padding: 16px 12px;
font-size: 16px; /* 防止iOS缩放 */
}
/* 文件操作按钮优化 */
td button {
padding: 8px 12px;
margin: 2px;
font-size: 12px;
}
/* 空状态优化 */
.empty-state {
padding: 40px 20px;
}
.empty-state-icon {
font-size: 48px;
}
}
@media (max-width: 480px) {
.header {
padding: 12px 16px;
}
.header h1 {
font-size: 20px;
}
.main-content {
padding: 12px;
}
.auth-section h2 {
font-size: 20px;
}
.toolbar {
padding: 12px;
gap: 8px;
}
.modal-content {
padding: 12px;
margin: 8px;
}
/* 更小的屏幕优化 */
th, td {
padding: 8px 4px;
font-size: 12px;
}
td button {
padding: 6px 8px;
font-size: 10px;
}
/* 隐藏部分列在小屏幕上 */
@media (max-width: 360px) {
th:nth-child(3), td:nth-child(3), /* 大小列 */
th:nth-child(4), td:nth-child(4) /* 修改时间列 */
{
display: none;
}
}
}
/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
button:hover {
transform: none;
}
tr:hover td {
background: var(--background-primary);
}
.chip:hover {
border-color: var(--border-color);
color: var(--text-primary);
}
}