@biunow/agent-biutalk 1.1.1 → 1.1.3
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/bin/server.js +2 -0
- package/lib/host.mjs +86 -2
- package/manifest.json +3 -3
- package/package.json +1 -1
- package/studio/app.js +30 -3
- package/studio/composer.css +53 -3
- package/studio/composer.js +147 -9
package/bin/server.js
CHANGED
package/lib/host.mjs
CHANGED
|
@@ -45,6 +45,36 @@ export function writeJson(file, data) {
|
|
|
45
45
|
fs.writeFileSync(file, JSON.stringify(data, null, 2));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/** 旧任务只存了短标题时,从工程 brief 补回完整需求,方便点选回填。 */
|
|
49
|
+
function fillFromBrief(job) {
|
|
50
|
+
if (!job || job.prompt || job.brief) return job;
|
|
51
|
+
const dirs = [];
|
|
52
|
+
if (job.projectPath) dirs.push(job.projectPath);
|
|
53
|
+
const artifact = String(job.artifact || '');
|
|
54
|
+
if (artifact && !artifact.toLowerCase().endsWith('.mp4')) dirs.push(artifact);
|
|
55
|
+
for (const dir of dirs) {
|
|
56
|
+
const data = readJson(path.join(dir, 'brief.json'), null);
|
|
57
|
+
if (!data || typeof data !== 'object') continue;
|
|
58
|
+
const prompt = String(data.prompt || data.brief || '').trim();
|
|
59
|
+
if (!prompt) continue;
|
|
60
|
+
job.prompt = prompt;
|
|
61
|
+
if (job.look == null && data.look != null) job.look = data.look;
|
|
62
|
+
if (!job.size && data.size) job.size = data.size;
|
|
63
|
+
if (job.pace == null && data.pace != null) job.pace = data.pace;
|
|
64
|
+
if (!job.style && data.style) job.style = data.style;
|
|
65
|
+
if (!job.styleName && data.styleName) job.styleName = data.styleName;
|
|
66
|
+
if (job.storyboard == null && typeof data.storyboard === 'boolean') job.storyboard = data.storyboard;
|
|
67
|
+
if (!('durationSec' in job) && (data.durationSec != null || data.durationMode === 'auto')) {
|
|
68
|
+
job.durationSec = data.durationSec ?? null;
|
|
69
|
+
}
|
|
70
|
+
if (!job.screen && data.screen) job.screen = data.screen;
|
|
71
|
+
if (!job.styleId && data.styleId) job.styleId = data.styleId;
|
|
72
|
+
if (!job.urls && Array.isArray(data.urls)) job.urls = data.urls;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return job;
|
|
76
|
+
}
|
|
77
|
+
|
|
48
78
|
export function sendJson(res, status, body) {
|
|
49
79
|
const data = JSON.stringify(body);
|
|
50
80
|
res.writeHead(status, {
|
|
@@ -110,6 +140,51 @@ export function serveStatic(res, file) {
|
|
|
110
140
|
fs.createReadStream(file).pipe(res);
|
|
111
141
|
}
|
|
112
142
|
|
|
143
|
+
/** 把本机成片按 Range 流给浏览器,播放器才能拖动进度。 */
|
|
144
|
+
export function serveLocalFile(req, res, file) {
|
|
145
|
+
if (!file || !fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
|
146
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8', 'access-control-allow-origin': '*' });
|
|
147
|
+
res.end('not found');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const size = fs.statSync(file).size;
|
|
151
|
+
const type = mime(file);
|
|
152
|
+
const common = {
|
|
153
|
+
'content-type': type,
|
|
154
|
+
'accept-ranges': 'bytes',
|
|
155
|
+
'cache-control': 'no-store',
|
|
156
|
+
'access-control-allow-origin': '*',
|
|
157
|
+
};
|
|
158
|
+
const range = String(req.headers.range || '');
|
|
159
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(range);
|
|
160
|
+
if (match) {
|
|
161
|
+
const hasStart = match[1] !== '';
|
|
162
|
+
const hasEnd = match[2] !== '';
|
|
163
|
+
let start = hasStart ? Number(match[1]) : 0;
|
|
164
|
+
let end = hasEnd ? Number(match[2]) : size - 1;
|
|
165
|
+
if (!hasStart && hasEnd) {
|
|
166
|
+
const suffix = Number(match[2]);
|
|
167
|
+
start = Number.isFinite(suffix) && suffix > 0 ? Math.max(0, size - suffix) : size;
|
|
168
|
+
end = size - 1;
|
|
169
|
+
}
|
|
170
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || start >= size || end < start) {
|
|
171
|
+
res.writeHead(416, { ...common, 'content-range': `bytes */${size}` });
|
|
172
|
+
res.end();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
end = Math.min(end, size - 1);
|
|
176
|
+
res.writeHead(206, {
|
|
177
|
+
...common,
|
|
178
|
+
'content-length': end - start + 1,
|
|
179
|
+
'content-range': `bytes ${start}-${end}/${size}`,
|
|
180
|
+
});
|
|
181
|
+
fs.createReadStream(file, { start, end }).pipe(res);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
res.writeHead(200, { ...common, 'content-length': size });
|
|
185
|
+
fs.createReadStream(file).pipe(res);
|
|
186
|
+
}
|
|
187
|
+
|
|
113
188
|
export class JobStore {
|
|
114
189
|
constructor(workspace) {
|
|
115
190
|
this.dir = ensureDir(path.join(workspace, 'jobs'));
|
|
@@ -444,11 +519,20 @@ export function createAgentServer({ root, studioDir, api }) {
|
|
|
444
519
|
});
|
|
445
520
|
}
|
|
446
521
|
|
|
447
|
-
if (pathname === '/api/jobs' && req.method === 'GET')
|
|
522
|
+
if (pathname === '/api/jobs' && req.method === 'GET') {
|
|
523
|
+
return sendJson(res, 200, { jobs: jobs.list().map(fillFromBrief) });
|
|
524
|
+
}
|
|
525
|
+
if (req.method === 'GET' && /^\/api\/jobs\/[^/]+\/film$/.test(pathname)) {
|
|
526
|
+
const id = decodeURIComponent(pathname.slice('/api/jobs/'.length, -'/film'.length));
|
|
527
|
+
const job = jobs.get(id);
|
|
528
|
+
const file = job ? String(job.outputMp4 || '') : '';
|
|
529
|
+
if (!file || !file.toLowerCase().endsWith('.mp4')) return sendJson(res, 404, { error: '成片还没有' });
|
|
530
|
+
return serveLocalFile(req, res, file);
|
|
531
|
+
}
|
|
448
532
|
if (pathname.startsWith('/api/jobs/') && req.method === 'GET') {
|
|
449
533
|
const job = jobs.get(pathname.slice('/api/jobs/'.length));
|
|
450
534
|
if (!job) return sendJson(res, 404, { error: 'job not found' });
|
|
451
|
-
return sendJson(res, 200, { job });
|
|
535
|
+
return sendJson(res, 200, { job: fillFromBrief(job) });
|
|
452
536
|
}
|
|
453
537
|
if (pathname.startsWith('/api/jobs/') && req.method === 'DELETE') {
|
|
454
538
|
const id = pathname.slice('/api/jobs/'.length);
|
package/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "biutalk",
|
|
4
4
|
"name": "BiuTalk",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.3",
|
|
6
6
|
"publisher": "Biunow",
|
|
7
7
|
"description": "BiuTalk 解说视频 Studio:模板、尺寸、附件与本地渲染引擎。",
|
|
8
8
|
"entry": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"requiresEntitlement": "export"
|
|
48
48
|
},
|
|
49
49
|
"integrity": {
|
|
50
|
-
"sha256": "
|
|
51
|
-
"signature": "
|
|
50
|
+
"sha256": "f0522a456028f5ff10473092a3d8f0a7ab3f978c0751e775912be8eae395a01d",
|
|
51
|
+
"signature": "+Sausjf8RQEhGqmvLVprLTu+5mXZaX3RfmRQA/ZBrCiGszlWNPT2m2s/mfuJHc3wHpztVSWcAjHQPyWTkRuSAw==",
|
|
52
52
|
"signedBy": "publisher-key"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/package.json
CHANGED
package/studio/app.js
CHANGED
|
@@ -70,9 +70,36 @@
|
|
|
70
70
|
renderAssets();
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
let sizeMenu = null;
|
|
74
|
+
let lookMenu = null;
|
|
75
|
+
|
|
76
|
+
function fillJob(job) {
|
|
77
|
+
const text = String(job.prompt || job.brief || (job.kind === 'create' ? job.title : '') || '').trim();
|
|
78
|
+
if (text) {
|
|
79
|
+
$('prompt').value = text;
|
|
80
|
+
$('prompt').dispatchEvent(new Event('input'));
|
|
81
|
+
}
|
|
82
|
+
if (job.size && sizeMenu) {
|
|
83
|
+
state.size = job.size;
|
|
84
|
+
sizeMenu.setValue(job.size, true);
|
|
85
|
+
}
|
|
86
|
+
if (typeof job.look === 'string' && lookMenu) {
|
|
87
|
+
state.look = job.look;
|
|
88
|
+
lookMenu.setValue(job.look, true);
|
|
89
|
+
}
|
|
90
|
+
if (job.pace != null && Number.isFinite(Number(job.pace))) {
|
|
91
|
+
state.pace = Number(job.pace);
|
|
92
|
+
syncPaceHint();
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(job.urls)) {
|
|
95
|
+
state.urls = job.urls.slice();
|
|
96
|
+
renderAssets();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
73
100
|
async function refreshJobs() {
|
|
74
101
|
const { jobs } = await api('/api/jobs');
|
|
75
|
-
renderJobs($('jobs'), jobs);
|
|
102
|
+
renderJobs($('jobs'), jobs, { onPick: fillJob });
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
$('linkInput').addEventListener('input', () => {
|
|
@@ -170,7 +197,7 @@
|
|
|
170
197
|
addChip(chips, state.meta.canExport ? '已授权导出' : '未授权 / 只读', state.meta.canExport ? '' : 'bad');
|
|
171
198
|
addChip(chips, state.meta.enginePresent ? '引擎已连接' : '引擎未连接', state.meta.enginePresent ? '' : 'warn');
|
|
172
199
|
|
|
173
|
-
SelectMenu.mount($('sizePick'), {
|
|
200
|
+
sizeMenu = SelectMenu.mount($('sizePick'), {
|
|
174
201
|
value: state.size,
|
|
175
202
|
options: (state.meta.sizes || []).map((s) => ({
|
|
176
203
|
value: s.id,
|
|
@@ -184,7 +211,7 @@
|
|
|
184
211
|
},
|
|
185
212
|
});
|
|
186
213
|
|
|
187
|
-
SelectMenu.mount($('lookPick'), {
|
|
214
|
+
lookMenu = SelectMenu.mount($('lookPick'), {
|
|
188
215
|
value: state.look,
|
|
189
216
|
options: (state.meta.looks || []).map((l) => ({
|
|
190
217
|
value: l.id,
|
package/studio/composer.css
CHANGED
|
@@ -214,13 +214,23 @@ button:disabled { cursor: not-allowed; opacity: .5; }
|
|
|
214
214
|
.jobs { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow: auto; }
|
|
215
215
|
.job {
|
|
216
216
|
border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff;
|
|
217
|
+
cursor: pointer;
|
|
217
218
|
}
|
|
219
|
+
.job:hover { border-color: #c8c8c2; }
|
|
218
220
|
.job.run { border-left: 3px solid var(--accent-deep); }
|
|
219
221
|
.job.ok { border-left: 3px solid var(--success); }
|
|
220
222
|
.job.bad { border-left: 3px solid var(--danger); }
|
|
221
223
|
.job.warn { border-left: 3px solid var(--warn); }
|
|
222
|
-
.job-
|
|
223
|
-
.job
|
|
224
|
+
.job-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
225
|
+
.job-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
|
|
226
|
+
.job-chip {
|
|
227
|
+
min-width: 0; font-size: 10px; color: var(--muted);
|
|
228
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
229
|
+
}
|
|
230
|
+
.job .t {
|
|
231
|
+
margin-top: 6px; font-weight: 600; font-size: 12px; line-height: 1.45;
|
|
232
|
+
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
|
233
|
+
}
|
|
224
234
|
.job-del {
|
|
225
235
|
flex: none; width: 22px; height: 22px; border-radius: 7px; border: 1px solid transparent;
|
|
226
236
|
background: transparent; color: var(--muted-2); font-size: 16px; line-height: 1;
|
|
@@ -240,7 +250,10 @@ button:disabled { cursor: not-allowed; opacity: .5; }
|
|
|
240
250
|
.job .badge.run { background: var(--accent-soft); color: var(--ink); }
|
|
241
251
|
.job .badge.ok { background: rgba(47,107,79,.12); color: var(--success); }
|
|
242
252
|
.job .badge.bad { background: #f7dcd7; color: var(--danger); }
|
|
243
|
-
.job .m {
|
|
253
|
+
.job .m {
|
|
254
|
+
color: var(--muted); font-size: 11px; margin-top: 4px;
|
|
255
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
256
|
+
}
|
|
244
257
|
.job .result {
|
|
245
258
|
margin-top: 6px; display: flex; gap: 6px; align-items: flex-start; min-width: 0;
|
|
246
259
|
}
|
|
@@ -253,6 +266,43 @@ button:disabled { cursor: not-allowed; opacity: .5; }
|
|
|
253
266
|
.bar { height: 4px; background: #ececea; border-radius: 99px; overflow: hidden; margin-top: 8px; }
|
|
254
267
|
.bar i { display: block; height: 100%; background: var(--accent-deep); width: 0; }
|
|
255
268
|
.muted { color: var(--muted); font-size: 12px; }
|
|
269
|
+
.film-stage {
|
|
270
|
+
margin: 0 0 12px; border: 1px solid var(--line); border-radius: 12px;
|
|
271
|
+
overflow: hidden; background: #111;
|
|
272
|
+
}
|
|
273
|
+
.film-stage[hidden] { display: none; }
|
|
274
|
+
.film-video { display: block; width: 100%; max-height: 220px; background: #000; }
|
|
275
|
+
.film-bar {
|
|
276
|
+
display: flex; align-items: center; gap: 8px;
|
|
277
|
+
padding: 8px 10px; background: #fff;
|
|
278
|
+
}
|
|
279
|
+
.film-title {
|
|
280
|
+
flex: 1; min-width: 0; font-size: 12px; font-weight: 600;
|
|
281
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
282
|
+
}
|
|
283
|
+
.film-pop {
|
|
284
|
+
flex: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
|
|
285
|
+
border-radius: 999px; font: inherit; font-size: 11px; padding: 3px 10px; cursor: pointer;
|
|
286
|
+
}
|
|
287
|
+
.film-pop:hover { background: var(--accent-soft); }
|
|
288
|
+
.job.playable { cursor: pointer; }
|
|
289
|
+
.job.on { outline: 2px solid var(--accent-deep); outline-offset: 1px; }
|
|
290
|
+
.film-modal {
|
|
291
|
+
position: fixed; inset: 0; z-index: 80; background: rgba(10,10,10,.72);
|
|
292
|
+
display: grid; place-items: center; padding: 24px;
|
|
293
|
+
}
|
|
294
|
+
.film-modal[hidden] { display: none; }
|
|
295
|
+
.film-modal-card { width: min(960px, 100%); background: #111; border-radius: 16px; overflow: hidden; }
|
|
296
|
+
.film-modal-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #f4f1ea; }
|
|
297
|
+
.film-modal-bar strong {
|
|
298
|
+
flex: 1; min-width: 0; font-size: 13px; font-weight: 600;
|
|
299
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
300
|
+
}
|
|
301
|
+
.film-modal-x {
|
|
302
|
+
width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent;
|
|
303
|
+
color: #f4f1ea; font-size: 20px; line-height: 1; cursor: pointer;
|
|
304
|
+
}
|
|
305
|
+
.film-modal video { display: block; width: 100%; max-height: min(72vh, 640px); background: #000; }
|
|
256
306
|
|
|
257
307
|
/* SelectMenu */
|
|
258
308
|
.sm { position: relative; display: block; min-width: 0; }
|
package/studio/composer.js
CHANGED
|
@@ -83,8 +83,125 @@
|
|
|
83
83
|
sync();
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
let filmSelectedId = '';
|
|
87
|
+
let selectedJobId = '';
|
|
88
|
+
|
|
89
|
+
function filmSrc(id) {
|
|
90
|
+
return '/api/jobs/' + encodeURIComponent(id) + '/film';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function ensureFilmModal() {
|
|
94
|
+
let back = document.querySelector('.film-modal');
|
|
95
|
+
if (back) return back;
|
|
96
|
+
back = document.createElement('div');
|
|
97
|
+
back.className = 'film-modal';
|
|
98
|
+
back.hidden = true;
|
|
99
|
+
back.innerHTML = `
|
|
100
|
+
<div class="film-modal-card" role="dialog" aria-modal="true">
|
|
101
|
+
<div class="film-modal-bar">
|
|
102
|
+
<strong></strong>
|
|
103
|
+
<button type="button" class="film-modal-x" aria-label="关闭">×</button>
|
|
104
|
+
</div>
|
|
105
|
+
<video controls playsinline></video>
|
|
106
|
+
</div>`;
|
|
107
|
+
document.body.appendChild(back);
|
|
108
|
+
const close = () => {
|
|
109
|
+
const video = back.querySelector('video');
|
|
110
|
+
video.pause();
|
|
111
|
+
video.removeAttribute('src');
|
|
112
|
+
video.load();
|
|
113
|
+
back.hidden = true;
|
|
114
|
+
};
|
|
115
|
+
back.querySelector('.film-modal-x').addEventListener('click', close);
|
|
116
|
+
back.addEventListener('click', (e) => {
|
|
117
|
+
if (e.target === back) close();
|
|
118
|
+
});
|
|
119
|
+
document.addEventListener('keydown', (e) => {
|
|
120
|
+
if (e.key === 'Escape' && !back.hidden) close();
|
|
121
|
+
});
|
|
122
|
+
return back;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function openFilmModal(src, title, inlineVideo) {
|
|
126
|
+
const back = ensureFilmModal();
|
|
127
|
+
const video = back.querySelector('video');
|
|
128
|
+
back.querySelector('strong').textContent = title || '成片';
|
|
129
|
+
const startAt = inlineVideo && inlineVideo.dataset.src === src ? inlineVideo.currentTime || 0 : 0;
|
|
130
|
+
if (inlineVideo) inlineVideo.pause();
|
|
131
|
+
back.hidden = false;
|
|
132
|
+
let started = false;
|
|
133
|
+
const start = () => {
|
|
134
|
+
if (started) return;
|
|
135
|
+
started = true;
|
|
136
|
+
video.removeEventListener('loadedmetadata', start);
|
|
137
|
+
if (startAt > 0) {
|
|
138
|
+
try { video.currentTime = startAt; } catch { /* 还没解析出时长 */ }
|
|
139
|
+
}
|
|
140
|
+
video.play().catch(() => {});
|
|
141
|
+
};
|
|
142
|
+
const changed = video.dataset.src !== src;
|
|
143
|
+
video.addEventListener('loadedmetadata', start);
|
|
144
|
+
if (changed) {
|
|
145
|
+
video.dataset.src = src;
|
|
146
|
+
video.src = src;
|
|
147
|
+
} else if (video.readyState >= 1) {
|
|
148
|
+
start();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function ensureFilmStage(box) {
|
|
153
|
+
const parent = box.parentElement;
|
|
154
|
+
if (!parent) return null;
|
|
155
|
+
let stage = parent.querySelector(':scope > .film-stage');
|
|
156
|
+
if (stage) return stage;
|
|
157
|
+
stage = document.createElement('div');
|
|
158
|
+
stage.className = 'film-stage';
|
|
159
|
+
stage.hidden = true;
|
|
160
|
+
stage.innerHTML = `
|
|
161
|
+
<video class="film-video" controls playsinline preload="metadata"></video>
|
|
162
|
+
<div class="film-bar">
|
|
163
|
+
<span class="film-title"></span>
|
|
164
|
+
<button type="button" class="film-pop">弹窗播放</button>
|
|
165
|
+
</div>`;
|
|
166
|
+
parent.insertBefore(stage, box);
|
|
167
|
+
stage.querySelector('.film-pop').addEventListener('click', () => {
|
|
168
|
+
const video = stage.querySelector('video');
|
|
169
|
+
if (!video.dataset.src) return;
|
|
170
|
+
openFilmModal(video.dataset.src, stage.dataset.title || '', video);
|
|
171
|
+
});
|
|
172
|
+
return stage;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function showFilm(box, job, opts) {
|
|
176
|
+
const stage = ensureFilmStage(box);
|
|
177
|
+
if (!stage) return;
|
|
178
|
+
const video = stage.querySelector('video');
|
|
179
|
+
if (!job || !job.outputMp4) {
|
|
180
|
+
stage.hidden = true;
|
|
181
|
+
if (video && !video.paused) video.pause();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
stage.hidden = false;
|
|
185
|
+
const title = job.title || job.kind || '成片';
|
|
186
|
+
stage.dataset.title = title;
|
|
187
|
+
const label = stage.querySelector('.film-title');
|
|
188
|
+
if (label) label.textContent = title;
|
|
189
|
+
const src = filmSrc(job.id);
|
|
190
|
+
const same = video.dataset.src === src;
|
|
191
|
+
if (!same) {
|
|
192
|
+
video.dataset.src = src;
|
|
193
|
+
video.src = src;
|
|
194
|
+
}
|
|
195
|
+
if (!same || (opts && opts.autoplay)) video.play().catch(() => {});
|
|
196
|
+
}
|
|
197
|
+
|
|
86
198
|
function renderJobs(box, jobs, opts) {
|
|
87
199
|
const onDelete = opts && typeof opts.onDelete === 'function' ? opts.onDelete : null;
|
|
200
|
+
const onPick = opts && typeof opts.onPick === 'function' ? opts.onPick : null;
|
|
201
|
+
const selected = jobs.find((j) => j.id === selectedJobId) || null;
|
|
202
|
+
if (!selected) selectedJobId = '';
|
|
203
|
+
filmSelectedId = selected && selected.outputMp4 ? selected.id : '';
|
|
204
|
+
showFilm(box, selected && selected.outputMp4 ? selected : null);
|
|
88
205
|
if (!jobs.length) {
|
|
89
206
|
box.innerHTML = '<p class="muted">还没有任务</p>';
|
|
90
207
|
return;
|
|
@@ -93,17 +210,21 @@
|
|
|
93
210
|
jobs.forEach((j) => {
|
|
94
211
|
const phase = phaseLabel(j);
|
|
95
212
|
const sessionId = String(j.dshSessionId || '').trim();
|
|
213
|
+
const playable = Boolean(j.outputMp4);
|
|
214
|
+
const meta = [j.styleName, j.screen].filter(Boolean).join(' · ');
|
|
96
215
|
const el = document.createElement('div');
|
|
97
|
-
el.className = 'job' + (phase.cls ? ' ' + phase.cls : '');
|
|
216
|
+
el.className = 'job' + (phase.cls ? ' ' + phase.cls : '') + (playable ? ' playable' : '') + (j.id === selectedJobId ? ' on' : '');
|
|
217
|
+
el.title = '把这条需求填回创作框';
|
|
98
218
|
el.innerHTML = `
|
|
99
|
-
<div class="job-
|
|
100
|
-
<div class="t">${esc(j.title || j.kind)}${j.styleName ? ' · ' + esc(j.styleName) : ''}${
|
|
101
|
-
j.styleId ? ' · ' + esc(j.styleId) : ''
|
|
102
|
-
}</div>
|
|
219
|
+
<div class="job-top">
|
|
103
220
|
<span class="badge ${phase.cls}">${esc(phase.text)}</span>
|
|
104
|
-
|
|
105
|
-
<
|
|
221
|
+
${meta ? `<span class="job-chip">${esc(meta)}</span>` : ''}
|
|
222
|
+
<span class="job-actions">
|
|
223
|
+
<button type="button" class="job-open" ${sessionId ? '' : 'disabled'} title="${sessionId ? '打开这次创作的对话' : '这次任务没有对话'}">任务详情</button>
|
|
224
|
+
<button type="button" class="job-del" title="从列表删除" aria-label="删除">×</button>
|
|
225
|
+
</span>
|
|
106
226
|
</div>
|
|
227
|
+
<div class="t">${esc(j.title || j.kind || '未命名')}</div>
|
|
107
228
|
<div class="m">${esc(j.message || '')}</div>
|
|
108
229
|
<div class="bar"><i style="width:${Number(j.progress) || 0}%"></i></div>`;
|
|
109
230
|
const openBtn = el.querySelector('.job-open');
|
|
@@ -114,16 +235,33 @@
|
|
|
114
235
|
window.parent.postMessage({ source: 'bn-studio', type: 'open-session', sessionId }, '*');
|
|
115
236
|
});
|
|
116
237
|
}
|
|
238
|
+
el.addEventListener('click', () => {
|
|
239
|
+
selectedJobId = j.id;
|
|
240
|
+
filmSelectedId = playable ? j.id : '';
|
|
241
|
+
box.querySelectorAll('.job.on').forEach((node) => node.classList.remove('on'));
|
|
242
|
+
el.classList.add('on');
|
|
243
|
+
showFilm(box, playable ? j : null, { autoplay: playable });
|
|
244
|
+
if (onPick) onPick(j);
|
|
245
|
+
});
|
|
117
246
|
const delBtn = el.querySelector('.job-del');
|
|
118
247
|
if (delBtn) {
|
|
119
248
|
delBtn.addEventListener('click', (e) => {
|
|
120
249
|
e.preventDefault();
|
|
121
250
|
e.stopPropagation();
|
|
122
251
|
if (!j.id) return;
|
|
123
|
-
|
|
124
|
-
|
|
252
|
+
const clearFilm = () => {
|
|
253
|
+
if (selectedJobId === j.id) selectedJobId = '';
|
|
254
|
+
if (filmSelectedId !== j.id) return;
|
|
255
|
+
filmSelectedId = '';
|
|
256
|
+
showFilm(box, null);
|
|
257
|
+
};
|
|
258
|
+
if (onDelete) {
|
|
259
|
+
clearFilm();
|
|
260
|
+
onDelete(j);
|
|
261
|
+
} else {
|
|
125
262
|
void api('/api/jobs/' + encodeURIComponent(j.id), { method: 'DELETE' })
|
|
126
263
|
.then(() => {
|
|
264
|
+
clearFilm();
|
|
127
265
|
el.remove();
|
|
128
266
|
if (!box.querySelector('.job')) box.innerHTML = '<p class="muted">还没有任务</p>';
|
|
129
267
|
})
|