krillplayer-plugin 0.2.0 → 0.3.0

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 CHANGED
@@ -28,6 +28,23 @@ npx krillplayer-plugin check
28
28
 
29
29
  插件里只 import 类型:`import type { BrowseSlot, PlaySlot, PluginManifest } from "krillplayer-plugin";`。类型、`krillplayer` 对象与每个槽位的调用约定都在 `contract.d.ts`,它由 App 仓库的契约生成器产出,开头写着契约的修订号。App 只运行修订号与它一致的插件;契约升修订时本包随之发新版本,Skill 里的参考跟着重新生成。
30
30
 
31
+ ## 单元测试与发布脚本用的入口
32
+
33
+ 用例一次只跑一个调用。用例测不到的(带随机数的加密、自己的发布脚本)可以写 Node 的单元测试,用本包的两个入口,它们只在 Node 里用,类型要带 Node 的(`@types/node`):
34
+
35
+ | 入口 | 导出 | 用途 |
36
+ |---|---|---|
37
+ | `krillplayer-plugin/zip` | `writeZip(entries)`、`readZip(zip)` | 读写插件包,与 `bundle` 同一份代码:同样的文件、同样的顺序写出同样的字节。签名时读出包里的文件 |
38
+ | `krillplayer-plugin/crypto` | `createCrypto()` | 新建一份 `krillplayer.crypto`,与 `trial` 里插件拿到的是同一份实现,单元测试里当假的 `krillplayer` 的 `crypto` |
39
+
40
+ ```ts
41
+ import { createCrypto } from "krillplayer-plugin/crypto";
42
+ import { readZip } from "krillplayer-plugin/zip";
43
+
44
+ const krillplayer = { crypto: createCrypto(), /* 测试要用的别的成员 */ };
45
+ const manifest = readZip(zip).get("manifest.json");
46
+ ```
47
+
31
48
  ## 给 AI
32
49
 
