web-listener 0.3.0 → 0.4.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/index.d.ts +33 -12
- package/index.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -248,6 +248,7 @@ declare const getQuery: (req: IncomingMessage, id: string) => string | null;
|
|
|
248
248
|
type CommonMethod = 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
|
|
249
249
|
type CommonUpgrade = 'http/2' | 'http/3' | 'https' | 'h2c' | 'websocket';
|
|
250
250
|
type RelaxedRequestHandler<Req = {}> = RequestHandlerFn<Req> | RequestHandler<Req> | ErrorHandler<Req>;
|
|
251
|
+
type RelaxedRequestHandlerOrExplicitUpgrade<Req = {}> = RelaxedRequestHandler<Req> | UpgradeHandler<Req>;
|
|
251
252
|
type RelaxedUpgradeHandler<Req = {}> = UpgradeHandlerFn<Req> | UpgradeHandler<Req> | ErrorHandler<Req>;
|
|
252
253
|
type MethodWrapper<Req, This> = <Path extends string>(path: Path, ...handlers: RelaxedRequestHandler<Req & WithPathParameters<ParametersFromPath<Path>>>[]) => This;
|
|
253
254
|
type UpgradeWrapper<Req, This> = <Path extends string>(path: Path, ...handlers: RelaxedUpgradeHandler<Req & WithPathParameters<ParametersFromPath<Path>>>[]) => This;
|
|
@@ -256,14 +257,14 @@ declare class Router<Req = {}> implements Required<Handler<Req>> {
|
|
|
256
257
|
/**
|
|
257
258
|
* Register handlers or routers for all requests, upgrades, and errors, on all methods and paths.
|
|
258
259
|
*/
|
|
259
|
-
use(...handlers:
|
|
260
|
+
use(...handlers: RelaxedRequestHandlerOrExplicitUpgrade<Req>[]): this;
|
|
260
261
|
/**
|
|
261
262
|
* Register handlers or routers for all requests, upgrades, and errors, on all methods for all
|
|
262
263
|
* paths within the given path root.
|
|
263
264
|
*
|
|
264
265
|
* To register handlers at the path but not subpaths, use `.at` instead.
|
|
265
266
|
*/
|
|
266
|
-
mount<Path extends string>(path: Path, ...handlers:
|
|
267
|
+
mount<Path extends string>(path: Path, ...handlers: RelaxedRequestHandlerOrExplicitUpgrade<Req & WithPathParameters<ParametersFromPath<Path>>>[]): this;
|
|
267
268
|
/**
|
|
268
269
|
* Create a new router mounted at the path, and call the given function to configure it.
|
|
269
270
|
*/
|
|
@@ -274,7 +275,7 @@ declare class Router<Req = {}> implements Required<Handler<Req>> {
|
|
|
274
275
|
*
|
|
275
276
|
* To register handlers at the path and all subpaths, use `.mount` instead.
|
|
276
277
|
*/
|
|
277
|
-
at<Path extends string>(path: Path, ...handlers:
|
|
278
|
+
at<Path extends string>(path: Path, ...handlers: RelaxedRequestHandlerOrExplicitUpgrade<Req & WithPathParameters<ParametersFromPath<Path>>>[]): this;
|
|
278
279
|
/**
|
|
279
280
|
* Register handlers for requests or errors (not upgrades) on a specific method for a specific
|
|
280
281
|
* path.
|
|
@@ -516,8 +517,11 @@ declare const ENCODING_MAPPING: {
|
|
|
516
517
|
type FileEncodingFormat = keyof typeof ENCODING_MAPPING;
|
|
517
518
|
declare const negotiateEncoding: (options: FileEncodingFormat[] | Record<FileEncodingFormat, string>) => FileNegotiation;
|
|
518
519
|
interface NegotiationOutputInfo {
|
|
520
|
+
/** The negotiated mime type for the resolved file */
|
|
519
521
|
mime?: string | undefined;
|
|
522
|
+
/** The negotiated language for the resolved file */
|
|
520
523
|
language?: string | undefined;
|
|
524
|
+
/** The negotiated encoding for the resolved file */
|
|
521
525
|
encoding?: string | undefined;
|
|
522
526
|
}
|
|
523
527
|
interface NegotiationOutput {
|
|
@@ -683,9 +687,13 @@ declare class FileFinder implements FileFinderCore {
|
|
|
683
687
|
precompute(): Promise<FileFinderCore>;
|
|
684
688
|
}
|
|
685
689
|
interface ResolvedFileInfo extends NegotiationOutputInfo {
|
|
690
|
+
/** An active filehandle for the resolved file. Note that this MUST be closed by the caller. */
|
|
686
691
|
handle: FileHandle;
|
|
692
|
+
/** The full path of the requested file (after adding implicit extensions and index files) */
|
|
687
693
|
canonicalPath: string;
|
|
694
|
+
/** The full path of the resolved file (which may differ from canonicalPath by including e.g. `.gz` if gzip encoding was negotiated) */
|
|
688
695
|
negotiatedPath: string;
|
|
696
|
+
/** Filesystem stats about the resolved file */
|
|
689
697
|
stats: Stats;
|
|
690
698
|
}
|
|
691
699
|
|
|
@@ -828,14 +836,23 @@ declare function getBodyJson(req: IncomingMessage, options?: GetBodyJsonOptions)
|
|
|
828
836
|
|
|
829
837
|
declare function acceptBody(req: IncomingMessage): void;
|
|
830
838
|
|
|
831
|
-
declare function getFormFields(req: IncomingMessage, { allowMultipart, closeAfterErrorDelay, limits }?:
|
|
832
|
-
declare function getFormData(req: IncomingMessage, config?:
|
|
833
|
-
interface
|
|
839
|
+
declare function getFormFields(req: IncomingMessage, { allowMultipart, closeAfterErrorDelay, limits }?: GetFormFieldsOptions): AsyncIterable<FormField, unknown, undefined>;
|
|
840
|
+
declare function getFormData(req: IncomingMessage, config?: GetFormDataOptions): Promise<AugmentedFormData>;
|
|
841
|
+
interface GetFormFieldsOptions {
|
|
842
|
+
/**
|
|
843
|
+
* True to allow `multipart/form-data` (including file uploads). Otherwise only `application/x-www-form-urlencoded` is supported.
|
|
844
|
+
* @default false
|
|
845
|
+
*/
|
|
834
846
|
allowMultipart?: boolean;
|
|
847
|
+
/**
|
|
848
|
+
* Delay (in milliseconds) before forcibly closing the request if an error occurs (e.g. a limit is exceeded).
|
|
849
|
+
* This can be used to prevent clients uploading large files when the request has already been rejected.
|
|
850
|
+
* @default 500
|
|
851
|
+
*/
|
|
835
852
|
closeAfterErrorDelay?: number;
|
|
836
853
|
limits?: Limits;
|
|
837
854
|
}
|
|
838
|
-
interface
|
|
855
|
+
interface GetFormDataOptions extends GetFormFieldsOptions {
|
|
839
856
|
/** true to apply .trim() to all field values */
|
|
840
857
|
trimAllValues?: boolean;
|
|
841
858
|
/** function to apply to all uploaded files (e.g. to check available disk space) */
|
|
@@ -868,6 +885,10 @@ type FormField = {
|
|
|
868
885
|
interface AugmentedFormData extends FormData {
|
|
869
886
|
getTempFilePath(file: Blob): string;
|
|
870
887
|
getBoolean(name: string): boolean | null;
|
|
888
|
+
getString(name: string): string | null;
|
|
889
|
+
getAllStrings(name: string): string[];
|
|
890
|
+
getFile(name: string): File | null;
|
|
891
|
+
getAllFiles(name: string): File[];
|
|
871
892
|
}
|
|
872
893
|
interface Limits {
|
|
873
894
|
/**
|
|
@@ -1155,17 +1176,17 @@ declare class WebSocketError extends Error {
|
|
|
1155
1176
|
static readonly BAD_GATEWAY = 1014;
|
|
1156
1177
|
}
|
|
1157
1178
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1179
|
+
declare class Property<T> {
|
|
1180
|
+
constructor(defaultValue?: T | ((req: IncomingMessage) => T));
|
|
1160
1181
|
set(req: IncomingMessage, value: T): void;
|
|
1161
1182
|
get(req: IncomingMessage): T;
|
|
1162
1183
|
clear(req: IncomingMessage): void;
|
|
1184
|
+
withValue(value: T): RequestHandler<unknown> & UpgradeHandler<unknown>;
|
|
1163
1185
|
}
|
|
1164
|
-
declare function makeProperty<T>(defaultValue: T | ((req: IncomingMessage) => T)): Property<T>;
|
|
1165
1186
|
declare const makeMemo: <T, Args extends any[] = []>(fn: (req: IncomingMessage, ...args: Args) => T, ...args: Args) => ((req: IncomingMessage) => T);
|
|
1166
1187
|
declare function setProperty<T>(req: IncomingMessage, property: Property<T>, value: T): void;
|
|
1167
1188
|
declare function getProperty<T>(req: IncomingMessage, property: Property<T>): T;
|
|
1168
1189
|
declare function clearProperty<T>(req: IncomingMessage, property: Property<T>): void;
|
|
1169
1190
|
|
|
1170
|
-
export { BlockingQueue, CONTINUE, FileFinder, HTTPError, NEXT_ROUTE, NEXT_ROUTER, Queue, Router, STOP, ServerSentEvents, WebListener, WebSocketError, WebSocketMessage, WebSocketMessages, acceptBody, acceptUpgrade, addTeardown, anyHandler, checkIfModified, checkIfRange, clearProperty, compareETag, compressFileOffline, compressFilesInDir, decompressMime, defer, errorHandler, fileServer, findCause, generateStrongETag, generateWeakETag, getAbortSignal, getAbsolutePath, getAddressURL, getAuthData, getAuthorization, getBodyJson, getBodyStream, getBodyText, getBodyTextStream, getCharset, getFormData, getFormFields, getIfRange, getMime, getPathParameter, getPathParameters, getProperty, getQuery, getRange, getRemainingPathComponents, getSearch, getSearchParams, getWebSocketOrigin, hasAuthScope, isSoftClosed, isWebSocketRequest, makeAcceptWebSocket, makeAddressTester, makeGetClient, makeMemo, makeNegotiator,
|
|
1171
|
-
export type { AcceptUpgradeHandler, AcceptUpgradeResult, Address, AugmentedFormData, CSVOptions, CombinedServerOptions, CommonMethod, CommonUpgrade, CompressionInfo, ErrorHandler, FileFinderCore, FileFinderOptions, FileNegotiation, FileNegotiationOption, FileServerOptions, FormField, GetClientOptions,
|
|
1191
|
+
export { BlockingQueue, CONTINUE, FileFinder, HTTPError, NEXT_ROUTE, NEXT_ROUTER, Property, Queue, Router, STOP, ServerSentEvents, WebListener, WebSocketError, WebSocketMessage, WebSocketMessages, acceptBody, acceptUpgrade, addTeardown, anyHandler, checkIfModified, checkIfRange, clearProperty, compareETag, compressFileOffline, compressFilesInDir, decompressMime, defer, errorHandler, fileServer, findCause, generateStrongETag, generateWeakETag, getAbortSignal, getAbsolutePath, getAddressURL, getAuthData, getAuthorization, getBodyJson, getBodyStream, getBodyText, getBodyTextStream, getCharset, getFormData, getFormFields, getIfRange, getMime, getPathParameter, getPathParameters, getProperty, getQuery, getRange, getRemainingPathComponents, getSearch, getSearchParams, getWebSocketOrigin, hasAuthScope, isSoftClosed, isWebSocketRequest, makeAcceptWebSocket, makeAddressTester, makeGetClient, makeMemo, makeNegotiator, makeTempFileStorage, makeWebSocketFallbackTokenFetcher, negotiateEncoding, nextWebSocketMessage, parseAddress, proxy, readHTTPDateSeconds, readHTTPInteger, readHTTPKeyValues, readHTTPQualityValues, readHTTPUnquotedCommaSeparated, readMimeTypes, registerCharset, registerMime, registerUTF32, removeForwarded, replaceForwarded, requestHandler, requireAuthScope, requireBearerAuth, resetMime, restoreAbsolutePath, sanitiseAndAppendForwarded, sendCSVStream, sendFile, sendJSON, sendJSONStream, sendRanges, setDefaultCacheHeaders, setProperty, setSoftCloseHandler, simpleAppendForwarded, simplifyRange, toListeners, upgradeHandler };
|
|
1192
|
+
export type { AcceptUpgradeHandler, AcceptUpgradeResult, Address, AugmentedFormData, CSVOptions, CombinedServerOptions, CommonMethod, CommonUpgrade, CompressionInfo, ErrorHandler, FileFinderCore, FileFinderOptions, FileNegotiation, FileNegotiationOption, FileServerOptions, FormField, GetClientOptions, GetFormDataOptions, GetFormFieldsOptions, GetRangeOptions, HTTPErrorOptions, HTTPRange, HandlerResult, JSONOptions, ListenOptions, ListenerOptions, NativeListeners, NegotiationInput, NegotiationOutput, NegotiationOutputInfo, Negotiator, ParametersFromPath, PostCheckFile, PostCheckFileInfo, PreCheckFile, PreCheckFileInfo, ProxyChain, ProxyNode, ProxyOptions, ProxyRequestHeaderAdapter, ProxyResponseHeaderAdapter, QualityValue, RangePart, RequestHandler, ResolvedFileInfo, ServerErrorCallback, ServerGeneralErrorCallback, ServerSentEvent, SimplifyRangeOptions, UpgradeHandler, UpgradeListener, WithPathParameters };
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isIPv4 as t,isIPv6 as e}from"node:net";import{STATUS_CODES as n,createServer as i,Agent as r,request as s,ServerResponse as o}from"node:http";import{createReadStream as c,constants as a,createWriteStream as f,openAsBlob as u}from"node:fs";import{createHash as h,randomUUID as l}from"node:crypto";import{pipeline as d}from"node:stream/promises";import p from"node:zlib";import{promisify as w}from"node:util";import{extname as m,join as y,dirname as g,basename as b,sep as v,resolve as _}from"node:path";import{readFile as E,writeFile as x,stat as T,readdir as k,realpath as S,open as $,mkdtemp as O,rm as P}from"node:fs/promises";import{tmpdir as A,platform as M}from"node:os";import{Agent as R,request as F}from"node:https";import{TransformStream as N,TextDecoderStream as C,DecompressionStream as U,ReadableStream as B}from"node:stream/web";import{Readable as j,Duplex as D}from"node:stream";import I from"node:stream";function H(n){if(!n||"unknown"===n)return;const i=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(i?.[1]&&t(i[1]))return{type:"IPv4",ip:i[1],port:i[2]?Number.parseInt(i[2]):void 0};const r=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(r?.[1]&&e(r[1]))return{type:"IPv6",ip:r[1].toLowerCase(),port:r[2]?Number.parseInt(r[2]):void 0};if(r?.[3]&&e(r[3]))return{type:"IPv6",ip:r[3].toLowerCase(),port:void 0};const s=/^(.*?):(\d+)$/i.exec(n);return s?.[2]?{type:"alias",ip:s[1],port:Number.parseInt(s[2])}:{type:"alias",ip:n,port:void 0}}function q(t){const e=new Set,n=[],i=[];for(const r of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(r);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,i=e<32?4294967295>>>e:0;n.push([z(t[1])|i,i]);continue}const s=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(r);if(s?.[1]){const t=W(s[1]),e=s[2]?L>>BigInt(Number.parseInt(s[2])):0n;i.push([t|e,e]);continue}e.add(r)}return t=>{switch(t?.type){case"alias":return e.has(t.ip);case"IPv4":const r=z(t.ip);return n.some(([t,e])=>(r|e)===t);case"IPv6":const s=W(t.ip);return i.some(([t,e])=>(s|e)===t);default:return!1}}}const L=BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function z(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function W(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}class J{t;i;constructor(t){const e={o:null,u:null};this.t=e,this.i=e,void 0!==t&&this.push(t)}isEmpty(){return!this.t.u}clear(){this.t.u=null,this.t.o=null,this.i=this.t}push(t){const e={o:t,u:null};this.i.u=e,this.i=e}shift(){if(!this.t.u)return null;this.t=this.t.u;const t=this.t.o;return this.t.o=null,t}remove(t){for(let e=this.t;e.u;e=e.u)if(e.u.o===t){e.u=e.u.u;break}}[Symbol.iterator](){return{next:()=>{if(!this.t.u)return{value:null,done:!0};this.t=this.t.u;const t=this.t.o;return this.t.o=null,{value:t,done:!1}}}}}class G{h;l;m;v;constructor(){this.h=new J,this.l=new J,this.m=0}push(t){if(this.m)return;const e=this.l.shift();e?(e._&&clearTimeout(e._),e.T(t)):this.h.push(t)}shift(t){return this.h.isEmpty()?this.m?Promise.reject(this.v):new Promise((e,n)=>{const i={T:e,k:n,_:null};this.l.push(i),void 0!==t&&(i._=setTimeout(()=>{this.l.remove(i),n(new Error(`Timeout after ${t}ms`))},t))}):Promise.resolve(this.h.shift())}S(t){this.v=t;for(const e of this.l)e.k(t),e._&&clearTimeout(e._)}close(t){this.m||(this.m=1,this.S(t))}fail(t){this.m||(this.m=2,this.S(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function V(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return V(t.cause,e);if("error"in t)return V(t.error,e)}}function X(t,e="http"){if(!t)throw new Error("no address");if("string"==typeof t)return t;if("IPv4"===t.family)return`${e}://${t.address}:${t.port}`;if("IPv6"===t.family)return`${e}://[${t.address}]:${t.port}`;throw new Error(`unknown address family: ${t.family}`)}const Y=/*@__PURE__*/Buffer.alloc(0),Z=t=>new URL("http://localhost"+(t.url??"/"));class K extends Error{error;suppressed;constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const Q=globalThis.SuppressedError??K;class tt{$;O;constructor(){this.$=!1}P(t){this.$?t!==this.O&&(this.O=new Q(t,this.O)):(this.O=t,this.$=!0)}A(){this.$=!1,this.O=void 0}}class et{M;R;F;constructor(t){this.M=t,this.R=Object.create(null),this.F=!1}get headersSent(){return this.F}writeHead(t,e,i){if(this.F)throw new Error("headers already sent");const r={...this.R};for(const[t,e]of(t=>{if(!t)return[];const e=[];if(Array.isArray(t)){const n=t.length;if(1&n)throw new Error("headers must be a list of alternating keys and values");for(let i=0;i<n;i+=2){const n=t[i],r=t[i+1];if("string"!=typeof n)throw new Error("invalid header name");void 0!==r&&e.push([n.toLowerCase(),r])}}else for(const[n,i]of Object.entries(t))void 0!==i&&e.push([n.toLowerCase(),i]);return e})(i))r[t]=e;return this.M.write([`HTTP/1.1 ${t} ${rt(e??n[t]??"-")}`,...nt(r),"",""].join("\r\n"),"ascii"),this.F=!0,this}write(t,e="utf-8",n){return this.M.write(t,e,n)}end(t,e="utf-8",n){return this.M.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.R[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function nt(t){const e=[];for(const[n,i]of Object.entries(t)){const t=it(i);t&&e.push(`${rt(n)}: ${rt(t)}`)}return e}const it=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",rt=t=>t.replaceAll(/[^ \t!-~]/g,"");class st extends Error{statusCode;statusMessage;headers;body;constructor(t,{message:e,statusMessage:i,headers:r,body:s,...o}={}){super(e??("string"==typeof s?s:void 0),o),this.statusCode=0|t,this.statusMessage=i??n[this.statusCode]??"-",this.headers=r,this.body=s??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}static INTERNAL_SERVER_ERROR=new st(500);send(t,e){t.setHeaders((t=>{if(t){if(t instanceof Headers)return t;if(Array.isArray(t))return new Headers(t);{const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,it(e)]).filter(([t,e])=>e))}}return new Headers})(this.headers));const n=Buffer.byteLength(this.body,"utf-8");t.setHeader("content-length",String(n)),t.writeHead(this.statusCode,this.statusMessage,e),t.end(this.body,"utf-8")}}const ot=(t,e,n)=>{n.headersSent?n.end():(V(t,st)??st.INTERNAL_SERVER_ERROR).send(n)},ct=(t,e,n)=>{if(n.writable){n.addListener("finish",()=>n.destroy());const e=new et(n);(V(t,st)??st.INTERNAL_SERVER_ERROR).send(e,{connection:"close"})}else n.destroy()},at=(t,e,n)=>{(V(t,st)?.statusCode??1)&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},ft=new WeakMap;function ut(t,e){const n=ft.get(t);if(n)return n;const i=Z(t),r={N:t,C:i,U:decodeURIComponent(i.pathname),B:ct,j:new AbortController,D:[],I:[],H:e?dt(t):null};return ft.set(t,r),r}function ht(t,e,n,i){e||(t.H=null),t.L=n;const r=async()=>{t.j.abort(n.W.writableEnded?"complete":"client abort");const e=new tt;await lt(t.D,e,t),await lt(t.I,e,t,()=>{t.J=async e=>{try{await e()}catch(e){i(e,t.N)}}}),e.$&&i(e.O,t.N)};return n.W.closed?r():n.W.once("close",r),t}async function lt(t,e,n,i){for(;n.G;)await n.G;const r=(async()=>{for(;;){const n=t.pop();if(!n)return void i?.();try{await n()}catch(t){e.P(t)}}})().then(()=>{n.G===r&&(n.G=void 0)});n.G=r,await r}function dt(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const pt=t=>ft.get(t);function wt(t){const e=pt(t);if(!e)throw new Error("unknown request");return e}function mt(t,e){const n=pt(t);n&&yt(n,e)}function yt(t,e){t.V=e;const n=t.X;n&&queueMicrotask(()=>Et(e,t.N,n))}const gt=t=>Boolean(pt(t)?.X);function bt(t,e,n){if(!t.X){if(t.L&&!t.H){const e=t.L.W;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.L?.W.once("close",()=>t.N.socket.destroy()),t.X={Y:e,Z:n},Et(t.V,t.N,t.X),_t(t)}}function vt(t){if(t.L){if(!t.H){const e=t.L.W;e.headersSent||(e.statusCode=503,e.hasHeader("connection")||e.setHeader("connection","close"))}t.L.W.end(()=>t.N.socket.destroy())}else t.N.socket.destroy()}function _t(t){if(clearTimeout(t.K),!t.tt||t.J)return;const e=Date.now();if(e>=t.tt)return void vt(t);let n=t.tt;t.et&&!t.X&&(e<t.et.nt?n=t.et.nt:(t.X=t.et,Et(t.V,t.N,t.X))),void 0===t.K&&t.I.push(()=>clearTimeout(t.K)),t.K=setTimeout(()=>_t(t),n-e)}async function Et(t,e,n){try{await(t?.(n.Y))}catch(t){n.Z(t,"soft closing",e)}}const xt=(t,e)=>{const n=wt(t);n.J?n.J(e):n.D.push(e)},Tt=(t,e)=>{const n=wt(t);n.J?n.J(e):n.I.push(e)},kt=t=>wt(t).j.signal;class St extends Error{}const $t=new St("STOP"),Ot=new St("CONTINUE"),Pt=new St("NEXT_ROUTE"),At=new St("NEXT_ROUTER");async function Mt(t,e){const n=wt(t);if(!n.L)throw new Error("cannot call acceptUpgrade from shouldUpgrade");if(!n.H)throw new Error("not an upgrade request");if(n.it)return n.rt;const i=n.L.W;if(!i.readable||!i.writable)throw $t;const r=await e(t,i,n.L.t);return n.L.t=Y,n.B=r.onError,yt(n,r.softCloseHandler),n.rt=r.return,n.it=!0,r.return}const Rt=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),Ft=t=>t,Nt=t=>void 0===t?void 0:""===t?[]:t.split("/"),Ct=t=>void 0===t?void 0:""===t?[]:t.split("/").filter(t=>t);function Ut(t){const e={},n=new Map;for(const[i,r]of Object.entries(t))e[i]=!1,n.set(r,i);return t=>{const i={...e};for(let e=0;e<t.length;++e){const r=n.get(t[e]);if(!r)return[i,t.substring(e)];i[r]=!0}return[i,""]}}const Bt=/*@__PURE__*/Ut({st:"i",ot:"!"}),jt=Object.freeze({});function Dt(t,e,n){const i=t.N.url,r=t.U,s=t.ct??jt;return t.N.url=encodeURIComponent(e).replaceAll(/%2F/g,"/")+t.C.search,t.U=e,n.length>0&&(t.ct=Object.freeze(Object.fromEntries([...Object.entries(s),...n]))),()=>{t.N.url=i,t.U=r,t.ct=s}}function It(t){return pt(t)?.ct??jt}function Ht(t,e){return It(t)[e]}function qt(t){const e=pt(t);return e?e.C.pathname+e.C.search:t.url??"/"}function Lt(t){const e=pt(t);e&&(t.url=e.C.pathname+e.C.search)}const zt=t=>"function"==typeof t?{handleRequest:t}:t,Wt=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},Jt=(t,e=Yt)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),Gt=t=>"function"==typeof t?{handleError:t}:t,Vt=t=>"function"==typeof t?{handleRequest:t}:t,Xt=t=>"function"==typeof t?{handleUpgrade:t}:t,Yt=()=>!1,Zt=Symbol("http");class Kt{ft;ut;constructor(){this.ft=[],this.ut=[]}P(t,e,n,i,r){const s=n?((t,e)=>{const n=["^"],i=[],r=/[{}]|\/+|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{st:s,ot:o},c]=Bt(t);if("/"!==c[0])throw new Error("path must begin with '/' or flags");let a=0,f=0;for(const t of c.matchAll(r)){t.index>a&&n.push(Rt(c.substring(a,t.index)));const e=t[0];if("{"===e)n.push("(?:"),++f;else if("}"===e){if(0===f)throw new Error(`unbalanced optional braces in path at ${t.index}`);--f,n.push(")?")}else if("/"===e[0])n.push(e),o||n.push("+");else if("\\"===e[0])n.push(Rt(t[1]));else{const r=e[0],s=t[2];if(!s)throw new Error(`unnamed parameter or unescaped '${r}' at ${t.index}`);"*"===r?(n.push("(.*?)"),i.push({ht:s,lt:o?Nt:Ct})):(n.push("([^/]+?)"),i.push({ht:s,lt:Ft}))}a=t.index+e.length}if(a<c.length&&n.push(Rt(c.substring(a))),f>0)throw new Error("unbalanced optional braces in path");return e&&(n.push("(?:"),o?n.push("(?:(?<=/)|/)"):n.push("(?:/+|(?<=/))"),n.push("(?<rest>.*))?")),n.push("$"),{dt:new RegExp(n.join(""),s?"i":""),wt:i}})(n,i):{dt:null,wt:[]};return this.ft.push({yt:t,gt:"string"==typeof e?e.toLowerCase():e,bt:s.dt,vt:s.wt,_t:r}),this}use(...t){return this.P(null,null,null,!0,t)}mount(t,...e){return this.P(null,null,t,!0,e)}within(t,e){const n=new Kt;return e(n),this.mount(t,n)}at(t,...e){return this.P(null,null,t,!1,e)}onRequest(t,e,...n){return this.P(te(t),Zt,e,!1,n.map(Vt))}onUpgrade(t,e,n,...i){return this.P(te(t),e,n,!1,i.map(Xt))}onError(...t){return this.P(null,null,null,!0,t.map(Gt))}onReturn(...t){return this.ut.push(...t),this}on(t,...e){const n=/^([A-Z]+) (\/.*)$/.exec(t);if(!n)throw new Error("invalid method + path spec: "+JSON.stringify(t));return this.P(n[1],Zt,n[2],!1,e.map(Vt))}get=(t,...e)=>this.P(Qt,Zt,t,!1,e.map(Vt));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this.Et(t,new tt)}async handleUpgrade(t){return this.Et(t,new tt)}async handleError(t,e){const n=new tt;return n.P(t),this.Et(e,n)}shouldUpgrade(t){return this.xt(wt(t))}xt(t){for(const e of this.ft){const n=ee(t,e);if(!n)continue;let i=()=>{};if(!0!==n)try{i=Dt(t,n.Tt,[])}catch{continue}try{for(const n of e._t)if(re(n,t))return!0}finally{i()}}return!1}async Et(t,e){const n=wt(t),i=await this.kt(n,e);if(e.$)throw e.O;return i}async kt(t,e){for(const n of this.ft){const i=ee(t,n);if(!i)continue;let r=()=>{};if(!0!==i)try{const e=i.St();r=Dt(t,i.Tt,e)}catch(t){e.P(t);continue}try{const i=await ne(t,n._t,this.ut,e);if(i===At)break;if(i===Pt)continue;return i}finally{r()}}return Ot}}const Qt=new Set(["HEAD","GET"]),te=t=>t?"string"==typeof t?t:new Set(t):null;function ee(t,e){if("string"==typeof e.yt){if(e.yt!==t.N.method)return!1}else if(null!==e.yt&&!e.yt.has(t.N.method??""))return!1;if(e.gt===Zt){if(t.H)return!1}else if(null!==e.gt&&!t.H?.has(e.gt))return!1;if(null===e.bt)return!0;const n=e.bt.exec(t.U);return!!n&&{Tt:"/"+(n.groups?.rest??""),St:()=>e.vt.map((t,e)=>[t.ht,t.lt(n[e+1])])}}async function ne(t,e,n,i){for(const r of e){let e=await ie(r,t,i);if(e!==Ot){if(!t.H&&!(e instanceof St)&&n.length)try{const i="object"==typeof e?e:void 0,r=t.N,s=t.L.W;for(const t of n)await t(i,r,s)}catch(t){i.P(t);continue}return e}}return Pt}async function ie(t,e,n){if(t instanceof Kt)return t.kt(e,n);let i=Ot;try{if(n.$){if(t.handleError){const r=n.O;n.A(),i=await t.handleError(r,e.N,e.H?{socket:e.L.W,head:e.L.t}:{response:e.L.W})}}else if(e.H){if(t.handleUpgrade){const n=e.L;i=await t.handleUpgrade(e.N,n.W,n.t)}}else t.handleRequest&&(i=await t.handleRequest(e.N,e.L.W))}catch(t){t instanceof St?i=t:n.P(t)}finally{await((t,e)=>lt(t.D,e,t))(e,n)}return i===$t?void 0:i}function re(t,e){if(t instanceof Kt)return t.xt(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.N)}catch(t){return e.$t(t),!1}}function se(t,{onError:e=at,socketCloseTimeout:n=500}={}){const i=[],r=new Set,s=()=>{const t=[...i];i.length=0;for(const e of t)e()},o=t=>{t&&(r.size?i.push(t):setImmediate(t))},c=t=>{r.add(t),t.I.push(()=>{r.delete(t),!r.size&&i.length&&setImmediate(s)})},a=(t,n)=>e(t,"tearing down",n);return{request:async(n,i)=>{let r;try{r=ut(n,!1)}catch(t){return e(t,"parsing request",n),void ot(new st(400),0,i)}ht(r,!1,{W:i},a),c(r);const s=new tt,o=await ie(t,r,s);s.$?(e(s.O,"handling request",n),ot(s.O,0,i)):o!==Ot&&o!==Pt&&o!==At||ot(new st(404),0,i)},upgrade:async(i,r,s)=>{let o;r.once("finish",()=>{const t=setTimeout(()=>r.destroy(),n);r.once("close",()=>clearTimeout(t))});try{o=ut(i,!0)}catch(t){return e(t,"parsing upgrade",i),void ct(new st(400),0,r)}ht(o,!0,{W:r,t:s},a),s=Y,c(o);const f=new tt,u=await ie(t,o,f);f.$?(e(f.O,"handling upgrade",i),o.B(f.O,i,r)):u!==Ot&&u!==Pt&&u!==At||(console.warn(`Upgrade ${i.headers.upgrade} request for ${i.url} fell-through. This probably means you need to add shouldUpgrade to one of your upgrade handlers, or if this is intentional, explicitly reject the request (throw new HTTPError(404)) instead of using CONTINUE.`),o.B(new st(404),i,r))},shouldUpgrade:n=>{try{const i=ut(n,!0);return i.$t=t=>e(t,"checking should upgrade",n),re(t,i)}catch{return!1}},clientError:(t,n)=>{const i=n.Ot,r=t.code;n.writable&&!i?.headersSent&&n.end(ce.get(r)??ae),n.destroy(t),"HPE_INVALID_EOF_STATE"===r||e(t,"initialising request")},softClose(t,e,n){for(const n of r)bt(n,t,e);o(n)},hardClose(t){for(const t of r)vt(t);o(t)},countConnections:()=>r.size}}const oe=t=>Buffer.from(`HTTP/1.1 ${t} ${n[t]}\r\nConnection: close\r\n\r\n`),ce=new Map([["HPE_HEADER_OVERFLOW",oe(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",oe(413)],["ERR_HTTP_REQUEST_TIMEOUT",oe(408)]]),ae=oe(400);class fe extends EventTarget{Pt;constructor(t){super(),this.Pt=t}attach(t,e={}){const n=se(this.Pt,{...e,onError:this.At.bind(this,t)});!1===e.autoContinue&&t.addListener("checkContinue",n.request),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",n.request),t.addListener("request",n.request),t.addListener("upgrade",n.upgrade);const i=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=n.shouldUpgrade),t.addListener("clientError",n.clientError);let r=!1;return(e="",s=-1,o=!1)=>{r||(r=!0,t.removeListener("checkContinue",n.request),t.removeListener("checkExpectation",n.request),t.removeListener("request",n.request),t.removeListener("upgrade",n.upgrade),t.shouldUpgradeCallback===n.shouldUpgrade&&(t.shouldUpgradeCallback=i),t.removeListener("clientError",n.clientError));const c=()=>{o&&t.closeAllConnections()};if(s>0){const i=setTimeout(n.hardClose,s);n.softClose(e,this.At.bind(this,t),()=>{clearTimeout(i),c()})}else 0===s&&n.hardClose(c);return n}}listen(t,e,n={}){n.shouldUpgradeCallback&&(n={overrideShouldUpgradeCallback:!1,...n});const r=i(n);n.socketTimeout&&r.setTimeout(n.socketTimeout);const s=this.attach(r,n),o=Object.assign(r,{closeWithTimeout:(t,e)=>new Promise(n=>{r.close(()=>n()),s(t,e,!0)})});return new Promise((i,s)=>{r.once("error",s),r.listen(t,e,n.backlog??511,()=>{r.off("error",s),i(o)})})}At(t,e,n,i){const r={error:e,server:t,action:n,request:i};this.dispatchEvent(new CustomEvent("error",{detail:r}))&&at(e,n,i)}}const ue=t=>pt(t)?.C??Z(t),he=t=>ue(t).search,le=t=>new URLSearchParams(ue(t).searchParams),de=(t,e)=>ue(t).searchParams.get(e);function pe(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function we(t){const e=t.headers.authorization;if(!e)return;const[n,i]=pe(e," ");return void 0!==i?[n.trim().toLowerCase(),i.trim()]:void 0}function me(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function ye(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:xe(e)}:{}}function ge(t,e,{maxRanges:n=10,maxNonSequential:i=2,maxWithOverlap:r=2}={}){const s=t.headers.range;if(!s||0===e)return;const[o,c]=pe(s,"=");if("bytes"!==o||!c)return;const a=new st(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=ve(t);if(void 0===e)throw a;return e},u=[];for(const t of c.split(",")){const[i,r]=pe(t.trim(),"-");if(void 0===r)throw a;let s;if(i)s={start:f(i),end:r?Math.min(f(r),e-1):e-1};else{if(!r)throw a;s={start:Math.max(e-f(r),0),end:e-1}}if(!(s.start>=e)){if(s.end<s.start||u.length>=n)throw a;u.push(s)}}if(!u.length)throw a;if(u.length>i)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw a;if(u.length>r)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw a}}return{ranges:u,totalSize:e}}function be(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function ve(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}function _e(t){if(t)return t.split(",").map(t=>{const[e,...n]=t.split(";"),i=new Map(n.map(t=>{const[e,n]=pe(t,"=");return[e.trim(),n?.trim()??""]})),r=e.trim(),s="*/*"===r||"*"===r?0:r.endsWith("/*")?1:2,o=Math.max(0,Math.min(1,Number.parseFloat(i.get("q")??"1")));return{name:r,specifiers:i,specificity:s,q:o}})}function Ee(t){const e=new Map,n=/\s*([^=]+)=([^";]*?|"(?:[^\\"]|\\.)*")\s*(?:;|$)/y;for(;n.lastIndex<t.length;){const i=n.exec(t);if(!i)throw new st(400,{body:"invalid HTTP key values"});const r=i[1].toLowerCase();let s=i[2];'"'===s[0]&&(s=s.substring(1,s.length-1).replaceAll(/\\(.)/g,(t,e)=>e)),e.set(r,s)}return e}function xe(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const Te=t=>"function"==typeof t?t:()=>t;function ke(t){return{factory:Te(t),set(t,e){Oe(t,this,e)},get(t){return Pe(t,this)},clear(t){Ae(t,this)}}}const Se=(t,...e)=>{const n={factory:n=>t(n,...e)};return t=>Pe(t,n)};function $e(t){return t.Mt||(t.Mt=new Map),t.Mt}function Oe(t,e,n){$e(wt(t)).set(e,n)}function Pe(t,e){const n=pt(t);if(!n)return e.factory(t);const i=$e(n);if(i.has(e))return i.get(e);const r=e.factory(t);return i.set(e,r),r}function Ae(t,e){const n=pt(t);n?.Mt?.delete(e)}function Me({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:i=!0,softCloseBufferTime:r=0,onSoftCloseError:s}){const o=Te(t);return Jt(async t=>{const c=Date.now(),a=await o(t),f={"www-authenticate":`Bearer realm="${a}"`},u=we(t),h="bearer"===u?.[0]?u[1]:await(n?.(t));if(!h)throw new st(401,{headers:f,body:"no token provided"});const l=await e(h,a,t);if(!l)throw new st(401,{headers:f,body:"invalid token"});if("object"==typeof l){if("nbf"in l&&"number"==typeof l.nbf&&c<1e3*l.nbf)throw new st(401,{headers:f,body:"token not valid yet"});if("exp"in l&&"number"==typeof l.exp){const e=1e3*l.exp;if(c>=e-r)throw new st(401,{headers:f,body:"token expired"});i&&((t,e,n,i=0,r=at)=>{const s=wt(t),o=n-Math.max(i,0),c=s.tt??Number.POSITIVE_INFINITY,a=s.et?.nt??c;o>=a&&n>=c||(n<c&&(s.tt=n),o<a&&(s.et={nt:o,Y:e,Z:r}),_t(s))})(t,"token expired",e,r,s)}}return Ce.set(t,{realm:a,data:l,scopes:Ue(l)}),Ot})}const Re=t=>Ce.get(t).data,Fe=(t,e)=>Ce.get(t).scopes.has(e),Ne=t=>Jt(e=>{const n=Ce.get(e);if(!n.scopes.has(t))throw new st(403,{headers:{"www-authenticate":`Bearer realm="${n.realm}", scope="${t}"`},body:`scope required: ${t}`});return Ot}),Ce=/*@__PURE__*/ke({realm:"",data:null,scopes:new Set});function Ue(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return Array.isArray(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function Be(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${h("sha256").update(n).digest("base64").substring(0,12)}"`}async function je(t){const e=h("sha256");return"string"==typeof t?await d(c(t),e):await d(t.createReadStream({start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const De=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),Ie={mime:"accept",language:"accept-language",encoding:"accept-encoding"},He={zstd:"{file}.zst",br:"{file}.br",gzip:"{file}.gz",deflate:"{file}.deflate",identity:"{file}"},qe=t=>{return{type:"encoding",options:(e=t,n=He,Array.isArray(e)?e.map(t=>[t,n[t]]):Object.entries(e)).map(([t,e])=>({match:t,file:e}))};var e,n};function Le(t,e=10){const n=t.map(t=>({Rt:t.type,Ft:t.options.map(t=>({Nt:t.file,Ct:"string"==typeof t.match?t.match.toLowerCase():De(t.match,!0),Ut:t.as??("string"==typeof t.match?t.match:void 0)}))})).filter(t=>t.Ft.length>0);return{options(t,i){let r=e;const s={},o={mime:ze(i.mime),language:ze(i.language),encoding:ze(i.encoding)};return function*t(e,i){const c=n[i];if(!c)return--r,void(yield{filename:e,info:s});const a=new Set,f=o[c.Rt]??[];for(const n of f){const o=n.name.toLowerCase();for(const n of c.Ft)if("string"==typeof n.Ct?n.Ct===o:n.Ct.test(o)){const o=We(e,n.Nt);if(a.has(o))continue;if(a.add(o),s[c.Rt]=n.Ut,yield*t(o,i+1),r<=0)return}}s[c.Rt]=void 0,!a.has(e)&&r>0&&(yield*t(e,i+1))}(t,0)},vary:[...new Set(n.map(t=>Ie[t.Rt]))].join(" ")}}function ze(t){if(t?.length)return 1===t.length?t:[...t].sort((t,e)=>e.q-t.q||e.specificity-t.specificity)}function We(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):m(t))}const Je=/*@__PURE__*/Ye("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let Ge=/*@__PURE__*/new Map(Je);function Ve(){Ge=new Map(Je)}function Xe(t){const e=new Map;for(const n of t.split("\n")){const[t,...i]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of i)e.set(n.toLowerCase(),t)}return e}function Ye(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,i,r]=/^ *([^=]+)=(.*)$/.exec(n)??[null,null,""];for(const t of i?.split(",")??[]){const[n,i,s="",o=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),c=i+s+o,a=r.replace("{ext}",c);e.set(c.toLowerCase(),a),s&&e.set((i+o).toLowerCase(),a)}}return e}function Ze(t){for(const[e,n]of t)Ge.set(e.toLowerCase(),n)}function Ke(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=Ge.get(t)??"application/octet-stream";return n.startsWith("text/")&&!n.includes("charset=")?`${n}; charset=${e}`:n}async function Qe(t,e,n){const i=await E(t),r={file:t,mime:Ke(m(t)),rawSize:i.byteLength,bestSize:i.byteLength,created:0};if(r.rawSize<=n)return r;if(["image","video","audio","font"].includes(r.mime.split("/")[0]))return r;for(const s of e){const e=nn.get(s.match),o=y(g(t),We(b(t),s.file));if(!e||o===s.file)continue;const c=await e(i);c.byteLength<=r.rawSize-n&&(await x(o,c),r.bestSize=Math.min(r.bestSize,c.byteLength),++r.created)}return r}async function tn(t,e,n){const i=[];await en(t,i);const r=new Set(i);for(const t of r)for(const n of e){const e=y(g(t),We(b(t),n.file));e!==t&&r.delete(e)}return Promise.all([...r].map(t=>Qe(t,e,n)))}async function en(t,e){const n=await T(t);if(n.isDirectory())for(const n of await k(t))await en(y(t,n),e);else n.isFile()&&e.push(t)}const nn=/*@__PURE__*/new Map([["zstd",t=>w(p.zstdCompress)(t)],["brotli",t=>w(p.brotliCompress)(t,{params:{[p.constants.BROTLI_PARAM_QUALITY]:p.constants.BROTLI_MAX_QUALITY,[p.constants.BROTLI_PARAM_SIZE_HINT]:t.length}})],["gzip",t=>w(p.gzip)(t,{level:p.constants.Z_BEST_COMPRESSION})],["deflate",t=>w(p.deflate)(t)]]);class rn{Bt;jt;Dt;It;Ht;qt;Lt;zt;Wt;Jt;Gt;Vt;Xt;vary;constructor(t,{subDirectories:e=!0,caseSensitive:n="exact",allowAllDotfiles:i=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:s=!1,allow:o=[".well-known"],hide:c=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:f=[],negotiation:u}){this.Bt=t,this.jt=!0===e?Number.POSITIVE_INFINITY:e||0,this.Dt=n,this.It=i,this.Ht=r,this.qt=s,this.Jt=a,this.Vt=["",...f],this.Lt=new Set(o.map(t=>this.Yt(t))),this.zt=new Set,this.Wt=[];for(const t of c)"string"==typeof t?this.zt.add(this.Yt(t)):this.Wt.push(De(t,!n));this.Gt=new Set(a.map(t=>this.Yt(t))),u?.length?(this.Xt=Le(u),this.vary=this.Xt.vary):this.vary=""}static async build(t,e){return new rn(await S(t,{encoding:"utf-8"})+v,e)}Yt(t){return"exact"===this.Dt?t:t.toLowerCase()}Zt(t){if(this.Lt.has(t))return!0;const e=t.trim();return!(!("~"!==e[0]&&"~"!==e[e.length-1]||this.Ht)||"."===e[0]&&!this.It||this.zt.has(e)||this.Wt.some(t=>t.test(e)))}async find(t,e={}){let n=t.join(v);"force-lowercase"===this.Dt&&(n=n.toLowerCase());let i=_(this.Bt,n);if(!i.startsWith(this.Bt)&&i+v!==this.Bt)return null;let r=null,s=null;for(const t of this.Vt){const e=i+t;if(r=e.substring(this.Bt.length).split(v).filter(t=>t),r.length>this.jt+1)return null;if(r.some(t=>!this.Zt(this.Yt(t))))return null;const n=r[r.length-1]??"";if(!this.qt&&this.Gt.has(this.Yt(n))&&!this.Lt.has(this.Yt(n)))return null;if(s=await S(e,{encoding:"utf-8"}).catch(()=>null),s){i=e;break}}if(!s||!r)return null;if(this.Yt(s)!==this.Yt(i))return null;let o=s,c=await T(s).catch(()=>null);if(!c)return null;if(c.isDirectory()){if(r.length>this.jt)return null;for(const t of this.Jt){const e=y(s,t);if(c=await T(e).catch(()=>null),c?.isFile()){o=e;break}}}if(!c?.isFile())return null;if(this.Xt){const t=b(o),n=g(o);for(const i of this.Xt.options(t,e)){if(!i.filename||i.filename.includes(v))continue;const t=await on({canonicalPath:o,negotiatedPath:y(n,i.filename),...i.info});if(t)return t}}return on({canonicalPath:o,negotiatedPath:o})}async precompute(){const t=new Map,e=(e,n)=>{const i=t.get(e);(!i||n.p>i.p)&&t.set(e,n)},n=new J({dir:[this.Bt],depth:0});for(const{dir:t,depth:i}of n){const r=await k(y(...t),{withFileTypes:!0,encoding:"utf-8"}),s=new Set(r.map(t=>this.Yt(t.name)));for(const o of r){const r=this.Yt(o.name);if(!this.Zt(r))continue;const c=[...t,o.name];if(o.isDirectory())i<this.jt&&n.push({dir:c,depth:i+1}),e(this.Yt(c.slice(1).join("/")),sn);else if(o.isFile()){const n={file:y(...c),dir:y(...t),basename:r,siblings:s},i=this.Jt.indexOf(r);if(-1!==i&&(e(this.Yt(t.slice(1).join("/")),{...n,p:this.Jt.length+1-i}),!this.qt&&!this.Lt.has(r)))continue;const a=this.Yt(c.slice(1).join("/"));for(let t=0;t<this.Vt.length;++t){const i=this.Vt[t];o.name.endsWith(i)&&e(a.substring(0,a.length-i.length),{...n,p:-t})}}}}return{find:async(e,n={})=>{const i=t.get(this.Yt(e.join("/")));if(!i?.file)return null;if(this.Xt)for(const t of this.Xt.options(i.basename,n)){if(!i.siblings.has(this.Yt(t.filename)))continue;const e=await on({canonicalPath:i.file,negotiatedPath:y(i.dir,t.filename),...t.info});if(e)return e}return on({canonicalPath:i.file,negotiatedPath:i.file})},vary:this.vary}}}const sn={file:"",dir:"",basename:"",siblings:new Set,p:1};async function on(t){const e=await $(t.negotiatedPath,a.O_RDONLY).catch(()=>null);if(!e)return null;const n=()=>(e.close().catch(()=>{}),null),i=await e.stat().catch(n);return i?.isFile()?{handle:e,stats:i,...t}:n()}const cn=Se(async t=>{const e=kt(t);if(e.aborted)throw $t;e.throwIfAborted();const n=await O(y(A(),"upload"));Tt(t,()=>P(n,{recursive:!0}));let i=0;const r=()=>{if(e.aborted)throw $t;return y(n,(++i).toString(10).padStart(6,"0"))};return{dir:n,nextFile:r,save:async(t,{mode:n=384}={})=>{const i=r(),s=f(i,{mode:n});try{return await d(t,s,{signal:e}),{path:i,size:s.bytesWritten}}finally{s.close()}}}});function an(t){const e=wt(t);if(!e.L)throw new Error("cannot call acceptBody from shouldUpgrade");if(e.j.signal.aborted)throw $t;e.Kt||e.H||(e.Kt=!0,"100-continue"===t.headers.expect?.trim().toLowerCase()&&e.L.W.writeContinue())}function fn(t,{blockRequestHeaders:e=["connection","expect","host","keep-alive","proxy-authorization","transfer-encoding","upgrade","via"],requestHeaders:n=[],blockResponseHeaders:i=["connection","keep-alive","transfer-encoding"],responseHeaders:o=[],agent:c,keepAlive:a=!0,maxSockets:f=10,...u}={}){let h;t.startsWith("https://")?(c??=new R({keepAlive:a,maxSockets:f,...u}),h=s):(c??=new r({keepAlive:a,maxSockets:f,...u}),h=F);const l=t.endsWith("/")?t:t+"/";return zt((r,s)=>new Promise((a,f)=>{const u=kt(r),p=t=>f(u.aborted?$t:new st(502,{cause:t})),w=new URL(l+r.url?.substring(1)),m=w.toString();if(!m.startsWith(l)&&m!==t)return f(new st(400,{message:"directory traversal blocked"}));an(r);let y={...r.headers};un(y,e);for(const t of n)y=t(r,y);const g=h(w,{agent:c,method:r.method,headers:y,signal:u});g.once("error",p),g.once("response",t=>{if(!s.headersSent){let e={...t.headers};un(e,i);for(const n of o)e=n(r,t,e);s.writeHead(t.statusCode??200,t.statusMessage,e)}d(t,s).then(a,f)}),d(r,g).catch(p)}))}function un(t,e){for(const e of be(t.connection)??[])delete t[e.toLowerCase()];for(const n of e)delete t[n]}function hn({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const i=e?q(e):()=>!0,r=t??(e?Number.POSITIVE_INFINITY:0),s=new Set(n);return Se(t=>{const e=e=>{if(s.has(e))return be(t.headers[e])?.reverse()},n=e("forwarded"),o=e("x-forwarded-for"),c=e("x-forwarded-host"),a=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),h=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^ ]+) (.+)$/.exec(t);return e?.[3]?H(e[3]):void 0}),l=[ln(t)];if(n)for(const t of n)try{const e=Ee(t);l.push({client:H(e.get("for")),server:H(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{l.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(o){const t=o.map(H),e=c??[],n=a??f??u??[];let i=l[0].client;for(let r=0;r<t.length;++r){const s=t[r];l.push({client:s,server:h?.[r]??(i?{...i,port:void 0}:void 0),host:e[r],proto:n[r]}),i=s}}else if(h)for(const t of h)l.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+r,l.length);for(let t=0;t<d-1;++t)i(l[t].client)||(d=t+1);return Object.freeze({trusted:l.slice(0,d),untrusted:l.slice(d),outwardChain:l,edge:l[d-1]})})}const ln=t=>({client:{...H(t.socket.remoteAddress)??dn,port:t.socket.remotePort},server:{...H(t.socket.localAddress)??dn,port:t.socket.localPort},host:t.headers.host,proto:void 0}),dn={type:"alias",ip:"_disconnected",port:void 0};function pn(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],e}function wn(t,e){const n=pn(0,e);return n.forwarded=gn([ln(t)]),n}const mn=(t,{onlyTrusted:e=!1}={})=>(n,i)=>{const r=pn(0,i),s=t(n);return r.forwarded=gn([...e?s.trusted:s.outwardChain].reverse()),r};function yn(t,e){let n=t.headers.forwarded;const i=gn([ln(t)]);n?n+=", "+i:n=i;const r=pn(0,e);return r.forwarded=n,r}function gn(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.ip,by:t.server?.ip,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}class bn extends N{constructor(t){super({transform(r,s){const o=r.byteLength,c=[];let a=0;if(i>0){if(a=4-i,o<a)return e.set(r,i),void(i+=o);e.set(r.subarray(0,a),i),c.push(n.getUint32(0,t)),i=0}const f=new DataView(r.buffer,r.byteOffset,r.byteLength);let u=a;for(const e=o-3;u<e;u+=4)c.push(f.getUint32(u,t));c.length>0&&s.enqueue(String.fromCodePoint(...c)),u<o&&(e.set(r.subarray(u)),i=o-u)}});const e=new Uint8Array(4),n=new DataView(e.buffer);let i=0}}const vn=new Map;function _n(t,e){vn.set(t.toLowerCase(),e)}function En(){_n("utf-32be",()=>new bn(!1)),_n("utf-32le",()=>new bn(!0))}function xn(t,e){const n=vn.get(t);if(n)return n(e);try{return new C(t,e)}catch{throw new st(415,{body:`unsupported charset: ${t}`})}}const Tn=["utf-32be",null,"utf-16be","utf-16be","utf-32le","utf-16le",null,"utf-8"];function kn(t,e,n){const i=xe(t.headers["if-modified-since"]),r=be(t.headers["if-none-match"]);if(r){if($n(e,n,r))return!1}else if(i&&(n.mtimeMs/1e3|0)<=i)return!1;return!0}function Sn(t,e,n){let i=!0;const r=ye(t);return r.etag&&(i&&=$n(e,n,r.etag)),r.modifiedSeconds&&(i&&=(n.mtimeMs/1e3|0)===r.modifiedSeconds),i}function $n(t,e,n){if(n.includes("*"))return!0;const i=t.getHeader("etag");if("string"==typeof i){if(n.includes(i))return!0;if(i.startsWith('W/"'))return!1}return!!n.some(t=>t.startsWith('W/"'))&&n.includes(Be(t.getHeader("content-encoding"),e))}class On extends N{constructor(t,e){super({transform(i,r){n+=i.byteLength,n>t?r.error(e):r.enqueue(i)}});let n=0}}function Pn(t,{maxExpandedLength:e=Number.POSITIVE_INFINITY,maxContentLength:n=e,maxEncodingSteps:i=1}={}){const r=ve(t.headers["content-length"]);if(void 0!==r&&r>n)throw new st(413);const s=be(t.headers["content-encoding"])??[];if(s.length>i)throw new st(415,{body:"too many content-encoding stages"});an(t);let o=j.toWeb(t);void 0===r&&Number.isFinite(n)&&(o=o.pipeThrough(new On(n,new st(413))));for(const t of s.reverse())o=o.pipeThrough(Fn(t));return Number.isFinite(e)&&(o=o.pipeThrough(new On(e,new st(413,{body:"decoded content too large"})))),o}function An(t,e={}){const n=Pn(t,e),i=me(t)??e.defaultCharset??"utf-8";return n.pipeThrough(xn(i,e))}async function Mn(t,e={}){const n=[];for await(const i of An(t,e))n.push(i);return n.join("")}async function Rn(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),i=new Uint8Array(3);let r=0,s=null;for(;;){const t=await n.read(),e=3-r;if(t.done){0===r?(i[0]=1,i[1]=1):1===r&&(i[1]=i[0]),i[2]=i[0],s=null;break}if(s=t.value,s.byteLength>=e){i.set(s.subarray(0,e),r);break}i.set(s,r),r+=s.byteLength}const o=Tn[(i[0]?4:0)|(i[1]?2:0)|(i[2]?1:0)];if(!o)throw n.cancel(),new st(415,{body:"invalid JSON encoding"});const c=xn(o,e),a=c.writable.getWriter();return r&&a.write(i.subarray(0,r)),s&&a.write(s),n.releaseLock(),a.releaseLock(),t.pipeThrough(c)})(Pn(t,e),e),i=[];for await(const t of n)i.push(t);return JSON.parse(i.join(""))}function Fn(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new U("gzip");case"deflate":return new U("deflate");case"br":try{return new U("brotli")}catch{return D.toWeb(p.createBrotliDecompress())}case"zstd":try{return D.toWeb(p.createZstdDecompress())}catch{throw new st(415,{body:"unsupported content encoding"})}default:throw new st(415,{body:"unknown content encoding"})}}function Nn(t){return t&&t.Qt&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Cn,Un,Bn,jn,Dn,In,Hn,qn,Ln,zn;function Wn(){if(Un)return Cn;function t(t,e,n){for(;e<t.length;){for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)break;if(59!==t.charCodeAt(e++))return;for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)return;let i;const r=e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(61!==n)return;break}}if(e===t.length)return;if(i=t.slice(r,e),++e===t.length)return;let c,a="";if(34===t.charCodeAt(e)){c=++e;let n=!1;for(;e<t.length;++e){const i=t.charCodeAt(e);if(92!==i){if(34===i){if(n){c=e,n=!1;continue}a+=t.slice(c,e);break}if(n&&(c=e-1,n=!1),1!==o[i])return}else n?(c=e,n=!1):(a+=t.slice(c,e),n=!0)}if(e===t.length)return;++e}else{for(c=e;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(e===c)return;break}}a=t.slice(c,e)}i=i.toLowerCase(),void 0===n[i]&&(n[i]=a)}return n}function e(t,e,n,i){for(;e<t.length;){for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)break;if(59!==t.charCodeAt(e++))return;for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)return;let u;const h=e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(61===n)break;return}}if(e===t.length)return;let l,d,p="";if(u=t.slice(h,e),42===u.charCodeAt(u.length-1)){const n=++e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==c[n]){if(39!==n)return;break}}if(e===t.length)return;for(d=t.slice(n,e),++e;e<t.length&&39!==t.charCodeAt(e);++e);if(e===t.length)return;if(++e===t.length)return;l=e;let i=0;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==a[n]){if(37===n){let n,r;if(e+2<t.length&&-1!==(n=f[t.charCodeAt(e+1)])&&-1!==(r=f[t.charCodeAt(e+2)])){const s=(n<<4)+r;p+=t.slice(l,e),p+=String.fromCharCode(s),l=(e+=2)+1,s>=128?i=2:0===i&&(i=1);continue}return}break}}if(p+=t.slice(l,e),p=r(p,d,i),void 0===p)return}else{if(++e===t.length)return;if(34===t.charCodeAt(e)){l=++e;let n=!1;for(;e<t.length;++e){const i=t.charCodeAt(e);if(92!==i){if(34===i){if(n){l=e,n=!1;continue}p+=t.slice(l,e);break}if(n&&(l=e-1,n=!1),1!==o[i])return}else n?(l=e,n=!1):(p+=t.slice(l,e),n=!0)}if(e===t.length)return;++e}else{for(l=e;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(e===l)return;break}}p=t.slice(l,e)}if(p=i(p,2),void 0===p)return}u=u.toLowerCase(),void 0===n[u]&&(n[u]=p)}return n}function n(t){let e;for(;;)switch(t){case"utf-8":case"utf8":return i.utf8;case"latin1":case"ascii":case"us-ascii":case"iso-8859-1":case"iso8859-1":case"iso88591":case"iso_8859-1":case"windows-1252":case"iso_8859-1:1987":case"cp1252":case"x-cp1252":return i.latin1;case"utf16le":case"utf-16le":case"ucs2":case"ucs-2":return i.utf16le;case"base64":return i.base64;default:if(void 0===e){e=!0,t=t.toLowerCase();continue}return i.other.bind(t)}}Un=1;const i={utf8:(t,e)=>{if(0===t.length)return"";if("string"==typeof t){if(e<2)return t;t=Buffer.from(t,"latin1")}return t.utf8Slice(0,t.length)},latin1:(t,e)=>0===t.length?"":"string"==typeof t?t:t.latin1Slice(0,t.length),utf16le:(t,e)=>0===t.length?"":("string"==typeof t&&(t=Buffer.from(t,"latin1")),t.ucs2Slice(0,t.length)),base64:(t,e)=>0===t.length?"":("string"==typeof t&&(t=Buffer.from(t,"latin1")),t.base64Slice(0,t.length)),other:(t,e)=>{if(0===t.length)return"";"string"==typeof t&&(t=Buffer.from(t,"latin1"));try{return new TextDecoder(this).decode(t)}catch{}}};function r(t,e,i){const r=n(e);if(r)return r(t,i)}const s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];return Cn={basename:t=>{if("string"!=typeof t)return"";for(let e=t.length-1;e>=0;--e)switch(t.charCodeAt(e)){case 47:case 92:return".."===(t=t.slice(e+1))||"."===t?"":t}return".."===t||"."===t?"":t},convertToUTF8:r,getDecoder:n,parseContentType:e=>{if(0===e.length)return;const n=Object.create(null);let i=0;for(;i<e.length;++i){const t=e.charCodeAt(i);if(1!==s[t]){if(47!==t||0===i)return;break}}if(i===e.length)return;const r=e.slice(0,i).toLowerCase(),o=++i;for(;i<e.length;++i){const r=e.charCodeAt(i);if(1!==s[r]){if(i===o)return;if(void 0===t(e,i,n))return;break}}return i!==o?{type:r,subtype:e.slice(o,i).toLowerCase(),params:n}:void 0},parseDisposition:(t,n)=>{if(0===t.length)return;const i=Object.create(null);let r=0;for(;r<t.length;++r){const o=t.charCodeAt(r);if(1!==s[o]){if(void 0===e(t,r,i,n))return;break}}return{type:t.slice(0,r).toLowerCase(),params:i}}}}function Jn(){if(In)return Dn;In=1;const{Readable:t,Writable:e}=I,n=function(){if(jn)return Bn;function t(t,e,n,i,r){for(let s=0;s<r;++s)if(t[e+s]!==n[i+s])return!1;return!0}function e(e,i){const r=i.length,s=e.te,o=s.length;let c=-e.ee;const a=o-1,f=s[a],u=r-o,h=e.ne,l=e.ie;if(c<0){for(;c<0&&c<=u;){const t=c+a,r=t<0?l[e.ee+t]:i[t];if(r===f&&n(e,i,c,a))return e.ee=0,++e.matches,c>-e.ee?e.re(!0,l,0,e.ee+c,!1):e.re(!0,void 0,0,0,!0),e.se=c+o;c+=h[r]}for(;c<0&&!n(e,i,c,r-c);)++c;if(c<0){const t=e.ee+c;return t>0&&e.re(!1,l,0,t,!1),e.ee-=t,l.copy(l,0,t,e.ee),l.set(i,e.ee),e.ee+=r,e.se=r,r}e.re(!1,l,0,e.ee,!1),e.ee=0}c+=e.se;const d=s[0];for(;c<=u;){const n=i[c+a];if(n===f&&i[c]===d&&t(s,0,i,c,a))return++e.matches,c>0?e.re(!0,i,e.se,c,!0):e.re(!0,void 0,0,0,!0),e.se=c+o;c+=h[n]}for(;c<r;){if(i[c]===d&&t(i,c,s,0,r-c)){i.copy(l,0,c,r),e.ee=r-c;break}++c}return c>0&&e.re(!1,i,e.se,c<r?c:r,!0),e.se=r,r}function n(t,e,n,i){const r=t.ie,s=t.ee,o=t.te;for(let t=0;t<i;++t,++n)if((n<0?r[s+n]:e[n])!==o[t])return!1;return!0}return jn=1,Bn=class{constructor(t,e){if("function"!=typeof e)throw new Error("Missing match callback");if("string"==typeof t)t=Buffer.from(t);else if(!Buffer.isBuffer(t))throw new Error("Expected Buffer for needle, got "+typeof t);const n=t.length;if(this.maxMatches=1/0,this.matches=0,this.re=e,this.ee=0,this.te=t,this.se=0,this.ie=Buffer.allocUnsafe(n),this.ne=[n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n],n>1)for(let e=0;e<n-1;++e)this.ne[t[e]]=n-1-e}reset(){this.matches=0,this.ee=0,this.se=0}push(t,n){let i;Buffer.isBuffer(t)||(t=Buffer.from(t,"latin1"));const r=t.length;for(this.se=n||0;i!==r&&this.matches<this.maxMatches;)i=e(this,t);return i}destroy(){const t=this.ee;t&&this.re(!1,this.ie,0,t,!1),this.reset()}}}(),{basename:i,convertToUTF8:r,getDecoder:s,parseContentType:o,parseDisposition:c}=Wn(),a=Buffer.from("\r\n"),f=Buffer.from("\r"),u=Buffer.from("-");function h(){}const l=16384;class d{constructor(t){this.header=Object.create(null),this.pairCount=0,this.byteCount=0,this.state=0,this.name="",this.value="",this.crlf=0,this.cb=t}reset(){this.header=Object.create(null),this.pairCount=0,this.byteCount=0,this.state=0,this.name="",this.value="",this.crlf=0}push(t,e,n){let i=e;for(;e<n;)switch(this.state){case 0:{let r=!1;for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(1!==b[n]){if(58!==n)return-1;if(this.name+=t.latin1Slice(i,e),0===this.name.length)return-1;++e,r=!0,this.state=1;break}}if(!r){this.name+=t.latin1Slice(i,e);break}}case 1:{let r=!1;for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(32!==n&&9!==n){i=e,r=!0,this.state=2;break}}if(!r)break}case 2:switch(this.crlf){case 0:for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(1!==v[n]){if(13!==n)return-1;++this.crlf;break}}this.value+=t.latin1Slice(i,e++);break;case 1:if(this.byteCount===l)return-1;if(++this.byteCount,10!==t[e++])return-1;++this.crlf;break;case 2:{if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];32===n||9===n?(i=e,this.crlf=0):(++this.pairCount<2e3&&(this.name=this.name.toLowerCase(),void 0===this.header[this.name]?this.header[this.name]=[this.value]:this.header[this.name].push(this.value)),13===n?(++this.crlf,++e):(i=e,this.crlf=0,this.state=0,this.name="",this.value=""));break}case 3:{if(this.byteCount===l)return-1;if(++this.byteCount,10!==t[e++])return-1;const n=this.header;return this.reset(),this.cb(n),e}}}return e}}class p extends t{constructor(t,e){super(t),this.truncated=!1,this.oe=null,this.once("end",()=>{if(this.ce(),0===--e.ae&&e.fe){const t=e.fe;e.fe=null,process.nextTick(t)}})}ce(t){const e=this.oe;e&&(this.oe=null,e())}}const w={push:(t,e)=>{},destroy:()=>{}};function m(t,e){return t}function y(t,e,n){if(n)return e(n);e(n=g(t))}function g(t){if(t.ue)return new Error("Malformed part header");const e=t.he;return e&&(t.he=null,e.destroy(new Error("Unexpected end of file"))),t.le?void 0:new Error("Unexpected end of form")}const b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],v=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];return Dn=class extends e{constructor(t){if(super({autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.highWaterMark?t.highWaterMark:void 0}),!t.conType.params||"string"!=typeof t.conType.params.boundary)throw new Error("Multipart: Boundary not found");const e=t.conType.params.boundary,l="string"==typeof t.defParamCharset&&t.defParamCharset?s(t.defParamCharset):m,y=t.defCharset||"utf8",g=t.preservePath,b={autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.fileHwm?t.fileHwm:void 0},v=t.limits,_=v&&"number"==typeof v.fieldSize?v.fieldSize:1048576,E=v&&"number"==typeof v.fileSize?v.fileSize:1/0,x=v&&"number"==typeof v.files?v.files:1/0,T=v&&"number"==typeof v.fields?v.fields:1/0,k=v&&"number"==typeof v.parts?v.parts:1/0;let S=-1,$=0,O=0,P=!1;this.ae=0,this.he=void 0,this.le=!1;let A,M,R,F,N,C=0,U=0,B=!1,j=!1,D=!1;this.ue=null;const I=new d(t=>{let e;if(this.ue=null,P=!1,F="text/plain",M=y,R="7bit",N=void 0,B=!1,!t["content-disposition"])return void(P=!0);const n=c(t["content-disposition"][0],l);if(n&&"form-data"===n.type){if(n.params&&(n.params.name&&(N=n.params.name),n.params["filename*"]?e=n.params["filename*"]:n.params.filename&&(e=n.params.filename),void 0===e||g||(e=i(e))),t["content-type"]){const e=o(t["content-type"][0]);e&&(F=`${e.type}/${e.subtype}`,e.params&&"string"==typeof e.params.charset&&(M=e.params.charset.toLowerCase()))}if(t["content-transfer-encoding"]&&(R=t["content-transfer-encoding"][0].toLowerCase()),"application/octet-stream"===F||void 0!==e){if(O===x)return j||(j=!0,this.emit("filesLimit")),void(P=!0);if(++O,0===this.listenerCount("file"))return void(P=!0);C=0,this.he=new p(b,this),++this.ae,this.emit("file",N,this.he,{filename:e,encoding:R,mimeType:F})}else{if($===T)return D||(D=!0,this.emit("fieldsLimit")),void(P=!0);if(++$,0===this.listenerCount("field"))return void(P=!0);A=[],U=0}}else P=!0});let H=0;const q=(t,e,n,i,s)=>{t:for(;e;){if(null!==this.ue){const t=this.ue.push(e,n,i);if(-1===t){this.ue=null,I.reset(),this.emit("error",new Error("Malformed part header"));break}n=t}if(n===i)break;if(0!==H){if(1===H){switch(e[n]){case 45:H=2,++n;break;case 13:H=3,++n;break;default:H=0}if(n===i)return}if(2===H){if(H=0,45===e[n])return this.le=!0,void(this.de=w);const t=this.pe;this.pe=h,q(!1,u,0,1,!1),this.pe=t}else if(3===H){if(H=0,10===e[n]){if(++n,S>=k)break;if(this.ue=I,n===i)break;continue t}{const t=this.pe;this.pe=h,q(!1,f,0,1,!1),this.pe=t}}}if(!P)if(this.he){let t;const r=Math.min(i-n,E-C);s?t=e.slice(n,n+r):(t=Buffer.allocUnsafe(r),e.copy(t,0,n,n+r)),C+=t.length,C===E?(t.length>0&&this.he.push(t),this.he.emit("limit"),this.he.truncated=!0,P=!0):this.he.push(t)||(this.pe&&(this.he.oe=this.pe),this.pe=null)}else if(void 0!==A){let t;const r=Math.min(i-n,_-U);s?t=e.slice(n,n+r):(t=Buffer.allocUnsafe(r),e.copy(t,0,n,n+r)),U+=r,A.push(t),U===_&&(P=!0,B=!0)}break}if(t){if(H=1,this.he)this.he.push(null),this.he=null;else if(void 0!==A){let t;switch(A.length){case 0:t="";break;case 1:t=r(A[0],M,0);break;default:t=r(Buffer.concat(A,U),M,0)}A=void 0,U=0,this.emit("field",N,t,{nameTruncated:!1,valueTruncated:B,encoding:R,mimeType:F})}++S===k&&this.emit("partsLimit")}};this.de=new n(`\r\n--${e}`,q),this.pe=null,this.fe=null,this.write(a)}static detect(t){return"multipart"===t.type&&"form-data"===t.subtype}we(t,e,n){this.pe=n,this.de.push(t,0),this.pe&&(t=>{const e=t.pe;t.pe=null,e&&e()})(this)}me(t,e){this.ue=null,this.de=w,t||(t=g(this));const n=this.he;n&&(this.he=null,n.destroy(t)),e(t)}ye(t){if(this.de.destroy(),!this.le)return t(new Error("Unexpected end of form"));this.ae?this.fe=y.bind(null,this,t):y(this,t)}}}function Gn(){if(qn)return Hn;qn=1;const{Writable:t}=I,{getDecoder:e}=Wn();function n(t,e,n,i){if(n>=i)return i;if(-1===t.ge){const r=s[e[n++]];if(-1===r)return-1;if(r>=8&&(t.be=2),n<i){const i=s[e[n++]];if(-1===i)return-1;t.ve?t._e+=String.fromCharCode((r<<4)+i):t.Ee+=String.fromCharCode((r<<4)+i),t.ge=-2,t.xe=n}else t.ge=r}else{const i=s[e[n++]];if(-1===i)return-1;t.ve?t._e+=String.fromCharCode((t.ge<<4)+i):t.Ee+=String.fromCharCode((t.ge<<4)+i),t.ge=-2,t.xe=n}return n}function i(t,e,n,i){if(t.Te>t.fieldNameSizeLimit){for(t.ke||t.xe<n&&(t._e+=e.latin1Slice(t.xe,n-1)),t.ke=!0;n<i;++n){const i=e[n];if(61===i||38===i)break;++t.Te}t.xe=n}return n}function r(t,e,n,i){if(t.Se>t.fieldSizeLimit){for(t.$e||t.xe<n&&(t.Ee+=e.latin1Slice(t.xe,n-1)),t.$e=!0;n<i&&38!==e[n];++n)++t.Se;t.xe=n}return n}const s=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];return Hn=class extends t{constructor(t){super({autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.highWaterMark?t.highWaterMark:void 0});let n=t.defCharset||"utf8";t.conType.params&&"string"==typeof t.conType.params.charset&&(n=t.conType.params.charset),this.charset=n;const i=t.limits;this.fieldSizeLimit=i&&"number"==typeof i.fieldSize?i.fieldSize:1048576,this.fieldsLimit=i&&"number"==typeof i.fields?i.fields:1/0,this.fieldNameSizeLimit=i&&"number"==typeof i.fieldNameSize?i.fieldNameSize:100,this.ve=!0,this.ke=!1,this.$e=!1,this.Te=0,this.Se=0,this.Oe=0,this._e="",this.Ee="",this.ge=-2,this.xe=0,this.be=0,this.Pe=e(n)}static detect(t){return"application"===t.type&&"x-www-form-urlencoded"===t.subtype}we(t,e,s){if(this.Oe>=this.fieldsLimit)return s();let o=0;const c=t.length;if(this.xe=0,-2!==this.ge){if(o=n(this,t,o,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();this.ve?++this.Te:++this.Se}t:for(;o<c;)if(this.ve){for(o=i(this,t,o,c);o<c;){switch(t[o]){case 61:this.xe<o&&(this._e+=t.latin1Slice(this.xe,o)),this.xe=++o,this._e=this.Pe(this._e,this.be),this.be=0,this.ve=!1;continue t;case 38:if(this.xe<o&&(this._e+=t.latin1Slice(this.xe,o)),this.xe=++o,this._e=this.Pe(this._e,this.be),this.be=0,this.Te>0&&this.emit("field",this._e,"",{nameTruncated:this.ke,valueTruncated:!1,encoding:this.charset,mimeType:"text/plain"}),this._e="",this.Ee="",this.ke=!1,this.$e=!1,this.Te=0,this.Se=0,++this.Oe>=this.fieldsLimit)return this.emit("fieldsLimit"),s();continue;case 43:this.xe<o&&(this._e+=t.latin1Slice(this.xe,o)),this._e+=" ",this.xe=o+1;break;case 37:if(0===this.be&&(this.be=1),this.xe<o&&(this._e+=t.latin1Slice(this.xe,o)),this.xe=o+1,this.ge=-1,o=n(this,t,o+1,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();++this.Te,o=i(this,t,o,c);continue}++o,++this.Te,o=i(this,t,o,c)}this.xe<o&&(this._e+=t.latin1Slice(this.xe,o))}else{for(o=r(this,t,o,c);o<c;){switch(t[o]){case 38:if(this.xe<o&&(this.Ee+=t.latin1Slice(this.xe,o)),this.xe=++o,this.ve=!0,this.Ee=this.Pe(this.Ee,this.be),this.be=0,(this.Te>0||this.Se>0)&&this.emit("field",this._e,this.Ee,{nameTruncated:this.ke,valueTruncated:this.$e,encoding:this.charset,mimeType:"text/plain"}),this._e="",this.Ee="",this.ke=!1,this.$e=!1,this.Te=0,this.Se=0,++this.Oe>=this.fieldsLimit)return this.emit("fieldsLimit"),s();continue t;case 43:this.xe<o&&(this.Ee+=t.latin1Slice(this.xe,o)),this.Ee+=" ",this.xe=o+1;break;case 37:if(0===this.be&&(this.be=1),this.xe<o&&(this.Ee+=t.latin1Slice(this.xe,o)),this.xe=o+1,this.ge=-1,o=n(this,t,o+1,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();++this.Se,o=r(this,t,o,c);continue}++o,++this.Se,o=r(this,t,o,c)}this.xe<o&&(this.Ee+=t.latin1Slice(this.xe,o))}s()}ye(t){if(-2!==this.ge)return t(new Error("Malformed urlencoded form"));(!this.ve||this.Te>0||this.Se>0)&&(this.ve?this._e=this.Pe(this._e,this.be):this.Ee=this.Pe(this.Ee,this.be),this.emit("field",this._e,this.Ee,{nameTruncated:this.ke,valueTruncated:this.$e,encoding:this.charset,mimeType:"text/plain"})),t()}}}var Vn=/*@__PURE__*/Nn((()=>{if(zn)return Ln;zn=1;const{parseContentType:t}=Wn(),e=[Jn(),Gn()].filter(t=>"function"==typeof t.detect);return Ln=n=>{if("object"==typeof n&&null!==n||(n={}),"object"!=typeof n.headers||null===n.headers||"string"!=typeof n.headers["content-type"])throw new Error("Missing Content-Type");return(n=>{const i=n.headers,r=t(i["content-type"]);if(!r)throw new Error("Malformed content type");for(const t of e){if(!t.detect(r))continue;const e={limits:n.limits,headers:i,conType:r,highWaterMark:void 0,fileHwm:void 0,defCharset:void 0,defParamCharset:void 0,preservePath:!1};return n.highWaterMark&&(e.highWaterMark=n.highWaterMark),n.fileHwm&&(e.fileHwm=n.fileHwm),e.defCharset=n.defCharset,e.defParamCharset=n.defParamCharset,e.preservePath=n.preservePath,new t(e)}throw new Error(`Unsupported content type: ${i["content-type"]}`)})(n)}})());function Xn(t,{allowMultipart:e=!1,closeAfterErrorDelay:n=500,limits:i={}}={}){const r=t.headers["content-type"]??"";if(!(/^application\/x-www-form-urlencoded\s*(;|$)/i.test(r)||e&&/^multipart\/form-data\s*(;|$)/i.test(r)))throw new st(415);an(t);const s=new G;i={...i},e||(i.files=0);const o=(e,i)=>{if(s.fail(new st(e,i)),a.removeAllListeners(),t.unpipe(a),t.resume(),n>=0){const e=setTimeout(()=>t.socket.destroy(),n);t.once("end",()=>clearTimeout(e))}},c=i.fieldNameSize??100,a=Vn({headers:t.headers,limits:i,preservePath:!1});a.on("field",(t,e,{nameTruncated:n,valueTruncated:i,encoding:r,mimeType:a})=>t?n||t.length>c?o(400,{body:`field name ${JSON.stringify(t.slice(0,c))}... too long`}):i?o(400,{body:`value for ${JSON.stringify(t)} too long`}):void s.push({name:t,encoding:r,mimeType:a,type:"string",value:e}):o(400,{body:"missing field name"})),a.on("file",(t,e,{filename:n,encoding:i,mimeType:r})=>null===t?o(400,{body:"missing field name"}):t.length>c?o(400,{body:`field name ${JSON.stringify(t.slice(0,c))}... too long`}):void(n?(e.once("limit",()=>o(400,{body:`uploaded file for ${JSON.stringify(t)}: ${JSON.stringify(n)} too large`})),s.push({name:t,encoding:i,mimeType:r,type:"file",value:e,filename:n})):e.resume())),t.once("error",e=>{t.readableAborted?s.fail($t):o(500,{body:"request error",headers:{connection:"close"},cause:e})}),a.once("error",t=>o(400,{body:"error parsing form data",cause:t})),a.once("partsLimit",()=>o(400,{body:"too many parts"})),a.once("filesLimit",()=>o(400,{body:"too many files"})),a.once("fieldsLimit",()=>o(400,{body:"too many fields"}));const f=()=>s.close("complete");return a.once("close",f),Tt(t,f),t.pipe(a),s}async function Yn(t,e={}){const n=new FormData,i=new Map;for await(const r of Xn(t,e))if("file"===r.type){const s=r.value;let o=await(e.preCheckFile?.({fieldName:r.name,filename:r.filename,encoding:r.encoding,mimeType:r.mimeType,maxBytes:e.limits?.fileSize}));const c=t=>{if("function"==typeof o){const e=o;return o=void 0,e({actualBytes:t})}};Tt(t,()=>c(0));const a=await cn(t),f=await a.save(s,{mode:384});await c(f.size);const h=new File([await u(f.path)],r.filename,{type:r.mimeType});i.set(h,f.path),n.append(r.name,h)}else{let t=r.value;e.trimAllValues&&(t=t.trim()),n.append(r.name,t)}return Object.assign(n,{getTempFilePath(t){const e=i.get(t);if(!e)throw new Error("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e}})}const Zn="win32"===/*@__PURE__*/M();function Kn(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const i=pt(t);if(i){if("/"===i.U)return[];n=i.U.split("/")}else{const e=Z(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new Error("invalid path");if(n.shift(),e){const t=Zn?ti:Qn;if(n.some(e=>t.test(e)||e.includes(v)))throw new Error("invalid path");if(n.slice(0,n.length-1).includes(""))throw new Error("invalid path")}return n}const Qn=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,ti=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i,ei=t=>new Promise(e=>{const n=()=>{t.cork(),e()};t instanceof o?t.write(Y,n):t.once("drain",n),t.uncork()});async function ni(t,e,{delimiter:n=",",newline:i="\n",quote:r='"',encoding:s="utf-8",headerRow:c,end:a=!0}={}){"string"==typeof n&&(n=Buffer.from(n,s)),"string"==typeof i&&(i=Buffer.from(i,s));const f="string"==typeof r?Buffer.from(r,s):r,u=r+r,h=e=>{if(!e)return!0;const n=e.includes(r);return!n&&ii.test(e)?t.write(e,s):(t.write(f),n?t.write(e.replaceAll(r,u),s):t.write(e,s),t.write(f))};t instanceof o&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+s+(c?"; header=present":!1===c?"; header=absent":"")),t.cork();try{t.write(Y);for await(const r of e){if(t.writableAborted)break;let e=0;if(Symbol.iterator in r)for(const i of r)e&&t.write(n),h(i)||await ei(t),++e;else for await(const i of r)e&&t.write(n),h(i)||await ei(t),++e;t.write(i)||await ei(t)}}finally{t.uncork()}a&&t.end()}const ii=/^[^"':;,\\\r\n\t ]*$/i;function ri(t){if(!t||"object"!=typeof t)return!1;const e=t;return"number"==typeof e.fd&&"function"==typeof e.stat&&"function"==typeof e.createReadStream}class si{lt;Ae;Me;m;constructor(t){(t=>{const e=t;return"function"==typeof e.ce&&"function"==typeof e.pipe})(t)&&(t=j.toWeb(t)),this.lt=t.getReader(),this.Ae=null,this.Me=0,this.m=0}getRange(t,e){if(e<t)throw new Error("invalid range");if(t<this.Me)throw new Error("non-sequential range");if(this.m)throw new Error("previous range still active");let n=e-t+1,i=t-this.Me;this.Me=e+1,this.m=1;const r=this,s=(t,e)=>{const r=t.byteLength;r<=i?i-=r:r>i+n?(this.Ae=t.subarray(i+n),e.enqueue(t.subarray(i,i+n)),n=0):i>0?(e.enqueue(t.subarray(i)),n-=r-i,i=0):(e.enqueue(t),n-=r)};return new B({start(t){if(r.Ae){const e=r.Ae;r.Ae=null,s(e,t)}},async pull(t){if(n<=0)return r.m=0,void t.close();const e=await r.lt.read();e.done?t.error(new Error("range exceeds content")):"string"==typeof e.value?s(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?s(e.value,t):t.error(new Error("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.lt.cancel(),this.lt.releaseLock()}}function oi(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const i=[];if(n>=0)for(const e of t.ranges){let t=null,r=0;for(let s=0;s<i.length;++s){const o=i[s];e.end>=o.start-n-1&&o.end>=e.start-n-1?t?(++r,t.start=Math.min(t.start,o.start),t.end=Math.max(t.end,o.end)):(t=o,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):r>0&&(i[s-r]=o)}t?i.length-=r:i.push({...e})}else i.push(...t.ranges);if(e)for(let t=0;t<i.length-1;++t)if(i[t].start>i[t+1].start){i.sort((t,e)=>t.start-e.start);break}return{ranges:i,totalSize:t.totalSize}}async function ci(t,e,n,i){if("string"==typeof n||ri(n)||(i=oi(i,{mergeOverlapDistance:0,forceSequential:!0})),1===i.ranges.length){const r=i.ranges[0];if(e.setHeader("content-length",r.end-r.start+1),e.setHeader("content-range",`bytes ${r.start}-${r.end}/${i.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const s=await ai(n);return await d(s.Re(r.start,r.end),e),void(s.Fe&&await s.Fe())}const r=e.getHeader("content-type"),s=l()+l()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${s}`);const o=i.ranges.map(t=>({t:[`--${s}`,...nt({"content-type":r,"content-range":`bytes ${t.start}-${t.end}/${i.totalSize??"*"}`}),"",""].join("\r\n"),Ne:t})),c=`--${s}--`;let a=c.length;for(const{t,Ne:e}of o)a+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",a),"HEAD"===t.method)return void e.end();let f="";const u=await ai(n);try{for(const{t,Ne:n}of o)e.write(f+t,"ascii"),await d(u.Re(n.start,n.end),e,{end:!1}),f="\r\n";e.end(f+c)}finally{u.Fe&&await u.Fe()}}async function ai(t){if("string"==typeof t){const e=await $(t,"r");return{Re:(t,n)=>e.createReadStream({start:t,end:n,autoClose:!1}),Fe:()=>e.close()}}if(ri(t))return{Re:(e,n)=>t.createReadStream({start:e,end:n,autoClose:!1})};{const e=new si(t);return{Re:(t,n)=>e.getRange(t,n),Fe:()=>e.close()}}}async function fi(t,e,n,i,r){if(i||("string"==typeof n?i=await T(n):ri(n)&&(i=await n.stat())),i){if("GET"===t.method||"HEAD"===t.method){if(!kn(t,e,i))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const s=ge(t,i.size,r);if(s&&Sn(t,e,i))return ci(t,e,n,oi(s,r))}e.setHeader("content-length",i.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method)return"string"==typeof n?n=c(n):ri(n)&&(n=n.createReadStream({start:0,autoClose:!1})),d(n,e);e.end()}function ui(t,e,{replacer:n,space:i,undefinedAsNull:r=!1,encoding:s="utf-8",end:c=!0}={}){const a=JSON.stringify(e,n,i)??(r?"null":void 0);t instanceof o&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),c&&t.setHeader("content-length",Buffer.byteLength(a,s))),c?t.end(a,s):a&&t.write(a,s)}async function hi(t,e,{replacer:n=null,space:i="",undefinedAsNull:r=!1,encoding:s="utf-8",end:c=!0}={}){if(Array.isArray(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||Array.isArray(this)||t.has(e)?n:void 0}}"number"==typeof i&&(i=" ".substring(0,i));const a={we:e=>t.write(e,s),Ce:()=>ei(t),Ue:n,Be:i};if(t instanceof o&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e=di(null,"",e,a),pi(e))r&&a.we("null");else{t.cork(),t.write(Y);try{await li(a,e,i?"\n":"")}finally{t.uncork()}}c&&t.end()}async function li(t,e,n){const i=(i,r,s)=>{t.we(i);const o=n+t.Be,c=t.Be?": ":":";let a=!0;return{u:async(n,i)=>{const r=di(e,n,i,t);s&&pi(r)||(a?a=!1:t.we(","),t.we(o),s&&(t.we(JSON.stringify(n))||await t.Ce(),t.we(c)),await li(t,r,o))},Fe:()=>{a||t.we(n),t.we(r)}}};if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||wi(e))t.we(JSON.stringify(e)??"null")||await t.Ce();else if(e instanceof j){t.we('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");const e=JSON.stringify(n);t.we(e.substring(1,e.length-1))||await t.Ce()}t.we('"')}else if(e instanceof Map){const t=i("{","}",!0);for(const[n,i]of e)await t.u(n,i);t.Fe()}else if(mi(e)){let t=0;const n=i("[","]",!1);for(const i of e)await n.u(String(t++),i);n.Fe()}else if(yi(e)){let t=0;const n=i("[","]",!1);for await(const i of e)await n.u(String(t++),i);n.Fe()}else{const t=i("{","}",!0);for(const[n,i]of Object.entries(e))await t.u(n,i);t.Fe()}}function di(t,e,n,i){return i.Ue&&(n=i.Ue.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const pi=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,wi=t=>JSON.isRawJSON?.(t)??!1,mi=t=>Symbol.iterator in t,yi=t=>Symbol.asyncIterator in t;class gi{je;j;De;Ie;constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:i=500,softCloseReconnectStagger:r=2e3}={}){this.je=e,this.De=n??0,this.j=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.He(),t.once("close",()=>this.close()),mt(t,()=>this.close(i,r))}get signal(){return this.j.signal}get open(){return!this.j.signal.aborted}He(){this.De&&(this.Ie=setTimeout(this.ping,this.De))}ping(){!this.j.signal.aborted&&this.je.writable&&(clearTimeout(this.Ie),this.je.write(":\n\n",()=>this.He()))}send({event:t,id:e,data:n,reconnectDelay:i=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",i>=0?String(0|i):void 0]])}async sendFields(t){if(this.j.signal.aborted)throw new Error("ServerSentEvents closed");let e;this.je.cork();try{let n=!1;for(const[e,i]of t){if(void 0===i)continue;const t=i.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.je.write(e)," "===n[0]?this.je.write(": "):this.je.write(":"),this.je.write(n);/[\r\n]$/.test(i)?(this.je.write(e),this.je.write(":\n")):this.je.write("\n"),n=!0}if(!n)return;clearTimeout(this.Ie),this.je.write("\n",()=>e())}finally{this.je.uncork()}await new Promise(t=>{e=t}),this.He()}async close(t=0,e=0){if(this.j.signal.aborted){if(this.je.closed)return;return new Promise(t=>this.je.once("close",t))}this.De=0,clearTimeout(this.Ie),this.j.abort(),await new Promise(n=>{if(this.je.writable&&(t>0||e>0)){const i=t+Math.random()*e;this.je.end(`retry:${0|i}\n\n`,n)}else this.je.end(n)})}}const bi=async(t,{mode:e="dynamic",fallback:n,callback:i=vi,...r}={})=>{const s=await rn.build(_(process.cwd(),t),r);let o=null;const c=n?.statusCode??200;if(n){let t=n.filePath;t.startsWith("/")&&(t=t.substring(1)),o=t.split("/")}const a="dynamic"===e?{}:{rejectPotentiallyUnsafe:!1},f="dynamic"===e?s:await s.precompute();return{handleRequest:async(t,e)=>{if("GET"!==t.method&&"HEAD"!==t.method)return Ot;let n=!1;const r=Kn(t,a),s={mime:_e(t.headers.accept),language:_e(t.headers["accept-language"]),encoding:_e(t.headers["accept-encoding"])};let u=await f.find(r,s);if(!u&&o&&(n=!0,u=await f.find(o,s)),!u)return Ot;try{n&&(e.statusCode=c),e.setHeader("content-type",u.mime??Ke(m(u.canonicalPath))),u.encoding&&"identity"!==u.encoding&&e.setHeader("content-encoding",u.encoding);const r=f.vary;if(r){const t=e.getHeader("vary")??"";e.setHeader("vary",(t?t+", ":"")+r)}await i(t,e,u,n),await fi(t,e,u.handle,u.stats)}finally{u.handle.close().catch(()=>{})}}}};function vi(t,e,n){e.setHeader("etag",Be(e.getHeader("content-encoding"),n.stats)),e.setHeader("last-modified",n.stats.mtime.toUTCString())}class _i extends Error{statusCode;statusMessage;constructor(t,{message:e,statusMessage:n,...i}={}){super(e,i),this.statusCode=0|t,this.statusMessage=n??"",this.name=`WebSocketError(${this.statusCode} ${this.statusMessage})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function Ei(t,{softCloseStatusCode:e=_i.GOING_AWAY,...n}={}){const i=(i,r,s)=>new Promise((o,c)=>{const a=new t({...n,noServer:!0,clientTracking:!1});a.once("wsClientError",c),a.handleUpgrade(i,r,s,t=>{a.off("wsClientError",c),o({return:t,onError:e=>{const n=V(e,_i);if(n)return void t.close(n.statusCode,n.statusMessage);const i=V(e,st)??st.INTERNAL_SERVER_ERROR,r=i.statusCode>=500?_i.INTERNAL_SERVER_ERROR:4e3+i.statusCode;t.close(r,i.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>Mt(t,i)}class xi{data;isBinary;constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new _i(_i.UNSUPPORTED_DATA,{statusMessage:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new _i(_i.UNSUPPORTED_DATA,{statusMessage:"expected binary"});return this.data}}class Ti{qe;detach;constructor(t,{limit:e=-1,signal:n}={}){this.qe=new G;const i=e=>{t.off("message",s),t.off("close",r),this.qe.close(new Error(e))},r=()=>i("connection closed"),s=(t,n)=>{void 0!==n?this.qe.push(new xi(t,n)):"string"==typeof t?this.qe.push(new xi(Buffer.from(t,"utf8"),!1)):this.qe.push(new xi(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.qe.close(new Error("signal aborted")):2===t.readyState||3===t.readyState?this.qe.close(new Error("connection closed")):(t.on("message",s),t.on("close",r),n?.addEventListener("abort",()=>i("signal aborted")),this.detach=()=>i("WebSocket listener detached"))}next(t){return this.qe.shift(t)}[Symbol.asyncIterator](){return this.qe[Symbol.asyncIterator]()}}function ki(t,{timeout:e,signal:n}={}){const i=new Ti(t,{limit:1,signal:n});return i.next(e).finally(()=>i.detach())}function Si(t){const e=wt(t);return"GET"===t.method&&(e.H?.has("websocket")??!1)}const $i=t=>t.headers.origin??it(t.headers["sec-websocket-origin"]),Oi=(t,e=5e3)=>async n=>{if(!Si(n))return;const i=await t(n);let r;try{r=await ki(i,{timeout:e})}catch(t){if((i.readyState??0)>=2)throw $t;throw new _i(_i.POLICY_VIOLATION,{statusMessage:"timeout waiting for authentication token",cause:t})}if(r.isBinary)throw new _i(_i.UNSUPPORTED_DATA,{statusMessage:"authentication token must be sent as text"});return r.data.toString("utf-8")};export{G as BlockingQueue,Ot as CONTINUE,rn as FileFinder,st as HTTPError,Pt as NEXT_ROUTE,At as NEXT_ROUTER,J as Queue,Kt as Router,$t as STOP,gi as ServerSentEvents,fe as WebListener,_i as WebSocketError,xi as WebSocketMessage,Ti as WebSocketMessages,an as acceptBody,Mt as acceptUpgrade,Tt as addTeardown,Jt as anyHandler,kn as checkIfModified,Sn as checkIfRange,Ae as clearProperty,$n as compareETag,Qe as compressFileOffline,tn as compressFilesInDir,Ye as decompressMime,xt as defer,Gt as errorHandler,bi as fileServer,V as findCause,je as generateStrongETag,Be as generateWeakETag,kt as getAbortSignal,qt as getAbsolutePath,X as getAddressURL,Re as getAuthData,we as getAuthorization,Rn as getBodyJson,Pn as getBodyStream,Mn as getBodyText,An as getBodyTextStream,me as getCharset,Yn as getFormData,Xn as getFormFields,ye as getIfRange,Ke as getMime,Ht as getPathParameter,It as getPathParameters,Pe as getProperty,de as getQuery,ge as getRange,Kn as getRemainingPathComponents,he as getSearch,le as getSearchParams,$i as getWebSocketOrigin,Fe as hasAuthScope,gt as isSoftClosed,Si as isWebSocketRequest,Ei as makeAcceptWebSocket,q as makeAddressTester,hn as makeGetClient,Se as makeMemo,Le as makeNegotiator,ke as makeProperty,cn as makeTempFileStorage,Oi as makeWebSocketFallbackTokenFetcher,qe as negotiateEncoding,ki as nextWebSocketMessage,H as parseAddress,fn as proxy,xe as readHTTPDateSeconds,ve as readHTTPInteger,Ee as readHTTPKeyValues,_e as readHTTPQualityValues,be as readHTTPUnquotedCommaSeparated,Xe as readMimeTypes,_n as registerCharset,Ze as registerMime,En as registerUTF32,pn as removeForwarded,wn as replaceForwarded,zt as requestHandler,Ne as requireAuthScope,Me as requireBearerAuth,Ve as resetMime,Lt as restoreAbsolutePath,mn as sanitiseAndAppendForwarded,ni as sendCSVStream,fi as sendFile,ui as sendJSON,hi as sendJSONStream,ci as sendRanges,vi as setDefaultCacheHeaders,Oe as setProperty,mt as setSoftCloseHandler,yn as simpleAppendForwarded,oi as simplifyRange,se as toListeners,Wt as upgradeHandler};
|
|
1
|
+
import{isIPv4 as t,isIPv6 as e}from"node:net";import{STATUS_CODES as n,createServer as i,Agent as r,request as s,ServerResponse as o}from"node:http";import{createReadStream as c,constants as a,createWriteStream as f,openAsBlob as u}from"node:fs";import{createHash as h,randomUUID as l}from"node:crypto";import{pipeline as d}from"node:stream/promises";import p from"node:zlib";import{promisify as w}from"node:util";import{extname as m,join as y,dirname as g,basename as b,sep as v,resolve as _}from"node:path";import{readFile as E,writeFile as x,stat as T,readdir as S,realpath as k,open as $,mkdtemp as O,rm as P}from"node:fs/promises";import{tmpdir as A,platform as F}from"node:os";import{Agent as M,request as R}from"node:https";import{TransformStream as N,TextDecoderStream as C,DecompressionStream as U,ReadableStream as B}from"node:stream/web";import{Readable as j,Duplex as D}from"node:stream";import I from"node:stream";function H(n){if(!n||"unknown"===n)return;const i=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(i?.[1]&&t(i[1]))return{type:"IPv4",ip:i[1],port:i[2]?Number.parseInt(i[2]):void 0};const r=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(r?.[1]&&e(r[1]))return{type:"IPv6",ip:r[1].toLowerCase(),port:r[2]?Number.parseInt(r[2]):void 0};if(r?.[3]&&e(r[3]))return{type:"IPv6",ip:r[3].toLowerCase(),port:void 0};const s=/^(.*?):(\d+)$/i.exec(n);return s?.[2]?{type:"alias",ip:s[1],port:Number.parseInt(s[2])}:{type:"alias",ip:n,port:void 0}}function q(t){const e=new Set,n=[],i=[];for(const r of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(r);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,i=e<32?4294967295>>>e:0;n.push([z(t[1])|i,i]);continue}const s=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(r);if(s?.[1]){const t=W(s[1]),e=s[2]?L>>BigInt(Number.parseInt(s[2])):0n;i.push([t|e,e]);continue}e.add(r)}return t=>{switch(t?.type){case"alias":return e.has(t.ip);case"IPv4":const r=z(t.ip);return n.some(([t,e])=>(r|e)===t);case"IPv6":const s=W(t.ip);return i.some(([t,e])=>(s|e)===t);default:return!1}}}const L=BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function z(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function W(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}class J{t;i;constructor(t){const e={o:null,u:null};this.t=e,this.i=e,void 0!==t&&this.push(t)}isEmpty(){return!this.t.u}clear(){this.t.u=null,this.t.o=null,this.i=this.t}push(t){const e={o:t,u:null};this.i.u=e,this.i=e}shift(){if(!this.t.u)return null;this.t=this.t.u;const t=this.t.o;return this.t.o=null,t}remove(t){for(let e=this.t;e.u;e=e.u)if(e.u.o===t){e.u=e.u.u;break}}[Symbol.iterator](){return{next:()=>{if(!this.t.u)return{value:null,done:!0};this.t=this.t.u;const t=this.t.o;return this.t.o=null,{value:t,done:!1}}}}}class G{h;l;m;v;constructor(){this.h=new J,this.l=new J,this.m=0}push(t){if(this.m)return;const e=this.l.shift();e?(e._&&clearTimeout(e._),e.T(t)):this.h.push(t)}shift(t){return this.h.isEmpty()?this.m?Promise.reject(this.v):new Promise((e,n)=>{const i={T:e,S:n,_:null};this.l.push(i),void 0!==t&&(i._=setTimeout(()=>{this.l.remove(i),n(new Error(`Timeout after ${t}ms`))},t))}):Promise.resolve(this.h.shift())}k(t){this.v=t;for(const e of this.l)e.S(t),e._&&clearTimeout(e._)}close(t){this.m||(this.m=1,this.k(t))}fail(t){this.m||(this.m=2,this.k(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function V(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return V(t.cause,e);if("error"in t)return V(t.error,e)}}function X(t,e="http"){if(!t)throw new Error("no address");if("string"==typeof t)return t;if("IPv4"===t.family)return`${e}://${t.address}:${t.port}`;if("IPv6"===t.family)return`${e}://[${t.address}]:${t.port}`;throw new Error(`unknown address family: ${t.family}`)}const Y=/*@__PURE__*/Buffer.alloc(0),Z=t=>new URL("http://localhost"+(t.url??"/"));class K extends Error{error;suppressed;constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const Q=globalThis.SuppressedError??K;class tt{$;O;constructor(){this.$=!1}P(t){this.$?t!==this.O&&(this.O=new Q(t,this.O)):(this.O=t,this.$=!0)}A(){this.$=!1,this.O=void 0}}class et{F;M;R;constructor(t){this.F=t,this.M=Object.create(null),this.R=!1}get headersSent(){return this.R}writeHead(t,e,i){if(this.R)throw new Error("headers already sent");const r={...this.M};for(const[t,e]of(t=>{if(!t)return[];const e=[];if(Array.isArray(t)){const n=t.length;if(1&n)throw new Error("headers must be a list of alternating keys and values");for(let i=0;i<n;i+=2){const n=t[i],r=t[i+1];if("string"!=typeof n)throw new Error("invalid header name");void 0!==r&&e.push([n.toLowerCase(),r])}}else for(const[n,i]of Object.entries(t))void 0!==i&&e.push([n.toLowerCase(),i]);return e})(i))r[t]=e;return this.F.write([`HTTP/1.1 ${t} ${rt(e??n[t]??"-")}`,...nt(r),"",""].join("\r\n"),"ascii"),this.R=!0,this}write(t,e="utf-8",n){return this.F.write(t,e,n)}end(t,e="utf-8",n){return this.F.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.M[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function nt(t){const e=[];for(const[n,i]of Object.entries(t)){const t=it(i);t&&e.push(`${rt(n)}: ${rt(t)}`)}return e}const it=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",rt=t=>t.replaceAll(/[^ \t!-~]/g,"");class st extends Error{statusCode;statusMessage;headers;body;constructor(t,{message:e,statusMessage:i,headers:r,body:s,...o}={}){super(e??("string"==typeof s?s:void 0),o),this.statusCode=0|t,this.statusMessage=i??n[this.statusCode]??"-",this.headers=r,this.body=s??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}static INTERNAL_SERVER_ERROR=new st(500);send(t,e){t.setHeaders((t=>{if(t){if(t instanceof Headers)return t;if(Array.isArray(t))return new Headers(t);{const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,it(e)]).filter(([t,e])=>e))}}return new Headers})(this.headers));const n=Buffer.byteLength(this.body,"utf-8");t.setHeader("content-length",String(n)),t.writeHead(this.statusCode,this.statusMessage,e),t.end(this.body,"utf-8")}}const ot=(t,e,n)=>{n.headersSent?n.end():(V(t,st)??st.INTERNAL_SERVER_ERROR).send(n)},ct=(t,e,n)=>{if(n.writable){n.addListener("finish",()=>n.destroy());const e=new et(n);(V(t,st)??st.INTERNAL_SERVER_ERROR).send(e,{connection:"close"})}else n.destroy()},at=(t,e,n)=>{(V(t,st)?.statusCode??1)&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},ft=new WeakMap;function ut(t,e){const n=ft.get(t);if(n)return n;const i=Z(t),r={N:t,C:i,U:decodeURIComponent(i.pathname),B:ct,j:new AbortController,D:[],I:[],H:e?dt(t):null};return ft.set(t,r),r}function ht(t,e,n,i){e||(t.H=null),t.L=n;const r=async()=>{t.j.abort(n.W.writableEnded?"complete":"client abort");const e=new tt;await lt(t.D,e,t),await lt(t.I,e,t,()=>{t.J=async e=>{try{await e()}catch(e){i(e,t.N)}}}),e.$&&i(e.O,t.N)};return n.W.closed?r():n.W.once("close",r),t}async function lt(t,e,n,i){for(;n.G;)await n.G;const r=(async()=>{for(;;){const n=t.pop();if(!n)return void i?.();try{await n()}catch(t){e.P(t)}}})().then(()=>{n.G===r&&(n.G=void 0)});n.G=r,await r}function dt(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const pt=t=>ft.get(t);function wt(t){const e=pt(t);if(!e)throw new Error("unknown request");return e}function mt(t,e){const n=pt(t);n&&yt(n,e)}function yt(t,e){t.V=e;const n=t.X;n&&queueMicrotask(()=>Et(e,t.N,n))}const gt=t=>Boolean(pt(t)?.X);function bt(t,e,n){if(!t.X){if(t.L&&!t.H){const e=t.L.W;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.L?.W.once("close",()=>t.N.socket.destroy()),t.X={Y:e,Z:n},Et(t.V,t.N,t.X),_t(t)}}function vt(t){if(t.L){if(!t.H){const e=t.L.W;e.headersSent||(e.statusCode=503,e.hasHeader("connection")||e.setHeader("connection","close"))}t.L.W.end(()=>t.N.socket.destroy())}else t.N.socket.destroy()}function _t(t){if(clearTimeout(t.K),!t.tt||t.J)return;const e=Date.now();if(e>=t.tt)return void vt(t);let n=t.tt;t.et&&!t.X&&(e<t.et.nt?n=t.et.nt:(t.X=t.et,Et(t.V,t.N,t.X))),void 0===t.K&&t.I.push(()=>clearTimeout(t.K)),t.K=setTimeout(()=>_t(t),n-e)}async function Et(t,e,n){try{await(t?.(n.Y))}catch(t){n.Z(t,"soft closing",e)}}const xt=(t,e)=>{const n=wt(t);n.J?n.J(e):n.D.push(e)},Tt=(t,e)=>{const n=wt(t);n.J?n.J(e):n.I.push(e)},St=t=>wt(t).j.signal;class kt extends Error{}const $t=new kt("STOP"),Ot=new kt("CONTINUE"),Pt=new kt("NEXT_ROUTE"),At=new kt("NEXT_ROUTER");async function Ft(t,e){const n=wt(t);if(!n.L)throw new Error("cannot call acceptUpgrade from shouldUpgrade");if(!n.H)throw new Error("not an upgrade request");if(n.it)return n.rt;const i=n.L.W;if(!i.readable||!i.writable)throw $t;const r=await e(t,i,n.L.t);return n.L.t=Y,n.B=r.onError,yt(n,r.softCloseHandler),n.rt=r.return,n.it=!0,r.return}const Mt=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),Rt=t=>t,Nt=t=>void 0===t?void 0:""===t?[]:t.split("/"),Ct=t=>void 0===t?void 0:""===t?[]:t.split("/").filter(t=>t);function Ut(t){const e={},n=new Map;for(const[i,r]of Object.entries(t))e[i]=!1,n.set(r,i);return t=>{const i={...e};for(let e=0;e<t.length;++e){const r=n.get(t[e]);if(!r)return[i,t.substring(e)];i[r]=!0}return[i,""]}}const Bt=/*@__PURE__*/Ut({st:"i",ot:"!"}),jt=Object.freeze({});function Dt(t,e,n){const i=t.N.url,r=t.U,s=t.ct??jt;return t.N.url=encodeURIComponent(e).replaceAll(/%2F/g,"/")+t.C.search,t.U=e,n.length>0&&(t.ct=Object.freeze(Object.fromEntries([...Object.entries(s),...n]))),()=>{t.N.url=i,t.U=r,t.ct=s}}function It(t){return pt(t)?.ct??jt}function Ht(t,e){return It(t)[e]}function qt(t){const e=pt(t);return e?e.C.pathname+e.C.search:t.url??"/"}function Lt(t){const e=pt(t);e&&(t.url=e.C.pathname+e.C.search)}const zt=t=>"function"==typeof t?{handleRequest:t}:t,Wt=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},Jt=(t,e=Yt)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),Gt=t=>"function"==typeof t?{handleError:t}:t,Vt=t=>"function"==typeof t?{handleRequest:t}:t,Xt=t=>"function"==typeof t?{handleUpgrade:t}:t,Yt=()=>!1,Zt=Symbol("http");class Kt{ft;ut;constructor(){this.ft=[],this.ut=[]}P(t,e,n,i,r){const s=n?((t,e)=>{const n=["^"],i=[],r=/[{}]|\/+|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{st:s,ot:o},c]=Bt(t);if("/"!==c[0])throw new Error("path must begin with '/' or flags");let a=0,f=0;for(const t of c.matchAll(r)){t.index>a&&n.push(Mt(c.substring(a,t.index)));const e=t[0];if("{"===e)n.push("(?:"),++f;else if("}"===e){if(0===f)throw new Error(`unbalanced optional braces in path at ${t.index}`);--f,n.push(")?")}else if("/"===e[0])n.push(e),o||n.push("+");else if("\\"===e[0])n.push(Mt(t[1]));else{const r=e[0],s=t[2];if(!s)throw new Error(`unnamed parameter or unescaped '${r}' at ${t.index}`);"*"===r?(n.push("(.*?)"),i.push({ht:s,lt:o?Nt:Ct})):(n.push("([^/]+?)"),i.push({ht:s,lt:Rt}))}a=t.index+e.length}if(a<c.length&&n.push(Mt(c.substring(a))),f>0)throw new Error("unbalanced optional braces in path");return e&&(n.push("(?:"),o?n.push("(?:(?<=/)|/)"):n.push("(?:/+|(?<=/))"),n.push("(?<rest>.*))?")),n.push("$"),{dt:new RegExp(n.join(""),s?"i":""),wt:i}})(n,i):{dt:null,wt:[]};return this.ft.push({yt:t,gt:"string"==typeof e?e.toLowerCase():e,bt:s.dt,vt:s.wt,_t:r}),this}use(...t){return this.P(null,null,null,!0,t.map(Vt))}mount(t,...e){return this.P(null,null,t,!0,e.map(Vt))}within(t,e){const n=new Kt;return e(n),this.mount(t,n)}at(t,...e){return this.P(null,null,t,!1,e.map(Vt))}onRequest(t,e,...n){return this.P(te(t),Zt,e,!1,n.map(Vt))}onUpgrade(t,e,n,...i){return this.P(te(t),e,n,!1,i.map(Xt))}onError(...t){return this.P(null,null,null,!0,t.map(Gt))}onReturn(...t){return this.ut.push(...t),this}on(t,...e){const n=/^([A-Z]+) (\/.*)$/.exec(t);if(!n)throw new Error("invalid method + path spec: "+JSON.stringify(t));return this.P(n[1],Zt,n[2],!1,e.map(Vt))}get=(t,...e)=>this.P(Qt,Zt,t,!1,e.map(Vt));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this.Et(t,new tt)}async handleUpgrade(t){return this.Et(t,new tt)}async handleError(t,e){const n=new tt;return n.P(t),this.Et(e,n)}shouldUpgrade(t){return this.xt(wt(t))}xt(t){for(const e of this.ft){const n=ee(t,e);if(!n)continue;let i=()=>{};if(!0!==n)try{i=Dt(t,n.Tt,[])}catch{continue}try{for(const n of e._t)if(re(n,t))return!0}finally{i()}}return!1}async Et(t,e){const n=wt(t),i=await this.St(n,e);if(e.$)throw e.O;return i}async St(t,e){for(const n of this.ft){const i=ee(t,n);if(!i)continue;let r=()=>{};if(!0!==i)try{const e=i.kt();r=Dt(t,i.Tt,e)}catch(t){e.P(t);continue}try{const i=await ne(t,n._t,this.ut,e);if(i===At)break;if(i===Pt)continue;return i}finally{r()}}return Ot}}const Qt=new Set(["HEAD","GET"]),te=t=>t?"string"==typeof t?t:new Set(t):null;function ee(t,e){if("string"==typeof e.yt){if(e.yt!==t.N.method)return!1}else if(null!==e.yt&&!e.yt.has(t.N.method??""))return!1;if(e.gt===Zt){if(t.H)return!1}else if(null!==e.gt&&!t.H?.has(e.gt))return!1;if(null===e.bt)return!0;const n=e.bt.exec(t.U);return!!n&&{Tt:"/"+(n.groups?.rest??""),kt:()=>e.vt.map((t,e)=>[t.ht,t.lt(n[e+1])])}}async function ne(t,e,n,i){for(const r of e){let e=await ie(r,t,i);if(e!==Ot){if(!t.H&&!(e instanceof kt)&&n.length)try{const i="object"==typeof e?e:void 0,r=t.N,s=t.L.W;for(const t of n)await t(i,r,s)}catch(t){i.P(t);continue}return e}}return Pt}async function ie(t,e,n){if(t instanceof Kt)return t.St(e,n);let i=Ot;try{if(n.$){if(t.handleError){const r=n.O;n.A(),i=await t.handleError(r,e.N,e.H?{socket:e.L.W,head:e.L.t}:{response:e.L.W})}}else if(e.H){if(t.handleUpgrade){const n=e.L;i=await t.handleUpgrade(e.N,n.W,n.t)}}else t.handleRequest&&(i=await t.handleRequest(e.N,e.L.W))}catch(t){t instanceof kt?i=t:n.P(t)}finally{await((t,e)=>lt(t.D,e,t))(e,n)}return i===$t?void 0:i}function re(t,e){if(t instanceof Kt)return t.xt(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.N)}catch(t){return e.$t(t),!1}}function se(t,{onError:e=at,socketCloseTimeout:n=500}={}){const i=[],r=new Set,s=()=>{const t=[...i];i.length=0;for(const e of t)e()},o=t=>{t&&(r.size?i.push(t):setImmediate(t))},c=t=>{r.add(t),t.I.push(()=>{r.delete(t),!r.size&&i.length&&setImmediate(s)})},a=(t,n)=>e(t,"tearing down",n);return{request:async(n,i)=>{let r;try{r=ut(n,!1)}catch(t){return e(t,"parsing request",n),void ot(new st(400),0,i)}ht(r,!1,{W:i},a),c(r);const s=new tt,o=await ie(t,r,s);s.$?(e(s.O,"handling request",n),ot(s.O,0,i)):o!==Ot&&o!==Pt&&o!==At||ot(new st(404),0,i)},upgrade:async(i,r,s)=>{let o;r.once("finish",()=>{const t=setTimeout(()=>r.destroy(),n);r.once("close",()=>clearTimeout(t))});try{o=ut(i,!0)}catch(t){return e(t,"parsing upgrade",i),void ct(new st(400),0,r)}ht(o,!0,{W:r,t:s},a),s=Y,c(o);const f=new tt,u=await ie(t,o,f);f.$?(e(f.O,"handling upgrade",i),o.B(f.O,i,r)):u!==Ot&&u!==Pt&&u!==At||(console.warn(`Upgrade ${i.headers.upgrade} request for ${i.url} fell-through. This probably means you need to add shouldUpgrade to one of your upgrade handlers, or if this is intentional, explicitly reject the request (throw new HTTPError(404)) instead of using CONTINUE.`),o.B(new st(404),i,r))},shouldUpgrade:n=>{try{const i=ut(n,!0);return i.$t=t=>e(t,"checking should upgrade",n),re(t,i)}catch{return!1}},clientError:(t,n)=>{const i=n.Ot,r=t.code;n.writable&&!i?.headersSent&&n.end(ce.get(r)??ae),n.destroy(t),"HPE_INVALID_EOF_STATE"===r||e(t,"initialising request")},softClose(t,e,n){for(const n of r)bt(n,t,e);o(n)},hardClose(t){for(const t of r)vt(t);o(t)},countConnections:()=>r.size}}const oe=t=>Buffer.from(`HTTP/1.1 ${t} ${n[t]}\r\nConnection: close\r\n\r\n`),ce=new Map([["HPE_HEADER_OVERFLOW",oe(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",oe(413)],["ERR_HTTP_REQUEST_TIMEOUT",oe(408)]]),ae=oe(400);class fe extends EventTarget{Pt;constructor(t){super(),this.Pt=t}attach(t,e={}){const n=se(this.Pt,{...e,onError:this.At.bind(this,t)});!1===e.autoContinue&&t.addListener("checkContinue",n.request),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",n.request),t.addListener("request",n.request),t.addListener("upgrade",n.upgrade);const i=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=n.shouldUpgrade),t.addListener("clientError",n.clientError);let r=!1;return(e="",s=-1,o=!1)=>{r||(r=!0,t.removeListener("checkContinue",n.request),t.removeListener("checkExpectation",n.request),t.removeListener("request",n.request),t.removeListener("upgrade",n.upgrade),t.shouldUpgradeCallback===n.shouldUpgrade&&(t.shouldUpgradeCallback=i),t.removeListener("clientError",n.clientError));const c=()=>{o&&t.closeAllConnections()};if(s>0){const i=setTimeout(n.hardClose,s);n.softClose(e,this.At.bind(this,t),()=>{clearTimeout(i),c()})}else 0===s&&n.hardClose(c);return n}}listen(t,e,n={}){n.shouldUpgradeCallback&&(n={overrideShouldUpgradeCallback:!1,...n});const r=i(n);n.socketTimeout&&r.setTimeout(n.socketTimeout);const s=this.attach(r,n),o=Object.assign(r,{closeWithTimeout:(t,e)=>new Promise(n=>{r.close(()=>n()),s(t,e,!0)})});return new Promise((i,s)=>{r.once("error",s),r.listen(t,e,n.backlog??511,()=>{r.off("error",s),i(o)})})}At(t,e,n,i){const r={error:e,server:t,action:n,request:i};this.dispatchEvent(new CustomEvent("error",{detail:r}))&&at(e,n,i)}}const ue=t=>pt(t)?.C??Z(t),he=t=>ue(t).search,le=t=>new URLSearchParams(ue(t).searchParams),de=(t,e)=>ue(t).searchParams.get(e);function pe(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function we(t){const e=t.headers.authorization;if(!e)return;const[n,i]=pe(e," ");return void 0!==i?[n.trim().toLowerCase(),i.trim()]:void 0}function me(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function ye(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:xe(e)}:{}}function ge(t,e,{maxRanges:n=10,maxNonSequential:i=2,maxWithOverlap:r=2}={}){const s=t.headers.range;if(!s||0===e)return;const[o,c]=pe(s,"=");if("bytes"!==o||!c)return;const a=new st(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=ve(t);if(void 0===e)throw a;return e},u=[];for(const t of c.split(",")){const[i,r]=pe(t.trim(),"-");if(void 0===r)throw a;let s;if(i)s={start:f(i),end:r?Math.min(f(r),e-1):e-1};else{if(!r)throw a;s={start:Math.max(e-f(r),0),end:e-1}}if(!(s.start>=e)){if(s.end<s.start||u.length>=n)throw a;u.push(s)}}if(!u.length)throw a;if(u.length>i)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw a;if(u.length>r)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw a}}return{ranges:u,totalSize:e}}function be(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function ve(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}function _e(t){if(t)return t.split(",").map(t=>{const[e,...n]=t.split(";"),i=new Map(n.map(t=>{const[e,n]=pe(t,"=");return[e.trim(),n?.trim()??""]})),r=e.trim(),s="*/*"===r||"*"===r?0:r.endsWith("/*")?1:2,o=Math.max(0,Math.min(1,Number.parseFloat(i.get("q")??"1")));return{name:r,specifiers:i,specificity:s,q:o}})}function Ee(t){const e=new Map,n=/\s*([^=]+)=([^";]*?|"(?:[^\\"]|\\.)*")\s*(?:;|$)/y;for(;n.lastIndex<t.length;){const i=n.exec(t);if(!i)throw new st(400,{body:"invalid HTTP key values"});const r=i[1].toLowerCase();let s=i[2];'"'===s[0]&&(s=s.substring(1,s.length-1).replaceAll(/\\(.)/g,(t,e)=>e)),e.set(r,s)}return e}function xe(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const Te=t=>"function"==typeof t?t:()=>t;class Se{Ft;constructor(t=Fe){this.Ft=Te(t)}set(t,e){Oe(t,this,e)}get(t){return Pe(t,this)}clear(t){Ae(t,this)}withValue(t){return Jt(e=>(Oe(e,this,t),Ot))}}const ke=(t,...e)=>{const n={Ft:n=>t(n,...e)};return t=>Pe(t,n)};function $e(t){return t.Mt||(t.Mt=new Map),t.Mt}function Oe(t,e,n){$e(wt(t)).set(e,n)}function Pe(t,e){const n=pt(t);if(!n)return e.Ft(t);const i=$e(n);if(i.has(e))return i.get(e);const r=e.Ft(t);return i.set(e,r),r}function Ae(t,e){const n=pt(t);n?.Mt?.delete(e)}const Fe=()=>{throw new Error("property has not been set")};function Me({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:i=!0,softCloseBufferTime:r=0,onSoftCloseError:s}){const o=Te(t);return Jt(async t=>{const c=Date.now(),a=await o(t),f={"www-authenticate":`Bearer realm="${a}"`},u=we(t),h="bearer"===u?.[0]?u[1]:await(n?.(t));if(!h)throw new st(401,{headers:f,body:"no token provided"});const l=await e(h,a,t);if(!l)throw new st(401,{headers:f,body:"invalid token"});if("object"==typeof l){if("nbf"in l&&"number"==typeof l.nbf&&c<1e3*l.nbf)throw new st(401,{headers:f,body:"token not valid yet"});if("exp"in l&&"number"==typeof l.exp){const e=1e3*l.exp;if(c>=e-r)throw new st(401,{headers:f,body:"token expired"});i&&((t,e,n,i=0,r=at)=>{const s=wt(t),o=n-Math.max(i,0),c=s.tt??Number.POSITIVE_INFINITY,a=s.et?.nt??c;o>=a&&n>=c||(n<c&&(s.tt=n),o<a&&(s.et={nt:o,Y:e,Z:r}),_t(s))})(t,"token expired",e,r,s)}}return Ue.set(t,{realm:a,data:l,scopes:Be(l)}),Ot})}const Re=t=>Ue.get(t).data,Ne=(t,e)=>Ue.get(t).scopes.has(e),Ce=t=>Jt(e=>{const n=Ue.get(e);if(!n.scopes.has(t))throw new st(403,{headers:{"www-authenticate":`Bearer realm="${n.realm}", scope="${t}"`},body:`scope required: ${t}`});return Ot}),Ue=/*@__PURE__*/new Se({realm:"",data:null,scopes:new Set});function Be(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return Array.isArray(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function je(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${h("sha256").update(n).digest("base64").substring(0,12)}"`}async function De(t){const e=h("sha256");return"string"==typeof t?await d(c(t),e):await d(t.createReadStream({start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const Ie=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),He={mime:"accept",language:"accept-language",encoding:"accept-encoding"},qe={zstd:"{file}.zst",br:"{file}.br",gzip:"{file}.gz",deflate:"{file}.deflate",identity:"{file}"},Le=t=>{return{type:"encoding",options:(e=t,n=qe,Array.isArray(e)?e.map(t=>[t,n[t]]):Object.entries(e)).map(([t,e])=>({match:t,file:e}))};var e,n};function ze(t,e=10){const n=t.map(t=>({Rt:t.type,Nt:t.options.map(t=>({Ct:t.file,Ut:"string"==typeof t.match?t.match.toLowerCase():Ie(t.match,!0),Bt:t.as??("string"==typeof t.match?t.match:void 0)}))})).filter(t=>t.Nt.length>0);return{options(t,i){let r=e;const s={},o={mime:We(i.mime),language:We(i.language),encoding:We(i.encoding)};return function*t(e,i){const c=n[i];if(!c)return--r,void(yield{filename:e,info:s});const a=new Set,f=o[c.Rt]??[];for(const n of f){const o=n.name.toLowerCase();for(const n of c.Nt)if("string"==typeof n.Ut?n.Ut===o:n.Ut.test(o)){const o=Je(e,n.Ct);if(a.has(o))continue;if(a.add(o),s[c.Rt]=n.Bt,yield*t(o,i+1),r<=0)return}}s[c.Rt]=void 0,!a.has(e)&&r>0&&(yield*t(e,i+1))}(t,0)},vary:[...new Set(n.map(t=>He[t.Rt]))].join(" ")}}function We(t){if(t?.length)return 1===t.length?t:[...t].sort((t,e)=>e.q-t.q||e.specificity-t.specificity)}function Je(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):m(t))}const Ge=/*@__PURE__*/Ze("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let Ve=/*@__PURE__*/new Map(Ge);function Xe(){Ve=new Map(Ge)}function Ye(t){const e=new Map;for(const n of t.split("\n")){const[t,...i]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of i)e.set(n.toLowerCase(),t)}return e}function Ze(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,i,r]=/^ *([^=]+)=(.*)$/.exec(n)??[null,null,""];for(const t of i?.split(",")??[]){const[n,i,s="",o=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),c=i+s+o,a=r.replace("{ext}",c);e.set(c.toLowerCase(),a),s&&e.set((i+o).toLowerCase(),a)}}return e}function Ke(t){for(const[e,n]of t)Ve.set(e.toLowerCase(),n)}function Qe(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=Ve.get(t)??"application/octet-stream";return n.startsWith("text/")&&!n.includes("charset=")?`${n}; charset=${e}`:n}async function tn(t,e,n){const i=await E(t),r={file:t,mime:Qe(m(t)),rawSize:i.byteLength,bestSize:i.byteLength,created:0};if(r.rawSize<=n)return r;if(["image","video","audio","font"].includes(r.mime.split("/")[0]))return r;for(const s of e){const e=rn.get(s.match),o=y(g(t),Je(b(t),s.file));if(!e||o===s.file)continue;const c=await e(i);c.byteLength<=r.rawSize-n&&(await x(o,c),r.bestSize=Math.min(r.bestSize,c.byteLength),++r.created)}return r}async function en(t,e,n){const i=[];await nn(t,i);const r=new Set(i);for(const t of r)for(const n of e){const e=y(g(t),Je(b(t),n.file));e!==t&&r.delete(e)}return Promise.all([...r].map(t=>tn(t,e,n)))}async function nn(t,e){const n=await T(t);if(n.isDirectory())for(const n of await S(t))await nn(y(t,n),e);else n.isFile()&&e.push(t)}const rn=/*@__PURE__*/new Map([["zstd",t=>w(p.zstdCompress)(t)],["brotli",t=>w(p.brotliCompress)(t,{params:{[p.constants.BROTLI_PARAM_QUALITY]:p.constants.BROTLI_MAX_QUALITY,[p.constants.BROTLI_PARAM_SIZE_HINT]:t.length}})],["gzip",t=>w(p.gzip)(t,{level:p.constants.Z_BEST_COMPRESSION})],["deflate",t=>w(p.deflate)(t)]]);class sn{jt;Dt;It;Ht;qt;Lt;zt;Wt;Jt;Gt;Vt;Xt;Yt;vary;constructor(t,{subDirectories:e=!0,caseSensitive:n="exact",allowAllDotfiles:i=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:s=!1,allow:o=[".well-known"],hide:c=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:f=[],negotiation:u}){this.jt=t,this.Dt=!0===e?Number.POSITIVE_INFINITY:e||0,this.It=n,this.Ht=i,this.qt=r,this.Lt=s,this.Gt=a,this.Xt=["",...f],this.zt=new Set(o.map(t=>this.Zt(t))),this.Wt=new Set,this.Jt=[];for(const t of c)"string"==typeof t?this.Wt.add(this.Zt(t)):this.Jt.push(Ie(t,!n));this.Vt=new Set(a.map(t=>this.Zt(t))),u?.length?(this.Yt=ze(u),this.vary=this.Yt.vary):this.vary=""}static async build(t,e){return new sn(await k(t,{encoding:"utf-8"})+v,e)}Zt(t){return"exact"===this.It?t:t.toLowerCase()}Kt(t){if(this.zt.has(t))return!0;const e=t.trim();return!(!("~"!==e[0]&&"~"!==e[e.length-1]||this.qt)||"."===e[0]&&!this.Ht||this.Wt.has(e)||this.Jt.some(t=>t.test(e)))}async find(t,e={}){let n=t.join(v);"force-lowercase"===this.It&&(n=n.toLowerCase());let i=_(this.jt,n);if(!i.startsWith(this.jt)&&i+v!==this.jt)return null;let r=null,s=null;for(const t of this.Xt){const e=i+t;if(r=e.substring(this.jt.length).split(v).filter(t=>t),r.length>this.Dt+1)return null;if(r.some(t=>!this.Kt(this.Zt(t))))return null;const n=r[r.length-1]??"";if(!this.Lt&&this.Vt.has(this.Zt(n))&&!this.zt.has(this.Zt(n)))return null;if(s=await k(e,{encoding:"utf-8"}).catch(()=>null),s){i=e;break}}if(!s||!r)return null;if(this.Zt(s)!==this.Zt(i))return null;let o=s,c=await T(s).catch(()=>null);if(!c)return null;if(c.isDirectory()){if(r.length>this.Dt)return null;for(const t of this.Gt){const e=y(s,t);if(c=await T(e).catch(()=>null),c?.isFile()){o=e;break}}}if(!c?.isFile())return null;if(this.Yt){const t=b(o),n=g(o);for(const i of this.Yt.options(t,e)){if(!i.filename||i.filename.includes(v))continue;const t=await cn({canonicalPath:o,negotiatedPath:y(n,i.filename),...i.info});if(t)return t}}return cn({canonicalPath:o,negotiatedPath:o})}async precompute(){const t=new Map,e=(e,n)=>{const i=t.get(e);(!i||n.p>i.p)&&t.set(e,n)},n=new J({dir:[this.jt],depth:0});for(const{dir:t,depth:i}of n){const r=await S(y(...t),{withFileTypes:!0,encoding:"utf-8"}),s=new Set(r.map(t=>this.Zt(t.name)));for(const o of r){const r=this.Zt(o.name);if(!this.Kt(r))continue;const c=[...t,o.name];if(o.isDirectory())i<this.Dt&&n.push({dir:c,depth:i+1}),e(this.Zt(c.slice(1).join("/")),on);else if(o.isFile()){const n={file:y(...c),dir:y(...t),basename:r,siblings:s},i=this.Gt.indexOf(r);if(-1!==i&&(e(this.Zt(t.slice(1).join("/")),{...n,p:this.Gt.length+1-i}),!this.Lt&&!this.zt.has(r)))continue;const a=this.Zt(c.slice(1).join("/"));for(let t=0;t<this.Xt.length;++t){const i=this.Xt[t];o.name.endsWith(i)&&e(a.substring(0,a.length-i.length),{...n,p:-t})}}}}return{find:async(e,n={})=>{const i=t.get(this.Zt(e.join("/")));if(!i?.file)return null;if(this.Yt)for(const t of this.Yt.options(i.basename,n)){if(!i.siblings.has(this.Zt(t.filename)))continue;const e=await cn({canonicalPath:i.file,negotiatedPath:y(i.dir,t.filename),...t.info});if(e)return e}return cn({canonicalPath:i.file,negotiatedPath:i.file})},vary:this.vary}}}const on={file:"",dir:"",basename:"",siblings:new Set,p:1};async function cn(t){const e=await $(t.negotiatedPath,a.O_RDONLY).catch(()=>null);if(!e)return null;const n=()=>(e.close().catch(()=>{}),null),i=await e.stat().catch(n);return i?.isFile()?{handle:e,stats:i,...t}:n()}const an=ke(async t=>{const e=St(t);if(e.aborted)throw $t;e.throwIfAborted();const n=await O(y(A(),"upload"));Tt(t,()=>P(n,{recursive:!0}));let i=0;const r=()=>{if(e.aborted)throw $t;return y(n,(++i).toString(10).padStart(6,"0"))};return{dir:n,nextFile:r,save:async(t,{mode:n=384}={})=>{const i=r(),s=f(i,{mode:n});try{return await d(t,s,{signal:e}),{path:i,size:s.bytesWritten}}finally{s.close()}}}});function fn(t){const e=wt(t);if(!e.L)throw new Error("cannot call acceptBody from shouldUpgrade");if(e.j.signal.aborted)throw $t;e.Qt||e.H||(e.Qt=!0,"100-continue"===t.headers.expect?.trim().toLowerCase()&&e.L.W.writeContinue())}function un(t,{blockRequestHeaders:e=["connection","expect","host","keep-alive","proxy-authorization","transfer-encoding","upgrade","via"],requestHeaders:n=[],blockResponseHeaders:i=["connection","keep-alive","transfer-encoding"],responseHeaders:o=[],agent:c,keepAlive:a=!0,maxSockets:f=10,...u}={}){let h;t.startsWith("https://")?(c??=new M({keepAlive:a,maxSockets:f,...u}),h=s):(c??=new r({keepAlive:a,maxSockets:f,...u}),h=R);const l=t.endsWith("/")?t:t+"/";return zt((r,s)=>new Promise((a,f)=>{const u=St(r),p=t=>f(u.aborted?$t:new st(502,{cause:t})),w=new URL(l+r.url?.substring(1)),m=w.toString();if(!m.startsWith(l)&&m!==t)return f(new st(400,{message:"directory traversal blocked"}));fn(r);let y={...r.headers};hn(y,e);for(const t of n)y=t(r,y);const g=h(w,{agent:c,method:r.method,headers:y,signal:u});g.once("error",p),g.once("response",t=>{if(!s.headersSent){let e={...t.headers};hn(e,i);for(const n of o)e=n(r,t,e);s.writeHead(t.statusCode??200,t.statusMessage,e)}d(t,s).then(a,f)}),d(r,g).catch(p)}))}function hn(t,e){for(const e of be(t.connection)??[])delete t[e.toLowerCase()];for(const n of e)delete t[n]}function ln({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const i=e?q(e):()=>!0,r=t??(e?Number.POSITIVE_INFINITY:0),s=new Set(n);return ke(t=>{const e=e=>{if(s.has(e))return be(t.headers[e])?.reverse()},n=e("forwarded"),o=e("x-forwarded-for"),c=e("x-forwarded-host"),a=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),h=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^ ]+) (.+)$/.exec(t);return e?.[3]?H(e[3]):void 0}),l=[dn(t)];if(n)for(const t of n)try{const e=Ee(t);l.push({client:H(e.get("for")),server:H(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{l.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(o){const t=o.map(H),e=c??[],n=a??f??u??[];let i=l[0].client;for(let r=0;r<t.length;++r){const s=t[r];l.push({client:s,server:h?.[r]??(i?{...i,port:void 0}:void 0),host:e[r],proto:n[r]}),i=s}}else if(h)for(const t of h)l.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+r,l.length);for(let t=0;t<d-1;++t)i(l[t].client)||(d=t+1);return Object.freeze({trusted:l.slice(0,d),untrusted:l.slice(d),outwardChain:l,edge:l[d-1]})})}const dn=t=>({client:{...H(t.socket.remoteAddress)??pn,port:t.socket.remotePort},server:{...H(t.socket.localAddress)??pn,port:t.socket.localPort},host:t.headers.host,proto:void 0}),pn={type:"alias",ip:"_disconnected",port:void 0};function wn(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],e}function mn(t,e){const n=wn(0,e);return n.forwarded=bn([dn(t)]),n}const yn=(t,{onlyTrusted:e=!1}={})=>(n,i)=>{const r=wn(0,i),s=t(n);return r.forwarded=bn([...e?s.trusted:s.outwardChain].reverse()),r};function gn(t,e){let n=t.headers.forwarded;const i=bn([dn(t)]);n?n+=", "+i:n=i;const r=wn(0,e);return r.forwarded=n,r}function bn(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.ip,by:t.server?.ip,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}class vn extends N{constructor(t){super({transform(r,s){const o=r.byteLength,c=[];let a=0;if(i>0){if(a=4-i,o<a)return e.set(r,i),void(i+=o);e.set(r.subarray(0,a),i),c.push(n.getUint32(0,t)),i=0}const f=new DataView(r.buffer,r.byteOffset,r.byteLength);let u=a;for(const e=o-3;u<e;u+=4)c.push(f.getUint32(u,t));c.length>0&&s.enqueue(String.fromCodePoint(...c)),u<o&&(e.set(r.subarray(u)),i=o-u)}});const e=new Uint8Array(4),n=new DataView(e.buffer);let i=0}}const _n=new Map;function En(t,e){_n.set(t.toLowerCase(),e)}function xn(){En("utf-32be",()=>new vn(!1)),En("utf-32le",()=>new vn(!0))}function Tn(t,e){const n=_n.get(t);if(n)return n(e);try{return new C(t,e)}catch{throw new st(415,{body:`unsupported charset: ${t}`})}}const Sn=["utf-32be",null,"utf-16be","utf-16be","utf-32le","utf-16le",null,"utf-8"];function kn(t,e,n){const i=xe(t.headers["if-modified-since"]),r=be(t.headers["if-none-match"]);if(r){if(On(e,n,r))return!1}else if(i&&(n.mtimeMs/1e3|0)<=i)return!1;return!0}function $n(t,e,n){let i=!0;const r=ye(t);return r.etag&&(i&&=On(e,n,r.etag)),r.modifiedSeconds&&(i&&=(n.mtimeMs/1e3|0)===r.modifiedSeconds),i}function On(t,e,n){if(n.includes("*"))return!0;const i=t.getHeader("etag");if("string"==typeof i){if(n.includes(i))return!0;if(i.startsWith('W/"'))return!1}return!!n.some(t=>t.startsWith('W/"'))&&n.includes(je(t.getHeader("content-encoding"),e))}class Pn extends N{constructor(t,e){super({transform(i,r){n+=i.byteLength,n>t?r.error(e):r.enqueue(i)}});let n=0}}function An(t,{maxExpandedLength:e=Number.POSITIVE_INFINITY,maxContentLength:n=e,maxEncodingSteps:i=1}={}){const r=ve(t.headers["content-length"]);if(void 0!==r&&r>n)throw new st(413);const s=be(t.headers["content-encoding"])??[];if(s.length>i)throw new st(415,{body:"too many content-encoding stages"});fn(t);let o=j.toWeb(t);void 0===r&&Number.isFinite(n)&&(o=o.pipeThrough(new Pn(n,new st(413))));for(const t of s.reverse())o=o.pipeThrough(Nn(t));return Number.isFinite(e)&&(o=o.pipeThrough(new Pn(e,new st(413,{body:"decoded content too large"})))),o}function Fn(t,e={}){const n=An(t,e),i=me(t)??e.defaultCharset??"utf-8";return n.pipeThrough(Tn(i,e))}async function Mn(t,e={}){const n=[];for await(const i of Fn(t,e))n.push(i);return n.join("")}async function Rn(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),i=new Uint8Array(3);let r=0,s=null;for(;;){const t=await n.read(),e=3-r;if(t.done){0===r?(i[0]=1,i[1]=1):1===r&&(i[1]=i[0]),i[2]=i[0],s=null;break}if(s=t.value,s.byteLength>=e){i.set(s.subarray(0,e),r);break}i.set(s,r),r+=s.byteLength}const o=Sn[(i[0]?4:0)|(i[1]?2:0)|(i[2]?1:0)];if(!o)throw n.cancel(),new st(415,{body:"invalid JSON encoding"});const c=Tn(o,e),a=c.writable.getWriter();return r&&a.write(i.subarray(0,r)),s&&a.write(s),n.releaseLock(),a.releaseLock(),t.pipeThrough(c)})(An(t,e),e),i=[];for await(const t of n)i.push(t);return JSON.parse(i.join(""))}function Nn(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new U("gzip");case"deflate":return new U("deflate");case"br":try{return new U("brotli")}catch{return D.toWeb(p.createBrotliDecompress())}case"zstd":try{return D.toWeb(p.createZstdDecompress())}catch{throw new st(415,{body:"unsupported content encoding"})}default:throw new st(415,{body:"unknown content encoding"})}}function Cn(t){return t&&t.te&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Un,Bn,jn,Dn,In,Hn,qn,Ln,zn,Wn;function Jn(){if(Bn)return Un;function t(t,e,n){for(;e<t.length;){for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)break;if(59!==t.charCodeAt(e++))return;for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)return;let i;const r=e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(61!==n)return;break}}if(e===t.length)return;if(i=t.slice(r,e),++e===t.length)return;let c,a="";if(34===t.charCodeAt(e)){c=++e;let n=!1;for(;e<t.length;++e){const i=t.charCodeAt(e);if(92!==i){if(34===i){if(n){c=e,n=!1;continue}a+=t.slice(c,e);break}if(n&&(c=e-1,n=!1),1!==o[i])return}else n?(c=e,n=!1):(a+=t.slice(c,e),n=!0)}if(e===t.length)return;++e}else{for(c=e;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(e===c)return;break}}a=t.slice(c,e)}i=i.toLowerCase(),void 0===n[i]&&(n[i]=a)}return n}function e(t,e,n,i){for(;e<t.length;){for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)break;if(59!==t.charCodeAt(e++))return;for(;e<t.length;++e){const n=t.charCodeAt(e);if(32!==n&&9!==n)break}if(e===t.length)return;let u;const h=e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(61===n)break;return}}if(e===t.length)return;let l,d,p="";if(u=t.slice(h,e),42===u.charCodeAt(u.length-1)){const n=++e;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==c[n]){if(39!==n)return;break}}if(e===t.length)return;for(d=t.slice(n,e),++e;e<t.length&&39!==t.charCodeAt(e);++e);if(e===t.length)return;if(++e===t.length)return;l=e;let i=0;for(;e<t.length;++e){const n=t.charCodeAt(e);if(1!==a[n]){if(37===n){let n,r;if(e+2<t.length&&-1!==(n=f[t.charCodeAt(e+1)])&&-1!==(r=f[t.charCodeAt(e+2)])){const s=(n<<4)+r;p+=t.slice(l,e),p+=String.fromCharCode(s),l=(e+=2)+1,s>=128?i=2:0===i&&(i=1);continue}return}break}}if(p+=t.slice(l,e),p=r(p,d,i),void 0===p)return}else{if(++e===t.length)return;if(34===t.charCodeAt(e)){l=++e;let n=!1;for(;e<t.length;++e){const i=t.charCodeAt(e);if(92!==i){if(34===i){if(n){l=e,n=!1;continue}p+=t.slice(l,e);break}if(n&&(l=e-1,n=!1),1!==o[i])return}else n?(l=e,n=!1):(p+=t.slice(l,e),n=!0)}if(e===t.length)return;++e}else{for(l=e;e<t.length;++e){const n=t.charCodeAt(e);if(1!==s[n]){if(e===l)return;break}}p=t.slice(l,e)}if(p=i(p,2),void 0===p)return}u=u.toLowerCase(),void 0===n[u]&&(n[u]=p)}return n}function n(t){let e;for(;;)switch(t){case"utf-8":case"utf8":return i.utf8;case"latin1":case"ascii":case"us-ascii":case"iso-8859-1":case"iso8859-1":case"iso88591":case"iso_8859-1":case"windows-1252":case"iso_8859-1:1987":case"cp1252":case"x-cp1252":return i.latin1;case"utf16le":case"utf-16le":case"ucs2":case"ucs-2":return i.utf16le;case"base64":return i.base64;default:if(void 0===e){e=!0,t=t.toLowerCase();continue}return i.other.bind(t)}}Bn=1;const i={utf8:(t,e)=>{if(0===t.length)return"";if("string"==typeof t){if(e<2)return t;t=Buffer.from(t,"latin1")}return t.utf8Slice(0,t.length)},latin1:(t,e)=>0===t.length?"":"string"==typeof t?t:t.latin1Slice(0,t.length),utf16le:(t,e)=>0===t.length?"":("string"==typeof t&&(t=Buffer.from(t,"latin1")),t.ucs2Slice(0,t.length)),base64:(t,e)=>0===t.length?"":("string"==typeof t&&(t=Buffer.from(t,"latin1")),t.base64Slice(0,t.length)),other:(t,e)=>{if(0===t.length)return"";"string"==typeof t&&(t=Buffer.from(t,"latin1"));try{return new TextDecoder(this).decode(t)}catch{}}};function r(t,e,i){const r=n(e);if(r)return r(t,i)}const s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];return Un={basename:t=>{if("string"!=typeof t)return"";for(let e=t.length-1;e>=0;--e)switch(t.charCodeAt(e)){case 47:case 92:return".."===(t=t.slice(e+1))||"."===t?"":t}return".."===t||"."===t?"":t},convertToUTF8:r,getDecoder:n,parseContentType:e=>{if(0===e.length)return;const n=Object.create(null);let i=0;for(;i<e.length;++i){const t=e.charCodeAt(i);if(1!==s[t]){if(47!==t||0===i)return;break}}if(i===e.length)return;const r=e.slice(0,i).toLowerCase(),o=++i;for(;i<e.length;++i){const r=e.charCodeAt(i);if(1!==s[r]){if(i===o)return;if(void 0===t(e,i,n))return;break}}return i!==o?{type:r,subtype:e.slice(o,i).toLowerCase(),params:n}:void 0},parseDisposition:(t,n)=>{if(0===t.length)return;const i=Object.create(null);let r=0;for(;r<t.length;++r){const o=t.charCodeAt(r);if(1!==s[o]){if(void 0===e(t,r,i,n))return;break}}return{type:t.slice(0,r).toLowerCase(),params:i}}}}function Gn(){if(Hn)return In;Hn=1;const{Readable:t,Writable:e}=I,n=function(){if(Dn)return jn;function t(t,e,n,i,r){for(let s=0;s<r;++s)if(t[e+s]!==n[i+s])return!1;return!0}function e(e,i){const r=i.length,s=e.ee,o=s.length;let c=-e.ne;const a=o-1,f=s[a],u=r-o,h=e.ie,l=e.re;if(c<0){for(;c<0&&c<=u;){const t=c+a,r=t<0?l[e.ne+t]:i[t];if(r===f&&n(e,i,c,a))return e.ne=0,++e.matches,c>-e.ne?e.se(!0,l,0,e.ne+c,!1):e.se(!0,void 0,0,0,!0),e.oe=c+o;c+=h[r]}for(;c<0&&!n(e,i,c,r-c);)++c;if(c<0){const t=e.ne+c;return t>0&&e.se(!1,l,0,t,!1),e.ne-=t,l.copy(l,0,t,e.ne),l.set(i,e.ne),e.ne+=r,e.oe=r,r}e.se(!1,l,0,e.ne,!1),e.ne=0}c+=e.oe;const d=s[0];for(;c<=u;){const n=i[c+a];if(n===f&&i[c]===d&&t(s,0,i,c,a))return++e.matches,c>0?e.se(!0,i,e.oe,c,!0):e.se(!0,void 0,0,0,!0),e.oe=c+o;c+=h[n]}for(;c<r;){if(i[c]===d&&t(i,c,s,0,r-c)){i.copy(l,0,c,r),e.ne=r-c;break}++c}return c>0&&e.se(!1,i,e.oe,c<r?c:r,!0),e.oe=r,r}function n(t,e,n,i){const r=t.re,s=t.ne,o=t.ee;for(let t=0;t<i;++t,++n)if((n<0?r[s+n]:e[n])!==o[t])return!1;return!0}return Dn=1,jn=class{constructor(t,e){if("function"!=typeof e)throw new Error("Missing match callback");if("string"==typeof t)t=Buffer.from(t);else if(!Buffer.isBuffer(t))throw new Error("Expected Buffer for needle, got "+typeof t);const n=t.length;if(this.maxMatches=1/0,this.matches=0,this.se=e,this.ne=0,this.ee=t,this.oe=0,this.re=Buffer.allocUnsafe(n),this.ie=[n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n],n>1)for(let e=0;e<n-1;++e)this.ie[t[e]]=n-1-e}reset(){this.matches=0,this.ne=0,this.oe=0}push(t,n){let i;Buffer.isBuffer(t)||(t=Buffer.from(t,"latin1"));const r=t.length;for(this.oe=n||0;i!==r&&this.matches<this.maxMatches;)i=e(this,t);return i}destroy(){const t=this.ne;t&&this.se(!1,this.re,0,t,!1),this.reset()}}}(),{basename:i,convertToUTF8:r,getDecoder:s,parseContentType:o,parseDisposition:c}=Jn(),a=Buffer.from("\r\n"),f=Buffer.from("\r"),u=Buffer.from("-");function h(){}const l=16384;class d{constructor(t){this.header=Object.create(null),this.pairCount=0,this.byteCount=0,this.state=0,this.name="",this.value="",this.crlf=0,this.cb=t}reset(){this.header=Object.create(null),this.pairCount=0,this.byteCount=0,this.state=0,this.name="",this.value="",this.crlf=0}push(t,e,n){let i=e;for(;e<n;)switch(this.state){case 0:{let r=!1;for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(1!==b[n]){if(58!==n)return-1;if(this.name+=t.latin1Slice(i,e),0===this.name.length)return-1;++e,r=!0,this.state=1;break}}if(!r){this.name+=t.latin1Slice(i,e);break}}case 1:{let r=!1;for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(32!==n&&9!==n){i=e,r=!0,this.state=2;break}}if(!r)break}case 2:switch(this.crlf){case 0:for(;e<n;++e){if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];if(1!==v[n]){if(13!==n)return-1;++this.crlf;break}}this.value+=t.latin1Slice(i,e++);break;case 1:if(this.byteCount===l)return-1;if(++this.byteCount,10!==t[e++])return-1;++this.crlf;break;case 2:{if(this.byteCount===l)return-1;++this.byteCount;const n=t[e];32===n||9===n?(i=e,this.crlf=0):(++this.pairCount<2e3&&(this.name=this.name.toLowerCase(),void 0===this.header[this.name]?this.header[this.name]=[this.value]:this.header[this.name].push(this.value)),13===n?(++this.crlf,++e):(i=e,this.crlf=0,this.state=0,this.name="",this.value=""));break}case 3:{if(this.byteCount===l)return-1;if(++this.byteCount,10!==t[e++])return-1;const n=this.header;return this.reset(),this.cb(n),e}}}return e}}class p extends t{constructor(t,e){super(t),this.truncated=!1,this.ce=null,this.once("end",()=>{if(this.ae(),0===--e.fe&&e.ue){const t=e.ue;e.ue=null,process.nextTick(t)}})}ae(t){const e=this.ce;e&&(this.ce=null,e())}}const w={push:(t,e)=>{},destroy:()=>{}};function m(t,e){return t}function y(t,e,n){if(n)return e(n);e(n=g(t))}function g(t){if(t.he)return new Error("Malformed part header");const e=t.le;return e&&(t.le=null,e.destroy(new Error("Unexpected end of file"))),t.de?void 0:new Error("Unexpected end of form")}const b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],v=[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];return In=class extends e{constructor(t){if(super({autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.highWaterMark?t.highWaterMark:void 0}),!t.conType.params||"string"!=typeof t.conType.params.boundary)throw new Error("Multipart: Boundary not found");const e=t.conType.params.boundary,l="string"==typeof t.defParamCharset&&t.defParamCharset?s(t.defParamCharset):m,y=t.defCharset||"utf8",g=t.preservePath,b={autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.fileHwm?t.fileHwm:void 0},v=t.limits,_=v&&"number"==typeof v.fieldSize?v.fieldSize:1048576,E=v&&"number"==typeof v.fileSize?v.fileSize:1/0,x=v&&"number"==typeof v.files?v.files:1/0,T=v&&"number"==typeof v.fields?v.fields:1/0,S=v&&"number"==typeof v.parts?v.parts:1/0;let k=-1,$=0,O=0,P=!1;this.fe=0,this.le=void 0,this.de=!1;let A,F,M,R,N,C=0,U=0,B=!1,j=!1,D=!1;this.he=null;const I=new d(t=>{let e;if(this.he=null,P=!1,R="text/plain",F=y,M="7bit",N=void 0,B=!1,!t["content-disposition"])return void(P=!0);const n=c(t["content-disposition"][0],l);if(n&&"form-data"===n.type){if(n.params&&(n.params.name&&(N=n.params.name),n.params["filename*"]?e=n.params["filename*"]:n.params.filename&&(e=n.params.filename),void 0===e||g||(e=i(e))),t["content-type"]){const e=o(t["content-type"][0]);e&&(R=`${e.type}/${e.subtype}`,e.params&&"string"==typeof e.params.charset&&(F=e.params.charset.toLowerCase()))}if(t["content-transfer-encoding"]&&(M=t["content-transfer-encoding"][0].toLowerCase()),"application/octet-stream"===R||void 0!==e){if(O===x)return j||(j=!0,this.emit("filesLimit")),void(P=!0);if(++O,0===this.listenerCount("file"))return void(P=!0);C=0,this.le=new p(b,this),++this.fe,this.emit("file",N,this.le,{filename:e,encoding:M,mimeType:R})}else{if($===T)return D||(D=!0,this.emit("fieldsLimit")),void(P=!0);if(++$,0===this.listenerCount("field"))return void(P=!0);A=[],U=0}}else P=!0});let H=0;const q=(t,e,n,i,s)=>{t:for(;e;){if(null!==this.he){const t=this.he.push(e,n,i);if(-1===t){this.he=null,I.reset(),this.emit("error",new Error("Malformed part header"));break}n=t}if(n===i)break;if(0!==H){if(1===H){switch(e[n]){case 45:H=2,++n;break;case 13:H=3,++n;break;default:H=0}if(n===i)return}if(2===H){if(H=0,45===e[n])return this.de=!0,void(this.pe=w);const t=this.we;this.we=h,q(!1,u,0,1,!1),this.we=t}else if(3===H){if(H=0,10===e[n]){if(++n,k>=S)break;if(this.he=I,n===i)break;continue t}{const t=this.we;this.we=h,q(!1,f,0,1,!1),this.we=t}}}if(!P)if(this.le){let t;const r=Math.min(i-n,E-C);s?t=e.slice(n,n+r):(t=Buffer.allocUnsafe(r),e.copy(t,0,n,n+r)),C+=t.length,C===E?(t.length>0&&this.le.push(t),this.le.emit("limit"),this.le.truncated=!0,P=!0):this.le.push(t)||(this.we&&(this.le.ce=this.we),this.we=null)}else if(void 0!==A){let t;const r=Math.min(i-n,_-U);s?t=e.slice(n,n+r):(t=Buffer.allocUnsafe(r),e.copy(t,0,n,n+r)),U+=r,A.push(t),U===_&&(P=!0,B=!0)}break}if(t){if(H=1,this.le)this.le.push(null),this.le=null;else if(void 0!==A){let t;switch(A.length){case 0:t="";break;case 1:t=r(A[0],F,0);break;default:t=r(Buffer.concat(A,U),F,0)}A=void 0,U=0,this.emit("field",N,t,{nameTruncated:!1,valueTruncated:B,encoding:M,mimeType:R})}++k===S&&this.emit("partsLimit")}};this.pe=new n(`\r\n--${e}`,q),this.we=null,this.ue=null,this.write(a)}static detect(t){return"multipart"===t.type&&"form-data"===t.subtype}me(t,e,n){this.we=n,this.pe.push(t,0),this.we&&(t=>{const e=t.we;t.we=null,e&&e()})(this)}ye(t,e){this.he=null,this.pe=w,t||(t=g(this));const n=this.le;n&&(this.le=null,n.destroy(t)),e(t)}ge(t){if(this.pe.destroy(),!this.de)return t(new Error("Unexpected end of form"));this.fe?this.ue=y.bind(null,this,t):y(this,t)}}}function Vn(){if(Ln)return qn;Ln=1;const{Writable:t}=I,{getDecoder:e}=Jn();function n(t,e,n,i){if(n>=i)return i;if(-1===t.be){const r=s[e[n++]];if(-1===r)return-1;if(r>=8&&(t.ve=2),n<i){const i=s[e[n++]];if(-1===i)return-1;t._e?t.Ee+=String.fromCharCode((r<<4)+i):t.xe+=String.fromCharCode((r<<4)+i),t.be=-2,t.Te=n}else t.be=r}else{const i=s[e[n++]];if(-1===i)return-1;t._e?t.Ee+=String.fromCharCode((t.be<<4)+i):t.xe+=String.fromCharCode((t.be<<4)+i),t.be=-2,t.Te=n}return n}function i(t,e,n,i){if(t.Se>t.fieldNameSizeLimit){for(t.ke||t.Te<n&&(t.Ee+=e.latin1Slice(t.Te,n-1)),t.ke=!0;n<i;++n){const i=e[n];if(61===i||38===i)break;++t.Se}t.Te=n}return n}function r(t,e,n,i){if(t.$e>t.fieldSizeLimit){for(t.Oe||t.Te<n&&(t.xe+=e.latin1Slice(t.Te,n-1)),t.Oe=!0;n<i&&38!==e[n];++n)++t.$e;t.Te=n}return n}const s=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];return qn=class extends t{constructor(t){super({autoDestroy:!0,emitClose:!0,highWaterMark:"number"==typeof t.highWaterMark?t.highWaterMark:void 0});let n=t.defCharset||"utf8";t.conType.params&&"string"==typeof t.conType.params.charset&&(n=t.conType.params.charset),this.charset=n;const i=t.limits;this.fieldSizeLimit=i&&"number"==typeof i.fieldSize?i.fieldSize:1048576,this.fieldsLimit=i&&"number"==typeof i.fields?i.fields:1/0,this.fieldNameSizeLimit=i&&"number"==typeof i.fieldNameSize?i.fieldNameSize:100,this._e=!0,this.ke=!1,this.Oe=!1,this.Se=0,this.$e=0,this.Pe=0,this.Ee="",this.xe="",this.be=-2,this.Te=0,this.ve=0,this.Ae=e(n)}static detect(t){return"application"===t.type&&"x-www-form-urlencoded"===t.subtype}me(t,e,s){if(this.Pe>=this.fieldsLimit)return s();let o=0;const c=t.length;if(this.Te=0,-2!==this.be){if(o=n(this,t,o,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();this._e?++this.Se:++this.$e}t:for(;o<c;)if(this._e){for(o=i(this,t,o,c);o<c;){switch(t[o]){case 61:this.Te<o&&(this.Ee+=t.latin1Slice(this.Te,o)),this.Te=++o,this.Ee=this.Ae(this.Ee,this.ve),this.ve=0,this._e=!1;continue t;case 38:if(this.Te<o&&(this.Ee+=t.latin1Slice(this.Te,o)),this.Te=++o,this.Ee=this.Ae(this.Ee,this.ve),this.ve=0,this.Se>0&&this.emit("field",this.Ee,"",{nameTruncated:this.ke,valueTruncated:!1,encoding:this.charset,mimeType:"text/plain"}),this.Ee="",this.xe="",this.ke=!1,this.Oe=!1,this.Se=0,this.$e=0,++this.Pe>=this.fieldsLimit)return this.emit("fieldsLimit"),s();continue;case 43:this.Te<o&&(this.Ee+=t.latin1Slice(this.Te,o)),this.Ee+=" ",this.Te=o+1;break;case 37:if(0===this.ve&&(this.ve=1),this.Te<o&&(this.Ee+=t.latin1Slice(this.Te,o)),this.Te=o+1,this.be=-1,o=n(this,t,o+1,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();++this.Se,o=i(this,t,o,c);continue}++o,++this.Se,o=i(this,t,o,c)}this.Te<o&&(this.Ee+=t.latin1Slice(this.Te,o))}else{for(o=r(this,t,o,c);o<c;){switch(t[o]){case 38:if(this.Te<o&&(this.xe+=t.latin1Slice(this.Te,o)),this.Te=++o,this._e=!0,this.xe=this.Ae(this.xe,this.ve),this.ve=0,(this.Se>0||this.$e>0)&&this.emit("field",this.Ee,this.xe,{nameTruncated:this.ke,valueTruncated:this.Oe,encoding:this.charset,mimeType:"text/plain"}),this.Ee="",this.xe="",this.ke=!1,this.Oe=!1,this.Se=0,this.$e=0,++this.Pe>=this.fieldsLimit)return this.emit("fieldsLimit"),s();continue t;case 43:this.Te<o&&(this.xe+=t.latin1Slice(this.Te,o)),this.xe+=" ",this.Te=o+1;break;case 37:if(0===this.ve&&(this.ve=1),this.Te<o&&(this.xe+=t.latin1Slice(this.Te,o)),this.Te=o+1,this.be=-1,o=n(this,t,o+1,c),-1===o)return s(new Error("Malformed urlencoded form"));if(o>=c)return s();++this.$e,o=r(this,t,o,c);continue}++o,++this.$e,o=r(this,t,o,c)}this.Te<o&&(this.xe+=t.latin1Slice(this.Te,o))}s()}ge(t){if(-2!==this.be)return t(new Error("Malformed urlencoded form"));(!this._e||this.Se>0||this.$e>0)&&(this._e?this.Ee=this.Ae(this.Ee,this.ve):this.xe=this.Ae(this.xe,this.ve),this.emit("field",this.Ee,this.xe,{nameTruncated:this.ke,valueTruncated:this.Oe,encoding:this.charset,mimeType:"text/plain"})),t()}}}var Xn=/*@__PURE__*/Cn((()=>{if(Wn)return zn;Wn=1;const{parseContentType:t}=Jn(),e=[Gn(),Vn()].filter(t=>"function"==typeof t.detect);return zn=n=>{if("object"==typeof n&&null!==n||(n={}),"object"!=typeof n.headers||null===n.headers||"string"!=typeof n.headers["content-type"])throw new Error("Missing Content-Type");return(n=>{const i=n.headers,r=t(i["content-type"]);if(!r)throw new Error("Malformed content type");for(const t of e){if(!t.detect(r))continue;const e={limits:n.limits,headers:i,conType:r,highWaterMark:void 0,fileHwm:void 0,defCharset:void 0,defParamCharset:void 0,preservePath:!1};return n.highWaterMark&&(e.highWaterMark=n.highWaterMark),n.fileHwm&&(e.fileHwm=n.fileHwm),e.defCharset=n.defCharset,e.defParamCharset=n.defParamCharset,e.preservePath=n.preservePath,new t(e)}throw new Error(`Unsupported content type: ${i["content-type"]}`)})(n)}})());function Yn(t,{allowMultipart:e=!1,closeAfterErrorDelay:n=500,limits:i={}}={}){const r=t.headers["content-type"]??"";if(!(/^application\/x-www-form-urlencoded\s*(;|$)/i.test(r)||e&&/^multipart\/form-data\s*(;|$)/i.test(r)))throw new st(415);fn(t);const s=new G;i={...i},e||(i.files=0);const o=(e,i)=>{if(s.fail(new st(e,i)),a.removeAllListeners(),t.unpipe(a),t.resume(),n>=0){const e=setTimeout(()=>t.socket.destroy(),n);t.once("end",()=>clearTimeout(e))}},c=i.fieldNameSize??100,a=Xn({headers:t.headers,limits:i,preservePath:!1});a.on("field",(t,e,{nameTruncated:n,valueTruncated:i,encoding:r,mimeType:a})=>t?n||t.length>c?o(400,{body:`field name ${JSON.stringify(t.slice(0,c))}... too long`}):i?o(400,{body:`value for ${JSON.stringify(t)} too long`}):void s.push({name:t,encoding:r,mimeType:a,type:"string",value:e}):o(400,{body:"missing field name"})),a.on("file",(t,e,{filename:n,encoding:i,mimeType:r})=>null===t?o(400,{body:"missing field name"}):t.length>c?o(400,{body:`field name ${JSON.stringify(t.slice(0,c))}... too long`}):void(n?(e.once("limit",()=>o(400,{body:`uploaded file for ${JSON.stringify(t)}: ${JSON.stringify(n)} too large`})),s.push({name:t,encoding:i,mimeType:r,type:"file",value:e,filename:n})):e.resume())),t.once("error",e=>{t.readableAborted?s.fail($t):o(500,{body:"request error",headers:{connection:"close"},cause:e})}),a.once("error",t=>o(400,{body:"error parsing form data",cause:t})),a.once("partsLimit",()=>o(400,{body:"too many parts"})),a.once("filesLimit",()=>o(400,{body:"too many files"})),a.once("fieldsLimit",()=>o(400,{body:"too many fields"}));const f=()=>s.close("complete");return a.once("close",f),Tt(t,f),t.pipe(a),s}async function Zn(t,e={}){const n=new FormData,i=new Map;for await(const r of Yn(t,e))if("file"===r.type){const s=r.value;let o=await(e.preCheckFile?.({fieldName:r.name,filename:r.filename,encoding:r.encoding,mimeType:r.mimeType,maxBytes:e.limits?.fileSize}));const c=t=>{if("function"==typeof o){const e=o;return o=void 0,e({actualBytes:t})}};Tt(t,()=>c(0));const a=await an(t),f=await a.save(s,{mode:384});await c(f.size);const h=new File([await u(f.path)],r.filename,{type:r.mimeType});i.set(h,f.path),n.append(r.name,h)}else{let t=r.value;e.trimAllValues&&(t=t.trim()),n.append(r.name,t)}return Object.assign(n,{getTempFilePath(t){const e=i.get(t);if(!e)throw new Error("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e},getString(t){const e=n.get(t);return"string"==typeof e?e:null},getAllStrings:t=>n.getAll(t).filter(t=>"string"==typeof t),getFile(t){const e=n.get(t);return"string"==typeof e?null:e},getAllFiles:t=>n.getAll(t).filter(t=>"string"!=typeof t)})}const Kn="win32"===/*@__PURE__*/F();function Qn(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const i=pt(t);if(i){if("/"===i.U)return[];n=i.U.split("/")}else{const e=Z(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new Error("invalid path");if(n.shift(),e){const t=Kn?ei:ti;if(n.some(e=>t.test(e)||e.includes(v)))throw new Error("invalid path");if(n.slice(0,n.length-1).includes(""))throw new Error("invalid path")}return n}const ti=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,ei=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i,ni=t=>new Promise(e=>{const n=()=>{t.cork(),e()};t instanceof o?t.write(Y,n):t.once("drain",n),t.uncork()});async function ii(t,e,{delimiter:n=",",newline:i="\n",quote:r='"',encoding:s="utf-8",headerRow:c,end:a=!0}={}){"string"==typeof n&&(n=Buffer.from(n,s)),"string"==typeof i&&(i=Buffer.from(i,s));const f="string"==typeof r?Buffer.from(r,s):r,u=r+r,h=e=>{if(!e)return!0;const n=e.includes(r);return!n&&ri.test(e)?t.write(e,s):(t.write(f),n?t.write(e.replaceAll(r,u),s):t.write(e,s),t.write(f))};t instanceof o&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+s+(c?"; header=present":!1===c?"; header=absent":"")),t.cork();try{t.write(Y);for await(const r of e){if(t.writableAborted)break;let e=0;if(Symbol.iterator in r)for(const i of r)e&&t.write(n),h(i)||await ni(t),++e;else for await(const i of r)e&&t.write(n),h(i)||await ni(t),++e;t.write(i)||await ni(t)}}finally{t.uncork()}a&&t.end()}const ri=/^[^"':;,\\\r\n\t ]*$/i;function si(t){if(!t||"object"!=typeof t)return!1;const e=t;return"number"==typeof e.fd&&"function"==typeof e.stat&&"function"==typeof e.createReadStream}class oi{lt;Fe;Me;m;constructor(t){(t=>{const e=t;return"function"==typeof e.ae&&"function"==typeof e.pipe})(t)&&(t=j.toWeb(t)),this.lt=t.getReader(),this.Fe=null,this.Me=0,this.m=0}getRange(t,e){if(e<t)throw new Error("invalid range");if(t<this.Me)throw new Error("non-sequential range");if(this.m)throw new Error("previous range still active");let n=e-t+1,i=t-this.Me;this.Me=e+1,this.m=1;const r=this,s=(t,e)=>{const r=t.byteLength;r<=i?i-=r:r>i+n?(this.Fe=t.subarray(i+n),e.enqueue(t.subarray(i,i+n)),n=0):i>0?(e.enqueue(t.subarray(i)),n-=r-i,i=0):(e.enqueue(t),n-=r)};return new B({start(t){if(r.Fe){const e=r.Fe;r.Fe=null,s(e,t)}},async pull(t){if(n<=0)return r.m=0,void t.close();const e=await r.lt.read();e.done?t.error(new Error("range exceeds content")):"string"==typeof e.value?s(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?s(e.value,t):t.error(new Error("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.lt.cancel(),this.lt.releaseLock()}}function ci(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const i=[];if(n>=0)for(const e of t.ranges){let t=null,r=0;for(let s=0;s<i.length;++s){const o=i[s];e.end>=o.start-n-1&&o.end>=e.start-n-1?t?(++r,t.start=Math.min(t.start,o.start),t.end=Math.max(t.end,o.end)):(t=o,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):r>0&&(i[s-r]=o)}t?i.length-=r:i.push({...e})}else i.push(...t.ranges);if(e)for(let t=0;t<i.length-1;++t)if(i[t].start>i[t+1].start){i.sort((t,e)=>t.start-e.start);break}return{ranges:i,totalSize:t.totalSize}}async function ai(t,e,n,i){if("string"==typeof n||si(n)||(i=ci(i,{mergeOverlapDistance:0,forceSequential:!0})),1===i.ranges.length){const r=i.ranges[0];if(e.setHeader("content-length",r.end-r.start+1),e.setHeader("content-range",`bytes ${r.start}-${r.end}/${i.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const s=await fi(n);return await d(s.Re(r.start,r.end),e),void(s.Ne&&await s.Ne())}const r=e.getHeader("content-type"),s=l()+l()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${s}`);const o=i.ranges.map(t=>({t:[`--${s}`,...nt({"content-type":r,"content-range":`bytes ${t.start}-${t.end}/${i.totalSize??"*"}`}),"",""].join("\r\n"),Ce:t})),c=`--${s}--`;let a=c.length;for(const{t,Ce:e}of o)a+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",a),"HEAD"===t.method)return void e.end();let f="";const u=await fi(n);try{for(const{t,Ce:n}of o)e.write(f+t,"ascii"),await d(u.Re(n.start,n.end),e,{end:!1}),f="\r\n";e.end(f+c)}finally{u.Ne&&await u.Ne()}}async function fi(t){if("string"==typeof t){const e=await $(t,"r");return{Re:(t,n)=>e.createReadStream({start:t,end:n,autoClose:!1}),Ne:()=>e.close()}}if(si(t))return{Re:(e,n)=>t.createReadStream({start:e,end:n,autoClose:!1})};{const e=new oi(t);return{Re:(t,n)=>e.getRange(t,n),Ne:()=>e.close()}}}async function ui(t,e,n,i,r){if(i||("string"==typeof n?i=await T(n):si(n)&&(i=await n.stat())),i){if("GET"===t.method||"HEAD"===t.method){if(!kn(t,e,i))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const s=ge(t,i.size,r);if(s&&$n(t,e,i))return ai(t,e,n,ci(s,r))}e.setHeader("content-length",i.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method)return"string"==typeof n?n=c(n):si(n)&&(n=n.createReadStream({start:0,autoClose:!1})),d(n,e);e.end()}function hi(t,e,{replacer:n,space:i,undefinedAsNull:r=!1,encoding:s="utf-8",end:c=!0}={}){const a=JSON.stringify(e,n,i)??(r?"null":void 0);t instanceof o&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),c&&t.setHeader("content-length",Buffer.byteLength(a,s))),c?t.end(a,s):a&&t.write(a,s)}async function li(t,e,{replacer:n=null,space:i="",undefinedAsNull:r=!1,encoding:s="utf-8",end:c=!0}={}){if(Array.isArray(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||Array.isArray(this)||t.has(e)?n:void 0}}"number"==typeof i&&(i=" ".substring(0,i));const a={me:e=>t.write(e,s),Ue:()=>ni(t),Be:n,je:i};if(t instanceof o&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e=pi(null,"",e,a),wi(e))r&&a.me("null");else{t.cork(),t.write(Y);try{await di(a,e,i?"\n":"")}finally{t.uncork()}}c&&t.end()}async function di(t,e,n){const i=(i,r,s)=>{t.me(i);const o=n+t.je,c=t.je?": ":":";let a=!0;return{u:async(n,i)=>{const r=pi(e,n,i,t);s&&wi(r)||(a?a=!1:t.me(","),t.me(o),s&&(t.me(JSON.stringify(n))||await t.Ue(),t.me(c)),await di(t,r,o))},Ne:()=>{a||t.me(n),t.me(r)}}};if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||mi(e))t.me(JSON.stringify(e)??"null")||await t.Ue();else if(e instanceof j){t.me('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");const e=JSON.stringify(n);t.me(e.substring(1,e.length-1))||await t.Ue()}t.me('"')}else if(e instanceof Map){const t=i("{","}",!0);for(const[n,i]of e)await t.u(n,i);t.Ne()}else if(yi(e)){let t=0;const n=i("[","]",!1);for(const i of e)await n.u(String(t++),i);n.Ne()}else if(gi(e)){let t=0;const n=i("[","]",!1);for await(const i of e)await n.u(String(t++),i);n.Ne()}else{const t=i("{","}",!0);for(const[n,i]of Object.entries(e))await t.u(n,i);t.Ne()}}function pi(t,e,n,i){return i.Be&&(n=i.Be.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const wi=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,mi=t=>JSON.isRawJSON?.(t)??!1,yi=t=>Symbol.iterator in t,gi=t=>Symbol.asyncIterator in t;class bi{De;j;Ie;He;constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:i=500,softCloseReconnectStagger:r=2e3}={}){this.De=e,this.Ie=n??0,this.j=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.qe(),t.once("close",()=>this.close()),mt(t,()=>this.close(i,r))}get signal(){return this.j.signal}get open(){return!this.j.signal.aborted}qe(){this.Ie&&(this.He=setTimeout(this.ping,this.Ie))}ping(){!this.j.signal.aborted&&this.De.writable&&(clearTimeout(this.He),this.De.write(":\n\n",()=>this.qe()))}send({event:t,id:e,data:n,reconnectDelay:i=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",i>=0?String(0|i):void 0]])}async sendFields(t){if(this.j.signal.aborted)throw new Error("ServerSentEvents closed");let e;this.De.cork();try{let n=!1;for(const[e,i]of t){if(void 0===i)continue;const t=i.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.De.write(e)," "===n[0]?this.De.write(": "):this.De.write(":"),this.De.write(n);/[\r\n]$/.test(i)?(this.De.write(e),this.De.write(":\n")):this.De.write("\n"),n=!0}if(!n)return;clearTimeout(this.He),this.De.write("\n",()=>e())}finally{this.De.uncork()}await new Promise(t=>{e=t}),this.qe()}async close(t=0,e=0){if(this.j.signal.aborted){if(this.De.closed)return;return new Promise(t=>this.De.once("close",t))}this.Ie=0,clearTimeout(this.He),this.j.abort(),await new Promise(n=>{if(this.De.writable&&(t>0||e>0)){const i=t+Math.random()*e;this.De.end(`retry:${0|i}\n\n`,n)}else this.De.end(n)})}}const vi=async(t,{mode:e="dynamic",fallback:n,callback:i=_i,...r}={})=>{const s=await sn.build(_(process.cwd(),t),r);let o=null;const c=n?.statusCode??200;if(n){let t=n.filePath;t.startsWith("/")&&(t=t.substring(1)),o=t.split("/")}const a="dynamic"===e?{}:{rejectPotentiallyUnsafe:!1},f="dynamic"===e?s:await s.precompute();return{handleRequest:async(t,e)=>{if("GET"!==t.method&&"HEAD"!==t.method)return Ot;let n=!1;const r=Qn(t,a),s={mime:_e(t.headers.accept),language:_e(t.headers["accept-language"]),encoding:_e(t.headers["accept-encoding"])};let u=await f.find(r,s);if(!u&&o&&(n=!0,u=await f.find(o,s)),!u)return Ot;try{n&&(e.statusCode=c),e.setHeader("content-type",u.mime??Qe(m(u.canonicalPath))),u.encoding&&"identity"!==u.encoding&&e.setHeader("content-encoding",u.encoding);const r=f.vary;if(r){const t=e.getHeader("vary")??"";e.setHeader("vary",(t?t+", ":"")+r)}await i(t,e,u,n),await ui(t,e,u.handle,u.stats)}finally{u.handle.close().catch(()=>{})}}}};function _i(t,e,n){e.setHeader("etag",je(e.getHeader("content-encoding"),n.stats)),e.setHeader("last-modified",n.stats.mtime.toUTCString())}class Ei extends Error{statusCode;statusMessage;constructor(t,{message:e,statusMessage:n,...i}={}){super(e,i),this.statusCode=0|t,this.statusMessage=n??"",this.name=`WebSocketError(${this.statusCode} ${this.statusMessage})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function xi(t,{softCloseStatusCode:e=Ei.GOING_AWAY,...n}={}){const i=(i,r,s)=>new Promise((o,c)=>{const a=new t({...n,noServer:!0,clientTracking:!1});a.once("wsClientError",c),a.handleUpgrade(i,r,s,t=>{a.off("wsClientError",c),o({return:t,onError:e=>{const n=V(e,Ei);if(n)return void t.close(n.statusCode,n.statusMessage);const i=V(e,st)??st.INTERNAL_SERVER_ERROR,r=i.statusCode>=500?Ei.INTERNAL_SERVER_ERROR:4e3+i.statusCode;t.close(r,i.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>Ft(t,i)}class Ti{data;isBinary;constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new Ei(Ei.UNSUPPORTED_DATA,{statusMessage:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new Ei(Ei.UNSUPPORTED_DATA,{statusMessage:"expected binary"});return this.data}}class Si{Le;detach;constructor(t,{limit:e=-1,signal:n}={}){this.Le=new G;const i=e=>{t.off("message",s),t.off("close",r),this.Le.close(new Error(e))},r=()=>i("connection closed"),s=(t,n)=>{void 0!==n?this.Le.push(new Ti(t,n)):"string"==typeof t?this.Le.push(new Ti(Buffer.from(t,"utf8"),!1)):this.Le.push(new Ti(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.Le.close(new Error("signal aborted")):2===t.readyState||3===t.readyState?this.Le.close(new Error("connection closed")):(t.on("message",s),t.on("close",r),n?.addEventListener("abort",()=>i("signal aborted")),this.detach=()=>i("WebSocket listener detached"))}next(t){return this.Le.shift(t)}[Symbol.asyncIterator](){return this.Le[Symbol.asyncIterator]()}}function ki(t,{timeout:e,signal:n}={}){const i=new Si(t,{limit:1,signal:n});return i.next(e).finally(()=>i.detach())}function $i(t){const e=wt(t);return"GET"===t.method&&(e.H?.has("websocket")??!1)}const Oi=t=>t.headers.origin??it(t.headers["sec-websocket-origin"]),Pi=(t,e=5e3)=>async n=>{if(!$i(n))return;const i=await t(n);let r;try{r=await ki(i,{timeout:e})}catch(t){if((i.readyState??0)>=2)throw $t;throw new Ei(Ei.POLICY_VIOLATION,{statusMessage:"timeout waiting for authentication token",cause:t})}if(r.isBinary)throw new Ei(Ei.UNSUPPORTED_DATA,{statusMessage:"authentication token must be sent as text"});return r.data.toString("utf-8")};export{G as BlockingQueue,Ot as CONTINUE,sn as FileFinder,st as HTTPError,Pt as NEXT_ROUTE,At as NEXT_ROUTER,Se as Property,J as Queue,Kt as Router,$t as STOP,bi as ServerSentEvents,fe as WebListener,Ei as WebSocketError,Ti as WebSocketMessage,Si as WebSocketMessages,fn as acceptBody,Ft as acceptUpgrade,Tt as addTeardown,Jt as anyHandler,kn as checkIfModified,$n as checkIfRange,Ae as clearProperty,On as compareETag,tn as compressFileOffline,en as compressFilesInDir,Ze as decompressMime,xt as defer,Gt as errorHandler,vi as fileServer,V as findCause,De as generateStrongETag,je as generateWeakETag,St as getAbortSignal,qt as getAbsolutePath,X as getAddressURL,Re as getAuthData,we as getAuthorization,Rn as getBodyJson,An as getBodyStream,Mn as getBodyText,Fn as getBodyTextStream,me as getCharset,Zn as getFormData,Yn as getFormFields,ye as getIfRange,Qe as getMime,Ht as getPathParameter,It as getPathParameters,Pe as getProperty,de as getQuery,ge as getRange,Qn as getRemainingPathComponents,he as getSearch,le as getSearchParams,Oi as getWebSocketOrigin,Ne as hasAuthScope,gt as isSoftClosed,$i as isWebSocketRequest,xi as makeAcceptWebSocket,q as makeAddressTester,ln as makeGetClient,ke as makeMemo,ze as makeNegotiator,an as makeTempFileStorage,Pi as makeWebSocketFallbackTokenFetcher,Le as negotiateEncoding,ki as nextWebSocketMessage,H as parseAddress,un as proxy,xe as readHTTPDateSeconds,ve as readHTTPInteger,Ee as readHTTPKeyValues,_e as readHTTPQualityValues,be as readHTTPUnquotedCommaSeparated,Ye as readMimeTypes,En as registerCharset,Ke as registerMime,xn as registerUTF32,wn as removeForwarded,mn as replaceForwarded,zt as requestHandler,Ce as requireAuthScope,Me as requireBearerAuth,Xe as resetMime,Lt as restoreAbsolutePath,yn as sanitiseAndAppendForwarded,ii as sendCSVStream,ui as sendFile,hi as sendJSON,li as sendJSONStream,ai as sendRanges,_i as setDefaultCacheHeaders,Oe as setProperty,mt as setSoftCloseHandler,gn as simpleAppendForwarded,ci as simplifyRange,se as toListeners,Wt as upgradeHandler};
|