cortico-world-extra-actions 0.3.26 → 0.3.28

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/dist/webui.js CHANGED
@@ -195,7 +195,7 @@ const CSS = `<style>
195
195
  /* 首启一次性提示 */
196
196
  .ea-onboard{position:fixed;inset:0;z-index:40;display:flex;align-items:center;justify-content:center;
197
197
  background:rgba(0,0,0,.42);padding:20px}
198
- .ea-onboard[hidden]{display:none}
198
+ .ea-onboard[hidden]{display:none}
199
199
  .ea-onboard-box{max-width:420px;background:var(--ea-bg);border:1px solid var(--ea-line2);padding:16px 18px;
200
200
  box-shadow:0 24px 48px -20px rgba(0,0,0,.5)}
201
201
  .ea-onboard-box b{display:block;font-size:14px;margin-bottom:6px}
@@ -414,7 +414,8 @@ const panel = {
414
414
  <div class="ea-onboard" data-role="onboard" hidden>
415
415
  <div class="ea-onboard-box">
416
416
  <b>完整动作库还没下载</b>
417
- <p>插件自带 <b data-role="onboard-have">若干</b> 段示例动作。完整库有 <b data-role="onboard-count">105</b> 段(640×360,约 <span data-role="onboard-size">370</span> MB),下载并指给插件之后,面板里的动作才能全部勾选。</p>
417
+ <p>插件自带 <b data-role="onboard-have">若干</b> 段示例动作。完整库有 <b data-role="onboard-count">105</b> 段(640×360,约 <span data-role="onboard-size">370</span> MB)。</p>
418
+ <p>下载之前,列表里那些<b>灰色的行</b>就是还没装进动作库的段 —— 灰色只代表「没下载」,不是坏了;下载完就会变成可勾选。</p>
418
419
  <p class="ea-dim" data-role="onboard-note">下载地址由维护者提供,拿到后这里会出现「去下载」按钮;也可以自己放好库,用「动作库」菜单里的「选择动作库位置…」指过去。</p>
419
420
  <div class="ea-onboard-acts">
420
421
  <button class="ea-btn pri" type="button" data-act="download-library" data-role="onboard-dl" hidden>一键下载并安装</button>
@@ -490,9 +491,32 @@ const panel = {
490
491
  return '扩展刚更新过,但 Coopanion 还在用旧的后台。请完全退出 Coopanion 再打开,这个按钮就能用了。';
491
492
  }
492
493
  if (/内置形象包不给写/.test(raw)) return '这是内置形象包,不能写。先「建立空的角色包」再保存。';
494
+ if (/超时|TimeoutError|连不上|ECONNRESET|ENOTFOUND|EAI_AGAIN/i.test(raw)) {
495
+ return `网络没连上(${raw})。换个网络再试,或者用「动作库 ▾」→「手动下载」自己下完整库,然后用「选择动作库位置…」指过去。`;
496
+ }
497
+ if (/HTTP 404/.test(raw)) return '下载源上那个文件不在了(404)。到「动作库 ▾」→「手动下载」拿完整库,再选位置指过去。';
493
498
  return raw || '操作失败';
494
499
  }
495
500
 
501
+ /** 下载期间轮询后台进度:第几片、下了多少 MB。 */
502
+ let pollTimer = null;
503
+ function startPoll() {
504
+ stopPoll();
505
+ const t0 = Date.now();
506
+ pollTimer = setInterval(async () => {
507
+ let p = null;
508
+ try { p = await ctx.invoke('download-progress', []); } catch { return; }
509
+ if (!p || !p.active) return;
510
+ const mb = (n) => (n / 1048576).toFixed(0);
511
+ const secs = Math.round((Date.now() - t0) / 1000);
512
+ const total = p.totalBytes ? ` / ${mb(p.totalBytes)} MB` : '';
513
+ say(`正在下载完整动作库… ${p.done}/${p.total} 片,已下 ${mb(p.bytes)} MB${total}(${secs}s)`);
514
+ }, 700);
515
+ }
516
+ function stopPoll() {
517
+ if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
518
+ }
519
+
496
520
  /** 一键:下载完整动作库并设为当前库。 */
497
521
  async function doDownloadLibrary() {
498
522
  if (!apiHas('download-library')) {
@@ -500,7 +524,8 @@ const panel = {
500
524
  return;
501
525
  }
502
526
  busy(true);
503
- say('正在下载完整动作库…(约 370 MB,视网速几分钟,别关这个页面)');
527
+ say('正在连接下载源…(约 370 MB,视网速几分钟,别关这个页面)');
528
+ startPoll();
504
529
  try {
505
530
  const r = await ctx.invoke('download-library', []);
506
531
  await loadAll();
@@ -508,6 +533,7 @@ const panel = {
508
533
  } catch (err) {
509
534
  say('下载没成功:' + explainErr(err), true);
510
535
  } finally {
536
+ stopPoll();
511
537
  busy(false);
512
538
  }
513
539
  }
@@ -549,7 +575,9 @@ const panel = {
549
575
  // 数字都从清单算,别写死(换库、加动作时不用改文案)
550
576
  const totalSeg = catalog?.count ?? 0;
551
577
  const haveSeg = catalog?.present ?? 0;
552
- const totalBytes = (catalog?.actions ?? []).reduce((sum, a) => sum + (a.bytes || 0), 0);
578
+ // 优先用后台给的分片总字节(准确);拿不到再退回清单求和
579
+ const totalBytes = state?.download?.bytes
580
+ || (catalog?.actions ?? []).reduce((sum, a) => sum + (a.bytes || 0), 0);
553
581
  const setTxt = (sel, v) => { const node = wrap.querySelector(sel); if (node) node.textContent = String(v); };
554
582
  if (totalSeg) setTxt('[data-role=onboard-count]', totalSeg);
555
583
  setTxt('[data-role=onboard-have]', haveSeg);
@@ -714,7 +742,8 @@ const panel = {
714
742
  const mounted = installed.has(a.id);
715
743
  const row = el('div', 'ea-row' + (on ? ' on' : '') + (isState || off ? ' off' : '') + (off ? ' miss' : ''));
716
744
  // 目录固定:悬停就能看到这段动作在库里的固定位置 actions/<分类>/<id>
717
- row.title = '固定目录:' + (a.dir || a.clip || `actions/${a.category}/${a.id}`) + (off ? '(库里还没有,补进来才能用)' : '');
745
+ row.title = '固定目录:' + (a.dir || a.clip || `actions/${a.category}/${a.id}`)
746
+ + (off ? '|这一段还没下载到动作库,所以是灰的、不能勾。点这一行右侧的「↓ 下载」只下这一段(约 3.5 MB),或点上面的「一键下载并安装」装完整 105 段。' : '');
718
747
  // 缩略图的 data URL 先不挂 src:等这一行进可视区再挂(见 mountThumbs)。
719
748
  // 尺寸由 CSS 的 64×36 定住,所以不挂 src 也不会让行跳动。
720
749
  row.__pickable = isSelectable(a) ? a : null; // 表头复选框要用:这一行到底算不算"可勾"
@@ -727,7 +756,7 @@ const panel = {
727
756
  <span class="tag">${esc(a.catZh)}</span>
728
757
  <span class="tag">${a.seconds.toFixed(1)}s</span>
729
758
  ${mounted ? '<span class="tag acc">已装</span>' : ''}
730
- ${off ? '<span class="tag warn">库里没有 · 缺帧</span>' : (isState ? '<span class="tag">状态 · 不用勾</span>' : '')}
759
+ ${off ? '<span class="tag warn">未下载</span>' : (isState ? '<span class="tag">状态 · 不用勾</span>' : '')}
731
760
  ${a.reaction ? '<span class="tag">点击</span>' : ''}
732
761
  ${a.noMirror ? '<span class="tag">带字</span>' : ''}
733
762
  ${a.random ? '' : '<span class="tag">不轮播</span>'}
@@ -899,7 +928,7 @@ const panel = {
899
928
  sumEl.innerHTML = `已勾选 <b>${n}</b> 段 · 约 <b>${mb(bytesOf(selected))}</b>`
900
929
  + (hiddenAll && !showAll ? ` | <b class="warn">另有 ${hiddenAll} 段未下载</b>(勾上「显示全部」可看)` : '')
901
930
  + ` | 清单 <b>${total}</b> 条:库里 <b>${have}</b>${miss ? ` · <b class="warn">缺 ${miss}</b>` : ''}`
902
- + (dead ? ` | <b class="warn">其中 ${dead} 段库里没有</b>(保存时跳过)` : '')
931
+ + (dead ? ` | <b class="warn">其中 ${dead} 段还没下载</b>(保存时会跳过)` : '')
903
932
  + (extra ? ` | 包里已有 ${extra} 段(${mb(p.extra.bytes || 0)})` : '');
904
933
  }
905
934
 
@@ -932,15 +961,19 @@ const panel = {
932
961
  if (!missSeg) return '';
933
962
  const names = (catalog?.actions ?? []).filter((a) => a.present === false).slice(0, 6).map((a) => a.zh || a.id);
934
963
  const more = names.length && missSeg > names.length ? '…' : '';
935
- return `<br>库里还缺 <b class="warn">${missSeg}</b> 段${names.length ? `(${esc(names.join('、'))}${more})` : ''}`
936
- + ' —— 这些勾了也写不进包;点上面的「动作库」菜单去补,或到 '
937
- + ' 到「动作库」菜单下载完整库。';
964
+ return `<br>列表里<b>灰色的行</b>就是还没下载到动作库的段 —— 现在缺 <b class="warn">${missSeg}</b> 段`
965
+ + (names.length ? `(${esc(names.join('、'))}${more})` : '')
966
+ + ';下载之后才会变成可勾选,现在勾了也写不进包。'
967
+ + '<div style="margin-top:6px;display:flex;gap:8px;align-items:center;flex-wrap:wrap">'
968
+ + '<button class="ea-btn pri" type="button" data-act="download-library">一键下载并安装</button>'
969
+ + '<span class="ea-dim">或者只补某一段:点那一行右侧的「↓ 下载」</span>'
970
+ + '</div>';
938
971
  };
939
972
  if (!state.library.ok) {
940
973
  noteEl.hidden = false;
941
974
  noteEl.className = 'ea-note bad';
942
975
  noteEl.innerHTML = `动作库目录没找到:<code>${esc(state.library.dir || '未设置')}</code> —— 点上面的「动作库」菜单:自动寻找,或手动选位置。`
943
- + `<br>清单里的 ${state.library.count ?? 105} 段现在都算「库里没有」。`;
976
+ + `<br>清单里的 ${state.library.count ?? 105} 段现在都算「还没下载」—— 先在上面选好动作库位置,再下载。`;
944
977
  return;
945
978
  }
946
979
  if (!p) {
@@ -1072,7 +1105,7 @@ const panel = {
1072
1105
  const skipped = Array.isArray(r.skipped) ? r.skipped : [];
1073
1106
  const names = skipped.slice(0, 5).map((id) => catalog.actions.find((a) => a.id === id)?.zh ?? id);
1074
1107
  const tail = skipped.length
1075
- ? `;库里没有的 ${skipped.length} 段已跳过${names.length ? `(${names.join('、')}${skipped.length > names.length ? '…' : ''})` : ''}`
1108
+ ? `;还没下载的 ${skipped.length} 段已跳过${names.length ? `(${names.join('、')}${skipped.length > names.length ? '…' : ''})` : ''}`
1076
1109
  : '';
1077
1110
  say(`已写入 ${r.count} 段,${mb(r.bytes)}${tail};词表 +${r.vocab.added.length} −${r.vocab.removed.length};去装扮页重新点一下这个形象才会生效`, !!skipped.length);
1078
1111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-extra-actions",
3
- "version": "0.3.26",
3
+ "version": "0.3.28",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "勾选动作库里的动作,写进形象包的「额外动作拓展」文件夹,让桌宠照着做。自带入门形象包与示例动作;完整 105 段可一键下载安装(不用解压、不用选文件夹)。",
package/src/online.js CHANGED
@@ -65,9 +65,17 @@ function commonTop(names) {
65
65
 
66
66
  const isHttp = (u) => typeof u === 'string' && /^https?:\/\//i.test(u);
67
67
 
68
+ const FETCH_TIMEOUT_MS = 5 * 60 * 1000; // 单片最长 5 分钟;连不上会在这里断掉,而不是无限转圈
69
+
68
70
  async function fetchBytes(url, cap) {
69
71
  if (!isHttp(url)) throw new Error(`只支持 http(s) 地址:${url}`);
70
- const r = await fetch(url, { redirect: 'follow' });
72
+ let r;
73
+ try {
74
+ r = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
75
+ } catch (e) {
76
+ const why = e?.name === 'TimeoutError' ? '超时(5 分钟没下完)' : (e?.cause?.code ?? e?.message ?? '网络错误');
77
+ throw new Error(`连不上:${why}`);
78
+ }
71
79
  if (!r.ok) throw new Error(`下载失败:HTTP ${r.status}`);
72
80
  const len = Number(r.headers.get('content-length') ?? 0);
73
81
  if (len && len > cap) throw new Error(`文件太大(${(len / 1048576).toFixed(0)} MB):${url}`);
@@ -156,8 +164,10 @@ export const flatActionUrl = (base, id) => `${String(base).replace(/\/+$/, '')}/
156
164
  export async function installLibraryParts({ parts = LIB_PARTS, dest, log, onProgress }) {
157
165
  mkdirSync(dest, { recursive: true });
158
166
  const before = new Set(summarize(dest));
167
+ const totalBytes = parts.reduce((sum, p) => sum + (p.bytes || 0), 0);
159
168
  let bytes = 0;
160
169
  let failed = 0;
170
+ const errors = [];
161
171
  for (let i = 0; i < parts.length; i++) {
162
172
  const p = parts[i];
163
173
  let buf = null;
@@ -165,7 +175,12 @@ export async function installLibraryParts({ parts = LIB_PARTS, dest, log, onProg
165
175
  for (const url of partTarballs(p)) {
166
176
  try { buf = await fetchBytes(url, MAX_LIBRARY_BYTES); break; } catch (e) { lastErr = e; }
167
177
  }
168
- if (!buf) { failed++; log?.(`第 ${i + 1} 片下载失败:${lastErr?.message ?? '未知错误'}`); continue; }
178
+ if (!buf) {
179
+ failed++;
180
+ errors.push(`第 ${i + 1} 片:${lastErr?.message ?? '未知错误'}`);
181
+ log?.(`第 ${i + 1} 片下载失败:${lastErr?.message ?? '未知错误'}`);
182
+ continue;
183
+ }
169
184
  bytes += buf.length;
170
185
  if (p.sha256) {
171
186
  const got = createHash('sha256').update(buf).digest('hex');
@@ -177,9 +192,9 @@ export async function installLibraryParts({ parts = LIB_PARTS, dest, log, onProg
177
192
  onFile: (rel) => WANT.test(rel),
178
193
  });
179
194
  log?.(`第 ${i + 1}/${parts.length} 片:${r.files.length} 个文件`);
180
- onProgress?.(i + 1, parts.length);
195
+ onProgress?.({ done: i + 1, total: parts.length, bytes, totalBytes });
181
196
  }
182
197
  const mods = summarize(dest);
183
198
  const added = mods.filter((m) => !before.has(m));
184
- return { ok: failed === 0, path: dest, modules: mods.length, added: added.length, failed, bytes };
199
+ return { ok: failed === 0, path: dest, modules: mods.length, added: added.length, failed, bytes, totalBytes, errors };
185
200
  }
package/src/world.js CHANGED
@@ -29,7 +29,7 @@ const LIBRARY_PAGE = 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/relea
29
29
  const METHODS = [
30
30
  'state', 'catalog', 'dirs', 'save', 'remove', 'clear', 'prune', 'add',
31
31
  'reindex', 'find-libraries', 'set-library', 'use-starter-library', 'restore-pack',
32
- 'download-library', 'download-action', 'preview', 'dismiss-onboard', 'reload',
32
+ 'download-library', 'download-action', 'download-progress', 'preview', 'dismiss-onboard', 'reload',
33
33
  ];
34
34
 
35
35
  const ID = 'extra-actions';
@@ -387,6 +387,8 @@ export class ExtraActionsWorld {
387
387
  return this.downloadLibrary();
388
388
  case 'download-action':
389
389
  return this.downloadAction(String(a[0] ?? ''), String(a[1] ?? ''));
390
+ case 'download-progress':
391
+ return this.downloadProgress();
390
392
  // 老版本面板会调 reload:当成「重新读一遍状态」,避免 unknown method 弹错
391
393
  case 'reload':
392
394
  return this.state();
@@ -594,12 +596,19 @@ export class ExtraActionsWorld {
594
596
  base,
595
597
  actionBase,
596
598
  libraryUrl: base ? libraryUrl(base) : FALLBACK_LIBRARY,
599
+ // 完整库的真实字节数(分片之和):面板提示里的「约 N MB」用它,别拿清单里的体积去猜
600
+ bytes: LIB_PARTS.reduce((sum, p) => sum + (p.bytes || 0), 0),
597
601
  // 完整库有 GitHub 兜底;单段必须有专门的前缀
598
602
  perAction: !!(actionBase || base),
599
603
  flat: !!actionBase,
600
604
  };
601
605
  }
602
606
 
607
+ /** 面板轮询:这次下载进行到哪了(没有下载时 active=false)。 */
608
+ downloadProgress() {
609
+ return this._dl ?? { active: false };
610
+ }
611
+
603
612
  /** 一键:下载完整动作库 → 解压进动作库 → 设为当前库。 */
604
613
  async downloadLibrary() {
605
614
  const info = this.downloadInfo();
@@ -607,11 +616,22 @@ export class ExtraActionsWorld {
607
616
  // 没配自家源时:走 npm 分片(国内走 npmmirror,比 GitHub 稳)
608
617
  if (!info.base && LIB_PARTS.length) {
609
618
  const dest = existing && existsSync(existing) ? existing : join(this.dataDir, 'shenshen-library');
610
- const r = await installLibraryParts({
611
- dest,
612
- log: (m) => this.host?.log?.info?.(m),
613
- onProgress: (i, n) => this.host?.log?.info?.(`动作库 ${i}/${n} 片`),
614
- });
619
+ this._dl = { active: true, phase: 'download', done: 0, total: LIB_PARTS.length, bytes: 0, totalBytes: info.bytes, startedAt: Date.now() };
620
+ let r;
621
+ try {
622
+ r = await installLibraryParts({
623
+ dest,
624
+ log: (m) => this.host?.log?.info?.(m),
625
+ onProgress: (p) => {
626
+ this._dl = { ...this._dl, ...p, active: true, phase: 'download' };
627
+ this.host?.log?.info?.(`动作库 ${p.done}/${p.total} 片`);
628
+ },
629
+ });
630
+ } catch (e) {
631
+ this._dl = { ...(this._dl ?? {}), active: false, phase: 'error', error: String(e?.message ?? e) };
632
+ throw e;
633
+ }
634
+ this._dl = { ...this._dl, active: false, phase: 'done', modules: r.modules, failed: r.failed, errors: r.errors };
615
635
  // 分片有失败(镜像没同步等)时就再用整包兜一次,别让用户停在半截
616
636
  if (!r.ok || r.modules < 20) {
617
637
  this.host?.log?.warn?.(`分片装了 ${r.modules} 段(失败 ${r.failed} 片),改用整包兜底`);
@@ -626,9 +646,11 @@ export class ExtraActionsWorld {
626
646
  }
627
647
  this.saveSettings({ libraryDir: r.path });
628
648
  this.bustCatalog();
649
+ this._dl = { ...(this._dl ?? {}), active: false, phase: 'done', modules: r.modules, failed: r.failed };
629
650
  return { ok: r.ok, ...r, libraryDir: r.path };
630
651
  }
631
652
  if (!info.libraryUrl) throw new Error('还没配置下载源');
653
+ this._dl = { active: true, phase: 'zip', done: 0, total: 1, bytes: 0, totalBytes: 0, startedAt: Date.now() };
632
654
  const r = await installLibrary({
633
655
  url: info.libraryUrl,
634
656
  libraryDir: existing,
@@ -637,6 +659,7 @@ export class ExtraActionsWorld {
637
659
  });
638
660
  this.saveSettings({ libraryDir: r.path });
639
661
  this.bustCatalog();
662
+ this._dl = { ...(this._dl ?? {}), active: false, phase: 'done', modules: r.modules, bytes: r.bytes };
640
663
  this.host?.log?.info?.(`动作库已装好:${r.modules} 段(新增 ${r.added})`);
641
664
  return { ok: true, ...r, libraryDir: r.path };
642
665
  }