33
50
  ```sh
package/dist/cli.js CHANGED
@@ -77,9 +77,10 @@ var Capability = enumeration("Capability", [
77
77
  "status",
78
78
  "login",
79
79
  "playbackReport",
80
- "views",
81
80
  "danmakuSend",
82
- "browseLists"
81
+ "browseLists",
82
+ "playerPanels",
83
+ "cardActions"
83
84
  ]);
84
85
  var Media = enumeration("Media", ["video", "audio"]);
85
86
  var ChannelKind = enumeration("ChannelKind", ["creator", "station", "podcast"]);
@@ -418,32 +419,31 @@ var Playable = object("Playable", {
418
419
  // 这一路的原始文件名,给字幕插件与弹幕插件匹配用(contract.md 3.1);不给时内核用条目的文件名或标题。
419
420
  filename: optional(string)
420
421
  });
421
- var Card = object("Card", {
422
- kind: enumeration("CardKind", ["entry", "comment"]),
423
- title: string,
424
- subtitle: optional(string),
425
- caption: optional(string),
426
- image: optional(string),
427
- text: optional(string),
422
+ var Comment = object("Comment", {
423
+ id: string,
424
+ author: string,
425
+ text: string,
426
+ avatar: optional(string),
428
427
  time: optional(number),
429
- entry: optional(Entry)
428
+ likes: optional(integer)
430
429
  });
431
- var Section = object("Section", {
432
- layout: enumeration("SectionLayout", ["row", "grid", "list"]),
430
+ var EntriesPanel = object("EntriesPanel", {
431
+ kind: constant("entries"),
433
432
  title: optional(string),
434
- cards: array(Card)
433
+ entries: array(Entry),
434
+ next: optional(string),
435
+ maxAge: optional(number)
435
436
  });
436
- var ComponentPage = object("ComponentPage", {
437
- title: optional(string),
438
- filters: optional(array(Parameter)),
439
- sections: array(Section),
437
+ var CommentsPanel = object("CommentsPanel", {
438
+ kind: constant("comments"),
439
+ comments: array(Comment),
440
440
  next: optional(string),
441
- maxAge: optional(number),
442
- empty: optional(string)
443
- }, "PageContent");
444
- var ActionResult = object("ActionResult", {
445
- message: optional(string)
441
+ maxAge: optional(number)
446
442
  });
443
+ var PanelPage = union("PanelPage", "kind", [EntriesPanel, CommentsPanel], "PanelContent");
444
+ var ActionMessage = object("ActionMessage", { kind: constant("message"), message: string });
445
+ var ActionEntries = object("ActionEntries", { kind: constant("entries"), title: optional(string), entries: array(Entry) });
446
+ var ActionResult = union("ActionResult", "kind", [ActionMessage, ActionEntries]);
447
447
  var ChannelStatus = object("ChannelStatus", {
448
448
  id: string,
449
449
  live: enumeration("ChannelLive", ["online", "offline", "unknown"], "unknown"),
@@ -793,8 +793,9 @@ var SLOT_RULES = {
793
793
  capabilities: { login: ["methods"] }
794
794
  },
795
795
  playbackReport: { functions: ["report"], required: ["report"], pairs: [], capabilities: { playbackReport: ["report"] } },
796
- // 组件页面 page 去掉了(ADR 0040),剩下播放器面板与卡片操作。
797
- views: { functions: ["panel", "action"], required: [], pairs: [], capabilities: { views: ["panel", "action"] } },
796
+ // 组件页面 page 去掉了(ADR 0040),剩下播放器面板与卡片操作,都交数据(#753)。面板与操作各一项能力,
797
+ // 不再是 views:交组件格式的旧插件打的是 views,新内核不认识、跳过,不会按数据去解它;旧内核也不认识这两项,不会按组件格式去解新插件。
798
+ views: { functions: ["panel", "action"], required: [], pairs: [], capabilities: { playerPanels: ["panel"], cardActions: ["action"] } },
798
799
  // 顶层的 parameters 不算能力(contract.md 第 2 节)。
799
800
  parameters: { functions: ["options"], required: ["options"], pairs: [], capabilities: {} }
800
801
  };
@@ -837,7 +838,7 @@ var SLOT_RETURNS = {
837
838
  poll: { schema: LoginPoll },
838
839
  account: { schema: LoginAccount, nullable: true }
839
840
  },
840
- views: { panel: { schema: ComponentPage }, action: { schema: ActionResult } },
841
+ views: { panel: { schema: PanelPage }, action: { schema: ActionResult } },
841
842
  parameters: { options: { schema: array(Option) } },
842
843
  resolve: { "": { schema: Resolved, nullable: true } }
843
844
  };
@@ -877,6 +878,7 @@ var NOT_YET_USED = [
877
878
  "ChannelRef.kind",
878
879
  "ChannelStatus.latest",
879
880
  "CollectionRef.kind",
881
+ "Comment.avatar",
880
882
  "CommentGift.count",
881
883
  "CommentGift.name",
882
884
  "CommentImage.height",
@@ -915,7 +917,6 @@ var NOT_YET_USED = [
915
917
  "MusicPlaylist.count",
916
918
  "MusicPlaylist.owner",
917
919
  "MusicPlaylist.summary",
918
- "MusicSection.kind",
919
920
  "OnDemand.index",
920
921
  "OnDemand.summary",
921
922
  "OnDemand.version",
@@ -1380,7 +1381,7 @@ var Chain = class {
1380
1381
  let headers2 = becomesGet ? without(previous.headers, BODY_HEADERS) : previous.headers;
1381
1382
  if (this.seen.has(`${method} ${address.href}`)) throw this.refuse("redirect-loop", address, `redirect loop at ${this.label(address)}`);
1382
1383
  const downgrade = previous.address.scheme === "https" && address.scheme === "http";
1383
- if (downgrade && this.use !== "playback-follow" && this.use !== "playback-probe") {
1384
+ if (downgrade && this.use !== "playback" && this.use !== "playback-follow" && this.use !== "playback-probe") {
1384
1385
  throw this.refuse("no-downgrade", address, `will not follow a redirect from https to http at ${this.label(address)}`);
1385
1386
  }
1386
1387
  const hostClass = this.classify(address.host);
@@ -2895,6 +2896,19 @@ function createSubtle() {
2895
2896
  unwrapKey
2896
2897
  };
2897
2898
  }
2899
+ var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
2900
+ async function plainDigest(algorithm, data) {
2901
+ const name2 = DIGESTS.get(algorithm.toLowerCase());
2902
+ if (name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
2903
+ return new Uint8Array(await subtle().digest(name2, typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data)));
2904
+ }
2905
+ function createCrypto() {
2906
+ return {
2907
+ randomBytes: (length) => globalThis.crypto.getRandomValues(new Uint8Array(length)),
2908
+ digest: plainDigest,
2909
+ subtle: createSubtle()
2910
+ };
2911
+ }
2898
2912
 
2899
2913
  // host/krillplayer.ts
2900
2914
  function userAddressesOf(manifest, parameters) {
@@ -2912,7 +2926,6 @@ function userHostsOf(manifest, parameters) {
2912
2926
  });
2913
2927
  }
2914
2928
  var STATUS_SLOT_CAPABILITIES = /* @__PURE__ */ new Set(["http", "decompress", "crypto", "formats", "log", "cache", "credentials", "parameters", "error"]);
2915
- var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
2916
2929
  var COMPRESSION_FORMATS = /* @__PURE__ */ new Set(["gzip", "deflate", "deflate-raw"]);
2917
2930
  function createCache(now2 = Date.now) {
2918
2931
  const entries = /* @__PURE__ */ new Map();
@@ -3016,8 +3029,8 @@ function createDerivedURLs() {
3016
3029
  },
3017
3030
  async parsed(data, guideURLs) {
3018
3031
  if (typeof data === "string" || guideURLs.length === 0) return;
3019
- const digest3 = hex(await crypto.subtle.digest("SHA-256", toBytes(data)));
3020
- if (!state().bodies.includes(digest3)) return;
3032
+ const digest2 = hex(await crypto.subtle.digest("SHA-256", toBytes(data)));
3033
+ if (!state().bodies.includes(digest2)) return;
3021
3034
  for (const url of guideURLs) keep(state().urls, url, DERIVED_URLS_KEPT);
3022
3035
  },
3023
3036
  // 从用户填的地址跳到的派生主机(derived-lifetime):这个实例之后可以直接请求,只读、不带凭证。最多留 REMEMBERED_HOSTS 台。
@@ -3167,11 +3180,7 @@ function createKrillPlayer({
3167
3180
  }
3168
3181
  },
3169
3182
  decompress: (format2, data) => decompress(format2, data),
3170
- crypto: {
3171
- randomBytes: (length) => crypto.getRandomValues(new Uint8Array(length)),
3172
- digest: digest2,
3173
- subtle: createSubtle()
3174
- },
3183
+ crypto: createCrypto(),
3175
3184
  formats: {
3176
3185
  async m3u(data) {
3177
3186
  const playlist = parseM3U(data);
@@ -3327,11 +3336,6 @@ async function decompress(format2, data, limit = FORMAT_LIMITS.decompressedBytes
3327
3336
  }
3328
3337
  return output;
3329
3338
  }
3330
- async function digest2(algorithm, data) {
3331
- const name2 = DIGESTS.get(algorithm.toLowerCase());
3332
- if (name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
3333
- return new Uint8Array(await crypto.subtle.digest(name2, toBytes(data)));
3334
- }
3335
3339
 
3336
3340
  // contract/validate.ts
3337
3341
  var UNKNOWN_KIND_HINTS = [
@@ -0,0 +1,8 @@
1
+ // krillplayer-plugin/crypto:试跑器交给插件的 krillplayer.crypto,给插件的单元测试当假的 krillplayer 用,只在 Node 里用。
2
+ import type { KrillPlayer } from "../skill/krillplayer-plugin/references/contract.js";
3
+
4
+ /**
5
+ * 新建一份 krillplayer.crypto(randomBytes、digest、subtle),与 `krillplayer-plugin trial` 里插件拿到的是同一份实现:
6
+ * 收的参数、PEM 公私钥、报错文本都一样。
7
+ */
8
+ export function createCrypto(): KrillPlayer["crypto"];