krillplayer-plugin 0.4.0 → 0.6.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 +2 -0
- package/dist/cli.js +391 -86
- package/dist/crypto.js +135 -4
- package/kernel/Sources/Kernel/Network/PublicSuffixList.dat +16978 -0
- package/kernel/Sources/Kernel/PluginPrelude.js +1 -0
- package/package.json +2 -2
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-backup-line.json +38 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-line-gone.json +38 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +13 -1
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +21 -3
- package/skill/krillplayer-plugin/references/cases.md +2 -2
- package/skill/krillplayer-plugin/references/contract.d.ts +24 -4
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// package/cli.ts
|
|
2
2
|
import { execFile as execFile2 } from "node:child_process";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
4
4
|
import { cp, mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir5, readFile as readFile6, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
|
|
5
5
|
import { createRequire as createRequire2 } from "node:module";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
-
import { basename as basename2, dirname as dirname2, join as
|
|
8
|
-
import { fileURLToPath as
|
|
7
|
+
import { basename as basename2, dirname as dirname2, join as join6, relative as relative3, resolve as resolve3 } from "node:path";
|
|
8
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
9
9
|
import { parseArgs, promisify as promisify2 } from "node:util";
|
|
10
10
|
|
|
11
11
|
// contract/schema.ts
|
|
@@ -396,7 +396,8 @@ var PlayableStream = object("PlayableStream", {
|
|
|
396
396
|
});
|
|
397
397
|
var PlayableLine = object("PlayableLine", {
|
|
398
398
|
name: string,
|
|
399
|
-
streams: array(PlayableStream)
|
|
399
|
+
streams: array(PlayableStream),
|
|
400
|
+
qualities: optional(array(string))
|
|
400
401
|
});
|
|
401
402
|
var Playable = object("Playable", {
|
|
402
403
|
timing: enumeration("PlayableTiming", ["live", "onDemand"]),
|
|
@@ -877,8 +878,8 @@ function slotMember(slot, name2) {
|
|
|
877
878
|
// packer/pack.ts
|
|
878
879
|
import { build as build2 } from "esbuild";
|
|
879
880
|
import { mkdir as mkdir2, readdir as readdir4, readFile as readFile5, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
880
|
-
import { join as
|
|
881
|
-
import { fileURLToPath as
|
|
881
|
+
import { join as join5 } from "node:path";
|
|
882
|
+
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
882
883
|
|
|
883
884
|
// contract/not-yet-used.ts
|
|
884
885
|
var NOT_YET_USED = [
|
|
@@ -1087,7 +1088,12 @@ function translate({ locale, language, dictionaries: dictionaries2 }, text, valu
|
|
|
1087
1088
|
|
|
1088
1089
|
// trial-runner/trial.ts
|
|
1089
1090
|
import { readdir as readdir3, readFile as readFile4, writeFile } from "node:fs/promises";
|
|
1090
|
-
import { basename, join as
|
|
1091
|
+
import { basename, join as join4, resolve } from "node:path";
|
|
1092
|
+
|
|
1093
|
+
// host/network.ts
|
|
1094
|
+
import { readFileSync } from "node:fs";
|
|
1095
|
+
import { join } from "node:path";
|
|
1096
|
+
import { domainToASCII, fileURLToPath } from "node:url";
|
|
1091
1097
|
|
|
1092
1098
|
// host/files.ts
|
|
1093
1099
|
var FileServiceError = class extends Error {
|
|
@@ -1166,6 +1172,52 @@ function createFiles(host) {
|
|
|
1166
1172
|
}
|
|
1167
1173
|
|
|
1168
1174
|
// host/network.ts
|
|
1175
|
+
function sameSite(host, other) {
|
|
1176
|
+
if (host === other) return true;
|
|
1177
|
+
const domain = registrableDomain(host);
|
|
1178
|
+
return domain !== null && domain === registrableDomain(other);
|
|
1179
|
+
}
|
|
1180
|
+
function vouchedByUserHost(host, use, userHosts, downgrade) {
|
|
1181
|
+
if (use !== "playback" && use !== "playback-follow" && use !== "playback-probe" || downgrade) return false;
|
|
1182
|
+
return [...userHosts].some((user) => sameSite(host, user));
|
|
1183
|
+
}
|
|
1184
|
+
function registrableDomain(host) {
|
|
1185
|
+
const labels = host.split(".");
|
|
1186
|
+
if (labels.length < 2 || labels.includes("") || host.includes(":") || /^[0-9]+$/.test(labels[labels.length - 1])) return null;
|
|
1187
|
+
const rules = publicSuffixRules();
|
|
1188
|
+
const suffix = (start) => labels.slice(start).join(".");
|
|
1189
|
+
let suffixLength = 1;
|
|
1190
|
+
const exception = labels.findIndex((_, start) => rules.exceptions.has(suffix(start)));
|
|
1191
|
+
if (exception >= 0) {
|
|
1192
|
+
suffixLength = labels.length - exception - 1;
|
|
1193
|
+
} else {
|
|
1194
|
+
const start = labels.findIndex((_, index) => rules.exact.has(suffix(index)) || index + 1 < labels.length && rules.wildcards.has(suffix(index + 1)));
|
|
1195
|
+
if (start >= 0) suffixLength = labels.length - start;
|
|
1196
|
+
}
|
|
1197
|
+
return labels.length > suffixLength ? labels.slice(labels.length - suffixLength - 1).join(".") : null;
|
|
1198
|
+
}
|
|
1199
|
+
var suffixRules;
|
|
1200
|
+
var suffixListKernel;
|
|
1201
|
+
function usePublicSuffixListFrom(kernelDirectory2) {
|
|
1202
|
+
suffixListKernel = kernelDirectory2;
|
|
1203
|
+
suffixRules = void 0;
|
|
1204
|
+
}
|
|
1205
|
+
function publicSuffixRules() {
|
|
1206
|
+
if (suffixRules !== void 0) return suffixRules;
|
|
1207
|
+
const kernel = process.env.KRILLPLAYER_KERNEL_DIR ?? suffixListKernel ?? fileURLToPath(new URL("../../Packages/Kernel", import.meta.url));
|
|
1208
|
+
const text = readFileSync(join(kernel, "Sources/Kernel/Network/PublicSuffixList.dat"), "utf8");
|
|
1209
|
+
const rules = { exact: /* @__PURE__ */ new Set(), wildcards: /* @__PURE__ */ new Set(), exceptions: /* @__PURE__ */ new Set() };
|
|
1210
|
+
const domain = (text2) => text2.includes("*") ? "" : bareHost(domainToASCII(text2));
|
|
1211
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1212
|
+
const rule = line.trim().split(/\s/)[0];
|
|
1213
|
+
if (rule === "" || rule.startsWith("//")) continue;
|
|
1214
|
+
const [set, name2] = rule.startsWith("!") ? [rules.exceptions, rule.slice(1)] : rule.startsWith("*.") ? [rules.wildcards, rule.slice(2)] : [rules.exact, rule];
|
|
1215
|
+
const ascii = domain(name2);
|
|
1216
|
+
if (ascii !== "") set.add(ascii);
|
|
1217
|
+
}
|
|
1218
|
+
suffixRules = rules;
|
|
1219
|
+
return rules;
|
|
1220
|
+
}
|
|
1169
1221
|
var MAX_REDIRECTS = 20;
|
|
1170
1222
|
var REMEMBERED_HOSTS = 8;
|
|
1171
1223
|
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -1419,7 +1471,7 @@ var Chain = class {
|
|
|
1419
1471
|
this.leftOrigin = true;
|
|
1420
1472
|
headers2 = hostClass === "derived" ? only(headers2, SAFELIST) : this.withoutCredentials(headers2);
|
|
1421
1473
|
}
|
|
1422
|
-
return this.settle({ address, hostClass, method, headers: headers2, body });
|
|
1474
|
+
return this.settle({ address, hostClass, method, headers: headers2, body, downgrade });
|
|
1423
1475
|
}
|
|
1424
1476
|
// 主机解析出的地址。解析不出(空)算连不上,不是这里的事。
|
|
1425
1477
|
resolved(addresses) {
|
|
@@ -1502,7 +1554,7 @@ var Chain = class {
|
|
|
1502
1554
|
return "only network stream addresses are allowed";
|
|
1503
1555
|
}
|
|
1504
1556
|
}
|
|
1505
|
-
settle({ address, hostClass, method, headers: headers2, body, frames }) {
|
|
1557
|
+
settle({ address, hostClass, method, headers: headers2, body, frames, downgrade = false }) {
|
|
1506
1558
|
if (hostClass === "derived") {
|
|
1507
1559
|
if (method !== "GET" && method !== "HEAD" || body) {
|
|
1508
1560
|
throw this.refuse(
|
|
@@ -1512,7 +1564,7 @@ var Chain = class {
|
|
|
1512
1564
|
);
|
|
1513
1565
|
}
|
|
1514
1566
|
const carried = [address.href, ...Object.keys(headers2), ...Object.values(headers2), ...frames ?? []];
|
|
1515
|
-
if (this.tokens.some((secret) => carried.some((text) => carries(text, secret)))) {
|
|
1567
|
+
if (this.tokens.some((secret) => carried.some((text) => carries(text, secret))) && !vouchedByUserHost(address.host, this.use, this.user, downgrade)) {
|
|
1516
1568
|
throw this.refuse("derived-no-secrets", address, `credentials may not be sent to ${address.host}, a host that is neither declared nor given by the user`);
|
|
1517
1569
|
}
|
|
1518
1570
|
}
|
|
@@ -1831,11 +1883,85 @@ function readAttributes(text) {
|
|
|
1831
1883
|
}
|
|
1832
1884
|
return { attributes, rest: void 0 };
|
|
1833
1885
|
}
|
|
1834
|
-
var
|
|
1886
|
+
var PAIRS = /* @__PURE__ */ Symbol("pairs");
|
|
1887
|
+
var HEADER_FORMS = [
|
|
1888
|
+
{ directive: "#extinf", key: "http-header", carrier: PAIRS },
|
|
1889
|
+
{ directive: "#extinf", key: "http-user-agent", carrier: "User-Agent" },
|
|
1890
|
+
{ directive: "#extinf", key: "http-referrer", carrier: "Referer" },
|
|
1891
|
+
{ directive: "#extinf", key: "http-referer", carrier: "Referer" },
|
|
1892
|
+
{ directive: "#extvlcopt", key: "http-user-agent", carrier: "User-Agent" },
|
|
1893
|
+
{ directive: "#extvlcopt", key: "http-referrer", carrier: "Referer" },
|
|
1894
|
+
{ directive: "#extvlcopt", key: "http-referer", carrier: "Referer" },
|
|
1895
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.common_headers", carrier: PAIRS },
|
|
1896
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.manifest_headers", carrier: PAIRS },
|
|
1897
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.stream_headers", carrier: PAIRS }
|
|
1898
|
+
];
|
|
1899
|
+
var HEADER_NAMES = /* @__PURE__ */ new Map([["user-agent", "User-Agent"], ["referer", "Referer"], ["referrer", "Referer"]]);
|
|
1900
|
+
var NON_HEADER_OPTIONS = /* @__PURE__ */ new Set([
|
|
1901
|
+
"seekable",
|
|
1902
|
+
"reconnect_at_eof",
|
|
1903
|
+
"reconnect_streamed",
|
|
1904
|
+
"reconnect_delay_max",
|
|
1905
|
+
"icy",
|
|
1906
|
+
"icy_metadata_headers",
|
|
1907
|
+
"icy_metadata_packet"
|
|
1908
|
+
]);
|
|
1909
|
+
var RESERVED_HEADERS = /* @__PURE__ */ new Set(["host", "content-length", "connection", "proxy-authenticate", "proxy-authorization", "www-authenticate"]);
|
|
1910
|
+
var HEADER_TOKEN = /^[!#$%&'*+\-.^_\x60|~0-9A-Za-z]+$/;
|
|
1911
|
+
var HEADER_CONTROL = /[\x00-\x08\x0A-\x1F\x7F]/;
|
|
1912
|
+
var M3UHeaders = class {
|
|
1913
|
+
fields = /* @__PURE__ */ new Map();
|
|
1914
|
+
record() {
|
|
1915
|
+
return this.fields.size === 0 ? void 0 : Object.fromEntries(this.fields.values());
|
|
1916
|
+
}
|
|
1917
|
+
set(name2, raw) {
|
|
1918
|
+
const value = trimSpace(raw);
|
|
1919
|
+
if (!HEADER_TOKEN.test(name2) || value === "" || HEADER_CONTROL.test(value)) return;
|
|
1920
|
+
const lower2 = asciiLower(name2);
|
|
1921
|
+
if (RESERVED_HEADERS.has(lower2)) return;
|
|
1922
|
+
this.fields.set(lower2, [name2, value]);
|
|
1923
|
+
}
|
|
1924
|
+
apply(carrier, value) {
|
|
1925
|
+
if (carrier === PAIRS) this.setPairs(value);
|
|
1926
|
+
else this.set(carrier, value);
|
|
1927
|
+
}
|
|
1928
|
+
// `名=值&名=值`:名字前的 `!` 是 Kodi 的自定义头记号;值能按 URL 解码就解码,解不了按原样。
|
|
1929
|
+
setPairs(text) {
|
|
1930
|
+
for (const pair of headerPairs(text)) {
|
|
1931
|
+
if (pair === void 0) continue;
|
|
1932
|
+
const [name2, raw] = pair;
|
|
1933
|
+
const lower2 = asciiLower(name2);
|
|
1934
|
+
if (NON_HEADER_OPTIONS.has(lower2)) continue;
|
|
1935
|
+
this.set(HEADER_NAMES.get(lower2) ?? name2, decodedOr(raw));
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
function headerPairs(text) {
|
|
1940
|
+
return text.split("&").filter((pair) => pair !== "").map((pair) => {
|
|
1941
|
+
const equals = pair.indexOf("=");
|
|
1942
|
+
if (equals === -1) return void 0;
|
|
1943
|
+
const name2 = trimSpace(pair.slice(0, equals));
|
|
1944
|
+
return [name2.startsWith("!") ? name2.slice(1) : name2, pair.slice(equals + 1)];
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
function headerSuffix(line) {
|
|
1948
|
+
const bar = line.indexOf("|");
|
|
1949
|
+
if (bar <= 0) return void 0;
|
|
1950
|
+
const suffix = line.slice(bar + 1);
|
|
1951
|
+
const isHeaders = headerPairs(suffix).every((pair) => pair !== void 0 && HEADER_TOKEN.test(pair[0]));
|
|
1952
|
+
return isHeaders ? { url: trimSpace(line.slice(0, bar)), suffix } : void 0;
|
|
1953
|
+
}
|
|
1954
|
+
function decodedOr(raw) {
|
|
1955
|
+
try {
|
|
1956
|
+
return decodeURIComponent(raw);
|
|
1957
|
+
} catch {
|
|
1958
|
+
return raw;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1835
1961
|
function parseM3U(data) {
|
|
1836
1962
|
const playlist = { guideURLs: [], attributes: {}, entries: [] };
|
|
1837
1963
|
let info;
|
|
1838
|
-
let
|
|
1964
|
+
let directiveHeaders = [];
|
|
1839
1965
|
let group;
|
|
1840
1966
|
for (const raw of splitLines(textOf(data))) {
|
|
1841
1967
|
const line = trimSpace(raw);
|
|
@@ -1843,19 +1969,28 @@ function parseM3U(data) {
|
|
|
1843
1969
|
if (line[0] !== "#") {
|
|
1844
1970
|
const attributes = info?.attributes ?? /* @__PURE__ */ new Map();
|
|
1845
1971
|
const tvgName = nonEmpty(attributes.get("tvg-name"));
|
|
1972
|
+
const headers2 = new M3UHeaders();
|
|
1973
|
+
for (const form of HEADER_FORMS) {
|
|
1974
|
+
const value2 = form.directive === "#extinf" ? attributes.get(form.key) : void 0;
|
|
1975
|
+
if (value2 !== void 0) headers2.apply(form.carrier, value2);
|
|
1976
|
+
}
|
|
1977
|
+
for (const [carrier, value2] of directiveHeaders) headers2.apply(carrier, value2);
|
|
1978
|
+
const split = headerSuffix(line);
|
|
1979
|
+
const url = split?.url ?? line;
|
|
1980
|
+
if (split !== void 0) headers2.setPairs(split.suffix);
|
|
1846
1981
|
playlist.entries.push(compact({
|
|
1847
|
-
url
|
|
1848
|
-
title: nonEmpty(info?.title) ?? tvgName ??
|
|
1982
|
+
url,
|
|
1983
|
+
title: nonEmpty(info?.title) ?? tvgName ?? url,
|
|
1849
1984
|
duration: info?.duration ?? -1,
|
|
1850
1985
|
tvgId: nonEmpty(attributes.get("tvg-id")),
|
|
1851
1986
|
tvgName,
|
|
1852
1987
|
logo: nonEmpty(attributes.get("tvg-logo")),
|
|
1853
1988
|
group: nonEmpty(attributes.get("group-title")) ?? group,
|
|
1854
|
-
headers: headers2.
|
|
1989
|
+
headers: headers2.record(),
|
|
1855
1990
|
attributes: Object.fromEntries(attributes)
|
|
1856
1991
|
}));
|
|
1857
1992
|
info = void 0;
|
|
1858
|
-
|
|
1993
|
+
directiveHeaders = [];
|
|
1859
1994
|
group = void 0;
|
|
1860
1995
|
continue;
|
|
1861
1996
|
}
|
|
@@ -1876,13 +2011,13 @@ function parseM3U(data) {
|
|
|
1876
2011
|
const { attributes, rest } = readAttributes(duration === null ? value : value.slice(duration[0].length));
|
|
1877
2012
|
const seconds = duration === null ? -1 : Number(duration[1]);
|
|
1878
2013
|
info = { duration: Number.isFinite(seconds) ? seconds : -1, attributes, title: trimSpace(rest ?? "") };
|
|
1879
|
-
} else if (directive === "#extvlcopt") {
|
|
1880
|
-
const equals = value.indexOf("=");
|
|
1881
|
-
const name3 = VLC_HEADERS.get(asciiLower(trimSpace(equals === -1 ? value : value.slice(0, equals))));
|
|
1882
|
-
const headerValue = equals === -1 ? "" : trimSpace(value.slice(equals + 1));
|
|
1883
|
-
if (name3 !== void 0 && headerValue !== "") headers2.set(name3, headerValue);
|
|
1884
2014
|
} else if (directive === "#extgrp") {
|
|
1885
2015
|
group = nonEmpty(value);
|
|
2016
|
+
} else {
|
|
2017
|
+
const equals = value.indexOf("=");
|
|
2018
|
+
const key = asciiLower(trimSpace(equals === -1 ? value : value.slice(0, equals)));
|
|
2019
|
+
const form = HEADER_FORMS.find((row) => row.directive === directive && row.key === key);
|
|
2020
|
+
if (equals !== -1 && form !== void 0) directiveHeaders.push([form.carrier, value.slice(equals + 1)]);
|
|
1886
2021
|
}
|
|
1887
2022
|
}
|
|
1888
2023
|
return playlist;
|
|
@@ -2134,6 +2269,121 @@ function createMetadata(service) {
|
|
|
2134
2269
|
};
|
|
2135
2270
|
}
|
|
2136
2271
|
|
|
2272
|
+
// host/interop-crypto.ts
|
|
2273
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
2274
|
+
function padded(data, littleEndian) {
|
|
2275
|
+
const length = (data.length + 8 >> 6) + 1 << 6;
|
|
2276
|
+
const block = new Uint8Array(length);
|
|
2277
|
+
block.set(data);
|
|
2278
|
+
block[data.length] = 128;
|
|
2279
|
+
const view = new DataView(block.buffer);
|
|
2280
|
+
const bits = data.length * 8;
|
|
2281
|
+
const high = Math.floor(bits / 4294967296);
|
|
2282
|
+
const low = bits >>> 0;
|
|
2283
|
+
if (littleEndian) {
|
|
2284
|
+
view.setUint32(length - 8, low, true);
|
|
2285
|
+
view.setUint32(length - 4, high, true);
|
|
2286
|
+
} else {
|
|
2287
|
+
view.setUint32(length - 8, high);
|
|
2288
|
+
view.setUint32(length - 4, low);
|
|
2289
|
+
}
|
|
2290
|
+
return view;
|
|
2291
|
+
}
|
|
2292
|
+
var MD5_K = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
|
|
2293
|
+
var MD5_S = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21];
|
|
2294
|
+
function md5(data) {
|
|
2295
|
+
const view = padded(data, true);
|
|
2296
|
+
let a0 = 1732584193, b0 = 4023233417, c0 = 2562383102, d0 = 271733878;
|
|
2297
|
+
const m = new Array(16);
|
|
2298
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
2299
|
+
for (let i = 0; i < 16; i++) m[i] = view.getUint32(offset + i * 4, true);
|
|
2300
|
+
let a = a0, b = b0, c = c0, d = d0;
|
|
2301
|
+
for (let i = 0; i < 64; i++) {
|
|
2302
|
+
const round = i >> 4;
|
|
2303
|
+
let f, g;
|
|
2304
|
+
if (round === 0) {
|
|
2305
|
+
f = b & c | ~b & d;
|
|
2306
|
+
g = i;
|
|
2307
|
+
} else if (round === 1) {
|
|
2308
|
+
f = d & b | ~d & c;
|
|
2309
|
+
g = 5 * i + 1 & 15;
|
|
2310
|
+
} else if (round === 2) {
|
|
2311
|
+
f = b ^ c ^ d;
|
|
2312
|
+
g = 3 * i + 5 & 15;
|
|
2313
|
+
} else {
|
|
2314
|
+
f = c ^ (b | ~d);
|
|
2315
|
+
g = 7 * i & 15;
|
|
2316
|
+
}
|
|
2317
|
+
const next = d;
|
|
2318
|
+
d = c;
|
|
2319
|
+
c = b;
|
|
2320
|
+
b = b + rotl(a + f + MD5_K[i] + m[g] | 0, MD5_S[round << 2 | i & 3]) | 0;
|
|
2321
|
+
a = next;
|
|
2322
|
+
}
|
|
2323
|
+
a0 = a0 + a | 0;
|
|
2324
|
+
b0 = b0 + b | 0;
|
|
2325
|
+
c0 = c0 + c | 0;
|
|
2326
|
+
d0 = d0 + d | 0;
|
|
2327
|
+
}
|
|
2328
|
+
const out = new DataView(new ArrayBuffer(16));
|
|
2329
|
+
[a0, b0, c0, d0].forEach((word, i) => out.setUint32(i * 4, word >>> 0, true));
|
|
2330
|
+
return new Uint8Array(out.buffer);
|
|
2331
|
+
}
|
|
2332
|
+
var SM3_IV = [1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214];
|
|
2333
|
+
var p0 = (x) => x ^ rotl(x, 9) ^ rotl(x, 17);
|
|
2334
|
+
var p1 = (x) => x ^ rotl(x, 15) ^ rotl(x, 23);
|
|
2335
|
+
function sm3(data) {
|
|
2336
|
+
const view = padded(data, false);
|
|
2337
|
+
const v = [...SM3_IV];
|
|
2338
|
+
const w = new Array(68);
|
|
2339
|
+
const w1 = new Array(64);
|
|
2340
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
2341
|
+
for (let j = 0; j < 16; j++) w[j] = view.getUint32(offset + j * 4) | 0;
|
|
2342
|
+
for (let j = 16; j < 68; j++) w[j] = p1(w[j - 16] ^ w[j - 9] ^ rotl(w[j - 3], 15)) ^ rotl(w[j - 13], 7) ^ w[j - 6];
|
|
2343
|
+
for (let j = 0; j < 64; j++) w1[j] = w[j] ^ w[j + 4];
|
|
2344
|
+
let [a, b, c, d, e, f, g, h] = v;
|
|
2345
|
+
for (let j = 0; j < 64; j++) {
|
|
2346
|
+
const t = j < 16 ? 2043430169 : 2055708042;
|
|
2347
|
+
const ss1 = rotl(rotl(a, 12) + e + rotl(t, j % 32) | 0, 7);
|
|
2348
|
+
const ss2 = ss1 ^ rotl(a, 12);
|
|
2349
|
+
const ff = j < 16 ? a ^ b ^ c : a & b | a & c | b & c;
|
|
2350
|
+
const gg = j < 16 ? e ^ f ^ g : e & f | ~e & g;
|
|
2351
|
+
const tt1 = ff + d + ss2 + w1[j] | 0;
|
|
2352
|
+
const tt2 = gg + h + ss1 + w[j] | 0;
|
|
2353
|
+
d = c;
|
|
2354
|
+
c = rotl(b, 9);
|
|
2355
|
+
b = a;
|
|
2356
|
+
a = tt1;
|
|
2357
|
+
h = g;
|
|
2358
|
+
g = rotl(f, 19);
|
|
2359
|
+
f = e;
|
|
2360
|
+
e = p0(tt2);
|
|
2361
|
+
}
|
|
2362
|
+
[a, b, c, d, e, f, g, h].forEach((word, i) => {
|
|
2363
|
+
v[i] ^= word;
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
const out = new DataView(new ArrayBuffer(32));
|
|
2367
|
+
v.forEach((word, i) => out.setUint32(i * 4, word >>> 0));
|
|
2368
|
+
return new Uint8Array(out.buffer);
|
|
2369
|
+
}
|
|
2370
|
+
function rc4(key, data) {
|
|
2371
|
+
const s = new Uint8Array(256);
|
|
2372
|
+
for (let i = 0; i < 256; i++) s[i] = i;
|
|
2373
|
+
for (let i = 0, j = 0; i < 256; i++) {
|
|
2374
|
+
j = j + s[i] + key[i % key.length] & 255;
|
|
2375
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
2376
|
+
}
|
|
2377
|
+
const out = new Uint8Array(data.length);
|
|
2378
|
+
for (let n = 0, i = 0, j = 0; n < data.length; n++) {
|
|
2379
|
+
i = i + 1 & 255;
|
|
2380
|
+
j = j + s[i] & 255;
|
|
2381
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
2382
|
+
out[n] = data[n] ^ s[s[i] + s[j] & 255];
|
|
2383
|
+
}
|
|
2384
|
+
return out;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2137
2387
|
// host/json-depth.ts
|
|
2138
2388
|
function pluginJSONText(bytes2) {
|
|
2139
2389
|
if (bytes2[0] === 239 && bytes2[1] === 187 && bytes2[2] === 191) return void 0;
|
|
@@ -2922,15 +3172,30 @@ function createSubtle() {
|
|
|
2922
3172
|
};
|
|
2923
3173
|
}
|
|
2924
3174
|
var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
|
|
3175
|
+
var INTEROP_DIGESTS = /* @__PURE__ */ new Map([["md5", md5], ["sm3", sm3]]);
|
|
3176
|
+
function plainBytes(value) {
|
|
3177
|
+
if (typeof value === "string") return new TextEncoder().encode(value);
|
|
3178
|
+
if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]") return new Uint8Array(value);
|
|
3179
|
+
throw new TypeError("expected a Uint8Array or a string");
|
|
3180
|
+
}
|
|
2925
3181
|
async function plainDigest(algorithm, data) {
|
|
2926
|
-
const
|
|
2927
|
-
|
|
2928
|
-
|
|
3182
|
+
const lowered = String(algorithm).toLowerCase();
|
|
3183
|
+
const interop = INTEROP_DIGESTS.get(lowered);
|
|
3184
|
+
const name2 = DIGESTS.get(lowered);
|
|
3185
|
+
if (interop === void 0 && name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
|
|
3186
|
+
const bytes2 = plainBytes(data);
|
|
3187
|
+
return interop !== void 0 ? interop(bytes2) : new Uint8Array(await subtle().digest(name2, bytes2));
|
|
3188
|
+
}
|
|
3189
|
+
async function plainRC4(key, data) {
|
|
3190
|
+
const keyBytes = plainBytes(key);
|
|
3191
|
+
if (keyBytes.length < 1 || keyBytes.length > 256) throw new TypeError("krillplayer.crypto.rc4 needs a key of 1 to 256 bytes");
|
|
3192
|
+
return rc4(keyBytes, plainBytes(data));
|
|
2929
3193
|
}
|
|
2930
3194
|
function createCrypto() {
|
|
2931
3195
|
return {
|
|
2932
3196
|
randomBytes: (length) => globalThis.crypto.getRandomValues(new Uint8Array(length)),
|
|
2933
3197
|
digest: plainDigest,
|
|
3198
|
+
rc4: plainRC4,
|
|
2934
3199
|
subtle: createSubtle()
|
|
2935
3200
|
};
|
|
2936
3201
|
}
|
|
@@ -3703,7 +3968,7 @@ function readZip(zip) {
|
|
|
3703
3968
|
|
|
3704
3969
|
// trial-runner/cases.ts
|
|
3705
3970
|
import { readdir, readFile as readFile2 } from "node:fs/promises";
|
|
3706
|
-
import { join, relative } from "node:path";
|
|
3971
|
+
import { join as join2, relative } from "node:path";
|
|
3707
3972
|
|
|
3708
3973
|
// trial-runner/credentials.ts
|
|
3709
3974
|
import { readFile } from "node:fs/promises";
|
|
@@ -3716,11 +3981,21 @@ var BadJSON = class extends Error {
|
|
|
3716
3981
|
var JSON_DEPTH = 128;
|
|
3717
3982
|
var NUMBER = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;
|
|
3718
3983
|
function parseJSONBody(text) {
|
|
3984
|
+
return readJSON(text, true, () => {
|
|
3985
|
+
throw new BadJSON("duplicate key");
|
|
3986
|
+
});
|
|
3987
|
+
}
|
|
3988
|
+
function duplicateKeys(text) {
|
|
3989
|
+
const keys = [];
|
|
3990
|
+
readJSON(text, false, (key) => keys.push(key));
|
|
3991
|
+
return keys;
|
|
3992
|
+
}
|
|
3993
|
+
function readJSON(text, strict, onDuplicate) {
|
|
3719
3994
|
let index = 0;
|
|
3720
3995
|
let depth = 0;
|
|
3721
3996
|
const enter = () => {
|
|
3722
3997
|
depth += 1;
|
|
3723
|
-
if (depth > JSON_DEPTH) throw new BadJSON(`nesting deeper than ${JSON_DEPTH}`);
|
|
3998
|
+
if (strict && depth > JSON_DEPTH) throw new BadJSON(`nesting deeper than ${JSON_DEPTH}`);
|
|
3724
3999
|
};
|
|
3725
4000
|
const space = () => {
|
|
3726
4001
|
while (index < text.length && " \n\r".includes(text[index])) index += 1;
|
|
@@ -3777,7 +4052,7 @@ function parseJSONBody(text) {
|
|
|
3777
4052
|
space();
|
|
3778
4053
|
expect(":");
|
|
3779
4054
|
const entry = value();
|
|
3780
|
-
if (object2.has(key))
|
|
4055
|
+
if (object2.has(key)) onDuplicate(key);
|
|
3781
4056
|
object2.set(key, entry);
|
|
3782
4057
|
space();
|
|
3783
4058
|
if (text[index] === ",") {
|
|
@@ -3823,7 +4098,7 @@ function parseJSONBody(text) {
|
|
|
3823
4098
|
if (match === null) throw new NotJSON();
|
|
3824
4099
|
index += match[0].length;
|
|
3825
4100
|
const number2 = Number(match[0]);
|
|
3826
|
-
if (!Number.isFinite(number2)) throw new BadJSON("number is not a finite double");
|
|
4101
|
+
if (strict && !Number.isFinite(number2)) throw new BadJSON("number is not a finite double");
|
|
3827
4102
|
return number2;
|
|
3828
4103
|
};
|
|
3829
4104
|
const result = value();
|
|
@@ -3835,7 +4110,7 @@ function parseJSONBody(text) {
|
|
|
3835
4110
|
if (item instanceof Map) return [...item].some(([key, entry]) => !key.isWellFormed() || loneSurrogate(entry));
|
|
3836
4111
|
return false;
|
|
3837
4112
|
};
|
|
3838
|
-
if (loneSurrogate(result)) throw new BadJSON("lone surrogate in a string");
|
|
4113
|
+
if (strict && loneSurrogate(result)) throw new BadJSON("lone surrogate in a string");
|
|
3839
4114
|
return result;
|
|
3840
4115
|
}
|
|
3841
4116
|
function bodyKind(bytes2) {
|
|
@@ -3912,8 +4187,35 @@ var SECRET_VALUES = [
|
|
|
3912
4187
|
/\beyJ[\w-]{8,}\.eyJ[\w-]{8,}\.[\w-]+/,
|
|
3913
4188
|
/\b(?:access_key|access_token)=(?!(?:REDACTED-0{10}|REDACTED)(?![\w.-]))[\w.-]{16,}/
|
|
3914
4189
|
];
|
|
3915
|
-
var
|
|
3916
|
-
|
|
4190
|
+
var COOKIE_ATTRIBUTES = /* @__PURE__ */ new Set(["path", "domain", "expires", "max-age", "samesite", "secure", "httponly", "partitioned", "priority"]);
|
|
4191
|
+
function setCookieValueRanges(line) {
|
|
4192
|
+
const ranges = [];
|
|
4193
|
+
let start = 0;
|
|
4194
|
+
for (const [index, segment] of line.split(";").entries()) {
|
|
4195
|
+
const end = start + segment.length;
|
|
4196
|
+
const equals = segment.indexOf("=");
|
|
4197
|
+
const name2 = (equals < 0 ? segment : segment.slice(0, equals)).trim().toLowerCase();
|
|
4198
|
+
if (index === 0) {
|
|
4199
|
+
if (equals < 0) return void 0;
|
|
4200
|
+
ranges.push([start + equals + 1, end]);
|
|
4201
|
+
} else if (segment.trim() !== "" && !COOKIE_ATTRIBUTES.has(name2)) {
|
|
4202
|
+
ranges.push(equals < 0 ? [start + segment.length - segment.trimStart().length, end] : [start + equals + 1, end]);
|
|
4203
|
+
}
|
|
4204
|
+
start = end + 1;
|
|
4205
|
+
}
|
|
4206
|
+
return ranges;
|
|
4207
|
+
}
|
|
4208
|
+
var redactSetCookie = (lines) => lines.split("\n").map((line) => {
|
|
4209
|
+
const ranges = setCookieValueRanges(line);
|
|
4210
|
+
return ranges === void 0 ? line : ranges.reduceRight((text, [from, to]) => `${text.slice(0, from)}${REDACTED}${text.slice(to)}`, line);
|
|
4211
|
+
}).join("\n");
|
|
4212
|
+
var isPlaceholder = (value) => isRedacted(value) || isFakeId(value);
|
|
4213
|
+
var COOKIE_PAIR = /^[^=;]*=([^;]*)$/;
|
|
4214
|
+
function cookieValues(header, value) {
|
|
4215
|
+
const values = header === "set-cookie" ? value.split("\n").flatMap((line) => setCookieValueRanges(line)?.map(([from, to]) => line.slice(from, to)) ?? [void 0]) : value.split(/;[ \t]*/).map((pair) => COOKIE_PAIR.exec(pair)?.[1]);
|
|
4216
|
+
return values.every((entry) => entry !== void 0) ? values : void 0;
|
|
4217
|
+
}
|
|
4218
|
+
var isRedactedCookie = (header, value) => (header === "cookie" || header === "set-cookie") && cookieValues(header, value)?.every((entry) => entry === "" || isPlaceholder(entry)) === true;
|
|
3917
4219
|
function redactHeaders(headers2) {
|
|
3918
4220
|
return Object.fromEntries(Object.entries(headers2).flatMap(([name2, value]) => {
|
|
3919
4221
|
if (name2.toLowerCase() === "set-cookie") return [[name2, redactSetCookie(value)]];
|
|
@@ -4019,8 +4321,7 @@ function findingsIn(value, path, findings) {
|
|
|
4019
4321
|
return;
|
|
4020
4322
|
}
|
|
4021
4323
|
for (const [key, entry] of Object.entries(value)) {
|
|
4022
|
-
|
|
4023
|
-
if (isSecretName(key) && typeof entry === "string" && !redacted && entry !== "") {
|
|
4324
|
+
if (isSecretName(key) && typeof entry === "string" && entry !== "" && !isPlaceholder(entry) && !isRedactedCookie(key.toLowerCase(), entry)) {
|
|
4024
4325
|
findings.push(`${path}.${key}: ${key}`);
|
|
4025
4326
|
}
|
|
4026
4327
|
findingsIn(entry, `${path}.${key}`, findings);
|
|
@@ -4037,7 +4338,9 @@ async function scanDirectories(directories) {
|
|
|
4037
4338
|
for (const directory of directories) {
|
|
4038
4339
|
for (const file of await jsonFiles(directory)) {
|
|
4039
4340
|
files2 += 1;
|
|
4040
|
-
|
|
4341
|
+
const text = await readFile(file, "utf8");
|
|
4342
|
+
for (const finding of scanValue(JSON.parse(text))) findings.push(`${file} ${finding}`);
|
|
4343
|
+
for (const key of duplicateKeys(text)) findings.push(`${file} duplicate key ${JSON.stringify(key)}`);
|
|
4041
4344
|
}
|
|
4042
4345
|
}
|
|
4043
4346
|
return { files: files2, findings };
|
|
@@ -4146,7 +4449,7 @@ function recordingFetch(fetch) {
|
|
|
4146
4449
|
}
|
|
4147
4450
|
async function jsonFiles(directory) {
|
|
4148
4451
|
const entries = await readdir(directory, { recursive: true, withFileTypes: true });
|
|
4149
|
-
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.parentPath.includes("node_modules")).map((entry) =>
|
|
4452
|
+
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.parentPath.includes("node_modules")).map((entry) => join2(entry.parentPath, entry.name)).sort();
|
|
4150
4453
|
}
|
|
4151
4454
|
var BYTE_ORDER_MARK_IN_CASE = "case file holds U+FEFF, which the Swift kernel's JSON reader drops; keep such text as $bytes";
|
|
4152
4455
|
var holdsByteOrderMark = (raw) => raw.includes("\uFEFF") || /\\u[fF][eE][fF][fF]/.test(raw);
|
|
@@ -4235,8 +4538,8 @@ import { constants } from "node:fs";
|
|
|
4235
4538
|
import { access, mkdir, mkdtemp, readdir as readdir2, readFile as readFile3, rename, rm, stat } from "node:fs/promises";
|
|
4236
4539
|
import { createRequire } from "node:module";
|
|
4237
4540
|
import { homedir } from "node:os";
|
|
4238
|
-
import { dirname, join as
|
|
4239
|
-
import { fileURLToPath } from "node:url";
|
|
4541
|
+
import { dirname, join as join3, relative as relative2 } from "node:path";
|
|
4542
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
4240
4543
|
import { promisify } from "node:util";
|
|
4241
4544
|
|
|
4242
4545
|
// host/globals.ts
|
|
@@ -4348,7 +4651,7 @@ function decode(json, blob) {
|
|
|
4348
4651
|
}
|
|
4349
4652
|
|
|
4350
4653
|
// trial-runner/engine.ts
|
|
4351
|
-
var here = dirname(
|
|
4654
|
+
var here = dirname(fileURLToPath2(import.meta.url));
|
|
4352
4655
|
var run3 = promisify(execFile);
|
|
4353
4656
|
var KERNEL_LIMITS = {
|
|
4354
4657
|
memoryBytes: RUNTIME_LIMITS.memoryBytes,
|
|
@@ -4358,17 +4661,18 @@ var KERNEL_LIMITS = {
|
|
|
4358
4661
|
var packagedKernel;
|
|
4359
4662
|
function useKernelDirectory(directory) {
|
|
4360
4663
|
packagedKernel = directory;
|
|
4664
|
+
usePublicSuffixListFrom(directory);
|
|
4361
4665
|
}
|
|
4362
4666
|
function kernelDirectory() {
|
|
4363
|
-
return process.env.KRILLPLAYER_KERNEL_DIR ?? packagedKernel ??
|
|
4667
|
+
return process.env.KRILLPLAYER_KERNEL_DIR ?? packagedKernel ?? join3(here, "../../Packages/Kernel");
|
|
4364
4668
|
}
|
|
4365
4669
|
var FLAGS = ["-O2", "-D_GNU_SOURCE", "-DQUICKJS_NG_BUILD", "-DNDEBUG", "-w"];
|
|
4366
4670
|
async function files(directory) {
|
|
4367
4671
|
const entries = await readdir2(directory, { withFileTypes: true, recursive: true });
|
|
4368
|
-
return entries.filter((entry) => entry.isFile()).map((entry) =>
|
|
4672
|
+
return entries.filter((entry) => entry.isFile()).map((entry) => join3(entry.parentPath, entry.name)).sort();
|
|
4369
4673
|
}
|
|
4370
|
-
var DRIVER =
|
|
4371
|
-
async function engineSourceHash(quickjs =
|
|
4674
|
+
var DRIVER = join3(here, "engine/engine.c");
|
|
4675
|
+
async function engineSourceHash(quickjs = join3(kernelDirectory(), "Sources/CQuickJS")) {
|
|
4372
4676
|
const hash = createHash("sha256").update(JSON.stringify(FLAGS)).update("engine.c").update(await readFile3(DRIVER));
|
|
4373
4677
|
for (const file of await files(quickjs)) hash.update(relative2(quickjs, file)).update(await readFile3(file));
|
|
4374
4678
|
return hash.digest("hex");
|
|
@@ -4378,7 +4682,7 @@ async function prebuilt(source) {
|
|
|
4378
4682
|
try {
|
|
4379
4683
|
const manifest = createRequire(import.meta.url).resolve(`${ENGINE_PACKAGE()}/engine.json`);
|
|
4380
4684
|
if (JSON.parse(await readFile3(manifest, "utf8"))?.source !== source) return void 0;
|
|
4381
|
-
const binary2 =
|
|
4685
|
+
const binary2 = join3(dirname(manifest), "engine");
|
|
4382
4686
|
return await executable(binary2) ? binary2 : void 0;
|
|
4383
4687
|
} catch {
|
|
4384
4688
|
return void 0;
|
|
@@ -4394,7 +4698,7 @@ async function executable(file) {
|
|
|
4394
4698
|
}
|
|
4395
4699
|
var environment = (name2) => process.env[name2] || void 0;
|
|
4396
4700
|
async function build() {
|
|
4397
|
-
const quickjs =
|
|
4701
|
+
const quickjs = join3(kernelDirectory(), "Sources/CQuickJS");
|
|
4398
4702
|
const compiler = environment("CC") ?? "cc";
|
|
4399
4703
|
const source = await engineSourceHash(quickjs).catch((error) => {
|
|
4400
4704
|
throw new EngineFailure(`could not read the QuickJS-ng engine sources in ${quickjs}: ${error.message}`);
|
|
@@ -4408,15 +4712,15 @@ async function build() {
|
|
|
4408
4712
|
}
|
|
4409
4713
|
}
|
|
4410
4714
|
async function compileEngine(output, { compiler = environment("CC") ?? "cc", arch } = {}) {
|
|
4411
|
-
const quickjs =
|
|
4715
|
+
const quickjs = join3(kernelDirectory(), "Sources/CQuickJS");
|
|
4412
4716
|
await run3(compiler, [
|
|
4413
4717
|
...FLAGS,
|
|
4414
4718
|
...arch === void 0 ? [] : ["-arch", arch],
|
|
4415
|
-
`-I${
|
|
4719
|
+
`-I${join3(quickjs, "include")}`,
|
|
4416
4720
|
`-I${quickjs}`,
|
|
4417
4721
|
DRIVER,
|
|
4418
|
-
|
|
4419
|
-
|
|
4722
|
+
join3(quickjs, "kernel_qjs.c"),
|
|
4723
|
+
join3(quickjs, "quickjs_vendor.c"),
|
|
4420
4724
|
"-lm",
|
|
4421
4725
|
"-lpthread",
|
|
4422
4726
|
"-o",
|
|
@@ -4426,14 +4730,14 @@ async function compileEngine(output, { compiler = environment("CC") ?? "cc", arc
|
|
|
4426
4730
|
async function compile(quickjs, compiler, source) {
|
|
4427
4731
|
const version = (await run3(compiler, ["--version"])).stdout;
|
|
4428
4732
|
const key = createHash("sha256").update(source).update(version).digest("hex");
|
|
4429
|
-
const cache = environment("KRILLPLAYER_ENGINE_CACHE") ??
|
|
4430
|
-
const target =
|
|
4431
|
-
const binary2 =
|
|
4733
|
+
const cache = environment("KRILLPLAYER_ENGINE_CACHE") ?? join3(environment("XDG_CACHE_HOME") ?? join3(homedir(), ".cache"), "krillplayer-plugin/engine");
|
|
4734
|
+
const target = join3(cache, key.slice(0, 32));
|
|
4735
|
+
const binary2 = join3(target, "engine");
|
|
4432
4736
|
if (await executable(binary2)) return binary2;
|
|
4433
4737
|
await mkdir(cache, { recursive: true });
|
|
4434
|
-
const staging = await mkdtemp(
|
|
4738
|
+
const staging = await mkdtemp(join3(cache, "build-"));
|
|
4435
4739
|
try {
|
|
4436
|
-
await compileEngine(
|
|
4740
|
+
await compileEngine(join3(staging, "engine"), { compiler });
|
|
4437
4741
|
await rename(staging, target).catch(async (error) => {
|
|
4438
4742
|
if (error.code !== "ENOTEMPTY" && error.code !== "EEXIST") throw error;
|
|
4439
4743
|
await rm(staging, { recursive: true, force: true });
|
|
@@ -4451,7 +4755,7 @@ function engineBinary() {
|
|
|
4451
4755
|
}
|
|
4452
4756
|
var prelude;
|
|
4453
4757
|
function preludeSource() {
|
|
4454
|
-
const path =
|
|
4758
|
+
const path = join3(kernelDirectory(), "Sources/Kernel/PluginPrelude.js");
|
|
4455
4759
|
prelude ??= readFile3(path, "utf8").then(
|
|
4456
4760
|
(template) => template.replaceAll("__GLOBALS__", `[${[...PLUGIN_GLOBALS].sort().map((name2) => JSON.stringify(name2)).join(", ")}]`),
|
|
4457
4761
|
(error) => {
|
|
@@ -4584,6 +4888,7 @@ var CALLS = {
|
|
|
4584
4888
|
"formats.xml": (k, [data]) => k.formats.xml(data),
|
|
4585
4889
|
"decompress": (k, [format2, data]) => k.decompress(format2, data),
|
|
4586
4890
|
"crypto.digest": (k, [algorithm, data]) => k.crypto.digest(algorithm, data),
|
|
4891
|
+
"crypto.rc4": (k, [key, data]) => k.crypto.rc4(key, data),
|
|
4587
4892
|
"crypto.randomBytes": (k, [length]) => k.crypto.randomBytes(length),
|
|
4588
4893
|
"crypto.subtle.generateKey": (k, [algorithm, extractable, usages]) => k.crypto.subtle.generateKey(algorithm, extractable, usages),
|
|
4589
4894
|
"crypto.subtle.importKey": (k, [format2, keyData, algorithm, extractable, usages]) => k.crypto.subtle.importKey(format2, keyData, algorithm, extractable, usages),
|
|
@@ -5087,9 +5392,9 @@ function checkManifest(manifest) {
|
|
|
5087
5392
|
// trial-runner/trial.ts
|
|
5088
5393
|
async function readFiles(path) {
|
|
5089
5394
|
const entries = path.endsWith(".zip") ? [...readZip(await readFile4(path))] : await (async () => {
|
|
5090
|
-
const locales = (await readdir3(
|
|
5395
|
+
const locales = (await readdir3(join4(path, LOCALES)).catch(() => [])).filter((name2) => name2.endsWith(".json")).map((name2) => `${LOCALES}/${name2}`);
|
|
5091
5396
|
const names = [...(await readdir3(path)).filter((name2) => /\.m?js$/.test(name2) || name2 === "manifest.json"), ...locales];
|
|
5092
|
-
return Promise.all(names.map(async (name2) => [name2, await readFile4(
|
|
5397
|
+
return Promise.all(names.map(async (name2) => [name2, await readFile4(join4(path, name2))]));
|
|
5093
5398
|
})();
|
|
5094
5399
|
return new Map(entries.map(([name2, data]) => {
|
|
5095
5400
|
if (!name2.endsWith(".json")) return [name2, Buffer.from(data).toString("utf8")];
|
|
@@ -5114,10 +5419,10 @@ async function readPlugin(path) {
|
|
|
5114
5419
|
const manifest = JSON.parse(files2.get("manifest.json") ?? "{}");
|
|
5115
5420
|
const source = files2.get(scripts[0]);
|
|
5116
5421
|
const checked = checkPlugin(source);
|
|
5117
|
-
const capabilities = Array.isArray(manifest.capabilities) || checked.violations.length > 0 ? manifest.capabilities : await loadPlugin(source, { identifier:
|
|
5422
|
+
const capabilities = Array.isArray(manifest.capabilities) || checked.violations.length > 0 ? manifest.capabilities : await loadPlugin(source, { identifier: join4(path, scripts[0]), allowCodeGeneration: !checked.exports.includes("status") }).then((namespace) => capabilitiesOf(namespace).capabilities, () => void 0);
|
|
5118
5423
|
return {
|
|
5119
5424
|
id: manifest.id ?? basename(resolve(path)),
|
|
5120
|
-
file:
|
|
5425
|
+
file: join4(path, scripts[0]),
|
|
5121
5426
|
name: scripts[0],
|
|
5122
5427
|
source,
|
|
5123
5428
|
network: { hosts: manifest.hosts ?? [], userProvidedURLs: manifest.userProvidedURLs ?? false },
|
|
@@ -5465,14 +5770,14 @@ if (false) {
|
|
|
5465
5770
|
}
|
|
5466
5771
|
|
|
5467
5772
|
// packer/pack.ts
|
|
5468
|
-
var TEMPLATES =
|
|
5469
|
-
var SAMPLES =
|
|
5470
|
-
var SAMPLE_PACKAGES =
|
|
5773
|
+
var TEMPLATES = fileURLToPath3(new URL("../templates/", import.meta.url));
|
|
5774
|
+
var SAMPLES = fileURLToPath3(new URL("../samples/src/", import.meta.url));
|
|
5775
|
+
var SAMPLE_PACKAGES = fileURLToPath3(new URL("../samples/dist/", import.meta.url));
|
|
5471
5776
|
var ICON = "icon.png";
|
|
5472
5777
|
var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
5473
5778
|
var LOCALES2 = "locales";
|
|
5474
5779
|
async function dictionaries(directory) {
|
|
5475
|
-
const files2 = (await readdir4(
|
|
5780
|
+
const files2 = (await readdir4(join5(directory, LOCALES2)).catch(() => [])).sort();
|
|
5476
5781
|
const problems = [];
|
|
5477
5782
|
const tags = /* @__PURE__ */ new Map();
|
|
5478
5783
|
const result = [];
|
|
@@ -5488,7 +5793,7 @@ async function dictionaries(directory) {
|
|
|
5488
5793
|
continue;
|
|
5489
5794
|
}
|
|
5490
5795
|
tags.set(tag, file);
|
|
5491
|
-
const data = await readFile5(
|
|
5796
|
+
const data = await readFile5(join5(directory, LOCALES2, file));
|
|
5492
5797
|
bytes2 += data.length;
|
|
5493
5798
|
let table;
|
|
5494
5799
|
try {
|
|
@@ -5536,12 +5841,12 @@ async function pack(directory, warn = () => {
|
|
|
5536
5841
|
const source = result.outputFiles[0].text;
|
|
5537
5842
|
const { exports, violations } = checkPlugin(source);
|
|
5538
5843
|
if (violations.length > 0) throw new Error(`${directory}: ${violations.join("; ")}`);
|
|
5539
|
-
const namespace = await loadPlugin(source, { identifier:
|
|
5844
|
+
const namespace = await loadPlugin(source, { identifier: join5(directory, "plugin.js"), allowCodeGeneration: !exports.includes("status") });
|
|
5540
5845
|
const { capabilities, problems } = capabilitiesOf(namespace);
|
|
5541
5846
|
if (capabilities.length === 0 && problems.length === 0) problems.push("exports no capability; a plugin exports at least one slot or resolve");
|
|
5542
5847
|
if (problems.length > 0) throw new Error(`${directory}: ${problems.join("; ")}`);
|
|
5543
5848
|
for (const name2 of notYetUsedExports(namespace)) warn(`WARN ${directory}: exports ${name2}, which this version of the App does not call yet (App \u5C1A\u672A\u4F7F\u7528)`);
|
|
5544
|
-
const { default: metadata } = await import(pathToFileURL(
|
|
5849
|
+
const { default: metadata } = await import(pathToFileURL(join5(directory, "manifest.ts")).href);
|
|
5545
5850
|
if (metadata.interfaceLevel > CONTRACT.interfaceLevel || metadata.contractRevision !== CONTRACT.revision) {
|
|
5546
5851
|
throw new Error(`${directory}/manifest.ts targets interface level ${metadata.interfaceLevel} revision ${metadata.contractRevision}; the contract is level ${CONTRACT.interfaceLevel} revision ${CONTRACT.revision}`);
|
|
5547
5852
|
}
|
|
@@ -5556,7 +5861,7 @@ async function pack(directory, warn = () => {
|
|
|
5556
5861
|
throw new Error(`${directory}/manifest.ts: language ${metadata.language} is not a language tag (for example zh-Hans, en, ja)`);
|
|
5557
5862
|
}
|
|
5558
5863
|
const manifest = { ...metadata, ...language === void 0 ? {} : { language }, capabilities };
|
|
5559
|
-
const icon = await readFile5(
|
|
5864
|
+
const icon = await readFile5(join5(directory, ICON)).catch(() => void 0);
|
|
5560
5865
|
if (icon !== void 0 && !icon.subarray(0, 8).equals(PNG_SIGNATURE)) throw new Error(`${directory}/${ICON} is not a PNG`);
|
|
5561
5866
|
return writeZip([
|
|
5562
5867
|
{ name: "manifest.json", data: Buffer.from(`${JSON.stringify(manifest, null, 2)}
|
|
@@ -5578,20 +5883,20 @@ if (false) {
|
|
|
5578
5883
|
}
|
|
5579
5884
|
|
|
5580
5885
|
// package/cli.ts
|
|
5581
|
-
var here2 = dirname2(
|
|
5886
|
+
var here2 = dirname2(fileURLToPath4(import.meta.url));
|
|
5582
5887
|
var ROOT = basename2(here2) === "dist" ? dirname2(here2) : here2;
|
|
5583
5888
|
var PACKAGED = basename2(here2) === "dist";
|
|
5584
|
-
if (PACKAGED) useKernelDirectory(
|
|
5585
|
-
var TEMPLATES2 = PACKAGED ?
|
|
5586
|
-
var SKILL =
|
|
5889
|
+
if (PACKAGED) useKernelDirectory(join6(ROOT, "kernel"));
|
|
5890
|
+
var TEMPLATES2 = PACKAGED ? join6(ROOT, "templates") : join6(ROOT, "../templates");
|
|
5891
|
+
var SKILL = join6(ROOT, "skill/krillplayer-plugin");
|
|
5587
5892
|
var PACKAGE_NAME = "krillplayer-plugin";
|
|
5588
5893
|
function plugin(directory) {
|
|
5589
5894
|
const root = resolve3(directory ?? ".");
|
|
5590
|
-
return { root, cases:
|
|
5895
|
+
return { root, cases: join6(root, "cases"), zip: join6(root, "dist", `${basename2(root)}.zip`) };
|
|
5591
5896
|
}
|
|
5592
5897
|
function requirePlugin(directory) {
|
|
5593
5898
|
for (const file of ["plugin.ts", "manifest.ts"]) {
|
|
5594
|
-
if (!existsSync(
|
|
5899
|
+
if (!existsSync(join6(directory, file))) throw new UsageError(`${directory} has no ${file}; run this in a plugin directory, or npx ${PACKAGE_NAME} new <dir>`);
|
|
5595
5900
|
}
|
|
5596
5901
|
}
|
|
5597
5902
|
async function bundle(directory, out, log) {
|
|
@@ -5630,38 +5935,38 @@ var COMPILER_OPTIONS = {
|
|
|
5630
5935
|
};
|
|
5631
5936
|
var SCAFFOLD_TSCONFIG = { compilerOptions: COMPILER_OPTIONS, include: ["plugin.ts", "manifest.ts", "src/**/*.ts"] };
|
|
5632
5937
|
async function fallbackConfig(directory) {
|
|
5633
|
-
const config =
|
|
5634
|
-
await writeFile3(config, JSON.stringify({ compilerOptions: COMPILER_OPTIONS, files: ["plugin.ts", "manifest.ts"].map((file) =>
|
|
5938
|
+
const config = join6(await mkdtemp2(join6(tmpdir(), "krillplayer-plugin-tsconfig-")), "tsconfig.json");
|
|
5939
|
+
await writeFile3(config, JSON.stringify({ compilerOptions: COMPILER_OPTIONS, files: ["plugin.ts", "manifest.ts"].map((file) => join6(directory, file)) }));
|
|
5635
5940
|
return config;
|
|
5636
5941
|
}
|
|
5637
5942
|
async function newCommand(directory, { id, name: name2, template = "apple-hls" }, log) {
|
|
5638
5943
|
const target = resolve3(directory);
|
|
5639
5944
|
if (existsSync(target) && (await readdir5(target)).length > 0) throw new UsageError(`${target} already exists and is not empty`);
|
|
5640
|
-
const source =
|
|
5945
|
+
const source = join6(TEMPLATES2, template);
|
|
5641
5946
|
if (!existsSync(source)) throw new UsageError(`no template ${template}; templates: ${(await readdir5(TEMPLATES2)).join(", ")}`);
|
|
5642
5947
|
const slug = basename2(target).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "plugin";
|
|
5643
5948
|
const pluginId = id ?? `com.example.${slug}`;
|
|
5644
5949
|
await cp(source, target, { recursive: true });
|
|
5645
5950
|
for (const file of ["plugin.ts", "manifest.ts"]) {
|
|
5646
|
-
await writeFile3(
|
|
5951
|
+
await writeFile3(join6(target, file), rewriteImports(await readFile6(join6(target, file), "utf8")));
|
|
5647
5952
|
}
|
|
5648
|
-
const manifest = (await readFile6(
|
|
5649
|
-
await writeFile3(
|
|
5650
|
-
const { version } = JSON.parse(await readFile6(
|
|
5651
|
-
await writeFile3(
|
|
5953
|
+
const manifest = (await readFile6(join6(target, "manifest.ts"), "utf8")).replace(/id: "[^"]*"/, () => `id: ${JSON.stringify(pluginId)}`).replace(/sourceId: "[^"]*"/, () => `sourceId: ${JSON.stringify(slug)}`).replace(/name: "[^"]*"/, () => `name: ${JSON.stringify(name2 ?? basename2(target))}`).replace(/author: "[^"]*"/, () => `author: "<your name>"`).replace(/version: "[^"]*"/, () => `version: "0.1.0"`);
|
|
5954
|
+
await writeFile3(join6(target, "manifest.ts"), manifest);
|
|
5955
|
+
const { version } = JSON.parse(await readFile6(join6(ROOT, "package.json"), "utf8"));
|
|
5956
|
+
await writeFile3(join6(target, "package.json"), `${JSON.stringify(SCAFFOLD_PACKAGE(slug, version), null, 2)}
|
|
5652
5957
|
`);
|
|
5653
|
-
await writeFile3(
|
|
5958
|
+
await writeFile3(join6(target, "tsconfig.json"), `${JSON.stringify(SCAFFOLD_TSCONFIG, null, 2)}
|
|
5654
5959
|
`);
|
|
5655
|
-
await writeFile3(
|
|
5960
|
+
await writeFile3(join6(target, ".gitignore"), "node_modules/\ndist/\n");
|
|
5656
5961
|
log(`created ${target} from the ${template} template (contract revision ${CONTRACT.revision})`);
|
|
5657
5962
|
log(`next: cd ${relative3(process.cwd(), target) || "."} && npm install && npx ${PACKAGE_NAME} check`);
|
|
5658
5963
|
}
|
|
5659
5964
|
function tsc(directory) {
|
|
5660
|
-
for (const from of [
|
|
5965
|
+
for (const from of [join6(directory, "package.json"), join6(ROOT, "package.json")]) {
|
|
5661
5966
|
try {
|
|
5662
5967
|
const manifest = createRequire2(from).resolve("typescript/package.json");
|
|
5663
|
-
const bin = JSON.parse(
|
|
5664
|
-
return
|
|
5968
|
+
const bin = JSON.parse(readFileSync2(manifest, "utf8")).bin?.tsc ?? "bin/tsc";
|
|
5969
|
+
return join6(dirname2(manifest), bin);
|
|
5665
5970
|
} catch {
|
|
5666
5971
|
}
|
|
5667
5972
|
}
|
|
@@ -5673,7 +5978,7 @@ async function typecheck(directory, log) {
|
|
|
5673
5978
|
log(`FAIL typecheck: typescript is not installed; run npm install --save-dev typescript in ${directory}`);
|
|
5674
5979
|
return false;
|
|
5675
5980
|
}
|
|
5676
|
-
const own = existsSync(
|
|
5981
|
+
const own = existsSync(join6(directory, "tsconfig.json"));
|
|
5677
5982
|
const config = own ? directory : await fallbackConfig(directory);
|
|
5678
5983
|
try {
|
|
5679
5984
|
await promisify2(execFile2)(process.execPath, [compiler, "--noEmit", "-p", config], { cwd: directory, maxBuffer: 16 << 20 });
|