1 | import { inflateRaw } from 'node:zlib';
|
2 | import { LAUNCHERS } from "./launchers.mjs";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export function htmlEncode(s, dq = false, sq = false) {
|
13 | s = s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
14 | if (dq) {
|
15 | s = s.replace(/"/g, '"');
|
16 | }
|
17 | if (sq) {
|
18 | s = s.replace(/'/g, ''');
|
19 | }
|
20 | return s;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export function trimDotSlash(path) {
|
30 | return path.replace(/^(\.\/)+/, '');
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | export function pathRelativeBase(path, start, nocase = false) {
|
42 | const p = trimDotSlash(nocase ? path.toLowerCase() : path);
|
43 | const s = trimDotSlash(nocase ? start.toLowerCase() : start);
|
44 | if (p === s) {
|
45 | return '';
|
46 | }
|
47 | if (p.startsWith(`${s}/`)) {
|
48 | return path.substring(s.length + 1);
|
49 | }
|
50 | return null;
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | export function pathRelativeBaseMatch(path, start, nocase = false) {
|
62 | return pathRelativeBase(path, start, nocase) !== null;
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export function trimExtension(path, ext, nocase = false) {
|
74 | const p = nocase ? path.toLowerCase() : path;
|
75 | const e = nocase ? ext.toLowerCase() : ext;
|
76 | return p.endsWith(e) ? path.substring(0, p.length - e.length) : path;
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export async function launcher(id) {
|
86 | const b64 = LAUNCHERS[id];
|
87 | if (typeof b64 !== 'string') {
|
88 | throw new Error(`Invalid launcher id: ${id}`);
|
89 | }
|
90 | return new Promise((resolve, reject) => {
|
91 | inflateRaw(Buffer.from(b64, 'base64'), (err, data) => {
|
92 | if (err) {
|
93 | reject(err);
|
94 | return;
|
95 | }
|
96 | resolve(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
97 | });
|
98 | });
|
99 | }
|
100 |
|
\ | No newline at end of file |