@craft_eco/craft-mcp 0.1.14 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist-server/game-workflow/draft-archive.mjs +53 -91
- package/dist-server/game-workflow/draft-uploads.mjs +207 -207
- package/dist-server/game-workflow/publications.mjs +4 -2
- package/dist-server/mcp/control-panel.mjs +59 -40
- package/dist-server/mcp/publication-page.html +86 -0
- package/dist-server/mcp/publication-page.mjs +347 -0
- package/dist-server/mcp/publication-preview.mjs +49 -0
- package/dist-server/mcp/publication-tools.mjs +4 -1
- package/dist-server/mcp/publish-panel.mjs +191 -0
- package/dist-server/mcp/server.mjs +312 -297
- package/dist-server/upstream/craft-aigc.mjs +169 -197
- package/dist-server/upstream/publication-transport.mjs +2 -1
- package/package.json +1 -1
- package/resources/craft-game-maker/SKILL.md +69 -67
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts +19 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js +107 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts +44 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js +106 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js.map +1 -0
- package/vendor/agent-cli/dist/src/index.d.ts +2 -0
- package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/index.js +2 -0
- package/vendor/agent-cli/dist/src/index.js.map +1 -1
|
@@ -1,40 +1,59 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import { randomBytes } from 'node:crypto';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import { sendJson, parseJsonBody } from '../core/http-utils.mjs';
|
|
5
|
-
|
|
6
|
-
export async function openControlPanel(platform) {
|
|
7
|
-
const csrf
|
|
8
|
-
const template
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { sendJson, parseJsonBody } from '../core/http-utils.mjs';
|
|
5
|
+
|
|
6
|
+
export async function openControlPanel(platform,{ allowLocalAuth=true,publishPanel,publicationDirectory=new URL('./',import.meta.url) }={}) {
|
|
7
|
+
const csrf=randomBytes(32).toString('hex');
|
|
8
|
+
const template=await readFile(new URL('./control-panel.html',import.meta.url),'utf8');
|
|
9
|
+
let port,origin;
|
|
10
|
+
const secure=(res,frameOrigin)=>{
|
|
11
|
+
res.setHeader('Content-Security-Policy',`default-src 'none'; script-src 'nonce-${csrf}'; style-src 'unsafe-inline'; connect-src 'self'; img-src 'self' data: blob:; frame-src ${frameOrigin || "'none'"}; frame-ancestors 'none'; base-uri 'none'; form-action 'self'`);
|
|
12
|
+
};
|
|
13
|
+
const server=http.createServer(async(req,res)=>{
|
|
14
|
+
res.setHeader('Cache-Control','no-store');res.setHeader('X-Content-Type-Options','nosniff');res.setHeader('Referrer-Policy','no-referrer');
|
|
15
|
+
if(req.headers.host!==`127.0.0.1:${port}` || (req.headers.origin && req.headers.origin!==origin) || req.headers['sec-fetch-site']==='cross-site') {
|
|
16
|
+
req.resume();sendJson(res,403,{error:'Only same-origin requests are accepted'});return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const url=new URL(req.url,origin);
|
|
20
|
+
const page=/^\/publish\/([A-Za-z0-9_-]{43})$/.exec(url.pathname);
|
|
21
|
+
if(publishPanel && req.method==='GET' && page) {
|
|
22
|
+
const data=await publishPanel.document(page[1]);
|
|
23
|
+
const html=await readFile(new URL('publication-page.html',publicationDirectory),'utf8');
|
|
24
|
+
secure(res,data.runtime_url ? new URL(data.runtime_url).origin : undefined);
|
|
25
|
+
res.writeHead(200,{'Content-Type':'text/html; charset=utf-8'});
|
|
26
|
+
res.end(html.replaceAll('__CSRF__',csrf).replaceAll('__PUBLISH_CAP__',page[1]));return;
|
|
27
|
+
}
|
|
28
|
+
if(publishPanel && req.method==='GET' && url.pathname==='/publication-page.mjs') {
|
|
29
|
+
const script=await readFile(new URL('publication-page.mjs',publicationDirectory));
|
|
30
|
+
res.writeHead(200,{'Content-Type':'text/javascript; charset=utf-8'});res.end(script);return;
|
|
31
|
+
}
|
|
32
|
+
if(req.method==='GET' && url.pathname==='/') {
|
|
33
|
+
if(!allowLocalAuth) {sendJson(res,404,{error:'Update credentials in the WorkBuddy connector and reconnect'});return;}
|
|
34
|
+
secure(res);res.writeHead(200,{'Content-Type':'text/html; charset=utf-8'});res.end(template.replaceAll('__CSRF__',csrf));return;
|
|
35
|
+
}
|
|
36
|
+
if(req.method==='GET' && url.pathname==='/data') {sendJson(res,200,await platform.status());return;}
|
|
37
|
+
const api=/^\/api\/publish\/([A-Za-z0-9_-]{43})\/(state|cover|prepare|review|submit|status|task)$/.exec(url.pathname);
|
|
38
|
+
const auth=allowLocalAuth && ['/login','/logout'].includes(url.pathname);
|
|
39
|
+
if(req.method==='POST') {
|
|
40
|
+
if((!api || !publishPanel) && !auth) {req.resume();sendJson(res,404,{error:'Not found'});return;}
|
|
41
|
+
if(req.headers.origin!==origin || req.headers['x-craft-csrf']!==csrf || req.headers['content-type']!=='application/json') {
|
|
42
|
+
req.resume();sendJson(res,403,{error:'Invalid local control request'});return;
|
|
43
|
+
}
|
|
44
|
+
const body=await parseJsonBody(req,api?.[2] === 'cover' ? 3*1024*1024 : api ? 64*1024 : 8192);
|
|
45
|
+
const result=api ? await publishPanel.handle(api[1],api[2],req.method,url.searchParams,body) :
|
|
46
|
+
url.pathname==='/login' ? await platform.login(body.token) : platform.logout();
|
|
47
|
+
sendJson(res,200,result);return;
|
|
48
|
+
}
|
|
49
|
+
if(publishPanel && api) {sendJson(res,200,await publishPanel.handle(api[1],api[2],req.method,url.searchParams));return;}
|
|
50
|
+
req.resume();sendJson(res,404,{error:'Not found'});
|
|
51
|
+
} catch(error) {
|
|
52
|
+
sendJson(res,Number.isInteger(error.status) && error.status>=400 && error.status<600 ? error.status : 400,
|
|
53
|
+
{error:error.message,platform:platform.base,...error.detail});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(0,'127.0.0.1',resolve);});
|
|
57
|
+
port=server.address().port;origin=`http://127.0.0.1:${port}`;publishPanel?.bindOrigin(origin);
|
|
58
|
+
return {url:origin,close:async()=>{await publishPanel?.close();server.closeAllConnections();await new Promise(resolve=>server.close(resolve));}};
|
|
59
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<meta name="craft-csrf" content="__CSRF__">
|
|
7
|
+
<title>发布到 Craft</title>
|
|
8
|
+
<style>
|
|
9
|
+
:root{font:15px/1.65 system-ui,-apple-system,"Segoe UI","Microsoft YaHei",sans-serif;color:#18223b;background:#f4f6fb;color-scheme:light;--muted:#5d6981;--line:#dce1ed;--brand:#2858c8;--danger:#a1232c}
|
|
10
|
+
*{box-sizing:border-box}body{margin:0}main{max-width:1120px;margin:0 auto;padding:36px 24px 56px}h1,h2,h3,p{margin:0}h1{font-size:28px;line-height:1.35}h2{font-size:19px}h3{font-size:15px}.intro{margin:10px 0 22px;color:var(--muted)}.topline{display:flex;gap:20px;align-items:flex-start;justify-content:space-between}
|
|
11
|
+
button,input,textarea,select{font:inherit}button{cursor:pointer;border:1px solid transparent;border-radius:8px;padding:10px 17px;background:var(--brand);color:white;font-weight:600}button.secondary{color:var(--brand);border-color:#c6d2ed;background:#fff}button.quiet{padding:5px 8px;background:transparent;color:var(--muted);font-weight:400}button:disabled{opacity:.5;cursor:not-allowed}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible,summary:focus-visible{outline:3px solid #9ab9ff;outline-offset:3px}
|
|
12
|
+
.steps{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;list-style:none;padding:0;margin:0 0 22px}.steps li{border-top:3px solid var(--line);padding-top:8px;color:var(--muted);font-size:13px}.steps li.current{border-color:var(--brand);color:var(--brand);font-weight:600}.steps li.done{border-color:#93abd9}
|
|
13
|
+
.notice{border:1px solid #cedbf4;border-radius:10px;background:#edf3ff;padding:13px 16px;margin-bottom:18px;white-space:pre-wrap}.notice.error{border-color:#ebc8cc;background:#fff2f3;color:var(--danger)}.notice[hidden],section[hidden],div[hidden],p[hidden],a[hidden]{display:none}.layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.1fr);gap:20px;align-items:start}.card{background:#fff;border:1px solid var(--line);border-radius:14px;padding:22px}.stack{display:grid;gap:20px}.section-intro{color:var(--muted);font-size:13px;margin:7px 0 18px}
|
|
14
|
+
.context{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:4px 14px;margin:14px 0 0;font-size:13px}.context dt{color:var(--muted)}.context dd{margin:0;overflow-wrap:anywhere}.state{display:inline-block;padding:2px 9px;border-radius:6px;background:#edf3ff;color:var(--brand);font-size:13px;margin-top:12px}
|
|
15
|
+
fieldset{padding:0;border:0;margin:0;min-width:0}label.field{display:block;margin:0 0 17px;font-weight:600}label.field>span{display:block;margin-bottom:6px}input[type=text],textarea,select{width:100%;padding:10px 12px;border:1px solid #aab5cc;border-radius:8px;background:#fff;color:inherit;font-weight:400}textarea{resize:vertical;min-height:125px}input[type=file]{width:100%;font-weight:400;font-size:13px}input[type=checkbox]{width:17px;height:17px;accent-color:var(--brand);flex:none;margin:3px 0 0}small,.help{display:block;font-size:12px;color:var(--muted);font-weight:400;margin-top:5px}.tag-group{margin-bottom:17px}.tag-group legend{font-weight:600;margin-bottom:6px}.tags{display:flex;flex-wrap:wrap;gap:7px;max-height:150px;overflow:auto}.tag{display:flex;gap:7px;align-items:flex-start;border:1px solid var(--line);padding:5px 8px;border-radius:6px;font-size:13px;font-weight:400}.tag input{width:14px;height:14px}.empty{font-size:13px;color:var(--muted)}
|
|
16
|
+
.cover-preview{display:block;width:100%;max-height:220px;object-fit:contain;border-radius:8px;background:#f4f6fb;margin-top:10px}.cover-actions{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:6px}.privacy-note{padding:11px 13px;background:#f4f6fb;border-radius:8px;font-size:13px;color:var(--muted);margin-bottom:17px}.actions{display:flex;flex-wrap:wrap;gap:9px;align-items:center}.preparing{margin-top:10px;font-size:13px;color:var(--brand)}
|
|
17
|
+
.review-data{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:8px 14px;margin:16px 0}.review-data dt{color:var(--muted);font-size:13px}.review-data dd{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}.revision{display:block;overflow-wrap:anywhere;background:#f4f6fb;border-radius:8px;padding:10px 12px;font:12px/1.6 ui-monospace,SFMono-Regular,Consolas,monospace}.image-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin:16px 0}figure{margin:0;min-width:0}.image-button{display:block;width:100%;padding:0;border:1px solid var(--line);border-radius:8px;background:#f4f6fb;overflow:hidden}.image-button img{display:block;width:100%;height:180px;object-fit:contain}.image-button:focus-visible{outline-offset:3px}figcaption{font-size:12px;color:var(--muted);padding-top:5px}.confirmation{display:flex;gap:10px;padding:14px 0;border-top:1px solid var(--line);font-size:13px}.confirmation strong{color:#18223b}.public-link{display:inline-block;color:var(--brand);font-weight:600;margin-top:10px;text-underline-offset:3px}.pending{font-size:13px;color:var(--muted);white-space:pre-wrap;margin-top:10px}
|
|
18
|
+
details.preview{grid-column:1/-1;background:#fff;border:1px solid var(--line);border-radius:14px;padding:16px 22px}summary{cursor:pointer;font-weight:600}iframe{display:block;width:100%;height:440px;border:1px solid var(--line);border-radius:8px;background:#111;margin-top:12px}.preview p{font-size:13px;color:var(--muted);margin-top:8px}
|
|
19
|
+
dialog{width:min(1000px,calc(100% - 32px));max-height:94vh;border:1px solid var(--line);border-radius:12px;padding:16px;color:#18223b}dialog::backdrop{background:#152344b3}.viewer-head{display:flex;justify-content:space-between;align-items:center;gap:16px;margin-bottom:12px}dialog img{display:block;width:100%;max-height:78vh;object-fit:contain;background:#f4f6fb}.footer-note{margin-top:22px;color:var(--muted);font-size:12px}
|
|
20
|
+
@media(max-width:800px){main{padding:24px 16px 40px}.layout{grid-template-columns:1fr}.topline{gap:12px}h1{font-size:24px}.card{padding:18px}.steps{gap:5px}.steps li{font-size:12px}.image-button img{height:155px}iframe{height:340px}}
|
|
21
|
+
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important}}
|
|
22
|
+
</style>
|
|
23
|
+
</head>
|
|
24
|
+
<body>
|
|
25
|
+
<main>
|
|
26
|
+
<header class="topline">
|
|
27
|
+
<div><h1>发布到 Craft</h1><p class="intro">先在本机准备和审阅材料,确认后再公开上传图片并提交审核。</p></div>
|
|
28
|
+
<button id="refresh" type="button" class="secondary">刷新进度</button>
|
|
29
|
+
</header>
|
|
30
|
+
<ol class="steps" aria-label="发布步骤">
|
|
31
|
+
<li id="step-edit" class="current">填写资料</li><li id="step-prepare">准备与采集</li><li id="step-review">审阅材料</li><li id="step-submit">提交审核</li>
|
|
32
|
+
</ol>
|
|
33
|
+
<div id="message" class="notice" role="status" aria-live="polite">正在读取本地发布会话…</div>
|
|
34
|
+
<div id="error" class="notice error" role="alert" hidden></div>
|
|
35
|
+
<div class="layout">
|
|
36
|
+
<div class="stack">
|
|
37
|
+
<section class="card" aria-labelledby="context-title">
|
|
38
|
+
<h2 id="context-title">当前游戏</h2><dl id="context" class="context"></dl><span id="status" class="state">尚未准备发布材料</span>
|
|
39
|
+
</section>
|
|
40
|
+
<section class="card" aria-labelledby="form-title">
|
|
41
|
+
<h2 id="form-title">发布资料</h2><p class="section-intro">修改文案或封面后,需要重新准备并确认材料。关闭页面不会自动提交。</p>
|
|
42
|
+
<form id="materials-form">
|
|
43
|
+
<fieldset id="materials-fields" disabled>
|
|
44
|
+
<label class="field" for="game-name"><span>游戏名称</span><input id="game-name" type="text" maxlength="40" required autocomplete="off"><small>最多 40 个字符</small></label>
|
|
45
|
+
<label class="field" for="instructions"><span>简介与操作说明</span><textarea id="instructions" maxlength="8000" required placeholder="介绍玩法、目标和操作方式"></textarea></label>
|
|
46
|
+
<label class="field" for="game-type"><span>游戏分类</span><select id="game-type" required><option value="">请选择分类</option></select></label>
|
|
47
|
+
<fieldset class="tag-group"><legend>美术风格 <small>可不选,最多 12 项</small></legend><div id="art-styles" class="tags"></div></fieldset>
|
|
48
|
+
<fieldset class="tag-group"><legend>玩法标签 <small>可不选,最多 12 项</small></legend><div id="play-tags" class="tags"></div></fieldset>
|
|
49
|
+
<label class="field" for="cover-file"><span>封面图片(可选)</span><input id="cover-file" type="file" accept="image/png,image/jpeg"><small>PNG / JPEG,最大 2 MiB。留空使用本次试玩截图;选图只在本机预览。</small></label>
|
|
50
|
+
<div id="cover-selection" hidden><img id="cover-preview" class="cover-preview" alt="本地封面预览"><div class="cover-actions"><small id="cover-name"></small><button id="clear-cover" type="button" class="quiet">移除封面</button></div></div>
|
|
51
|
+
<p class="privacy-note">此版本仅包含游戏成品,二创保持关闭。准备阶段不会公开上传封面或截图。</p>
|
|
52
|
+
<div class="actions"><button id="prepare" type="submit">准备发布材料</button></div>
|
|
53
|
+
<p id="preparing" class="preparing" hidden></p>
|
|
54
|
+
</fieldset>
|
|
55
|
+
</form>
|
|
56
|
+
</section>
|
|
57
|
+
</div>
|
|
58
|
+
<section class="card" aria-labelledby="review-title">
|
|
59
|
+
<h2 id="review-title">审阅与确认</h2>
|
|
60
|
+
<button id="review" type="button" class="quiet" hidden>重新读取本次材料</button>
|
|
61
|
+
<p id="review-empty" class="section-intro">准备完成后,这里会展示本次文案、封面与全部展示截图。请逐项核对后再提交。</p>
|
|
62
|
+
<div id="material-review" hidden>
|
|
63
|
+
<dl id="review-data" class="review-data"></dl>
|
|
64
|
+
<h3>本次材料版本</h3><code id="revision" class="revision"></code>
|
|
65
|
+
<p id="capture-info" class="help"></p>
|
|
66
|
+
<div id="review-images" class="image-grid"></div>
|
|
67
|
+
<p id="image-status" class="help"></p>
|
|
68
|
+
<label class="confirmation" for="confirm"><input id="confirm" type="checkbox" disabled><span><strong>我已核对本次版本的全部文案、封面和展示截图。</strong>确认将这些图片公开上传并提交审核,二创保持关闭。材料变更后,本确认失效。</span></label>
|
|
69
|
+
<button id="submit" type="button" disabled>确认公开图片并提交审核</button>
|
|
70
|
+
</div>
|
|
71
|
+
<p id="publication-progress" class="pending"></p>
|
|
72
|
+
<a id="public-url" class="public-link" target="_blank" rel="noopener noreferrer" hidden>打开已发布游戏</a>
|
|
73
|
+
</section>
|
|
74
|
+
<details id="runtime" class="preview" hidden>
|
|
75
|
+
<summary>本地试玩(可选)</summary>
|
|
76
|
+
<p>这里运行已检查的本地版本。发布准备仍会自动完成原有的 30 秒试玩采集。</p>
|
|
77
|
+
<iframe id="preview" title="已检查游戏的本地试玩" sandbox="allow-scripts" credentialless referrerpolicy="no-referrer"></iframe>
|
|
78
|
+
</details>
|
|
79
|
+
</div>
|
|
80
|
+
<p class="footer-note">平台凭据由本机 Craft MCP 持有,不会进入本页面。材料已准备或已受理审核,不等于游戏已公开发布。</p>
|
|
81
|
+
</main>
|
|
82
|
+
<dialog id="image-viewer" aria-labelledby="viewer-title"><div class="viewer-head"><h2 id="viewer-title">查看图片</h2><button id="close-viewer" class="secondary" type="button">关闭</button></div><img id="viewer-image" alt="发布材料大图"></dialog>
|
|
83
|
+
<script type="module" nonce="__CSRF__" src="/publication-page.mjs"></script>
|
|
84
|
+
</body>
|
|
85
|
+
</html>
|
|
86
|
+
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
const byId = id => document.getElementById(id);
|
|
2
|
+
const csrf = document.querySelector('meta[name="craft-csrf"]')?.content;
|
|
3
|
+
const cap = /^\/publish\/([A-Za-z0-9_-]{32,128})\/?$/.exec(location.pathname)?.[1];
|
|
4
|
+
const apiBase = cap ? '/api/publish/' + encodeURIComponent(cap) : '';
|
|
5
|
+
const pageAbort = new AbortController();
|
|
6
|
+
const hashPattern = /^[a-f0-9]{64}$/;
|
|
7
|
+
const idPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
8
|
+
const imageLimit = 2 * 1024 * 1024;
|
|
9
|
+
let context, publication, reviewedRevision, busy = false, dirty = false, needsSync = false;
|
|
10
|
+
let disposed = false, formInitialized = false, reviewGeneration = 0, statusTimer;
|
|
11
|
+
let coverData, coverId, coverURL, coverGeneration = 0, coverLoading = false, imagesReady = false;
|
|
12
|
+
const stateNames = { awaiting_confirmation:'等待审阅确认', submitting:'正在提交', submitted:'已提交,等待审核', sharing:'审核中',
|
|
13
|
+
share_repacking:'发布处理中', share_completed:'审核通过', share_failed:'发布未完成', share_delisted:'审核未通过或已下架',
|
|
14
|
+
different_publication:'目标版本存在另一条发布记录', not_submitted:'尚未提交', external_draft:'私有草稿' };
|
|
15
|
+
|
|
16
|
+
function message(text) { byId('message').textContent = text; }
|
|
17
|
+
function showError(error) {
|
|
18
|
+
byId('error').textContent = error instanceof Error ? error.message : String(error);
|
|
19
|
+
byId('error').hidden = false;
|
|
20
|
+
}
|
|
21
|
+
function clearError() { byId('error').textContent = ''; byId('error').hidden = true; }
|
|
22
|
+
function errorText(data) {
|
|
23
|
+
const detail = data && typeof data === 'object' ? data : {};
|
|
24
|
+
return [detail.error || detail.message || '本地请求未完成',
|
|
25
|
+
detail.request_id ? '请求 ID:' + detail.request_id : ''].filter(Boolean).join('\n');
|
|
26
|
+
}
|
|
27
|
+
async function request(route, body, query) {
|
|
28
|
+
const url = new URL(apiBase + '/' + route, location.origin);
|
|
29
|
+
if (query) for (const [key,value] of Object.entries(query)) url.searchParams.set(key,value);
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
response = await fetch(url, { method:body === undefined ? 'GET' : 'POST', credentials:'same-origin',
|
|
33
|
+
redirect:'error', cache:'no-store', headers:{ Accept:'application/json', 'x-craft-csrf':csrf,
|
|
34
|
+
...(body === undefined ? {} : { 'Content-Type':'application/json' }) },
|
|
35
|
+
...(body === undefined ? {} : { body:JSON.stringify(body) }),
|
|
36
|
+
signal:AbortSignal.any([pageAbort.signal,AbortSignal.timeout(30000)]) });
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (disposed) throw error;
|
|
39
|
+
const failure = new Error(body === undefined ? '暂时无法读取进度,请刷新后重试。' :
|
|
40
|
+
'操作响应尚未确认。请先刷新进度恢复原任务,不要重复准备或提交。');
|
|
41
|
+
failure.needsSync = body !== undefined; throw failure;
|
|
42
|
+
}
|
|
43
|
+
const data = await response.json().catch(() => null);
|
|
44
|
+
if (!response.ok || !data || typeof data !== 'object') {
|
|
45
|
+
const error = new Error(errorText(data)); error.httpStatus = response.status;
|
|
46
|
+
error.needsSync = body !== undefined && (!data || typeof data !== 'object' || response.status >= 500); throw error;
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
function delay(ms) { return new Promise(resolve => setTimeout(resolve,ms)); }
|
|
51
|
+
function addPair(list,label,value) {
|
|
52
|
+
const term = document.createElement('dt'), detail = document.createElement('dd');
|
|
53
|
+
term.textContent = label; detail.textContent = value === undefined || value === '' ? '—' : String(value);
|
|
54
|
+
list.append(term,detail);
|
|
55
|
+
}
|
|
56
|
+
function changeStep(current) {
|
|
57
|
+
['edit','prepare','review','submit'].forEach((name,index) => {
|
|
58
|
+
const item = byId('step-' + name);
|
|
59
|
+
item.classList.toggle('current',index === current); item.classList.toggle('done',index < current);
|
|
60
|
+
if (index === current) item.setAttribute('aria-current','step'); else item.removeAttribute('aria-current');
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function isInProgress() { return ['submitting','submitted','sharing','share_repacking'].includes(publication?.state); }
|
|
64
|
+
function isLocked() { return publication?.published === true || isInProgress() || publication?.state === 'different_publication'; }
|
|
65
|
+
function canConfirm() {
|
|
66
|
+
return Boolean(publication && reviewedRevision === publication.revision && imagesReady && !dirty && !needsSync &&
|
|
67
|
+
publication.materials?.open_to_recreate === false &&
|
|
68
|
+
(publication.state === 'awaiting_confirmation' || publication.finalization_retry_required === true));
|
|
69
|
+
}
|
|
70
|
+
function updateControls() {
|
|
71
|
+
byId('refresh').disabled = busy;
|
|
72
|
+
byId('materials-fields').disabled = busy || coverLoading || !context || needsSync || isLocked();
|
|
73
|
+
byId('review').hidden = !publication || dirty || !['awaiting_confirmation'].includes(publication.state) && !publication.finalization_retry_required;
|
|
74
|
+
byId('review').disabled = busy || needsSync;
|
|
75
|
+
byId('confirm').disabled = busy || !canConfirm();
|
|
76
|
+
byId('submit').disabled = busy || !canConfirm() || !byId('confirm').checked;
|
|
77
|
+
byId('submit').textContent = publication?.finalization_retry_required ? '重试已确认的发布' : '确认公开图片并提交审核';
|
|
78
|
+
byId('preparing').hidden = !busy;
|
|
79
|
+
}
|
|
80
|
+
function invalidateReview() {
|
|
81
|
+
dirty = true; reviewedRevision = undefined; imagesReady = false; reviewGeneration++;
|
|
82
|
+
byId('confirm').checked = false; byId('material-review').hidden = true;
|
|
83
|
+
byId('review-empty').hidden = false;
|
|
84
|
+
byId('review-empty').textContent = '资料已修改,请重新准备并审阅。本次修改尚未提交。';
|
|
85
|
+
byId('public-url').hidden = true; updateControls();
|
|
86
|
+
}
|
|
87
|
+
function renderContext() {
|
|
88
|
+
const list = byId('context'); list.replaceChildren();
|
|
89
|
+
addPair(list,'工程',context.name); addPair(list,'引擎',context.engine);
|
|
90
|
+
addPair(list,'账号',context.account?.nickname || context.account?.user_id);
|
|
91
|
+
addPair(list,'平台',context.platform);
|
|
92
|
+
addPair(list,'目标项目',publication?.conversation_id || context.draft?.conversation_id);
|
|
93
|
+
addPair(list,'目标版本',publication?.version_id || context.draft?.version_id);
|
|
94
|
+
}
|
|
95
|
+
function renderTags(id,values,selected = []) {
|
|
96
|
+
const root = byId(id); root.replaceChildren();
|
|
97
|
+
if (!values.length) { const empty = document.createElement('span'); empty.className = 'empty'; empty.textContent = '暂无可选项'; root.append(empty); }
|
|
98
|
+
for (const value of values) {
|
|
99
|
+
const label = document.createElement('label'), input = document.createElement('input'), text = document.createElement('span');
|
|
100
|
+
label.className = 'tag'; input.type = 'checkbox'; input.value = value; input.checked = selected.includes(value);
|
|
101
|
+
text.textContent = value; label.append(input,text); root.append(label);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function fillForm(materials) {
|
|
105
|
+
const input = materials || {};
|
|
106
|
+
byId('game-name').value = input.game_name || Array.from(context.name || '').slice(0,40).join('');
|
|
107
|
+
byId('instructions').value = input.instructions || '';
|
|
108
|
+
const options = context.options || {}, select = byId('game-type');
|
|
109
|
+
select.replaceChildren(new Option('请选择分类',''));
|
|
110
|
+
for (const value of options.game_types || []) select.add(new Option(value,value));
|
|
111
|
+
if (input.game_type && !(options.game_types || []).includes(input.game_type)) select.add(new Option(input.game_type,input.game_type));
|
|
112
|
+
select.value = input.game_type || '';
|
|
113
|
+
renderTags('art-styles',options.art_styles || [],input.art_styles || []);
|
|
114
|
+
renderTags('play-tags',options.play_tags || [],input.play_tags || []);
|
|
115
|
+
formInitialized = true;
|
|
116
|
+
}
|
|
117
|
+
function materialInput() {
|
|
118
|
+
const selected = id => Array.from(byId(id).querySelectorAll('input:checked'),input => input.value);
|
|
119
|
+
const art = selected('art-styles'), tags = selected('play-tags');
|
|
120
|
+
if (art.length > 12 || tags.length > 12) throw new Error('美术风格和玩法标签各最多选择 12 项。');
|
|
121
|
+
return { game_name:byId('game-name').value.trim(), instructions:byId('instructions').value.trim(),
|
|
122
|
+
game_type:byId('game-type').value, art_styles:art, play_tags:tags, open_to_recreate:false, cover_image_source:2 };
|
|
123
|
+
}
|
|
124
|
+
function renderPublicLink() {
|
|
125
|
+
const link = byId('public-url'); link.hidden = true; link.removeAttribute('href');
|
|
126
|
+
if (publication?.published !== true || publication.state !== 'share_completed' || !publication.public_url) return;
|
|
127
|
+
try {
|
|
128
|
+
const url = new URL(publication.public_url), platform = new URL(context.platform);
|
|
129
|
+
if (url.origin !== platform.origin || url.username || url.password ||
|
|
130
|
+
(url.protocol !== 'https:' && !(url.protocol === 'http:' && url.hostname === '127.0.0.1'))) return;
|
|
131
|
+
link.href = url.href; link.hidden = false;
|
|
132
|
+
} catch {}
|
|
133
|
+
}
|
|
134
|
+
function setPublication(value) {
|
|
135
|
+
if (!value || typeof value !== 'object' || !idPattern.test(value.publication_id || '') || !hashPattern.test(value.revision || '') ||
|
|
136
|
+
value.name !== context.name || value.check_task_id !== context.check_task_id) throw new Error('发布回执与当前检查不一致,请返回 WorkBuddy 重新打开发布页面。');
|
|
137
|
+
if (reviewedRevision !== value.revision) { reviewedRevision = undefined; imagesReady = false; byId('confirm').checked = false; }
|
|
138
|
+
publication = value;
|
|
139
|
+
byId('status').textContent = stateNames[value.state] || value.state;
|
|
140
|
+
byId('status').dataset.state = value.state;
|
|
141
|
+
byId('publication-progress').textContent = value.status_reason || (value.published ? '当前目标版本已通过审核。' :
|
|
142
|
+
value.finalization_retry_required ? '审核后的发布收尾尚未完成,可重试同一份已确认材料。' :
|
|
143
|
+
isInProgress() ? '材料已受理,正在查询同一发布记录的审核进度。请保留此页面,不要重复提交。' : '');
|
|
144
|
+
if (value.published) { changeStep(3); message('当前目标版本已通过审核,可以打开已发布游戏。'); }
|
|
145
|
+
else if (isInProgress()) { changeStep(3); message('已提交审核,正在等待当前版本的结果。'); }
|
|
146
|
+
else if (!dirty) changeStep(2);
|
|
147
|
+
renderContext(); renderPublicLink(); updateControls();
|
|
148
|
+
}
|
|
149
|
+
function renderReviewMetadata(value) {
|
|
150
|
+
const labels = { game_name:'游戏名称', instructions:'简介与操作说明', game_type:'游戏分类', art_styles:'美术风格',
|
|
151
|
+
play_tags:'玩法标签', open_to_recreate:'开放二创', cover_image_source:'封面来源' };
|
|
152
|
+
const list = byId('review-data'); list.replaceChildren();
|
|
153
|
+
addPair(list,'项目 ID',value.conversation_id); addPair(list,'版本 ID',value.version_id);
|
|
154
|
+
for (const [key,raw] of Object.entries(value.materials || {})) {
|
|
155
|
+
let text = Array.isArray(raw) ? raw.join('、') || '未选择' : raw;
|
|
156
|
+
if (key === 'open_to_recreate') text = raw === false ? '关闭' : '开启';
|
|
157
|
+
if (key === 'cover_image_source') text = raw === 1 ? 'AI 生成' : '本地封面或试玩截图';
|
|
158
|
+
addPair(list,labels[key] || key,typeof text === 'object' ? JSON.stringify(text) : text);
|
|
159
|
+
}
|
|
160
|
+
byId('revision').textContent = value.revision;
|
|
161
|
+
byId('capture-info').textContent = '实际采集 ' + value.playtest_seconds + ' 秒 · ' +
|
|
162
|
+
value.display_screenshot_count + ' 张展示截图 · ' + value.audit_screenshot_count + ' 张审核抽帧。下方含封面及全部展示截图,点击可看大图。';
|
|
163
|
+
}
|
|
164
|
+
async function reviewPublication(value) {
|
|
165
|
+
const generation = ++reviewGeneration;
|
|
166
|
+
reviewedRevision = undefined; imagesReady = false; byId('confirm').checked = false; updateControls();
|
|
167
|
+
const response = await request('review',{ publication_id:value.publication_id });
|
|
168
|
+
const blocks = response.content;
|
|
169
|
+
if (!Array.isArray(blocks)) throw new Error('本地材料审阅响应不完整。');
|
|
170
|
+
const text = blocks.find(block => block.type === 'text');
|
|
171
|
+
let reviewed; try { reviewed = JSON.parse(text?.text); } catch { throw new Error('无法读取本次材料版本。'); }
|
|
172
|
+
if (generation !== reviewGeneration || disposed) return;
|
|
173
|
+
if (reviewed.publication_id !== value.publication_id || reviewed.revision !== value.revision ||
|
|
174
|
+
reviewed.version_id !== value.version_id || reviewed.materials?.open_to_recreate !== false) throw new Error('审阅材料的目标或版本已变化,请重新准备。');
|
|
175
|
+
const images = blocks.filter(block => block.type === 'image');
|
|
176
|
+
if (!Number.isInteger(reviewed.display_screenshot_count) || reviewed.display_screenshot_count < 1 || reviewed.display_screenshot_count > 5 ||
|
|
177
|
+
images.length !== reviewed.display_screenshot_count + 1) throw new Error('封面或展示截图不完整,请重新准备。');
|
|
178
|
+
const sources = images.map(image => {
|
|
179
|
+
if (!['image/png','image/jpeg'].includes(image.mimeType) || typeof image.data !== 'string' ||
|
|
180
|
+
image.data.length > 4 * Math.ceil(imageLimit / 3) || !/^[A-Za-z0-9+/]+={0,2}$/.test(image.data)) throw new Error('发布图片格式或大小不符合要求。');
|
|
181
|
+
let bytes; try { bytes = atob(image.data).length; } catch { throw new Error('发布图片无法解码。'); }
|
|
182
|
+
if (!bytes || bytes > imageLimit) throw new Error('发布图片大小不符合要求。');
|
|
183
|
+
return 'data:' + image.mimeType + ';base64,' + image.data;
|
|
184
|
+
});
|
|
185
|
+
renderReviewMetadata(reviewed);
|
|
186
|
+
const container = byId('review-images'); container.replaceChildren();
|
|
187
|
+
let loaded = 0;
|
|
188
|
+
sources.forEach((source,index) => {
|
|
189
|
+
const figure = document.createElement('figure'), button = document.createElement('button');
|
|
190
|
+
const image = document.createElement('img'), caption = document.createElement('figcaption');
|
|
191
|
+
const title = index === 0 ? '封面' : '展示截图 ' + index;
|
|
192
|
+
button.type = 'button'; button.className = 'image-button'; button.setAttribute('aria-label','查看' + title + '大图');
|
|
193
|
+
image.alt = title; image.decoding = 'async'; caption.textContent = title;
|
|
194
|
+
image.onload = () => {
|
|
195
|
+
if (generation !== reviewGeneration || disposed) return;
|
|
196
|
+
loaded++; imagesReady = loaded === sources.length;
|
|
197
|
+
byId('image-status').textContent = imagesReady ? '全部图片已显示。请逐项核对上方材料后确认。' : '正在载入图片…';
|
|
198
|
+
updateControls();
|
|
199
|
+
};
|
|
200
|
+
image.onerror = () => {
|
|
201
|
+
if (generation !== reviewGeneration || disposed) return;
|
|
202
|
+
imagesReady = false; reviewedRevision = undefined;
|
|
203
|
+
byId('image-status').textContent = '图片未能完整显示,请刷新后重新审阅。'; updateControls();
|
|
204
|
+
};
|
|
205
|
+
button.onclick = () => {
|
|
206
|
+
byId('viewer-title').textContent = title; byId('viewer-image').src = source;
|
|
207
|
+
byId('image-viewer').showModal();
|
|
208
|
+
};
|
|
209
|
+
image.src = source; button.append(image); figure.append(button,caption); container.append(figure);
|
|
210
|
+
});
|
|
211
|
+
reviewedRevision = value.revision; byId('material-review').dataset.revision = value.revision;
|
|
212
|
+
byId('material-review').dataset.publicationId = value.publication_id; byId('material-review').hidden = false; byId('review-empty').hidden = true;
|
|
213
|
+
byId('image-status').textContent = '正在载入图片…'; changeStep(2); updateControls();
|
|
214
|
+
}
|
|
215
|
+
async function waitForTask(task) {
|
|
216
|
+
const deadline = Date.now() + 15 * 60 * 1000;
|
|
217
|
+
while (task?.status === 'running') {
|
|
218
|
+
if (!idPattern.test(task.task_id || '')) throw new Error('任务标识无效。');
|
|
219
|
+
byId('preparing').textContent = task.kind === 'publish_submit' ? '正在提交当前材料,请稍候…' :
|
|
220
|
+
'正在私有上传并采集真实试玩,通常至少需要 30 秒,请保持本机 MCP 运行。';
|
|
221
|
+
if (Date.now() > deadline) { const error = new Error('任务仍在处理中,请刷新进度恢复原任务。'); error.needsSync = true; throw error; }
|
|
222
|
+
await delay(document.hidden ? 3000 : 1200);
|
|
223
|
+
if (disposed) throw new DOMException('Page closed','AbortError');
|
|
224
|
+
try { task = await request('task',undefined,{ task_id:task.task_id }); }
|
|
225
|
+
catch (error) { error.needsSync = true; throw error; }
|
|
226
|
+
}
|
|
227
|
+
if (task?.status !== 'completed' || !task.result) throw new Error(errorText(task?.error || { error:'任务已中断,请刷新查看原记录。' }));
|
|
228
|
+
return task.result;
|
|
229
|
+
}
|
|
230
|
+
function configureRuntime(value) {
|
|
231
|
+
const details = byId('runtime'), frame = byId('preview');
|
|
232
|
+
try {
|
|
233
|
+
const url = new URL(value);
|
|
234
|
+
if (url.protocol !== 'http:' || url.hostname !== '127.0.0.1' || url.origin === location.origin || url.username || url.password) throw new Error();
|
|
235
|
+
details.hidden = false;
|
|
236
|
+
details.ontoggle = () => { if (details.open && !frame.src) frame.src = url.href; };
|
|
237
|
+
} catch { details.hidden = true; frame.removeAttribute('src'); }
|
|
238
|
+
}
|
|
239
|
+
async function loadState() {
|
|
240
|
+
const state = await request('state');
|
|
241
|
+
if (!state.name || !idPattern.test(state.check_task_id || '') || !state.account?.user_id) throw new Error('本地发布会话无效,请从 WorkBuddy 重新打开。');
|
|
242
|
+
context = state; needsSync = false; renderContext(); configureRuntime(state.runtime_url);
|
|
243
|
+
if (!formInitialized) fillForm(state.publication?.materials);
|
|
244
|
+
if (state.publication) setPublication(state.publication);
|
|
245
|
+
if (state.task_id) {
|
|
246
|
+
const task = await request('task',undefined,{ task_id:state.task_id });
|
|
247
|
+
if (task.status === 'running') { changeStep(1); message('正在恢复原发布任务…'); }
|
|
248
|
+
if (task.status === 'running' || task.status === 'completed' && !state.publication) {
|
|
249
|
+
const result = await waitForTask(task);
|
|
250
|
+
setPublication(await request('status',undefined,{ publication_id:result.publication_id }));
|
|
251
|
+
if (!dirty) fillForm(publication.materials);
|
|
252
|
+
} else if (task.status !== 'completed' && !state.publication) throw new Error(errorText(task.error || { error:'原任务已中断,请回 WorkBuddy 查看。' }));
|
|
253
|
+
}
|
|
254
|
+
if (publication && !dirty && (publication.state === 'awaiting_confirmation' || publication.finalization_retry_required)) {
|
|
255
|
+
await reviewPublication(publication); message('材料已准备。请核对文案、封面和全部展示截图,再确认公开提交。');
|
|
256
|
+
} else if (!publication) { changeStep(0); message('填写资料后准备材料。封面和采集结果会先保存在本机。'); }
|
|
257
|
+
scheduleStatus(); updateControls();
|
|
258
|
+
}
|
|
259
|
+
function scheduleStatus() {
|
|
260
|
+
clearTimeout(statusTimer);
|
|
261
|
+
if (disposed || !publication || !isInProgress()) return;
|
|
262
|
+
statusTimer = setTimeout(async () => {
|
|
263
|
+
if (busy) { scheduleStatus(); return; }
|
|
264
|
+
try {
|
|
265
|
+
const id = publication.publication_id;
|
|
266
|
+
const latest = await request('status',undefined,{ publication_id:id });
|
|
267
|
+
if (!busy && !disposed && publication?.publication_id === id) setPublication(latest);
|
|
268
|
+
scheduleStatus();
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (busy || disposed) { scheduleStatus(); return; }
|
|
271
|
+
showError(error);
|
|
272
|
+
if (![403,404].includes(error.httpStatus)) statusTimer = setTimeout(scheduleStatus,5000);
|
|
273
|
+
else { needsSync = true; updateControls(); }
|
|
274
|
+
}
|
|
275
|
+
},3000);
|
|
276
|
+
}
|
|
277
|
+
async function perform(action) {
|
|
278
|
+
if (busy || disposed) return;
|
|
279
|
+
busy = true; clearTimeout(statusTimer); clearError(); updateControls();
|
|
280
|
+
try { await action(); }
|
|
281
|
+
catch (error) { if (!disposed) { if (error.needsSync) needsSync = true; showError(error); } }
|
|
282
|
+
finally { busy = false; updateControls(); scheduleStatus(); }
|
|
283
|
+
}
|
|
284
|
+
function clearCover(resetInput = true) {
|
|
285
|
+
coverGeneration++; if (coverURL) URL.revokeObjectURL(coverURL);
|
|
286
|
+
coverData = undefined; coverId = undefined; coverURL = undefined; coverLoading = false;
|
|
287
|
+
if (resetInput) byId('cover-file').value = '';
|
|
288
|
+
byId('cover-preview').removeAttribute('src'); byId('cover-selection').hidden = true;
|
|
289
|
+
}
|
|
290
|
+
byId('materials-form').addEventListener('input',event => { if (event.target.id !== 'cover-file') invalidateReview(); });
|
|
291
|
+
byId('cover-file').addEventListener('change',async () => {
|
|
292
|
+
const file = byId('cover-file').files?.[0]; clearError(); clearCover(false); invalidateReview();
|
|
293
|
+
if (!file) return;
|
|
294
|
+
const generation = coverGeneration; coverLoading = true; updateControls();
|
|
295
|
+
try {
|
|
296
|
+
if (!file.size || file.size > imageLimit) throw new Error('封面必须是最大 2 MiB 的 PNG 或 JPEG。');
|
|
297
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
298
|
+
if (generation !== coverGeneration || disposed) return;
|
|
299
|
+
const png = [137,80,78,71,13,10,26,10].every((value,index) => bytes[index] === value);
|
|
300
|
+
const jpg = bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
|
|
301
|
+
if (!png && !jpg) throw new Error('请选择有效的 PNG 或 JPEG 图片。');
|
|
302
|
+
let binary = ''; for (let offset = 0; offset < bytes.length; offset += 32768) binary += String.fromCharCode(...bytes.subarray(offset,offset + 32768));
|
|
303
|
+
coverData = btoa(binary); coverURL = URL.createObjectURL(file);
|
|
304
|
+
byId('cover-preview').src = coverURL; byId('cover-name').textContent = file.name; byId('cover-selection').hidden = false;
|
|
305
|
+
} catch (error) { if (generation === coverGeneration) { clearCover(); showError(error); } }
|
|
306
|
+
finally { if (generation === coverGeneration) coverLoading = false; updateControls(); }
|
|
307
|
+
});
|
|
308
|
+
byId('clear-cover').onclick = () => { clearCover(); invalidateReview(); };
|
|
309
|
+
byId('materials-form').onsubmit = event => {
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
if (coverLoading || !byId('materials-form').reportValidity()) return;
|
|
312
|
+
void perform(async () => {
|
|
313
|
+
const materials = materialInput();
|
|
314
|
+
reviewedRevision = undefined; imagesReady = false; byId('confirm').checked = false;
|
|
315
|
+
changeStep(1); message('正在准备本地材料与真实试玩采集,尚未公开上传图片。');
|
|
316
|
+
if (coverData && !coverId) coverId = (await request('cover',{ data:coverData })).cover_id;
|
|
317
|
+
if (coverData && !idPattern.test(coverId || '')) throw new Error('封面暂存回执无效。');
|
|
318
|
+
const task = await request('prepare',{ materials,...(coverId ? { cover_id:coverId } : {}) });
|
|
319
|
+
const result = await waitForTask(task); dirty = false; setPublication(result);
|
|
320
|
+
await reviewPublication(result); message('材料已准备。请逐项审阅,并确认将图片公开上传后提交审核。');
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
byId('review').onclick = () => {
|
|
324
|
+
if (!publication || dirty || needsSync) return;
|
|
325
|
+
void perform(() => reviewPublication(publication));
|
|
326
|
+
};
|
|
327
|
+
byId('confirm').onchange = updateControls;
|
|
328
|
+
byId('submit').onclick = () => {
|
|
329
|
+
if (!canConfirm() || !byId('confirm').checked) return;
|
|
330
|
+
const approved = { publication_id:publication.publication_id,revision:reviewedRevision,confirmed:true };
|
|
331
|
+
void perform(async () => {
|
|
332
|
+
if (!canConfirm() || approved.revision !== publication.revision) throw new Error('材料已变化,请重新准备并审阅。');
|
|
333
|
+
byId('confirm').checked = false;
|
|
334
|
+
message('正在公开上传已确认的图片并提交当前版本审核…'); changeStep(3);
|
|
335
|
+
const result = await waitForTask(await request('submit',approved)); setPublication(result); scheduleStatus();
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
byId('refresh').onclick = () => void perform(loadState);
|
|
339
|
+
byId('close-viewer').onclick = () => byId('image-viewer').close();
|
|
340
|
+
window.addEventListener('pagehide',() => {
|
|
341
|
+
disposed = true; clearTimeout(statusTimer); pageAbort.abort(); if (coverURL) URL.revokeObjectURL(coverURL);
|
|
342
|
+
byId('preview').removeAttribute('src');
|
|
343
|
+
},{ once:true });
|
|
344
|
+
if (!cap || !csrf || csrf === '__CSRF__') {
|
|
345
|
+
needsSync = true; showError(new Error('发布页面已失效,请从 WorkBuddy 重新打开。')); updateControls();
|
|
346
|
+
} else void perform(loadState);
|
|
347
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { checkedDraftFiles } from '../game-workflow/draft-archive.mjs';
|
|
4
|
+
|
|
5
|
+
// Game scripts run on a separate sandboxed origin and only see this frozen file map.
|
|
6
|
+
export async function openPublicationPreview(check, evidence, signal = new AbortController().signal) {
|
|
7
|
+
if (check?.kind !== 'check' || check.status !== 'completed' || !check.result?.gate?.passed) {
|
|
8
|
+
throw new Error('A passing frozen check is required for publication preview');
|
|
9
|
+
}
|
|
10
|
+
const files = await checkedDraftFiles(evidence, check.result.snapshot_id, check.result.artifacts, signal);
|
|
11
|
+
signal.throwIfAborted();
|
|
12
|
+
const prefix = '/runtime/' + randomBytes(32).toString('hex') + '/';
|
|
13
|
+
let port;
|
|
14
|
+
const server = http.createServer((req, res) => {
|
|
15
|
+
const origin = `http://127.0.0.1:${port}`;
|
|
16
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
17
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
18
|
+
res.setHeader('Referrer-Policy', 'no-referrer');
|
|
19
|
+
if (req.headers.host !== `127.0.0.1:${port}` ||
|
|
20
|
+
(req.headers.origin && ![origin, 'null'].includes(req.headers.origin))) {
|
|
21
|
+
req.resume(); res.writeHead(403).end(); return;
|
|
22
|
+
}
|
|
23
|
+
if (!['GET', 'HEAD'].includes(req.method)) { req.resume(); res.writeHead(405).end(); return; }
|
|
24
|
+
let pathname;
|
|
25
|
+
try { pathname = decodeURIComponent(new URL(req.url, origin).pathname); }
|
|
26
|
+
catch { res.writeHead(400).end(); return; }
|
|
27
|
+
if (!pathname.startsWith(prefix)) { res.writeHead(404).end(); return; }
|
|
28
|
+
const entry = files.get('/' + pathname.slice(prefix.length));
|
|
29
|
+
if (!entry) { res.writeHead(404).end(); return; }
|
|
30
|
+
const source = origin + prefix;
|
|
31
|
+
res.writeHead(200, {
|
|
32
|
+
'Content-Type': entry.type,
|
|
33
|
+
'Content-Length': entry.data.length,
|
|
34
|
+
'Access-Control-Allow-Origin': 'null',
|
|
35
|
+
'Cross-Origin-Resource-Policy': 'cross-origin',
|
|
36
|
+
'Content-Security-Policy': `sandbox allow-scripts; default-src 'none'; base-uri 'none'; form-action 'none'; script-src ${source} 'unsafe-inline' 'wasm-unsafe-eval'; style-src ${source} 'unsafe-inline'; connect-src ${source}; img-src ${source} data: blob:; media-src ${source} blob:; font-src ${source} data:; worker-src blob:`,
|
|
37
|
+
});
|
|
38
|
+
res.end(req.method === 'HEAD' ? undefined : entry.data);
|
|
39
|
+
});
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
server.once('error', reject); server.listen(0, '127.0.0.1', resolve);
|
|
42
|
+
});
|
|
43
|
+
port = server.address().port;
|
|
44
|
+
let closing;
|
|
45
|
+
const close = () => closing ??= new Promise((resolve, reject) => {
|
|
46
|
+
server.closeAllConnections(); server.close(error => error ? reject(error) : resolve());
|
|
47
|
+
});
|
|
48
|
+
return { url: `http://127.0.0.1:${port}${prefix}index.html`, close };
|
|
49
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export function publicationTools(nameField, tool) {
|
|
2
2
|
const publication = { ...nameField,publication_id:{ type:'string',description:'The durable publication_id returned by preparation. Reuse it after interruption.' } };
|
|
3
3
|
return [
|
|
4
|
+
tool('craft_game_publish_open','Open an independent local publication page for this passing checked build. Preview the frozen game, edit materials and explicitly confirm the exact reviewed revision before submission. Requires no desktop client. Opening does not submit review. To resume, supply its existing publication_id.',{
|
|
5
|
+
...nameField,check_task_id:{ type:'string' },publication_id:{ type:'string' },
|
|
6
|
+
},['name','check_task_id']),
|
|
4
7
|
tool('craft_game_publish_options','Read the current platform publication category dictionary. Use these game_types/art_styles/play_tags when preparing materials. Public submission requires the platform publication feature and ACE configuration.',{}),
|
|
5
|
-
tool('craft_game_publish_prepare','Prepare materials for a previously uploaded passing check when the user requests public publication. WorkBuddy writes the metadata; Craft captures a real 30-second playtest of the same frozen build. Poll craft_task_status, then call craft_game_publish_review. This does not upload publication images or submit review.',{
|
|
8
|
+
tool('craft_game_publish_prepare','Compatibility headless entry; prefer craft_game_publish_open for the independent local publication page. Prepare materials for a previously uploaded passing check when the user requests public publication. WorkBuddy writes the metadata; Craft captures a real 30-second playtest of the same frozen build. Poll craft_task_status, then call craft_game_publish_review. This does not upload publication images or submit review.',{
|
|
6
9
|
...nameField,check_task_id:{ type:'string' },materials:{ type:'object',additionalProperties:false,properties:{
|
|
7
10
|
game_name:{ type:'string',maxLength:40 },instructions:{ type:'string',maxLength:8000 },game_type:{ type:'string' },
|
|
8
11
|
art_styles:{ type:'array',items:{ type:'string' },maxItems:12 },play_tags:{ type:'array',items:{ type:'string' },maxItems:12 },
|