@wp-playground/client 0.1.17 → 0.1.18
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 +38 -4
- package/index.d.ts +361 -160
- package/index.js +1126 -398
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,360 +1,1093 @@
|
|
|
1
|
+
class re {
|
|
2
|
+
#e;
|
|
3
|
+
#t;
|
|
4
|
+
/**
|
|
5
|
+
* @param server - The PHP server to browse.
|
|
6
|
+
* @param config - The browser configuration.
|
|
7
|
+
*/
|
|
8
|
+
constructor(e, n = {}) {
|
|
9
|
+
this.server = e, this.#e = {}, this.#t = {
|
|
10
|
+
handleRedirects: !1,
|
|
11
|
+
maxRedirects: 4,
|
|
12
|
+
...n
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sends the request to the server.
|
|
17
|
+
*
|
|
18
|
+
* When cookies are present in the response, this method stores
|
|
19
|
+
* them and sends them with any subsequent requests.
|
|
20
|
+
*
|
|
21
|
+
* When a redirection is present in the response, this method
|
|
22
|
+
* follows it by discarding a response and sending a subsequent
|
|
23
|
+
* request.
|
|
24
|
+
*
|
|
25
|
+
* @param request - The request.
|
|
26
|
+
* @param redirects - Internal. The number of redirects handled so far.
|
|
27
|
+
* @returns PHPRequestHandler response.
|
|
28
|
+
*/
|
|
29
|
+
async request(e, n = 0) {
|
|
30
|
+
const r = await this.server.request({
|
|
31
|
+
...e,
|
|
32
|
+
headers: {
|
|
33
|
+
...e.headers,
|
|
34
|
+
cookie: this.#r()
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (r.headers["set-cookie"] && this.#n(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && n < this.#t.maxRedirects) {
|
|
38
|
+
const o = new URL(
|
|
39
|
+
r.headers.location[0],
|
|
40
|
+
this.server.absoluteUrl
|
|
41
|
+
);
|
|
42
|
+
return this.request(
|
|
43
|
+
{
|
|
44
|
+
url: o.toString(),
|
|
45
|
+
method: "GET",
|
|
46
|
+
headers: {}
|
|
47
|
+
},
|
|
48
|
+
n + 1
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
#n(e) {
|
|
54
|
+
for (const n of e)
|
|
55
|
+
try {
|
|
56
|
+
if (!n.includes("="))
|
|
57
|
+
continue;
|
|
58
|
+
const r = n.indexOf("="), o = n.substring(0, r), a = n.substring(r + 1).split(";")[0];
|
|
59
|
+
this.#e[o] = a;
|
|
60
|
+
} catch (r) {
|
|
61
|
+
console.error(r);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
#r() {
|
|
65
|
+
const e = [];
|
|
66
|
+
for (const n in this.#e)
|
|
67
|
+
e.push(`${n}=${this.#e[n]}`);
|
|
68
|
+
return e.join("; ");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const oe = "http://example.com";
|
|
72
|
+
function j(t) {
|
|
73
|
+
return t.toString().substring(t.origin.length);
|
|
74
|
+
}
|
|
75
|
+
function B(t, e) {
|
|
76
|
+
return !e || !t.startsWith(e) ? t : t.substring(e.length);
|
|
77
|
+
}
|
|
78
|
+
function ie(t, e) {
|
|
79
|
+
return !e || t.startsWith(e) ? t : e + t;
|
|
80
|
+
}
|
|
81
|
+
class se {
|
|
82
|
+
constructor({ concurrency: e }) {
|
|
83
|
+
this._running = 0, this.concurrency = e, this.queue = [];
|
|
84
|
+
}
|
|
85
|
+
get running() {
|
|
86
|
+
return this._running;
|
|
87
|
+
}
|
|
88
|
+
async acquire() {
|
|
89
|
+
for (; ; )
|
|
90
|
+
if (this._running >= this.concurrency)
|
|
91
|
+
await new Promise((e) => this.queue.push(e));
|
|
92
|
+
else
|
|
93
|
+
return this._running++, () => {
|
|
94
|
+
this._running--, this.queue.length > 0 && this.queue.shift()();
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class I {
|
|
99
|
+
constructor(e, n, r, o = "", a = 0) {
|
|
100
|
+
this.httpStatusCode = e, this.headers = n, this.body = r, this.exitCode = a, this.errors = o;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Response body as JSON.
|
|
104
|
+
*/
|
|
105
|
+
get json() {
|
|
106
|
+
return JSON.parse(this.text);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Response body as text.
|
|
110
|
+
*/
|
|
111
|
+
get text() {
|
|
112
|
+
return new TextDecoder().decode(this.body);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Response body as bytes.
|
|
116
|
+
*/
|
|
117
|
+
get bytes() {
|
|
118
|
+
return this.body;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class ae {
|
|
122
|
+
#e;
|
|
123
|
+
#t;
|
|
124
|
+
#n;
|
|
125
|
+
#r;
|
|
126
|
+
#i;
|
|
127
|
+
#o;
|
|
128
|
+
#s;
|
|
129
|
+
#a;
|
|
130
|
+
#l;
|
|
131
|
+
/**
|
|
132
|
+
* @param php - The PHP instance.
|
|
133
|
+
* @param config - Request Handler configuration.
|
|
134
|
+
*/
|
|
135
|
+
constructor(e, n = {}) {
|
|
136
|
+
this.#a = new se({ concurrency: 1 });
|
|
137
|
+
const {
|
|
138
|
+
documentRoot: r = "/www/",
|
|
139
|
+
absoluteUrl: o = location.origin,
|
|
140
|
+
isStaticFilePath: a = () => !1
|
|
141
|
+
} = n;
|
|
142
|
+
this.php = e, this.#e = r, this.#l = a;
|
|
143
|
+
const i = new URL(o);
|
|
144
|
+
this.#n = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
|
|
145
|
+
const d = this.#r !== 443 && this.#r !== 80;
|
|
146
|
+
this.#i = [
|
|
147
|
+
this.#n,
|
|
148
|
+
d ? `:${this.#r}` : ""
|
|
149
|
+
].join(""), this.#o = i.pathname.replace(/\/+$/, ""), this.#s = [
|
|
150
|
+
`${this.#t}://`,
|
|
151
|
+
this.#i,
|
|
152
|
+
this.#o
|
|
153
|
+
].join("");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
157
|
+
* root.
|
|
158
|
+
*
|
|
159
|
+
* @param path The server path to convert to an absolute URL.
|
|
160
|
+
* @returns The absolute URL.
|
|
161
|
+
*/
|
|
162
|
+
pathToInternalUrl(e) {
|
|
163
|
+
return `${this.absoluteUrl}${e}`;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
167
|
+
* without the server pathname and scope.
|
|
168
|
+
*
|
|
169
|
+
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
170
|
+
* @returns The relative path.
|
|
171
|
+
*/
|
|
172
|
+
internalUrlToPath(e) {
|
|
173
|
+
const n = new URL(e);
|
|
174
|
+
return n.pathname.startsWith(this.#o) && (n.pathname = n.pathname.slice(this.#o.length)), j(n);
|
|
175
|
+
}
|
|
176
|
+
get isRequestRunning() {
|
|
177
|
+
return this.#a.running > 0;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
181
|
+
*/
|
|
182
|
+
get absoluteUrl() {
|
|
183
|
+
return this.#s;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The absolute URL of this PHPRequestHandler instance.
|
|
187
|
+
*/
|
|
188
|
+
get documentRoot() {
|
|
189
|
+
return this.#e;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Serves the request – either by serving a static file, or by
|
|
193
|
+
* dispatching it to the PHP runtime.
|
|
194
|
+
*
|
|
195
|
+
* @param request - The request.
|
|
196
|
+
* @returns The response.
|
|
197
|
+
*/
|
|
198
|
+
async request(e) {
|
|
199
|
+
const n = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
|
|
200
|
+
e.url,
|
|
201
|
+
n ? void 0 : oe
|
|
202
|
+
), o = B(
|
|
203
|
+
r.pathname,
|
|
204
|
+
this.#o
|
|
205
|
+
);
|
|
206
|
+
return this.#l(o) ? this.#c(o) : await this.#u(e, r);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Serves a static file from the PHP filesystem.
|
|
210
|
+
*
|
|
211
|
+
* @param path - The requested static file path.
|
|
212
|
+
* @returns The response.
|
|
213
|
+
*/
|
|
214
|
+
#c(e) {
|
|
215
|
+
const n = `${this.#e}${e}`;
|
|
216
|
+
if (!this.php.fileExists(n))
|
|
217
|
+
return new I(
|
|
218
|
+
404,
|
|
219
|
+
{},
|
|
220
|
+
new TextEncoder().encode("404 File not found")
|
|
221
|
+
);
|
|
222
|
+
const r = this.php.readFileAsBuffer(n);
|
|
223
|
+
return new I(
|
|
224
|
+
200,
|
|
225
|
+
{
|
|
226
|
+
"content-length": [`${r.byteLength}`],
|
|
227
|
+
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
228
|
+
// The code below won't return the correct mime-type if the extension
|
|
229
|
+
// was tampered with.
|
|
230
|
+
"content-type": [le(n)],
|
|
231
|
+
"accept-ranges": ["bytes"],
|
|
232
|
+
"cache-control": ["public, max-age=0"]
|
|
233
|
+
},
|
|
234
|
+
r
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Runs the requested PHP file with all the request and $_SERVER
|
|
239
|
+
* superglobals populated.
|
|
240
|
+
*
|
|
241
|
+
* @param request - The request.
|
|
242
|
+
* @returns The response.
|
|
243
|
+
*/
|
|
244
|
+
async #u(e, n) {
|
|
245
|
+
const r = await this.#a.acquire();
|
|
246
|
+
try {
|
|
247
|
+
this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
|
|
248
|
+
"HTTPS",
|
|
249
|
+
this.#s.startsWith("https://") ? "on" : ""
|
|
250
|
+
);
|
|
251
|
+
let o = "GET";
|
|
252
|
+
const a = [];
|
|
253
|
+
if (e.files) {
|
|
254
|
+
o = "POST";
|
|
255
|
+
for (const c in e.files) {
|
|
256
|
+
const s = e.files[c];
|
|
257
|
+
a.push({
|
|
258
|
+
key: c,
|
|
259
|
+
name: s.name,
|
|
260
|
+
type: s.type,
|
|
261
|
+
data: new Uint8Array(await s.arrayBuffer())
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const i = {
|
|
266
|
+
host: this.#i
|
|
267
|
+
};
|
|
268
|
+
let d;
|
|
269
|
+
return e.formData !== void 0 ? (o = "POST", i["content-type"] = "application/x-www-form-urlencoded", d = new URLSearchParams(
|
|
270
|
+
e.formData
|
|
271
|
+
).toString()) : d = e.body, await this.php.run({
|
|
272
|
+
relativeUri: ie(
|
|
273
|
+
j(n),
|
|
274
|
+
this.#o
|
|
275
|
+
),
|
|
276
|
+
protocol: this.#t,
|
|
277
|
+
method: e.method || o,
|
|
278
|
+
body: d,
|
|
279
|
+
fileInfos: a,
|
|
280
|
+
scriptPath: this.#d(n.pathname),
|
|
281
|
+
headers: {
|
|
282
|
+
...i,
|
|
283
|
+
...e.headers || {}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
} finally {
|
|
287
|
+
r();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
292
|
+
*
|
|
293
|
+
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
294
|
+
*
|
|
295
|
+
* @param requestedPath - The requested pathname.
|
|
296
|
+
* @returns The resolved filesystem path.
|
|
297
|
+
*/
|
|
298
|
+
#d(e) {
|
|
299
|
+
let n = B(e, this.#o);
|
|
300
|
+
n.includes(".php") ? n = n.split(".php")[0] + ".php" : (n.endsWith("/") || (n += "/"), n.endsWith("index.php") || (n += "index.php"));
|
|
301
|
+
const r = `${this.#e}${n}`;
|
|
302
|
+
return this.php.fileExists(r) ? r : `${this.#e}/index.php`;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function le(t) {
|
|
306
|
+
switch (t.split(".").pop()) {
|
|
307
|
+
case "css":
|
|
308
|
+
return "text/css";
|
|
309
|
+
case "js":
|
|
310
|
+
return "application/javascript";
|
|
311
|
+
case "png":
|
|
312
|
+
return "image/png";
|
|
313
|
+
case "jpg":
|
|
314
|
+
case "jpeg":
|
|
315
|
+
return "image/jpeg";
|
|
316
|
+
case "gif":
|
|
317
|
+
return "image/gif";
|
|
318
|
+
case "svg":
|
|
319
|
+
return "image/svg+xml";
|
|
320
|
+
case "woff":
|
|
321
|
+
return "font/woff";
|
|
322
|
+
case "woff2":
|
|
323
|
+
return "font/woff2";
|
|
324
|
+
case "ttf":
|
|
325
|
+
return "font/ttf";
|
|
326
|
+
case "otf":
|
|
327
|
+
return "font/otf";
|
|
328
|
+
case "eot":
|
|
329
|
+
return "font/eot";
|
|
330
|
+
case "ico":
|
|
331
|
+
return "image/x-icon";
|
|
332
|
+
case "html":
|
|
333
|
+
return "text/html";
|
|
334
|
+
case "json":
|
|
335
|
+
return "application/json";
|
|
336
|
+
case "xml":
|
|
337
|
+
return "application/xml";
|
|
338
|
+
case "txt":
|
|
339
|
+
case "md":
|
|
340
|
+
return "text/plain";
|
|
341
|
+
default:
|
|
342
|
+
return "application-octet-stream";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const W = {
|
|
346
|
+
0: "No error occurred. System call completed successfully.",
|
|
347
|
+
1: "Argument list too long.",
|
|
348
|
+
2: "Permission denied.",
|
|
349
|
+
3: "Address in use.",
|
|
350
|
+
4: "Address not available.",
|
|
351
|
+
5: "Address family not supported.",
|
|
352
|
+
6: "Resource unavailable, or operation would block.",
|
|
353
|
+
7: "Connection already in progress.",
|
|
354
|
+
8: "Bad file descriptor.",
|
|
355
|
+
9: "Bad message.",
|
|
356
|
+
10: "Device or resource busy.",
|
|
357
|
+
11: "Operation canceled.",
|
|
358
|
+
12: "No child processes.",
|
|
359
|
+
13: "Connection aborted.",
|
|
360
|
+
14: "Connection refused.",
|
|
361
|
+
15: "Connection reset.",
|
|
362
|
+
16: "Resource deadlock would occur.",
|
|
363
|
+
17: "Destination address required.",
|
|
364
|
+
18: "Mathematics argument out of domain of function.",
|
|
365
|
+
19: "Reserved.",
|
|
366
|
+
20: "File exists.",
|
|
367
|
+
21: "Bad address.",
|
|
368
|
+
22: "File too large.",
|
|
369
|
+
23: "Host is unreachable.",
|
|
370
|
+
24: "Identifier removed.",
|
|
371
|
+
25: "Illegal byte sequence.",
|
|
372
|
+
26: "Operation in progress.",
|
|
373
|
+
27: "Interrupted function.",
|
|
374
|
+
28: "Invalid argument.",
|
|
375
|
+
29: "I/O error.",
|
|
376
|
+
30: "Socket is connected.",
|
|
377
|
+
31: "There is a directory under that path.",
|
|
378
|
+
32: "Too many levels of symbolic links.",
|
|
379
|
+
33: "File descriptor value too large.",
|
|
380
|
+
34: "Too many links.",
|
|
381
|
+
35: "Message too large.",
|
|
382
|
+
36: "Reserved.",
|
|
383
|
+
37: "Filename too long.",
|
|
384
|
+
38: "Network is down.",
|
|
385
|
+
39: "Connection aborted by network.",
|
|
386
|
+
40: "Network unreachable.",
|
|
387
|
+
41: "Too many files open in system.",
|
|
388
|
+
42: "No buffer space available.",
|
|
389
|
+
43: "No such device.",
|
|
390
|
+
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
391
|
+
45: "Executable file format error.",
|
|
392
|
+
46: "No locks available.",
|
|
393
|
+
47: "Reserved.",
|
|
394
|
+
48: "Not enough space.",
|
|
395
|
+
49: "No message of the desired type.",
|
|
396
|
+
50: "Protocol not available.",
|
|
397
|
+
51: "No space left on device.",
|
|
398
|
+
52: "Function not supported.",
|
|
399
|
+
53: "The socket is not connected.",
|
|
400
|
+
54: "Not a directory or a symbolic link to a directory.",
|
|
401
|
+
55: "Directory not empty.",
|
|
402
|
+
56: "State not recoverable.",
|
|
403
|
+
57: "Not a socket.",
|
|
404
|
+
58: "Not supported, or operation not supported on socket.",
|
|
405
|
+
59: "Inappropriate I/O control operation.",
|
|
406
|
+
60: "No such device or address.",
|
|
407
|
+
61: "Value too large to be stored in data type.",
|
|
408
|
+
62: "Previous owner died.",
|
|
409
|
+
63: "Operation not permitted.",
|
|
410
|
+
64: "Broken pipe.",
|
|
411
|
+
65: "Protocol error.",
|
|
412
|
+
66: "Protocol not supported.",
|
|
413
|
+
67: "Protocol wrong type for socket.",
|
|
414
|
+
68: "Result too large.",
|
|
415
|
+
69: "Read-only file system.",
|
|
416
|
+
70: "Invalid seek.",
|
|
417
|
+
71: "No such process.",
|
|
418
|
+
72: "Reserved.",
|
|
419
|
+
73: "Connection timed out.",
|
|
420
|
+
74: "Text file busy.",
|
|
421
|
+
75: "Cross-device link.",
|
|
422
|
+
76: "Extension: Capabilities insufficient."
|
|
423
|
+
};
|
|
424
|
+
function m(t = "") {
|
|
425
|
+
return function(n, r, o) {
|
|
426
|
+
const a = o.value;
|
|
427
|
+
o.value = function(...i) {
|
|
428
|
+
try {
|
|
429
|
+
return a.apply(this, i);
|
|
430
|
+
} catch (d) {
|
|
431
|
+
const c = typeof d == "object" ? d?.errno : null;
|
|
432
|
+
if (c in W) {
|
|
433
|
+
const s = W[c], l = typeof i[0] == "string" ? i[0] : null, h = l !== null ? t.replaceAll("{path}", l) : t;
|
|
434
|
+
throw new Error(`${h}: ${s}`, {
|
|
435
|
+
cause: d
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
throw d;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
var ce = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, w = (t, e, n, r) => {
|
|
444
|
+
for (var o = r > 1 ? void 0 : r ? ue(e, n) : e, a = t.length - 1, i; a >= 0; a--)
|
|
445
|
+
(i = t[a]) && (o = (r ? i(e, n, o) : i(o)) || o);
|
|
446
|
+
return r && o && ce(e, n, o), o;
|
|
447
|
+
};
|
|
448
|
+
const f = "string", y = "number", G = [];
|
|
1
449
|
(function() {
|
|
2
450
|
return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
3
451
|
})();
|
|
452
|
+
class g {
|
|
453
|
+
/**
|
|
454
|
+
* Initializes a PHP runtime.
|
|
455
|
+
*
|
|
456
|
+
* @internal
|
|
457
|
+
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
458
|
+
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
459
|
+
*/
|
|
460
|
+
constructor(e, n) {
|
|
461
|
+
this.#t = [], this.#n = !1, e !== void 0 && this.initializeRuntime(e), n && (this.requestHandler = new re(
|
|
462
|
+
new ae(this, n)
|
|
463
|
+
));
|
|
464
|
+
}
|
|
465
|
+
#e;
|
|
466
|
+
#t;
|
|
467
|
+
#n;
|
|
468
|
+
initializeRuntime(e) {
|
|
469
|
+
if (this.#e)
|
|
470
|
+
throw new Error("PHP runtime already initialized.");
|
|
471
|
+
if (!G[e])
|
|
472
|
+
throw new Error("Invalid PHP runtime id.");
|
|
473
|
+
this.#e = G[e];
|
|
474
|
+
}
|
|
475
|
+
/** @inheritDoc */
|
|
476
|
+
setPhpIniPath(e) {
|
|
477
|
+
if (this.#n)
|
|
478
|
+
throw new Error("Cannot set PHP ini path after calling run().");
|
|
479
|
+
this.#e.ccall("wasm_set_phpini_path", null, ["string"], [e]);
|
|
480
|
+
}
|
|
481
|
+
/** @inheritDoc */
|
|
482
|
+
setPhpIniEntry(e, n) {
|
|
483
|
+
if (this.#n)
|
|
484
|
+
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
485
|
+
this.#t.push([e, n]);
|
|
486
|
+
}
|
|
487
|
+
/** @inheritDoc */
|
|
488
|
+
chdir(e) {
|
|
489
|
+
this.#e.FS.chdir(e);
|
|
490
|
+
}
|
|
491
|
+
/** @inheritDoc */
|
|
492
|
+
async request(e, n) {
|
|
493
|
+
if (!this.requestHandler)
|
|
494
|
+
throw new Error("No request handler available.");
|
|
495
|
+
return this.requestHandler.request(e, n);
|
|
496
|
+
}
|
|
497
|
+
/** @inheritDoc */
|
|
498
|
+
async run(e = {}) {
|
|
499
|
+
this.#n || (this.#r(), this.#n = !0), this.#u(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#a(e.method || "GET");
|
|
500
|
+
const { host: n, ...r } = {
|
|
501
|
+
host: "example.com:443",
|
|
502
|
+
...de(e.headers || {})
|
|
503
|
+
};
|
|
504
|
+
if (this.#s(n, e.protocol || "http"), this.#l(r), e.body && this.#c(e.body), e.fileInfos)
|
|
505
|
+
for (const o of e.fileInfos)
|
|
506
|
+
this.#d(o);
|
|
507
|
+
return e.code && this.#h(" ?>" + e.code), await this.#p();
|
|
508
|
+
}
|
|
509
|
+
#r() {
|
|
510
|
+
if (this.#t.length > 0) {
|
|
511
|
+
const e = this.#t.map(([n, r]) => `${n}=${r}`).join(`
|
|
512
|
+
`) + `
|
|
513
|
+
|
|
514
|
+
`;
|
|
515
|
+
this.#e.ccall(
|
|
516
|
+
"wasm_set_phpini_entries",
|
|
517
|
+
null,
|
|
518
|
+
[f],
|
|
519
|
+
[e]
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
this.#e.ccall("php_wasm_init", null, [], []);
|
|
523
|
+
}
|
|
524
|
+
cli(e) {
|
|
525
|
+
for (const n of e)
|
|
526
|
+
this.#e.ccall("wasm_add_cli_arg", null, [f], [n]);
|
|
527
|
+
return this.#e.ccall("run_cli", null, [], [], { async: !0 });
|
|
528
|
+
}
|
|
529
|
+
#i() {
|
|
530
|
+
const e = "/tmp/headers.json";
|
|
531
|
+
if (!this.fileExists(e))
|
|
532
|
+
throw new Error(
|
|
533
|
+
"SAPI Error: Could not find response headers file."
|
|
534
|
+
);
|
|
535
|
+
const n = JSON.parse(this.readFileAsText(e)), r = {};
|
|
536
|
+
for (const o of n.headers) {
|
|
537
|
+
if (!o.includes(": "))
|
|
538
|
+
continue;
|
|
539
|
+
const a = o.indexOf(": "), i = o.substring(0, a).toLowerCase(), d = o.substring(a + 2);
|
|
540
|
+
i in r || (r[i] = []), r[i].push(d);
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
headers: r,
|
|
544
|
+
httpStatusCode: n.status
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
#o(e) {
|
|
548
|
+
if (this.#e.ccall("wasm_set_request_uri", null, [f], [e]), e.includes("?")) {
|
|
549
|
+
const n = e.substring(e.indexOf("?") + 1);
|
|
550
|
+
this.#e.ccall(
|
|
551
|
+
"wasm_set_query_string",
|
|
552
|
+
null,
|
|
553
|
+
[f],
|
|
554
|
+
[n]
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
#s(e, n) {
|
|
559
|
+
this.#e.ccall("wasm_set_request_host", null, [f], [e]);
|
|
560
|
+
let r;
|
|
561
|
+
try {
|
|
562
|
+
r = parseInt(new URL(e).port, 10);
|
|
563
|
+
} catch {
|
|
564
|
+
}
|
|
565
|
+
(!r || isNaN(r) || r === 80) && (r = n === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [y], [r]), (n === "https" || !n && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
566
|
+
}
|
|
567
|
+
#a(e) {
|
|
568
|
+
this.#e.ccall("wasm_set_request_method", null, [f], [e]);
|
|
569
|
+
}
|
|
570
|
+
setSkipShebang(e) {
|
|
571
|
+
this.#e.ccall(
|
|
572
|
+
"wasm_set_skip_shebang",
|
|
573
|
+
null,
|
|
574
|
+
[y],
|
|
575
|
+
[e ? 1 : 0]
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
#l(e) {
|
|
579
|
+
e.cookie && this.#e.ccall(
|
|
580
|
+
"wasm_set_cookies",
|
|
581
|
+
null,
|
|
582
|
+
[f],
|
|
583
|
+
[e.cookie]
|
|
584
|
+
), e["content-type"] && this.#e.ccall(
|
|
585
|
+
"wasm_set_content_type",
|
|
586
|
+
null,
|
|
587
|
+
[f],
|
|
588
|
+
[e["content-type"]]
|
|
589
|
+
), e["content-length"] && this.#e.ccall(
|
|
590
|
+
"wasm_set_content_length",
|
|
591
|
+
null,
|
|
592
|
+
[y],
|
|
593
|
+
[parseInt(e["content-length"], 10)]
|
|
594
|
+
);
|
|
595
|
+
for (const n in e)
|
|
596
|
+
this.addServerGlobalEntry(
|
|
597
|
+
`HTTP_${n.toUpperCase().replace(/-/g, "_")}`,
|
|
598
|
+
e[n]
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
#c(e) {
|
|
602
|
+
this.#e.ccall("wasm_set_request_body", null, [f], [e]), this.#e.ccall(
|
|
603
|
+
"wasm_set_content_length",
|
|
604
|
+
null,
|
|
605
|
+
[y],
|
|
606
|
+
[e.length]
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
#u(e) {
|
|
610
|
+
this.#e.ccall("wasm_set_path_translated", null, [f], [e]);
|
|
611
|
+
}
|
|
612
|
+
addServerGlobalEntry(e, n) {
|
|
613
|
+
this.#e.ccall(
|
|
614
|
+
"wasm_add_SERVER_entry",
|
|
615
|
+
null,
|
|
616
|
+
[f, f],
|
|
617
|
+
[e, n]
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Adds file information to $_FILES superglobal in PHP.
|
|
622
|
+
*
|
|
623
|
+
* In particular:
|
|
624
|
+
* * Creates the file data in the filesystem
|
|
625
|
+
* * Registers the file details in PHP
|
|
626
|
+
*
|
|
627
|
+
* @param fileInfo - File details
|
|
628
|
+
*/
|
|
629
|
+
#d(e) {
|
|
630
|
+
const { key: n, name: r, type: o, data: a } = e, i = `/tmp/${Math.random().toFixed(20)}`;
|
|
631
|
+
this.writeFile(i, a);
|
|
632
|
+
const d = 0;
|
|
633
|
+
this.#e.ccall(
|
|
634
|
+
"wasm_add_uploaded_file",
|
|
635
|
+
null,
|
|
636
|
+
[f, f, f, f, y, y],
|
|
637
|
+
[n, r, o, i, d, a.byteLength]
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
#h(e) {
|
|
641
|
+
this.#e.ccall("wasm_set_php_code", null, [f], [e]);
|
|
642
|
+
}
|
|
643
|
+
async #p() {
|
|
644
|
+
const e = await await this.#e.ccall(
|
|
645
|
+
"wasm_sapi_handle_request",
|
|
646
|
+
y,
|
|
647
|
+
[],
|
|
648
|
+
[]
|
|
649
|
+
), { headers: n, httpStatusCode: r } = this.#i();
|
|
650
|
+
return new I(
|
|
651
|
+
r,
|
|
652
|
+
n,
|
|
653
|
+
this.readFileAsBuffer("/tmp/stdout"),
|
|
654
|
+
this.readFileAsText("/tmp/stderr"),
|
|
655
|
+
e
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
mkdirTree(e) {
|
|
659
|
+
this.#e.FS.mkdirTree(e);
|
|
660
|
+
}
|
|
661
|
+
readFileAsText(e) {
|
|
662
|
+
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
663
|
+
}
|
|
664
|
+
readFileAsBuffer(e) {
|
|
665
|
+
return this.#e.FS.readFile(e);
|
|
666
|
+
}
|
|
667
|
+
writeFile(e, n) {
|
|
668
|
+
this.#e.FS.writeFile(e, n);
|
|
669
|
+
}
|
|
670
|
+
unlink(e) {
|
|
671
|
+
this.#e.FS.unlink(e);
|
|
672
|
+
}
|
|
673
|
+
listFiles(e) {
|
|
674
|
+
if (!this.fileExists(e))
|
|
675
|
+
return [];
|
|
676
|
+
try {
|
|
677
|
+
return this.#e.FS.readdir(e).filter(
|
|
678
|
+
(n) => n !== "." && n !== ".."
|
|
679
|
+
);
|
|
680
|
+
} catch (n) {
|
|
681
|
+
return console.error(n, { path: e }), [];
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
isDir(e) {
|
|
685
|
+
return this.fileExists(e) ? this.#e.FS.isDir(
|
|
686
|
+
this.#e.FS.lookupPath(e).node.mode
|
|
687
|
+
) : !1;
|
|
688
|
+
}
|
|
689
|
+
fileExists(e) {
|
|
690
|
+
try {
|
|
691
|
+
return this.#e.FS.lookupPath(e), !0;
|
|
692
|
+
} catch {
|
|
693
|
+
return !1;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
mount(e, n) {
|
|
697
|
+
this.#e.FS.mount(
|
|
698
|
+
this.#e.FS.filesystems.NODEFS,
|
|
699
|
+
e,
|
|
700
|
+
n
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
w([
|
|
705
|
+
m('Could not create directory "{path}"')
|
|
706
|
+
], g.prototype, "mkdirTree", 1);
|
|
707
|
+
w([
|
|
708
|
+
m('Could not read "{path}"')
|
|
709
|
+
], g.prototype, "readFileAsText", 1);
|
|
710
|
+
w([
|
|
711
|
+
m('Could not read "{path}"')
|
|
712
|
+
], g.prototype, "readFileAsBuffer", 1);
|
|
713
|
+
w([
|
|
714
|
+
m('Could not write to "{path}"')
|
|
715
|
+
], g.prototype, "writeFile", 1);
|
|
716
|
+
w([
|
|
717
|
+
m('Could not unlink "{path}"')
|
|
718
|
+
], g.prototype, "unlink", 1);
|
|
719
|
+
w([
|
|
720
|
+
m('Could not list files in "{path}"')
|
|
721
|
+
], g.prototype, "listFiles", 1);
|
|
722
|
+
w([
|
|
723
|
+
m('Could not stat "{path}"')
|
|
724
|
+
], g.prototype, "isDir", 1);
|
|
725
|
+
w([
|
|
726
|
+
m('Could not stat "{path}"')
|
|
727
|
+
], g.prototype, "fileExists", 1);
|
|
728
|
+
w([
|
|
729
|
+
m("Could not mount a directory")
|
|
730
|
+
], g.prototype, "mount", 1);
|
|
731
|
+
function de(t) {
|
|
732
|
+
const e = {};
|
|
733
|
+
for (const n in t)
|
|
734
|
+
e[n.toLowerCase()] = t[n];
|
|
735
|
+
return e;
|
|
736
|
+
}
|
|
4
737
|
/**
|
|
5
738
|
* @license
|
|
6
739
|
* Copyright 2019 Google LLC
|
|
7
740
|
* SPDX-License-Identifier: Apache-2.0
|
|
8
741
|
*/
|
|
9
|
-
const
|
|
10
|
-
canHandle: (
|
|
11
|
-
serialize(
|
|
12
|
-
const { port1:
|
|
13
|
-
return
|
|
742
|
+
const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), C = Symbol("Comlink.thrown"), X = (t) => typeof t == "object" && t !== null || typeof t == "function", fe = {
|
|
743
|
+
canHandle: (t) => X(t) && t[K],
|
|
744
|
+
serialize(t) {
|
|
745
|
+
const { port1: e, port2: n } = new MessageChannel();
|
|
746
|
+
return N(t, e), [n, [n]];
|
|
14
747
|
},
|
|
15
|
-
deserialize(
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
canHandle: (
|
|
20
|
-
serialize({ value:
|
|
21
|
-
let
|
|
22
|
-
return
|
|
748
|
+
deserialize(t) {
|
|
749
|
+
return t.start(), M(t);
|
|
750
|
+
}
|
|
751
|
+
}, me = {
|
|
752
|
+
canHandle: (t) => X(t) && C in t,
|
|
753
|
+
serialize({ value: t }) {
|
|
754
|
+
let e;
|
|
755
|
+
return t instanceof Error ? e = {
|
|
23
756
|
isError: !0,
|
|
24
757
|
value: {
|
|
25
|
-
message:
|
|
26
|
-
name:
|
|
27
|
-
stack:
|
|
758
|
+
message: t.message,
|
|
759
|
+
name: t.name,
|
|
760
|
+
stack: t.stack
|
|
28
761
|
}
|
|
29
|
-
} :
|
|
762
|
+
} : e = { isError: !1, value: t }, [e, []];
|
|
30
763
|
},
|
|
31
|
-
deserialize(
|
|
32
|
-
throw
|
|
764
|
+
deserialize(t) {
|
|
765
|
+
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
33
766
|
}
|
|
34
|
-
},
|
|
35
|
-
["proxy",
|
|
36
|
-
["throw",
|
|
767
|
+
}, k = /* @__PURE__ */ new Map([
|
|
768
|
+
["proxy", fe],
|
|
769
|
+
["throw", me]
|
|
37
770
|
]);
|
|
38
|
-
function
|
|
39
|
-
for (const
|
|
40
|
-
if (
|
|
771
|
+
function we(t, e) {
|
|
772
|
+
for (const n of t)
|
|
773
|
+
if (e === n || n === "*" || n instanceof RegExp && n.test(e))
|
|
41
774
|
return !0;
|
|
42
775
|
return !1;
|
|
43
776
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
if (!
|
|
777
|
+
function N(t, e = globalThis, n = ["*"]) {
|
|
778
|
+
e.addEventListener("message", function r(o) {
|
|
779
|
+
if (!o || !o.data)
|
|
47
780
|
return;
|
|
48
|
-
if (!
|
|
49
|
-
console.warn(`Invalid origin '${
|
|
781
|
+
if (!we(n, o.origin)) {
|
|
782
|
+
console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
|
|
50
783
|
return;
|
|
51
784
|
}
|
|
52
|
-
const { id:
|
|
53
|
-
let
|
|
785
|
+
const { id: a, type: i, path: d } = Object.assign({ path: [] }, o.data), c = (o.data.argumentList || []).map(b);
|
|
786
|
+
let s;
|
|
54
787
|
try {
|
|
55
|
-
const
|
|
788
|
+
const l = d.slice(0, -1).reduce((u, p) => u[p], t), h = d.reduce((u, p) => u[p], t);
|
|
56
789
|
switch (i) {
|
|
57
790
|
case "GET":
|
|
58
|
-
|
|
791
|
+
s = h;
|
|
59
792
|
break;
|
|
60
793
|
case "SET":
|
|
61
|
-
|
|
794
|
+
l[d.slice(-1)[0]] = b(o.data.value), s = !0;
|
|
62
795
|
break;
|
|
63
796
|
case "APPLY":
|
|
64
|
-
|
|
797
|
+
s = h.apply(l, c);
|
|
65
798
|
break;
|
|
66
799
|
case "CONSTRUCT":
|
|
67
800
|
{
|
|
68
|
-
const
|
|
69
|
-
|
|
801
|
+
const u = new h(...c);
|
|
802
|
+
s = Ee(u);
|
|
70
803
|
}
|
|
71
804
|
break;
|
|
72
805
|
case "ENDPOINT":
|
|
73
806
|
{
|
|
74
|
-
const { port1:
|
|
75
|
-
|
|
807
|
+
const { port1: u, port2: p } = new MessageChannel();
|
|
808
|
+
N(t, p), s = Pe(u, [u]);
|
|
76
809
|
}
|
|
77
810
|
break;
|
|
78
811
|
case "RELEASE":
|
|
79
|
-
|
|
812
|
+
s = void 0;
|
|
80
813
|
break;
|
|
81
814
|
default:
|
|
82
815
|
return;
|
|
83
816
|
}
|
|
84
|
-
} catch (
|
|
85
|
-
|
|
817
|
+
} catch (l) {
|
|
818
|
+
s = { value: l, [C]: 0 };
|
|
86
819
|
}
|
|
87
|
-
Promise.resolve(
|
|
88
|
-
const [
|
|
89
|
-
|
|
90
|
-
}).catch((
|
|
91
|
-
const [
|
|
820
|
+
Promise.resolve(s).catch((l) => ({ value: l, [C]: 0 })).then((l) => {
|
|
821
|
+
const [h, u] = L(l);
|
|
822
|
+
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u), i === "RELEASE" && (e.removeEventListener("message", r), J(e), U in t && typeof t[U] == "function" && t[U]());
|
|
823
|
+
}).catch((l) => {
|
|
824
|
+
const [h, u] = L({
|
|
92
825
|
value: new TypeError("Unserializable return value"),
|
|
93
|
-
[
|
|
826
|
+
[C]: 0
|
|
94
827
|
});
|
|
95
|
-
|
|
828
|
+
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u);
|
|
96
829
|
});
|
|
97
|
-
}),
|
|
830
|
+
}), e.start && e.start();
|
|
98
831
|
}
|
|
99
|
-
function
|
|
100
|
-
return
|
|
832
|
+
function ge(t) {
|
|
833
|
+
return t.constructor.name === "MessagePort";
|
|
101
834
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
835
|
+
function J(t) {
|
|
836
|
+
ge(t) && t.close();
|
|
104
837
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
838
|
+
function M(t, e) {
|
|
839
|
+
return q(t, [], e);
|
|
107
840
|
}
|
|
108
|
-
function
|
|
109
|
-
if (
|
|
841
|
+
function S(t) {
|
|
842
|
+
if (t)
|
|
110
843
|
throw new Error("Proxy has been released and is not useable");
|
|
111
844
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
845
|
+
function Y(t) {
|
|
846
|
+
return P(t, {
|
|
114
847
|
type: "RELEASE"
|
|
115
848
|
}).then(() => {
|
|
116
|
-
|
|
849
|
+
J(t);
|
|
117
850
|
});
|
|
118
851
|
}
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
852
|
+
const O = /* @__PURE__ */ new WeakMap(), A = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
853
|
+
const e = (O.get(t) || 0) - 1;
|
|
854
|
+
O.set(t, e), e === 0 && Y(t);
|
|
122
855
|
});
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
|
|
856
|
+
function ye(t, e) {
|
|
857
|
+
const n = (O.get(e) || 0) + 1;
|
|
858
|
+
O.set(e, n), A && A.register(t, e, t);
|
|
126
859
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
860
|
+
function be(t) {
|
|
861
|
+
A && A.unregister(t);
|
|
129
862
|
}
|
|
130
|
-
function
|
|
863
|
+
function q(t, e = [], n = function() {
|
|
131
864
|
}) {
|
|
132
|
-
let
|
|
133
|
-
const
|
|
134
|
-
get(
|
|
135
|
-
if (
|
|
865
|
+
let r = !1;
|
|
866
|
+
const o = new Proxy(n, {
|
|
867
|
+
get(a, i) {
|
|
868
|
+
if (S(r), i === pe)
|
|
136
869
|
return () => {
|
|
137
|
-
|
|
870
|
+
be(o), Y(t), r = !0;
|
|
138
871
|
};
|
|
139
872
|
if (i === "then") {
|
|
140
|
-
if (
|
|
141
|
-
return { then: () =>
|
|
142
|
-
const
|
|
873
|
+
if (e.length === 0)
|
|
874
|
+
return { then: () => o };
|
|
875
|
+
const d = P(t, {
|
|
143
876
|
type: "GET",
|
|
144
|
-
path:
|
|
145
|
-
}).then(
|
|
146
|
-
return
|
|
877
|
+
path: e.map((c) => c.toString())
|
|
878
|
+
}).then(b);
|
|
879
|
+
return d.then.bind(d);
|
|
147
880
|
}
|
|
148
|
-
return
|
|
881
|
+
return q(t, [...e, i]);
|
|
149
882
|
},
|
|
150
|
-
set(
|
|
151
|
-
|
|
152
|
-
const [c,
|
|
153
|
-
return
|
|
883
|
+
set(a, i, d) {
|
|
884
|
+
S(r);
|
|
885
|
+
const [c, s] = L(d);
|
|
886
|
+
return P(t, {
|
|
154
887
|
type: "SET",
|
|
155
|
-
path: [...
|
|
888
|
+
path: [...e, i].map((l) => l.toString()),
|
|
156
889
|
value: c
|
|
157
|
-
},
|
|
890
|
+
}, s).then(b);
|
|
158
891
|
},
|
|
159
|
-
apply(
|
|
160
|
-
|
|
161
|
-
const c =
|
|
162
|
-
if (c ===
|
|
163
|
-
return
|
|
892
|
+
apply(a, i, d) {
|
|
893
|
+
S(r);
|
|
894
|
+
const c = e[e.length - 1];
|
|
895
|
+
if (c === he)
|
|
896
|
+
return P(t, {
|
|
164
897
|
type: "ENDPOINT"
|
|
165
|
-
}).then(
|
|
898
|
+
}).then(b);
|
|
166
899
|
if (c === "bind")
|
|
167
|
-
return
|
|
168
|
-
const [
|
|
169
|
-
return
|
|
900
|
+
return q(t, e.slice(0, -1));
|
|
901
|
+
const [s, l] = V(d);
|
|
902
|
+
return P(t, {
|
|
170
903
|
type: "APPLY",
|
|
171
|
-
path:
|
|
172
|
-
argumentList:
|
|
173
|
-
},
|
|
904
|
+
path: e.map((h) => h.toString()),
|
|
905
|
+
argumentList: s
|
|
906
|
+
}, l).then(b);
|
|
174
907
|
},
|
|
175
|
-
construct(
|
|
176
|
-
|
|
177
|
-
const [
|
|
178
|
-
return
|
|
908
|
+
construct(a, i) {
|
|
909
|
+
S(r);
|
|
910
|
+
const [d, c] = V(i);
|
|
911
|
+
return P(t, {
|
|
179
912
|
type: "CONSTRUCT",
|
|
180
|
-
path:
|
|
181
|
-
argumentList:
|
|
182
|
-
}, c).then(
|
|
913
|
+
path: e.map((s) => s.toString()),
|
|
914
|
+
argumentList: d
|
|
915
|
+
}, c).then(b);
|
|
183
916
|
}
|
|
184
917
|
});
|
|
185
|
-
return
|
|
918
|
+
return ye(o, t), o;
|
|
186
919
|
}
|
|
187
|
-
function
|
|
188
|
-
return Array.prototype.concat.apply([],
|
|
920
|
+
function ve(t) {
|
|
921
|
+
return Array.prototype.concat.apply([], t);
|
|
189
922
|
}
|
|
190
|
-
function
|
|
191
|
-
const
|
|
192
|
-
return [
|
|
923
|
+
function V(t) {
|
|
924
|
+
const e = t.map(L);
|
|
925
|
+
return [e.map((n) => n[0]), ve(e.map((n) => n[1]))];
|
|
193
926
|
}
|
|
194
|
-
const
|
|
195
|
-
function
|
|
196
|
-
return
|
|
927
|
+
const Q = /* @__PURE__ */ new WeakMap();
|
|
928
|
+
function Pe(t, e) {
|
|
929
|
+
return Q.set(t, e), t;
|
|
197
930
|
}
|
|
198
|
-
function
|
|
199
|
-
return Object.assign(
|
|
931
|
+
function Ee(t) {
|
|
932
|
+
return Object.assign(t, { [K]: !0 });
|
|
200
933
|
}
|
|
201
|
-
function
|
|
934
|
+
function xe(t, e = globalThis, n = "*") {
|
|
202
935
|
return {
|
|
203
|
-
postMessage: (
|
|
204
|
-
addEventListener:
|
|
205
|
-
removeEventListener:
|
|
936
|
+
postMessage: (r, o) => t.postMessage(r, n, o),
|
|
937
|
+
addEventListener: e.addEventListener.bind(e),
|
|
938
|
+
removeEventListener: e.removeEventListener.bind(e)
|
|
206
939
|
};
|
|
207
940
|
}
|
|
208
|
-
function
|
|
209
|
-
for (const [
|
|
210
|
-
if (
|
|
211
|
-
const [
|
|
941
|
+
function L(t) {
|
|
942
|
+
for (const [e, n] of k)
|
|
943
|
+
if (n.canHandle(t)) {
|
|
944
|
+
const [r, o] = n.serialize(t);
|
|
212
945
|
return [
|
|
213
946
|
{
|
|
214
947
|
type: "HANDLER",
|
|
215
|
-
name:
|
|
216
|
-
value:
|
|
948
|
+
name: e,
|
|
949
|
+
value: r
|
|
217
950
|
},
|
|
218
|
-
|
|
951
|
+
o
|
|
219
952
|
];
|
|
220
953
|
}
|
|
221
954
|
return [
|
|
222
955
|
{
|
|
223
956
|
type: "RAW",
|
|
224
|
-
value:
|
|
957
|
+
value: t
|
|
225
958
|
},
|
|
226
|
-
|
|
959
|
+
Q.get(t) || []
|
|
227
960
|
];
|
|
228
961
|
}
|
|
229
|
-
function
|
|
230
|
-
switch (
|
|
962
|
+
function b(t) {
|
|
963
|
+
switch (t.type) {
|
|
231
964
|
case "HANDLER":
|
|
232
|
-
return
|
|
965
|
+
return k.get(t.name).deserialize(t.value);
|
|
233
966
|
case "RAW":
|
|
234
|
-
return
|
|
967
|
+
return t.value;
|
|
235
968
|
}
|
|
236
969
|
}
|
|
237
|
-
function
|
|
238
|
-
return new Promise((
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
!i.data || !i.data.id || i.data.id !==
|
|
242
|
-
}),
|
|
970
|
+
function P(t, e, n) {
|
|
971
|
+
return new Promise((r) => {
|
|
972
|
+
const o = $e();
|
|
973
|
+
t.addEventListener("message", function a(i) {
|
|
974
|
+
!i.data || !i.data.id || i.data.id !== o || (t.removeEventListener("message", a), r(i.data));
|
|
975
|
+
}), t.start && t.start(), t.postMessage(Object.assign({ id: o }, e), n);
|
|
243
976
|
});
|
|
244
977
|
}
|
|
245
|
-
function
|
|
978
|
+
function $e() {
|
|
246
979
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
980
|
}
|
|
248
|
-
function
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
return
|
|
981
|
+
function Fe(t) {
|
|
982
|
+
Te();
|
|
983
|
+
const e = t instanceof Worker ? t : xe(t);
|
|
984
|
+
return M(e);
|
|
252
985
|
}
|
|
253
|
-
function
|
|
254
|
-
|
|
255
|
-
canHandle: (
|
|
256
|
-
serialize: (
|
|
986
|
+
function Te() {
|
|
987
|
+
k.set("EVENT", {
|
|
988
|
+
canHandle: (t) => t instanceof CustomEvent,
|
|
989
|
+
serialize: (t) => [
|
|
257
990
|
{
|
|
258
|
-
detail:
|
|
991
|
+
detail: t.detail
|
|
259
992
|
},
|
|
260
993
|
[]
|
|
261
994
|
],
|
|
262
|
-
deserialize: (
|
|
263
|
-
}),
|
|
264
|
-
canHandle: (
|
|
265
|
-
serialize(
|
|
995
|
+
deserialize: (t) => t
|
|
996
|
+
}), k.set("FUNCTION", {
|
|
997
|
+
canHandle: (t) => typeof t == "function",
|
|
998
|
+
serialize(t) {
|
|
266
999
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
267
|
-
const { port1:
|
|
268
|
-
return
|
|
1000
|
+
const { port1: e, port2: n } = new MessageChannel();
|
|
1001
|
+
return N(t, e), [n, [n]];
|
|
269
1002
|
},
|
|
270
|
-
deserialize(
|
|
271
|
-
return
|
|
1003
|
+
deserialize(t) {
|
|
1004
|
+
return t.start(), M(t);
|
|
272
1005
|
}
|
|
273
1006
|
});
|
|
274
1007
|
}
|
|
275
1008
|
(function() {
|
|
276
1009
|
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
277
1010
|
})();
|
|
278
|
-
var
|
|
1011
|
+
var F = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, z = {}, _e = {
|
|
279
1012
|
get exports() {
|
|
280
|
-
return
|
|
1013
|
+
return z;
|
|
281
1014
|
},
|
|
282
|
-
set exports(
|
|
283
|
-
|
|
1015
|
+
set exports(t) {
|
|
1016
|
+
z = t;
|
|
284
1017
|
}
|
|
285
1018
|
};
|
|
286
|
-
(function(
|
|
287
|
-
(function(
|
|
288
|
-
|
|
289
|
-
})(
|
|
290
|
-
function
|
|
291
|
-
return typeof
|
|
1019
|
+
(function(t, e) {
|
|
1020
|
+
(function(n, r) {
|
|
1021
|
+
r();
|
|
1022
|
+
})(F, function() {
|
|
1023
|
+
function n(s, l) {
|
|
1024
|
+
return typeof l > "u" ? l = { autoBom: !1 } : typeof l != "object" && (console.warn("Deprecated: Expected third argument to be a object"), l = { autoBom: !l }), l.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(s.type) ? new Blob(["\uFEFF", s], { type: s.type }) : s;
|
|
292
1025
|
}
|
|
293
|
-
function
|
|
294
|
-
var
|
|
295
|
-
|
|
296
|
-
c(
|
|
297
|
-
},
|
|
1026
|
+
function r(s, l, h) {
|
|
1027
|
+
var u = new XMLHttpRequest();
|
|
1028
|
+
u.open("GET", s), u.responseType = "blob", u.onload = function() {
|
|
1029
|
+
c(u.response, l, h);
|
|
1030
|
+
}, u.onerror = function() {
|
|
298
1031
|
console.error("could not download file");
|
|
299
|
-
},
|
|
1032
|
+
}, u.send();
|
|
300
1033
|
}
|
|
301
|
-
function s
|
|
302
|
-
var
|
|
303
|
-
|
|
1034
|
+
function o(s) {
|
|
1035
|
+
var l = new XMLHttpRequest();
|
|
1036
|
+
l.open("HEAD", s, !1);
|
|
304
1037
|
try {
|
|
305
|
-
|
|
1038
|
+
l.send();
|
|
306
1039
|
} catch {
|
|
307
1040
|
}
|
|
308
|
-
return 200 <=
|
|
1041
|
+
return 200 <= l.status && 299 >= l.status;
|
|
309
1042
|
}
|
|
310
|
-
function
|
|
1043
|
+
function a(s) {
|
|
311
1044
|
try {
|
|
312
|
-
|
|
1045
|
+
s.dispatchEvent(new MouseEvent("click"));
|
|
313
1046
|
} catch {
|
|
314
|
-
var
|
|
315
|
-
|
|
1047
|
+
var l = document.createEvent("MouseEvents");
|
|
1048
|
+
l.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), s.dispatchEvent(l);
|
|
316
1049
|
}
|
|
317
1050
|
}
|
|
318
|
-
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof
|
|
319
|
-
} : "download" in HTMLAnchorElement.prototype && !
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
1051
|
+
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof F == "object" && F.global === F ? F : void 0, d = i.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent), c = i.saveAs || (typeof window != "object" || window !== i ? function() {
|
|
1052
|
+
} : "download" in HTMLAnchorElement.prototype && !d ? function(s, l, h) {
|
|
1053
|
+
var u = i.URL || i.webkitURL, p = document.createElement("a");
|
|
1054
|
+
l = l || s.name || "download", p.download = l, p.rel = "noopener", typeof s == "string" ? (p.href = s, p.origin === location.origin ? a(p) : o(p.href) ? r(s, l, h) : a(p, p.target = "_blank")) : (p.href = u.createObjectURL(s), setTimeout(function() {
|
|
1055
|
+
u.revokeObjectURL(p.href);
|
|
323
1056
|
}, 4e4), setTimeout(function() {
|
|
324
|
-
|
|
1057
|
+
a(p);
|
|
325
1058
|
}, 0));
|
|
326
|
-
} : "msSaveOrOpenBlob" in navigator ? function(
|
|
327
|
-
if (
|
|
328
|
-
navigator.msSaveOrOpenBlob(
|
|
329
|
-
else if (s
|
|
330
|
-
|
|
1059
|
+
} : "msSaveOrOpenBlob" in navigator ? function(s, l, h) {
|
|
1060
|
+
if (l = l || s.name || "download", typeof s != "string")
|
|
1061
|
+
navigator.msSaveOrOpenBlob(n(s, h), l);
|
|
1062
|
+
else if (o(s))
|
|
1063
|
+
r(s, l, h);
|
|
331
1064
|
else {
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
u
|
|
1065
|
+
var u = document.createElement("a");
|
|
1066
|
+
u.href = s, u.target = "_blank", setTimeout(function() {
|
|
1067
|
+
a(u);
|
|
335
1068
|
});
|
|
336
1069
|
}
|
|
337
|
-
} : function(
|
|
338
|
-
if (
|
|
339
|
-
return
|
|
340
|
-
var
|
|
341
|
-
if ((
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
var
|
|
345
|
-
|
|
346
|
-
},
|
|
1070
|
+
} : function(s, l, h, u) {
|
|
1071
|
+
if (u = u || open("", "_blank"), u && (u.document.title = u.document.body.innerText = "downloading..."), typeof s == "string")
|
|
1072
|
+
return r(s, l, h);
|
|
1073
|
+
var p = s.type === "application/octet-stream", E = /constructor/i.test(i.HTMLElement) || i.safari, _ = /CriOS\/[\d]+/.test(navigator.userAgent);
|
|
1074
|
+
if ((_ || p && E || d) && typeof FileReader < "u") {
|
|
1075
|
+
var x = new FileReader();
|
|
1076
|
+
x.onloadend = function() {
|
|
1077
|
+
var $ = x.result;
|
|
1078
|
+
$ = _ ? $ : $.replace(/^data:[^;]*;/, "data:attachment/file;"), u ? u.location.href = $ : location = $, u = null;
|
|
1079
|
+
}, x.readAsDataURL(s);
|
|
347
1080
|
} else {
|
|
348
|
-
var
|
|
349
|
-
|
|
350
|
-
|
|
1081
|
+
var R = i.URL || i.webkitURL, v = R.createObjectURL(s);
|
|
1082
|
+
u ? u.location = v : location.href = v, u = null, setTimeout(function() {
|
|
1083
|
+
R.revokeObjectURL(v);
|
|
351
1084
|
}, 4e4);
|
|
352
1085
|
}
|
|
353
1086
|
});
|
|
354
|
-
i.saveAs = c.saveAs = c,
|
|
1087
|
+
i.saveAs = c.saveAs = c, t.exports = c;
|
|
355
1088
|
});
|
|
356
|
-
})(
|
|
357
|
-
const
|
|
1089
|
+
})(_e);
|
|
1090
|
+
const D = `<?php
|
|
358
1091
|
|
|
359
1092
|
function generateZipFile($exportPath, $databasePath, $docRoot) {
|
|
360
1093
|
$zip = new ZipArchive;
|
|
@@ -422,23 +1155,21 @@ function importZipFile($pathToZip) {
|
|
|
422
1155
|
$zip->close();
|
|
423
1156
|
}
|
|
424
1157
|
}
|
|
425
|
-
`,
|
|
426
|
-
async function
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
})
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const l = await e.wordPressVersion, s = await e.phpVersion, u = await e.documentRoot, i = `wordpress-playground--wp${l}--php${s}.zip`, p = `/${i}`, c = await e.run({
|
|
434
|
-
code: U + ` generateZipFile('${p}', '${k}', '${u}');`
|
|
1158
|
+
`, ee = "databaseExport.xml", H = "/" + ee;
|
|
1159
|
+
async function ke(t) {
|
|
1160
|
+
const n = (await t.request({
|
|
1161
|
+
url: "/wp-admin/export.php?download=true&content=all"
|
|
1162
|
+
})).text;
|
|
1163
|
+
await t.writeFile(H, n);
|
|
1164
|
+
const r = await t.wordPressVersion, o = await t.phpVersion, a = await t.documentRoot, i = `wordpress-playground--wp${r}--php${o}.zip`, d = `/${i}`, c = await t.run({
|
|
1165
|
+
code: D + ` generateZipFile('${d}', '${H}', '${a}');`
|
|
435
1166
|
});
|
|
436
1167
|
if (c.exitCode !== 0)
|
|
437
1168
|
throw c.errors;
|
|
438
|
-
const
|
|
439
|
-
|
|
1169
|
+
const s = await t.readFileAsBuffer(i), l = new File([s], i);
|
|
1170
|
+
z.saveAs(l);
|
|
440
1171
|
}
|
|
441
|
-
async function
|
|
1172
|
+
async function Oe(t, e) {
|
|
442
1173
|
if (
|
|
443
1174
|
// eslint-disable-next-line no-alert
|
|
444
1175
|
!confirm(
|
|
@@ -446,181 +1177,178 @@ async function we(e, t) {
|
|
|
446
1177
|
)
|
|
447
1178
|
)
|
|
448
1179
|
return !1;
|
|
449
|
-
const
|
|
450
|
-
await
|
|
451
|
-
const
|
|
452
|
-
code:
|
|
1180
|
+
const n = await e.arrayBuffer(), r = new Uint8Array(n), o = "/import.zip";
|
|
1181
|
+
await t.writeFile(o, r);
|
|
1182
|
+
const a = await t.run({
|
|
1183
|
+
code: D + ` readFileFromZipArchive('${o}', '${H}');`
|
|
453
1184
|
});
|
|
454
|
-
if (
|
|
455
|
-
throw
|
|
1185
|
+
if (a.exitCode !== 0)
|
|
1186
|
+
throw a.errors;
|
|
456
1187
|
const i = new TextDecoder().decode(
|
|
457
|
-
|
|
458
|
-
),
|
|
1188
|
+
a.bytes
|
|
1189
|
+
), d = new File(
|
|
459
1190
|
[i],
|
|
460
|
-
|
|
461
|
-
), c = await
|
|
462
|
-
|
|
463
|
-
}),
|
|
464
|
-
|
|
1191
|
+
ee
|
|
1192
|
+
), c = await t.request({
|
|
1193
|
+
url: "/wp-admin/admin.php?import=wordpress"
|
|
1194
|
+
}), l = new DOMParser().parseFromString(
|
|
1195
|
+
c.text,
|
|
465
1196
|
"text/html"
|
|
466
|
-
).getElementById("import-upload-form")?.getAttribute("action"),
|
|
467
|
-
|
|
1197
|
+
).getElementById("import-upload-form")?.getAttribute("action"), h = await t.request({
|
|
1198
|
+
url: `/wp-admin/${l}`,
|
|
468
1199
|
method: "POST",
|
|
469
|
-
files: { import:
|
|
470
|
-
}),
|
|
471
|
-
|
|
1200
|
+
files: { import: d }
|
|
1201
|
+
}), p = new DOMParser().parseFromString(
|
|
1202
|
+
h.text,
|
|
472
1203
|
"text/html"
|
|
473
1204
|
).querySelector(
|
|
474
1205
|
"#wpbody-content form"
|
|
475
|
-
),
|
|
1206
|
+
), E = p?.getAttribute(
|
|
476
1207
|
"action"
|
|
477
|
-
),
|
|
1208
|
+
), _ = (p?.querySelector(
|
|
478
1209
|
"input[name='_wpnonce']"
|
|
479
|
-
)).value,
|
|
1210
|
+
)).value, x = (p?.querySelector(
|
|
480
1211
|
"input[name='_wp_http_referer']"
|
|
481
|
-
)).value,
|
|
1212
|
+
)).value, R = (p?.querySelector(
|
|
482
1213
|
"input[name='import_id']"
|
|
483
1214
|
)).value;
|
|
484
|
-
await
|
|
485
|
-
|
|
1215
|
+
await t.request({
|
|
1216
|
+
url: E,
|
|
486
1217
|
method: "POST",
|
|
487
1218
|
formData: {
|
|
488
|
-
_wpnonce:
|
|
489
|
-
_wp_http_referer:
|
|
490
|
-
import_id:
|
|
1219
|
+
_wpnonce: _,
|
|
1220
|
+
_wp_http_referer: x,
|
|
1221
|
+
import_id: R
|
|
491
1222
|
}
|
|
492
1223
|
});
|
|
493
|
-
const
|
|
494
|
-
code:
|
|
1224
|
+
const v = await t.run({
|
|
1225
|
+
code: D + ` importZipFile('${o}');`
|
|
495
1226
|
});
|
|
496
|
-
if (
|
|
497
|
-
throw
|
|
1227
|
+
if (v.exitCode !== 0)
|
|
1228
|
+
throw v.errors;
|
|
498
1229
|
return !0;
|
|
499
1230
|
}
|
|
500
|
-
async function
|
|
501
|
-
await
|
|
502
|
-
|
|
503
|
-
}), await
|
|
504
|
-
|
|
1231
|
+
async function Ae(t, e = "admin", n = "password") {
|
|
1232
|
+
await t.request({
|
|
1233
|
+
url: "/wp-login.php"
|
|
1234
|
+
}), await t.request({
|
|
1235
|
+
url: "/wp-login.php",
|
|
505
1236
|
method: "POST",
|
|
506
1237
|
formData: {
|
|
507
|
-
log:
|
|
508
|
-
pwd:
|
|
1238
|
+
log: e,
|
|
1239
|
+
pwd: n,
|
|
509
1240
|
rememberme: "forever"
|
|
510
1241
|
}
|
|
511
1242
|
});
|
|
512
1243
|
}
|
|
513
|
-
function
|
|
514
|
-
return new DOMParser().parseFromString(
|
|
515
|
-
}
|
|
516
|
-
function ce(e) {
|
|
517
|
-
return new TextDecoder().decode(e.body);
|
|
1244
|
+
function T(t) {
|
|
1245
|
+
return new DOMParser().parseFromString(t.text, "text/html");
|
|
518
1246
|
}
|
|
519
|
-
function
|
|
520
|
-
const
|
|
521
|
-
return
|
|
1247
|
+
function te(t) {
|
|
1248
|
+
const e = t.split(".").shift().replace("-", " ");
|
|
1249
|
+
return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
|
|
522
1250
|
}
|
|
523
|
-
async function
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
}),
|
|
527
|
-
|
|
528
|
-
), { themezip:
|
|
1251
|
+
async function Re(t, e, n = {}) {
|
|
1252
|
+
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1253
|
+
url: "/wp-admin/theme-install.php"
|
|
1254
|
+
}), a = T(o), i = new FormData(
|
|
1255
|
+
a.querySelector(".wp-upload-form")
|
|
1256
|
+
), { themezip: d, ...c } = Object.fromEntries(
|
|
529
1257
|
i.entries()
|
|
530
|
-
),
|
|
531
|
-
|
|
1258
|
+
), s = await t.request({
|
|
1259
|
+
url: "/wp-admin/update.php?action=upload-theme",
|
|
532
1260
|
method: "POST",
|
|
533
1261
|
formData: c,
|
|
534
|
-
files: { themezip:
|
|
1262
|
+
files: { themezip: e }
|
|
535
1263
|
});
|
|
536
|
-
if (
|
|
537
|
-
const
|
|
1264
|
+
if (r) {
|
|
1265
|
+
const l = T(s), h = l.querySelector(
|
|
538
1266
|
"#wpbody-content > .wrap"
|
|
539
1267
|
);
|
|
540
|
-
if (
|
|
1268
|
+
if (h?.textContent?.includes(
|
|
541
1269
|
"Theme installation failed."
|
|
542
1270
|
)) {
|
|
543
|
-
console.error(
|
|
1271
|
+
console.error(h?.textContent);
|
|
544
1272
|
return;
|
|
545
1273
|
}
|
|
546
|
-
const
|
|
1274
|
+
const u = l.querySelector(
|
|
547
1275
|
"#wpbody-content .activatelink, .update-from-upload-actions .button.button-primary"
|
|
548
1276
|
);
|
|
549
|
-
if (!
|
|
1277
|
+
if (!u) {
|
|
550
1278
|
console.error('The "activate" button was not found.');
|
|
551
1279
|
return;
|
|
552
1280
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
await
|
|
1281
|
+
const p = u.attributes.getNamedItem("href").value, E = new URL(
|
|
1282
|
+
p,
|
|
1283
|
+
await t.pathToInternalUrl("/wp-admin/")
|
|
556
1284
|
).toString();
|
|
557
|
-
await
|
|
558
|
-
|
|
1285
|
+
await t.request({
|
|
1286
|
+
url: E
|
|
559
1287
|
});
|
|
560
1288
|
}
|
|
561
1289
|
}
|
|
562
|
-
async function
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
}),
|
|
566
|
-
|
|
567
|
-
), { pluginzip:
|
|
1290
|
+
async function Se(t, e, n = {}) {
|
|
1291
|
+
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1292
|
+
url: "/wp-admin/plugin-install.php?tab=upload"
|
|
1293
|
+
}), a = T(o), i = new FormData(
|
|
1294
|
+
a.querySelector(".wp-upload-form")
|
|
1295
|
+
), { pluginzip: d, ...c } = Object.fromEntries(
|
|
568
1296
|
i.entries()
|
|
569
|
-
),
|
|
570
|
-
|
|
1297
|
+
), s = await t.request({
|
|
1298
|
+
url: "/wp-admin/update.php?action=upload-plugin",
|
|
571
1299
|
method: "POST",
|
|
572
1300
|
formData: c,
|
|
573
|
-
files: { pluginzip:
|
|
1301
|
+
files: { pluginzip: e }
|
|
574
1302
|
});
|
|
575
|
-
if (
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
await
|
|
1303
|
+
if (r) {
|
|
1304
|
+
const u = T(s).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, p = new URL(
|
|
1305
|
+
u,
|
|
1306
|
+
await t.pathToInternalUrl("/wp-admin/")
|
|
579
1307
|
).toString();
|
|
580
|
-
await
|
|
581
|
-
|
|
1308
|
+
await t.request({
|
|
1309
|
+
url: p
|
|
582
1310
|
});
|
|
583
1311
|
}
|
|
584
|
-
async function
|
|
585
|
-
return await
|
|
586
|
-
|
|
587
|
-
|
|
1312
|
+
async function l(h, u) {
|
|
1313
|
+
return await t.writeFile(
|
|
1314
|
+
h,
|
|
1315
|
+
u(await t.readFileAsText(h))
|
|
588
1316
|
);
|
|
589
1317
|
}
|
|
590
|
-
await
|
|
1318
|
+
await t.isDir("/wordpress/wp-content/plugins/gutenberg") && !await t.fileExists("/wordpress/.gutenberg-patched") && (await t.writeFile("/wordpress/.gutenberg-patched", "1"), await l(
|
|
591
1319
|
"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
|
|
592
|
-
(
|
|
1320
|
+
(h) => h.replace(
|
|
593
1321
|
/srcDoc:("[^"]+"|[^,]+)/g,
|
|
594
1322
|
'src:"/wp-includes/empty.html"'
|
|
595
1323
|
)
|
|
596
|
-
), await
|
|
1324
|
+
), await l(
|
|
597
1325
|
"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
|
|
598
|
-
(
|
|
1326
|
+
(h) => h.replace(
|
|
599
1327
|
/srcDoc:("[^"]+"|[^,]+)/g,
|
|
600
1328
|
'src:"/wp-includes/empty.html"'
|
|
601
1329
|
)
|
|
602
1330
|
));
|
|
603
1331
|
}
|
|
604
|
-
async function
|
|
605
|
-
const
|
|
606
|
-
await
|
|
607
|
-
|
|
1332
|
+
async function Le(t, e) {
|
|
1333
|
+
const o = T(
|
|
1334
|
+
await t.request({
|
|
1335
|
+
url: "/wp-admin/plugins.php"
|
|
608
1336
|
})
|
|
609
1337
|
).querySelector(
|
|
610
|
-
`tr[data-slug="${
|
|
1338
|
+
`tr[data-slug="${e}"] a`
|
|
611
1339
|
).attributes.getNamedItem("href").value;
|
|
612
|
-
await
|
|
613
|
-
|
|
1340
|
+
await t.request({
|
|
1341
|
+
url: "/wp-admin/" + o
|
|
614
1342
|
});
|
|
615
1343
|
}
|
|
616
|
-
const
|
|
617
|
-
function
|
|
618
|
-
const
|
|
619
|
-
function
|
|
620
|
-
|
|
1344
|
+
const Ce = 5 * 1024 * 1024;
|
|
1345
|
+
function ne(t, e) {
|
|
1346
|
+
const n = t.headers.get("content-length") || "", r = parseInt(n, 10) || Ce;
|
|
1347
|
+
function o(a, i) {
|
|
1348
|
+
e(
|
|
621
1349
|
new CustomEvent("progress", {
|
|
622
1350
|
detail: {
|
|
623
|
-
loaded:
|
|
1351
|
+
loaded: a,
|
|
624
1352
|
total: i
|
|
625
1353
|
}
|
|
626
1354
|
})
|
|
@@ -628,114 +1356,114 @@ function V(e, t) {
|
|
|
628
1356
|
}
|
|
629
1357
|
return new Response(
|
|
630
1358
|
new ReadableStream({
|
|
631
|
-
async start(
|
|
632
|
-
if (!
|
|
633
|
-
|
|
1359
|
+
async start(a) {
|
|
1360
|
+
if (!t.body) {
|
|
1361
|
+
a.close();
|
|
634
1362
|
return;
|
|
635
1363
|
}
|
|
636
|
-
const i =
|
|
637
|
-
let
|
|
1364
|
+
const i = t.body.getReader();
|
|
1365
|
+
let d = 0;
|
|
638
1366
|
for (; ; )
|
|
639
1367
|
try {
|
|
640
|
-
const { done: c, value:
|
|
641
|
-
if (
|
|
642
|
-
|
|
1368
|
+
const { done: c, value: s } = await i.read();
|
|
1369
|
+
if (s && (d += s.byteLength), c) {
|
|
1370
|
+
o(d, d), a.close();
|
|
643
1371
|
break;
|
|
644
1372
|
} else
|
|
645
|
-
|
|
1373
|
+
o(d, r), a.enqueue(s);
|
|
646
1374
|
} catch (c) {
|
|
647
|
-
console.error({ e: c }),
|
|
1375
|
+
console.error({ e: c }), a.error(c);
|
|
648
1376
|
break;
|
|
649
1377
|
}
|
|
650
1378
|
}
|
|
651
1379
|
}),
|
|
652
1380
|
{
|
|
653
|
-
status:
|
|
654
|
-
statusText:
|
|
655
|
-
headers:
|
|
1381
|
+
status: t.status,
|
|
1382
|
+
statusText: t.statusText,
|
|
1383
|
+
headers: t.headers
|
|
656
1384
|
}
|
|
657
1385
|
);
|
|
658
1386
|
}
|
|
659
|
-
async function
|
|
660
|
-
let
|
|
661
|
-
if (
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
`Installing ${
|
|
1387
|
+
async function Ue(t, e, n = 100, r) {
|
|
1388
|
+
let o = await fetch("/plugin-proxy?theme=" + e);
|
|
1389
|
+
if (r && (o = ne(
|
|
1390
|
+
o,
|
|
1391
|
+
r.partialObserver(
|
|
1392
|
+
n / 2,
|
|
1393
|
+
`Installing ${te(e)} theme...`
|
|
666
1394
|
)
|
|
667
|
-
),
|
|
668
|
-
const
|
|
1395
|
+
), r.slowlyIncrementBy(n / 2)), o.status === 200) {
|
|
1396
|
+
const a = new File([await o.blob()], e);
|
|
669
1397
|
try {
|
|
670
|
-
await
|
|
1398
|
+
await Re(t, a);
|
|
671
1399
|
} catch (i) {
|
|
672
1400
|
console.error(
|
|
673
|
-
`Proceeding without the ${
|
|
1401
|
+
`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${i}`
|
|
674
1402
|
), console.error(i);
|
|
675
1403
|
}
|
|
676
1404
|
} else
|
|
677
1405
|
console.error(
|
|
678
|
-
`Proceeding without the ${
|
|
1406
|
+
`Proceeding without the ${e} theme. Could not download the zip bundle from https://downloads.wordpress.org/themes/${e} – Is the file name correct?`
|
|
679
1407
|
);
|
|
680
1408
|
}
|
|
681
|
-
async function
|
|
682
|
-
const
|
|
683
|
-
await new Promise((
|
|
684
|
-
for (const c of
|
|
685
|
-
|
|
686
|
-
let
|
|
1409
|
+
async function Ie(t, e, n = 100, r) {
|
|
1410
|
+
const o = new Z(), a = new Z(), i = n / e.length;
|
|
1411
|
+
await new Promise((d) => {
|
|
1412
|
+
for (const c of e)
|
|
1413
|
+
o.enqueue(async () => {
|
|
1414
|
+
let s = await fetch(
|
|
687
1415
|
"/plugin-proxy?plugin=" + c
|
|
688
1416
|
);
|
|
689
|
-
return
|
|
690
|
-
|
|
691
|
-
|
|
1417
|
+
return r && (s = ne(
|
|
1418
|
+
s,
|
|
1419
|
+
r.partialObserver(
|
|
692
1420
|
i * 0.66,
|
|
693
|
-
`Installing ${
|
|
1421
|
+
`Installing ${te(
|
|
694
1422
|
c
|
|
695
1423
|
)} plugin...`
|
|
696
1424
|
)
|
|
697
|
-
)),
|
|
1425
|
+
)), s.status !== 200 ? (console.error(
|
|
698
1426
|
`Proceeding without the ${c} plugin. Could not download the zip bundle from https://downloads.wordpress.org/plugin/${c} – Is the file name correct?`
|
|
699
|
-
), null) : new File([await
|
|
1427
|
+
), null) : new File([await s.blob()], c);
|
|
700
1428
|
});
|
|
701
|
-
|
|
702
|
-
|
|
1429
|
+
o.addEventListener("resolved", (c) => {
|
|
1430
|
+
a.enqueue(async () => {
|
|
703
1431
|
if (c.detail) {
|
|
704
|
-
|
|
1432
|
+
r?.slowlyIncrementBy(i * 0.33);
|
|
705
1433
|
try {
|
|
706
|
-
await
|
|
707
|
-
} catch (
|
|
1434
|
+
await Se(t, c.detail);
|
|
1435
|
+
} catch (s) {
|
|
708
1436
|
console.error(
|
|
709
|
-
`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${
|
|
710
|
-
), console.error(
|
|
1437
|
+
`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${s}`
|
|
1438
|
+
), console.error(s);
|
|
711
1439
|
}
|
|
712
1440
|
}
|
|
713
1441
|
});
|
|
714
|
-
}),
|
|
715
|
-
|
|
1442
|
+
}), a.addEventListener("empty", () => {
|
|
1443
|
+
a.resolved === e.length && d(null);
|
|
716
1444
|
});
|
|
717
1445
|
});
|
|
718
1446
|
}
|
|
719
|
-
class
|
|
1447
|
+
class Z extends EventTarget {
|
|
720
1448
|
#e = [];
|
|
721
1449
|
#t = !1;
|
|
722
1450
|
#n = 0;
|
|
723
1451
|
get resolved() {
|
|
724
1452
|
return this.#n;
|
|
725
1453
|
}
|
|
726
|
-
async enqueue(
|
|
727
|
-
this.#e.push(
|
|
1454
|
+
async enqueue(e) {
|
|
1455
|
+
this.#e.push(e), this.#r();
|
|
728
1456
|
}
|
|
729
1457
|
async #r() {
|
|
730
1458
|
if (!this.#t)
|
|
731
1459
|
try {
|
|
732
1460
|
for (this.#t = !0; this.#e.length; ) {
|
|
733
|
-
const
|
|
734
|
-
if (!
|
|
1461
|
+
const e = this.#e.shift();
|
|
1462
|
+
if (!e)
|
|
735
1463
|
break;
|
|
736
|
-
const
|
|
1464
|
+
const n = await e();
|
|
737
1465
|
++this.#n, this.dispatchEvent(
|
|
738
|
-
new CustomEvent("resolved", { detail:
|
|
1466
|
+
new CustomEvent("resolved", { detail: n })
|
|
739
1467
|
);
|
|
740
1468
|
}
|
|
741
1469
|
} finally {
|
|
@@ -743,21 +1471,21 @@ class I extends EventTarget {
|
|
|
743
1471
|
}
|
|
744
1472
|
}
|
|
745
1473
|
}
|
|
746
|
-
async function
|
|
747
|
-
e.src =
|
|
748
|
-
|
|
749
|
-
});
|
|
750
|
-
const
|
|
751
|
-
return await
|
|
1474
|
+
async function qe(t, e) {
|
|
1475
|
+
e?.loadRemote && (t.src = e?.loadRemote, await new Promise((r) => {
|
|
1476
|
+
t.addEventListener("load", r, !1);
|
|
1477
|
+
}));
|
|
1478
|
+
const n = Fe(t.contentWindow);
|
|
1479
|
+
return await n.absoluteUrl, n;
|
|
752
1480
|
}
|
|
753
1481
|
export {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
1482
|
+
Le as activatePlugin,
|
|
1483
|
+
qe as connectPlayground,
|
|
1484
|
+
ke as exportFile,
|
|
1485
|
+
Oe as importFile,
|
|
1486
|
+
Se as installPlugin,
|
|
1487
|
+
Ie as installPluginsFromDirectory,
|
|
1488
|
+
Re as installTheme,
|
|
1489
|
+
Ue as installThemeFromDirectory,
|
|
1490
|
+
Ae as login
|
|
763
1491
|
};
|