cortico-world-extra-actions 0.3.18 → 0.3.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-extra-actions",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "勾选动作库里的动作,写进形象包的「额外动作拓展」文件夹,让桌宠照着做。自带入门形象包与示例动作;完整 105 段可一键下载安装(不用解压、不用选文件夹)。",
package/src/online.js CHANGED
@@ -114,3 +114,5 @@ export async function installAction({ url, libraryDir, category, id, log }) {
114
114
  /** 由 remoteBase 拼出两个地址。 */
115
115
  export const libraryUrl = (base) => `${String(base).replace(/\/+$/, '')}/library.zip`;
116
116
  export const actionUrl = (base, category, id) => `${String(base).replace(/\/+$/, '')}/actions/${category}/${id}.zip`;
117
+ /** 扁平布局(GitHub Release 的资产做不到子目录):<base>/<id>.zip */
118
+ export const flatActionUrl = (base, id) => `${String(base).replace(/\/+$/, '')}/${id}.zip`;
package/src/world.js CHANGED
@@ -14,7 +14,7 @@ import { fileURLToPath } from 'node:url';
14
14
  import { EXTRA_DIR, clear, inspect, isInside, packLooksSupported, prunePack, readExtra, removeOne, save } from './writer.js';
15
15
  import { addModules, rebuildIndex, scanLibrary } from './importer.js';
16
16
  import { ensureStarter, installStarterLibrary, libraryHealth, restorePack, safePackName } from './starter.js';
17
- import { FALLBACK_LIBRARY, actionUrl, installAction, installLibrary, libraryUrl } from './online.js';
17
+ import { FALLBACK_LIBRARY, actionUrl, flatActionUrl, installAction, installLibrary, libraryUrl } from './online.js';
18
18
  import { petFigures, petState } from './pet.js';
19
19
 
20
20
  const ID = 'extra-actions';
@@ -506,17 +506,29 @@ export class ExtraActionsWorld {
506
506
 
507
507
  /** 下载源:设置里的 remoteBase(Gitee 等),没配就退回 GitHub 直链。 */
508
508
  remoteBase() {
509
- const fromCfg = this.ctx.cfg && typeof this.ctx.cfg === 'object' ? this.ctx.cfg.remoteBase : '';
510
- return typeof fromCfg === 'string' && fromCfg.trim() ? fromCfg.trim().replace(/\/+$/, '') : '';
509
+ const c = this.ctx.cfg && typeof this.ctx.cfg === 'object' ? this.ctx.cfg : {};
510
+ const pick = (v) => (typeof v === 'string' && v.trim() ? v.trim().replace(/\/+$/, '') : '');
511
+ return pick(c.remoteBase) || '';
512
+ }
513
+
514
+ /** 单段动作的地址前缀(GitHub Release 的资产是扁平的,没有 actions/<分类>/ 这层)。 */
515
+ remoteActionBase() {
516
+ const c = this.ctx.cfg && typeof this.ctx.cfg === 'object' ? this.ctx.cfg : {};
517
+ const pick = (v) => (typeof v === 'string' && v.trim() ? v.trim().replace(/\/+$/, '') : '');
518
+ return pick(c.remoteActionBase) || '';
511
519
  }
512
520
 
513
521
  /** 面板需要知道:完整库从哪下、能不能单个下。 */
514
522
  downloadInfo() {
515
523
  const base = this.remoteBase();
524
+ const actionBase = this.remoteActionBase();
516
525
  return {
517
526
  base,
527
+ actionBase,
518
528
  libraryUrl: base ? libraryUrl(base) : FALLBACK_LIBRARY,
519
- perAction: !!base,
529
+ // 完整库有 GitHub 兜底;单段必须有专门的前缀
530
+ perAction: !!(actionBase || base),
531
+ flat: !!actionBase,
520
532
  };
521
533
  }
522
534
 
@@ -542,8 +554,9 @@ export class ExtraActionsWorld {
542
554
  if (!info.perAction) throw new Error('还没配置单动作下载源(remoteBase)');
543
555
  const lib = this.libraryDir();
544
556
  if (!lib) throw new Error('动作库还没设置好');
557
+ const url = info.flat ? flatActionUrl(info.actionBase, id) : actionUrl(info.base, category, id);
545
558
  const r = await installAction({
546
- url: actionUrl(info.base, category, id),
559
+ url,
547
560
  libraryDir: lib,
548
561
  category,
549
562
  id,