| 59 | */var i=a(546);var n=a(937)("send");var r=a(186)("send");var o=a(397);var p=a(927);var s=a(354);var c=a(516);var l=a(890);var d=a(147);var m=a(396);var u=a(958);var v=a(71);var f=a(953);var x=a(17);var g=a(596);var h=a(781);var b=a(837);var y=x.extname;var w=x.join;var k=x.normalize;var S=x.resolve;var j=x.sep;var _=/^ *bytes=/;var E=60*60*24*365*1e3;var C=/(?:^|[\\/])\.\.(?:[\\/]|$)/;e.exports=send;e.exports.mime=m;function send(e,t,a){return new SendStream(e,t,a)}function SendStream(e,t,a){h.call(this);var i=a||{};this.options=i;this.path=t;this.req=e;this._acceptRanges=i.acceptRanges!==undefined?Boolean(i.acceptRanges):true;this._cacheControl=i.cacheControl!==undefined?Boolean(i.cacheControl):true;this._etag=i.etag!==undefined?Boolean(i.etag):true;this._dotfiles=i.dotfiles!==undefined?i.dotfiles:"ignore";if(this._dotfiles!=="ignore"&&this._dotfiles!=="allow"&&this._dotfiles!=="deny"){throw new TypeError('dotfiles option must be "allow", "deny", or "ignore"')}this._hidden=Boolean(i.hidden);if(i.hidden!==undefined){r("hidden: use dotfiles: '"+(this._hidden?"allow":"ignore")+"' instead")}if(i.dotfiles===undefined){this._dotfiles=undefined}this._extensions=i.extensions!==undefined?normalizeList(i.extensions,"extensions option"):[];this._immutable=i.immutable!==undefined?Boolean(i.immutable):false;this._index=i.index!==undefined?normalizeList(i.index,"index option"):["index.html"];this._lastModified=i.lastModified!==undefined?Boolean(i.lastModified):true;this._maxage=i.maxAge||i.maxage;this._maxage=typeof this._maxage==="string"?u(this._maxage):Number(this._maxage);this._maxage=!isNaN(this._maxage)?Math.min(Math.max(0,this._maxage),E):0;this._root=i.root?S(i.root):null;if(!this._root&&i.from){this.from(i.from)}}b.inherits(SendStream,h);SendStream.prototype.etag=r.function((function etag(e){this._etag=Boolean(e);n("etag %s",this._etag);return this}),"send.etag: pass etag as option");SendStream.prototype.hidden=r.function((function hidden(e){this._hidden=Boolean(e);this._dotfiles=undefined;n("hidden %s",this._hidden);return this}),"send.hidden: use dotfiles option");SendStream.prototype.index=r.function((function index(e){var index=!e?[]:normalizeList(e,"paths argument");n("index %o",e);this._index=index;return this}),"send.index: pass index as option");SendStream.prototype.root=function root(e){this._root=S(String(e));n("root %s",this._root);return this};SendStream.prototype.from=r.function(SendStream.prototype.root,"send.from: pass root as option");SendStream.prototype.root=r.function(SendStream.prototype.root,"send.root: pass root as option");SendStream.prototype.maxage=r.function((function maxage(e){this._maxage=typeof e==="string"?u(e):Number(e);this._maxage=!isNaN(this._maxage)?Math.min(Math.max(0,this._maxage),E):0;n("max-age %d",this._maxage);return this}),"send.maxage: pass maxAge as option");SendStream.prototype.error=function error(e,t){if(hasListeners(this,"error")){return this.emit("error",createHttpError(e,t))}var a=this.res;var i=g.message[e]||String(e);var n=createHtmlDocument("Error",s(i));clearHeaders(a);if(t&&t.headers){setHeaders(a,t.headers)}a.statusCode=e;a.setHeader("Content-Type","text/html; charset=UTF-8");a.setHeader("Content-Length",Buffer.byteLength(n));a.setHeader("Content-Security-Policy","default-src 'none'");a.setHeader("X-Content-Type-Options","nosniff");a.end(n)};SendStream.prototype.hasTrailingSlash=function hasTrailingSlash(){return this.path[this.path.length-1]==="/"};SendStream.prototype.isConditionalGET=function isConditionalGET(){return this.req.headers["if-match"]||this.req.headers["if-unmodified-since"]||this.req.headers["if-none-match"]||this.req.headers["if-modified-since"]};SendStream.prototype.isPreconditionFailure=function isPreconditionFailure(){var e=this.req;var t=this.res;var a=e.headers["if-match"];if(a){var i=t.getHeader("ETag");return!i||a!=="*"&&parseTokenList(a).every((function(e){return e!==i&&e!=="W/"+i&&"W/"+e!==i}))}var n=parseHttpDate(e.headers["if-unmodified-since"]);if(!isNaN(n)){var r=parseHttpDate(t.getHeader("Last-Modified"));return isNaN(r)||r>n}return false};SendStream.prototype.removeContentHeaderFields=function removeContentHeaderFields(){var e=this.res;e.removeHeader("Content-Encoding");e.removeHeader("Content-Language");e.removeHeader("Content-Length");e.removeHeader("Content-Range");e.removeHeader("Content-Type")};SendStream.prototype.notModified=function notModified(){var e=this.res;n("not modified");this.removeContentHeaderFields();e.statusCode=304;e.end()};SendStream.prototype.headersAlreadySent=function headersAlreadySent(){var e=new Error("Can't set headers after they are sent.");n("headers already sent");this.error(500,e)};SendStream.prototype.isCachable=function isCachable(){var e=this.res.statusCode;return e>=200&&e<300||e===304};SendStream.prototype.onStatError=function onStatError(e){switch(e.code){case"ENAMETOOLONG":case"ENOENT":case"ENOTDIR":this.error(404,e);break;default:this.error(500,e);break}};SendStream.prototype.isFresh=function isFresh(){return l(this.req.headers,{etag:this.res.getHeader("ETag"),"last-modified":this.res.getHeader("Last-Modified")})};SendStream.prototype.isRangeFresh=function isRangeFresh(){var e=this.req.headers["if-range"];if(!e){return true}if(e.indexOf('"')!==-1){var t=this.res.getHeader("ETag");return Boolean(t&&e.indexOf(t)!==-1)}var a=this.res.getHeader("Last-Modified");return parseHttpDate(a)<=parseHttpDate(e)};SendStream.prototype.redirect=function redirect(e){var t=this.res;if(hasListeners(this,"directory")){this.emit("directory",t,e);return}if(this.hasTrailingSlash()){this.error(403);return}var a=p(collapseLeadingSlashes(this.path+"/"));var i=createHtmlDocument("Redirecting",'Redirecting to <a href="'+s(a)+'">'+s(a)+"</a>");t.statusCode=301;t.setHeader("Content-Type","text/html; charset=UTF-8");t.setHeader("Content-Length",Buffer.byteLength(i));t.setHeader("Content-Security-Policy","default-src 'none'");t.setHeader("X-Content-Type-Options","nosniff");t.setHeader("Location",a);t.end(i)};SendStream.prototype.pipe=function pipe(e){var t=this._root;this.res=e;var a=decode(this.path);if(a===-1){this.error(400);return e}if(~a.indexOf("\0")){this.error(400);return e}var i;if(t!==null){if(a){a=k("."+j+a)}if(C.test(a)){n('malicious path "%s"',a);this.error(403);return e}i=a.split(j);a=k(w(t,a))}else{if(C.test(a)){n('malicious path "%s"',a);this.error(403);return e}i=k(a).split(j);a=S(a)}if(containsDotFile(i)){var r=this._dotfiles;if(r===undefined){r=i[i.length-1][0]==="."?this._hidden?"allow":"ignore":"allow"}n('%s dotfile "%s"',r,a);switch(r){case"allow":break;case"deny":this.error(403);return e;case"ignore":default:this.error(404);return e}}if(this._index.length&&this.hasTrailingSlash()){this.sendIndex(a);return e}this.sendFile(a);return e};SendStream.prototype.send=function send(e,t){var a=t.size;var i=this.options;var r={};var o=this.res;var p=this.req;var s=p.headers.range;var c=i.start||0;if(headersSent(o)){this.headersAlreadySent();return}n('pipe "%s"',e);this.setHeader(e,t);this.type(e);if(this.isConditionalGET()){if(this.isPreconditionFailure()){this.error(412);return}if(this.isCachable()&&this.isFresh()){this.notModified();return}}a=Math.max(0,a-c);if(i.end!==undefined){var l=i.end-c+1;if(a>l)a=l}if(this._acceptRanges&&_.test(s)){s=f(a,s,{combine:true});if(!this.isRangeFresh()){n("range stale");s=-2}if(s===-1){n("range unsatisfiable");o.setHeader("Content-Range",contentRange("bytes",a));return this.error(416,{headers:{"Content-Range":o.getHeader("Content-Range")}})}if(s!==-2&&s.length===1){n("range %j",s);o.statusCode=206;o.setHeader("Content-Range",contentRange("bytes",a,s[0]));c+=s[0].start;a=s[0].end-s[0].start+1}}for(var d in i){r[d]=i[d]}r.start=c;r.end=Math.max(c,c+a-1);o.setHeader("Content-Length",a);if(p.method==="HEAD"){o.end();return}this.stream(e,r)};SendStream.prototype.sendFile=function sendFile(e){var t=0;var a=this;n('stat "%s"',e);d.stat(e,(function onstat(t,i){if(t&&t.code==="ENOENT"&&!y(e)&&e[e.length-1]!==j){return next(t)}if(t)return a.onStatError(t);if(i.isDirectory())return a.redirect(e);a.emit("file",e,i);a.send(e,i)}));function next(i){if(a._extensions.length<=t){return i?a.onStatError(i):a.error(404)}var r=e+"."+a._extensions[t++];n('stat "%s"',r);d.stat(r,(function(e,t){if(e)return next(e);if(t.isDirectory())return next();a.emit("file",r,t);a.send(r,t)}))}};SendStream.prototype.sendIndex=function sendIndex(e){var t=-1;var a=this;function next(i){if(++t>=a._index.length){if(i)return a.onStatError(i);return a.error(404)}var r=w(e,a._index[t]);n('stat "%s"',r);d.stat(r,(function(e,t){if(e)return next(e);if(t.isDirectory())return next();a.emit("file",r,t);a.send(r,t)}))}next()};SendStream.prototype.stream=function stream(e,t){var a=this;var i=this.res;var stream=d.createReadStream(e,t);this.emit("stream",stream);stream.pipe(i);function cleanup(){o(stream,true)}v(i,cleanup);stream.on("error",(function onerror(e){cleanup();a.onStatError(e)}));stream.on("end",(function onend(){a.emit("end")}))};SendStream.prototype.type=function type(e){var t=this.res;if(t.getHeader("Content-Type"))return;var type=m.lookup(e);if(!type){n("no content-type");return}var a=m.charsets.lookup(type);n("content-type %s",type);t.setHeader("Content-Type",type+(a?"; charset="+a:""))};SendStream.prototype.setHeader=function setHeader(e,t){var a=this.res;this.emit("headers",a,e,t);if(this._acceptRanges&&!a.getHeader("Accept-Ranges")){n("accept ranges");a.setHeader("Accept-Ranges","bytes")}if(this._cacheControl&&!a.getHeader("Cache-Control")){var i="public, max-age="+Math.floor(this._maxage/1e3);if(this._immutable){i+=", immutable"}n("cache-control %s",i);a.setHeader("Cache-Control",i)}if(this._lastModified&&!a.getHeader("Last-Modified")){var r=t.mtime.toUTCString();n("modified %s",r);a.setHeader("Last-Modified",r)}if(this._etag&&!a.getHeader("ETag")){var o=c(t);n("etag %s",o);a.setHeader("ETag",o)}};function clearHeaders(e){var t=getHeaderNames(e);for(var a=0;a<t.length;a++){e.removeHeader(t[a])}}function collapseLeadingSlashes(e){for(var t=0;t<e.length;t++){if(e[t]!=="/"){break}}return t>1?"/"+e.substr(t):e}function containsDotFile(e){for(var t=0;t<e.length;t++){var a=e[t];if(a.length>1&&a[0]==="."){return true}}return false}function contentRange(e,t,a){return e+" "+(a?a.start+"-"+a.end:"*")+"/"+t}function createHtmlDocument(e,t){return"<!DOCTYPE html>\n"+'<html lang="en">\n'+"<head>\n"+'<meta charset="utf-8">\n'+"<title>"+e+"</title>\n"+"</head>\n"+"<body>\n"+"<pre>"+t+"</pre>\n"+"</body>\n"+"</html>\n"}function createHttpError(e,t){if(!t){return i(e)}return t instanceof Error?i(e,t,{expose:false}):i(e,t)}function decode(e){try{return decodeURIComponent(e)}catch(e){return-1}}function getHeaderNames(e){return typeof e.getHeaderNames!=="function"?Object.keys(e._headers||{}):e.getHeaderNames()}function hasListeners(e,t){var a=typeof e.listenerCount!=="function"?e.listeners(t).length:e.listenerCount(t);return a>0}function headersSent(e){return typeof e.headersSent!=="boolean"?Boolean(e._header):e.headersSent}function normalizeList(e,t){var a=[].concat(e||[]);for(var i=0;i<a.length;i++){if(typeof a[i]!=="string"){throw new TypeError(t+" must be array of strings or false")}}return a}function parseHttpDate(e){var t=e&&Date.parse(e);return typeof t==="number"?t:NaN}function parseTokenList(e){var t=0;var a=[];var i=0;for(var n=0,r=e.length;n<r;n++){switch(e.charCodeAt(n)){case 32:if(i===t){i=t=n+1}break;case 44:if(i!==t){a.push(e.substring(i,t))}i=t=n+1;break;default:t=n+1;break}}if(i!==t){a.push(e.substring(i,t))}return a}function setHeaders(e,t){var a=Object.keys(t);for(var i=0;i<a.length;i++){var n=a[i];e.setHeader(n,t[n])}}},832:e=>{"use strict";e.exports=Object.setPrototypeOf||({__proto__:[]}instanceof Array?setProtoOf:mixinProperties);function setProtoOf(e,t){e.__proto__=t;return e}function mixinProperties(e,t){for(var a in t){if(!Object.prototype.hasOwnProperty.call(e,a)){e[a]=t[a]}}return e}},596:(e,t,a)=>{"use strict"; |