Spaces:
Running
Running
Surf commited on
Commit ·
f6ca7f9
1
Parent(s): d62591f
统一入口并修复工作台密码无响应
Browse filesFiles changed (2)
83 unmodified lines84858687888983 unmodified linesres.type('application/x-ndjson').send(data)}))app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))app.get(['/fanqie', '/fanqie/*'], (_req, res) => { res.setHeader('Cache-Control', 'no-cache'); res.sendFile(path.join(DIST, 'index.html')) })console.log('番茄写作工作台 mounted at /fanqie/')}83 unmodified lines848586878889909183 unmodified linesres.type('application/x-ndjson').send(data)}))app.use('/fanqie', express.static(DIST, { index: false, maxAge: '1h' }))// 统一入口:不再区分“新旧工作台”,/fanqie/ 直接进入 R2 小说创作工作台。app.get(['/fanqie', '/fanqie/'], (_req, res) => res.redirect('/fanqie/workspace'))app.get('/fanqie/*', (_req, res) => res.redirect('/fanqie/workspace'))console.log('番茄写作工作台 mounted at /fanqie/')}
8 unmodified lines91011121314157 unmodified lines2324252627282911 unmodified lines41424344454647488 unmodified lines</head><body><div class="app"><header class="top"><div class="brand"><div class="brand-mark">AI</div><div><h1>AI 小说创作工作台</h1><p>项目、作品圣经、大纲、章节、版本与检查结果全部保存到 R2</p></div></div><div class="top-actions"><a class="link" href="/fanqie/">返回旧工作台</a><a class="link" href="/fanqie/batches">素材批次</a></div></header><div class="layout"><aside><div class="aside-title"><span>我的作品</span><button class="btn" id="new-project">+ 新建</button></div><div id="project-list" class="project-list"></div><div id="aside-status" class="status" style="margin-top:12px"></div></aside><main class="main"><div id="auth-box" class="panel"><h2 style="margin:0 0 5px">连接工作台</h2><p class="muted">输入当前网页访问密码。密码只用于请求受保护接口,不会写入作品数据。</p><div class="row"><input id="password" type="password" placeholder="网页访问密码" style="flex:1;min-width:220px;background:#10131a;color:var(--text);border:1px solid var(--line);padding:9px;border-radius:8px"><button class="btn primary" id="unlock">连接</button></div><div id="auth-status" class="status"></div></div><div id="empty" class="empty hidden"><div style="font-size:50px">📖</div><h2>先建立一部作品</h2><p>创建后,作品信息、人物、时间线、大纲、章节和版本都会保存到 R2。以后你可以直接在对话中让我继续写,我会按项目 ID 读取并修改这里的数据。</p><button class="btn primary" id="empty-new">新建小说项目</button></div>7 unmodified lines</div></main></div></div><script>(()=>{const $=id=>document.getElementById(id), API='/fanqie/api', PW_KEY='xiaoshuo_app_password';let password='',projects=[],current=null,chapters=[],selectedMaterials=[],searchMaterials=[],currentChapter=null,versions=[];try{password=localStorage.getItem(PW_KEY)||''}catch(_){} if(password)$('password').value=password;function msg(el,text,error=false){$(el).textContent=text;$(el).className='status'+(error?' error':' ok')}async function api(path,opt={}){const headers=Object.assign({'Content-Type':'application/json','x-app-password':encodeURIComponent(password)},opt.headers||{});const r=await fetch(API+path,Object.assign({},opt,{headers}));if(!r.ok){let e=r.statusText;try{e=(await r.json()).error||e}catch(_){}throw Error(e)}return r.status===204?null:r.json()}11 unmodified linesasync function saveProject(){try{const p=await api('/projects/'+current.project_id,{method:'PATCH',body:JSON.stringify({title:$('f-title').value,genre:$('f-genre').value,target_platform:$('f-platform').value,target_words:Number($('f-words').value||0),pov:$('f-pov').value,style:$('f-style').value,premise:$('f-premise').value})});current=p;$('project-title').textContent=p.title;$('project-meta').textContent=[p.genre,p.target_platform,p.target_words?p.target_words.toLocaleString()+'字':''].filter(Boolean).join(' · ');msg('save-status','已保存到 R2') ;await loadProjects()}catch(e){msg('save-status',e.message,true)}}async function saveBible(){try{const data={story_core:$('b-core').value,main_plot:$('b-plot').value,ending_direction:$('b-ending').value,reader_expectation:$('b-reader').value,characters:jsonValue('b-characters'),relationships:jsonValue('b-relations'),timeline:jsonValue('b-timeline'),settings:jsonValue('b-settings'),foreshadowing:jsonValue('b-foreshadowing'),open_questions:jsonValue('b-questions'),style_rules:jsonValue('b-style-rules'),safety_rules:jsonValue('b-safety-rules')};await api('/projects/'+current.project_id+'/bible',{method:'PUT',body:JSON.stringify(data)});msg('bible-status','作品圣经已保存到 R2')}catch(e){msg('bible-status',e.message,true)}}async function saveOutline(){try{const data={three_act:jsonValue('o-acts'),volumes:jsonValue('o-volumes'),chapters:jsonValue('o-chapters')};await api('/projects/'+current.project_id+'/outline',{method:'PUT',body:JSON.stringify(data)});msg('outline-status','总纲已保存到 R2')}catch(e){msg('outline-status',e.message,true)}}async function searchMaterials(){const q=$('material-query').value.trim();if(!q)return;try{const d=await api('/materials/search?q='+encodeURIComponent(q)+'&size=10');searchMaterials=d.items||[];renderMaterialResults()}catch(e){msg('materials-status',e.message,true)}}function renderMaterialResults(){$('material-results').innerHTML=searchMaterials.length?searchMaterials.map(x=>{const on=selectedMaterials.some(y=>y.uid===x.uid);return `<div class="card ${on?'selected':''}"><div class="row"><input type="checkbox" data-mid="${esc(x.uid)}" ${on?'checked':''}><h4>${esc(x.sum||x.uid)}</h4></div><p>${esc(x.text||'')}</p><footer>${esc(x.uid)} · ${esc(x.g||'')} · ${esc(x.k||'')}</footer></div>`}).join(''):'<div class="muted">请输入关键词搜索素材。</div>';document.querySelectorAll('[data-mid]').forEach(c=>c.onchange=()=>{const x=searchMaterials.find(y=>y.uid===c.dataset.mid);if(c.checked){if(selectedMaterials.length>=3){c.checked=false;alert('每个作品最多选择 3 条参考素材');return}selectedMaterials=[...selectedMaterials,x]}else selectedMaterials=selectedMaterials.filter(y=>y.uid!==c.dataset.mid);renderMaterialResults();renderSelected()})}function renderSelected(){$('selected-count').textContent=selectedMaterials.length+'/3';$('selected-materials').innerHTML=selectedMaterials.length?selectedMaterials.map(x=>`<div class="card selected"><h4>${esc(x.sum||x.uid)}</h4><p>${esc(x.text||'')}</p><footer>${esc(x.uid)} <button class="btn" data-remove="${esc(x.uid)}" style="float:right;padding:2px 7px">移除</button></footer></div>`).join(''):'<div class="muted">尚未选择参考素材</div>';document.querySelectorAll('[data-remove]').forEach(b=>b.onclick=()=>{selectedMaterials=selectedMaterials.filter(x=>x.uid!==b.dataset.remove);renderSelected();renderMaterialResults()})}async function saveMaterials(){try{await api('/projects/'+current.project_id+'/materials',{method:'PUT',body:JSON.stringify({items:selectedMaterials})});msg('materials-status','参考素材已保存到 R2')}catch(e){msg('materials-status',e.message,true)}}function renderChapters(){$('chapter-list').innerHTML=chapters.length?chapters.map(c=>`<button class="chapter-item ${currentChapter?.chapter_id===c.chapter_id?'active':''}" data-cid="${c.chapter_id}">第 ${c.number} 章:${esc(c.title)}<small>${esc(c.status||'planned')} · ${c.current_version_id?'已有版本':'未写正文'}</small></button>`).join(''):'<div class="muted">还没有章节</div>';document.querySelectorAll('[data-cid]').forEach(b=>b.onclick=()=>openChapter(b.dataset.cid))}8 unmodified lines91011121314157 unmodified lines2324252627282911 unmodified lines41424344454647488 unmodified lines</head><body><div class="app"><header class="top"><div class="brand"><div class="brand-mark">AI</div><div><h1>AI 小说创作工作台</h1><p>项目、作品圣经、大纲、章节、版本与检查结果全部保存到 R2</p></div></div><div class="top-actions"><a class="link" href="/fanqie/batches">素材批次</a></div></header><div class="layout"><aside><div class="aside-title"><span>我的作品</span><button class="btn" id="new-project">+ 新建</button></div><div id="project-list" class="project-list"></div><div id="aside-status" class="status" style="margin-top:12px"></div></aside><main class="main"><div id="auth-box" class="panel"><h2 style="margin:0 0 5px">连接工作台</h2><p class="muted">输入当前网页访问密码。密码只用于请求受保护接口,不会写入作品数据。</p><div class="row"><input id="password" type="password" placeholder="网页访问密码" style="flex:1;min-width:220px;background:#10131a;color:var(--text);border:1px solid var(--line);padding:9px;border-radius:8px"><button class="btn primary" id="unlock">连接</button></div><div id="auth-status" class="status"></div></div><div id="empty" class="empty hidden"><div style="font-size:50px">📖</div><h2>先建立一部作品</h2><p>创建后,作品信息、人物、时间线、大纲、章节和版本都会保存到 R2。以后你可以直接在对话中让我继续写,我会按项目 ID 读取并修改这里的数据。</p><button class="btn primary" id="empty-new">新建小说项目</button></div>7 unmodified lines</div></main></div></div><script>(()=>{const $=id=>document.getElementById(id), API='/fanqie/api', PW_KEY='xiaoshuo_app_password';let password='',projects=[],current=null,chapters=[],selectedMaterials=[],materialResults=[],currentChapter=null,versions=[];try{password=localStorage.getItem(PW_KEY)||''}catch(_){} if(password)$('password').value=password;function msg(el,text,error=false){$(el).textContent=text;$(el).className='status'+(error?' error':' ok')}async function api(path,opt={}){const headers=Object.assign({'Content-Type':'application/json','x-app-password':encodeURIComponent(password)},opt.headers||{});const r=await fetch(API+path,Object.assign({},opt,{headers}));if(!r.ok){let e=r.statusText;try{e=(await r.json()).error||e}catch(_){}throw Error(e)}return r.status===204?null:r.json()}11 unmodified linesasync function saveProject(){try{const p=await api('/projects/'+current.project_id,{method:'PATCH',body:JSON.stringify({title:$('f-title').value,genre:$('f-genre').value,target_platform:$('f-platform').value,target_words:Number($('f-words').value||0),pov:$('f-pov').value,style:$('f-style').value,premise:$('f-premise').value})});current=p;$('project-title').textContent=p.title;$('project-meta').textContent=[p.genre,p.target_platform,p.target_words?p.target_words.toLocaleString()+'字':''].filter(Boolean).join(' · ');msg('save-status','已保存到 R2') ;await loadProjects()}catch(e){msg('save-status',e.message,true)}}async function saveBible(){try{const data={story_core:$('b-core').value,main_plot:$('b-plot').value,ending_direction:$('b-ending').value,reader_expectation:$('b-reader').value,characters:jsonValue('b-characters'),relationships:jsonValue('b-relations'),timeline:jsonValue('b-timeline'),settings:jsonValue('b-settings'),foreshadowing:jsonValue('b-foreshadowing'),open_questions:jsonValue('b-questions'),style_rules:jsonValue('b-style-rules'),safety_rules:jsonValue('b-safety-rules')};await api('/projects/'+current.project_id+'/bible',{method:'PUT',body:JSON.stringify(data)});msg('bible-status','作品圣经已保存到 R2')}catch(e){msg('bible-status',e.message,true)}}async function saveOutline(){try{const data={three_act:jsonValue('o-acts'),volumes:jsonValue('o-volumes'),chapters:jsonValue('o-chapters')};await api('/projects/'+current.project_id+'/outline',{method:'PUT',body:JSON.stringify(data)});msg('outline-status','总纲已保存到 R2')}catch(e){msg('outline-status',e.message,true)}}async function searchMaterials(){const q=$('material-query').value.trim();if(!q)return;try{const d=await api('/materials/search?q='+encodeURIComponent(q)+'&size=10');materialResults=d.items||[];renderMaterialResults()}catch(e){msg('materials-status',e.message,true)}}function renderMaterialResults(){$('material-results').innerHTML=materialResults.length?materialResults.map(x=>{const on=selectedMaterials.some(y=>y.uid===x.uid);return `<div class="card ${on?'selected':''}"><div class="row"><input type="checkbox" data-mid="${esc(x.uid)}" ${on?'checked':''}><h4>${esc(x.sum||x.uid)}</h4></div><p>${esc(x.text||'')}</p><footer>${esc(x.uid)} · ${esc(x.g||'')} · ${esc(x.k||'')}</footer></div>`}).join(''):'<div class="muted">请输入关键词搜索素材。</div>';document.querySelectorAll('[data-mid]').forEach(c=>c.onchange=()=>{const x=materialResults.find(y=>y.uid===c.dataset.mid);if(c.checked){if(selectedMaterials.length>=3){c.checked=false;alert('每个作品最多选择 3 条参考素材');return}selectedMaterials=[...selectedMaterials,x]}else selectedMaterials=selectedMaterials.filter(y=>y.uid!==c.dataset.mid);renderMaterialResults();renderSelected()})}function renderSelected(){$('selected-count').textContent=selectedMaterials.length+'/3';$('selected-materials').innerHTML=selectedMaterials.length?selectedMaterials.map(x=>`<div class="card selected"><h4>${esc(x.sum||x.uid)}</h4><p>${esc(x.text||'')}</p><footer>${esc(x.uid)} <button class="btn" data-remove="${esc(x.uid)}" style="float:right;padding:2px 7px">移除</button></footer></div>`).join(''):'<div class="muted">尚未选择参考素材</div>';document.querySelectorAll('[data-remove]').forEach(b=>b.onclick=()=>{selectedMaterials=selectedMaterials.filter(x=>x.uid!==b.dataset.remove);renderSelected();renderMaterialResults()})}async function saveMaterials(){try{await api('/projects/'+current.project_id+'/materials',{method:'PUT',body:JSON.stringify({items:selectedMaterials})});msg('materials-status','参考素材已保存到 R2')}catch(e){msg('materials-status',e.message,true)}}function renderChapters(){$('chapter-list').innerHTML=chapters.length?chapters.map(c=>`<button class="chapter-item ${currentChapter?.chapter_id===c.chapter_id?'active':''}" data-cid="${c.chapter_id}">第 ${c.number} 章:${esc(c.title)}<small>${esc(c.status||'planned')} · ${c.current_version_id?'已有版本':'未写正文'}</small></button>`).join(''):'<div class="muted">还没有章节</div>';document.querySelectorAll('[data-cid]').forEach(b=>b.onclick=()=>openChapter(b.dataset.cid))}
fanqie/mount.js+3-1
fanqie/workspace.html+4-4