@lzwme/sserver 0.0.11 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +71 -108
- package/dist/assets/assets/localsend/style.css +2 -0
- package/dist/assets/assets/localsend/vendor/qr-code-styling.js +2 -0
- package/dist/assets/localsend/style.css +2 -0
- package/dist/assets/localsend/vendor/qr-code-styling.js +2 -0
- package/dist/cli.js +9 -6
- package/dist/config.d.ts +38 -1
- package/dist/config.js +54 -9
- package/dist/lib/get-cert.js +1 -1
- package/dist/lib/merge-config.d.ts +9 -0
- package/dist/lib/merge-config.js +66 -0
- package/dist/lib/utils.d.ts +27 -1
- package/dist/lib/utils.js +94 -14
- package/dist/localsend/audit.d.ts +36 -0
- package/dist/localsend/audit.js +104 -0
- package/dist/localsend/auth.d.ts +94 -0
- package/dist/localsend/auth.js +227 -0
- package/dist/localsend/cache.d.ts +34 -0
- package/dist/localsend/cache.js +269 -0
- package/dist/localsend/chunk.d.ts +114 -0
- package/dist/localsend/chunk.js +475 -0
- package/dist/localsend/cleaner.d.ts +19 -0
- package/dist/localsend/cleaner.js +80 -0
- package/dist/localsend/client/app.js +4131 -0
- package/dist/localsend/client/crypto.js +233 -0
- package/dist/localsend/client/favicon.png +0 -0
- package/dist/localsend/client/icons/icon-192.png +0 -0
- package/dist/localsend/client/icons/icon-512.png +0 -0
- package/dist/localsend/client/index.html +451 -0
- package/dist/localsend/client/manifest.webmanifest +33 -0
- package/dist/localsend/client/sw.js +128 -0
- package/dist/localsend/guard.d.ts +58 -0
- package/dist/localsend/guard.js +210 -0
- package/dist/localsend/index.d.ts +52 -0
- package/dist/localsend/index.js +1771 -0
- package/dist/localsend/manage.d.ts +96 -0
- package/dist/localsend/manage.js +304 -0
- package/dist/localsend/metrics.d.ts +26 -0
- package/dist/localsend/metrics.js +58 -0
- package/dist/localsend/paste.d.ts +72 -0
- package/dist/localsend/paste.js +125 -0
- package/dist/localsend/path.d.ts +33 -0
- package/dist/localsend/path.js +151 -0
- package/dist/localsend/query.d.ts +78 -0
- package/dist/localsend/query.js +147 -0
- package/dist/localsend/secret.d.ts +31 -0
- package/dist/localsend/secret.js +96 -0
- package/dist/localsend/settings.d.ts +53 -0
- package/dist/localsend/settings.js +285 -0
- package/dist/localsend/share.d.ts +35 -0
- package/dist/localsend/share.js +117 -0
- package/dist/localsend/temp.d.ts +10 -0
- package/dist/localsend/temp.js +47 -0
- package/dist/localsend/ticket.d.ts +40 -0
- package/dist/localsend/ticket.js +98 -0
- package/dist/localsend/trash.d.ts +39 -0
- package/dist/localsend/trash.js +261 -0
- package/dist/localsend/webdav.d.ts +50 -0
- package/dist/localsend/webdav.js +530 -0
- package/dist/localsend/zip.d.ts +20 -0
- package/dist/localsend/zip.js +186 -0
- package/dist/proxy/php-proxy.js +31 -20
- package/dist/static-server.js +10 -3
- package/package.json +13 -5
- package/dist/localsend/index.html +0 -531
- package/dist/localsend.d.ts +0 -19
- package/dist/localsend.js +0 -217
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.QRCodeStyling=e():t.QRCodeStyling=e()}(this,(()=>(()=>{var t={873:(t,e)=>{var i,r,n=function(){var t=function(t,e){var i=t,r=s[e],n=null,o=0,h=null,p=[],v={},m=function(t,e){n=function(t){for(var e=new Array(t),i=0;i<t;i+=1){e[i]=new Array(t);for(var r=0;r<t;r+=1)e[i][r]=null}return e}(o=4*i+17),b(0,0),b(o-7,0),b(0,o-7),x(),y(),C(t,e),i>=7&&S(t),null==h&&(h=M(i,r,p)),A(h,e)},b=function(t,e){for(var i=-1;i<=7;i+=1)if(!(t+i<=-1||o<=t+i))for(var r=-1;r<=7;r+=1)e+r<=-1||o<=e+r||(n[t+i][e+r]=0<=i&&i<=6&&(0==r||6==r)||0<=r&&r<=6&&(0==i||6==i)||2<=i&&i<=4&&2<=r&&r<=4)},y=function(){for(var t=8;t<o-8;t+=1)null==n[t][6]&&(n[t][6]=t%2==0);for(var e=8;e<o-8;e+=1)null==n[6][e]&&(n[6][e]=e%2==0)},x=function(){for(var t=a.getPatternPosition(i),e=0;e<t.length;e+=1)for(var r=0;r<t.length;r+=1){var o=t[e],s=t[r];if(null==n[o][s])for(var h=-2;h<=2;h+=1)for(var d=-2;d<=2;d+=1)n[o+h][s+d]=-2==h||2==h||-2==d||2==d||0==h&&0==d}},S=function(t){for(var e=a.getBCHTypeNumber(i),r=0;r<18;r+=1){var s=!t&&1==(e>>r&1);n[Math.floor(r/3)][r%3+o-8-3]=s}for(r=0;r<18;r+=1)s=!t&&1==(e>>r&1),n[r%3+o-8-3][Math.floor(r/3)]=s},C=function(t,e){for(var i=r<<3|e,s=a.getBCHTypeInfo(i),h=0;h<15;h+=1){var d=!t&&1==(s>>h&1);h<6?n[h][8]=d:h<8?n[h+1][8]=d:n[o-15+h][8]=d}for(h=0;h<15;h+=1)d=!t&&1==(s>>h&1),h<8?n[8][o-h-1]=d:h<9?n[8][15-h-1+1]=d:n[8][15-h-1]=d;n[o-8][8]=!t},A=function(t,e){for(var i=-1,r=o-1,s=7,h=0,d=a.getMaskFunction(e),u=o-1;u>0;u-=2)for(6==u&&(u-=1);;){for(var c=0;c<2;c+=1)if(null==n[r][u-c]){var l=!1;h<t.length&&(l=1==(t[h]>>>s&1)),d(r,u-c)&&(l=!l),n[r][u-c]=l,-1==(s-=1)&&(h+=1,s=7)}if((r+=i)<0||o<=r){r-=i,i=-i;break}}},M=function(t,e,i){for(var r=u.getRSBlocks(t,e),n=c(),o=0;o<i.length;o+=1){var s=i[o];n.put(s.getMode(),4),n.put(s.getLength(),a.getLengthInBits(s.getMode(),t)),s.write(n)}var h=0;for(o=0;o<r.length;o+=1)h+=r[o].dataCount;if(n.getLengthInBits()>8*h)throw"code length overflow. ("+n.getLengthInBits()+">"+8*h+")";for(n.getLengthInBits()+4<=8*h&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=8*h||(n.put(236,8),n.getLengthInBits()>=8*h));)n.put(17,8);return function(t,e){for(var i=0,r=0,n=0,o=new Array(e.length),s=new Array(e.length),h=0;h<e.length;h+=1){var u=e[h].dataCount,c=e[h].totalCount-u;r=Math.max(r,u),n=Math.max(n,c),o[h]=new Array(u);for(var l=0;l<o[h].length;l+=1)o[h][l]=255&t.getBuffer()[l+i];i+=u;var g=a.getErrorCorrectPolynomial(c),f=d(o[h],g.getLength()-1).mod(g);for(s[h]=new Array(g.getLength()-1),l=0;l<s[h].length;l+=1){var w=l+f.getLength()-s[h].length;s[h][l]=w>=0?f.getAt(w):0}}var p=0;for(l=0;l<e.length;l+=1)p+=e[l].totalCount;var v=new Array(p),_=0;for(l=0;l<r;l+=1)for(h=0;h<e.length;h+=1)l<o[h].length&&(v[_]=o[h][l],_+=1);for(l=0;l<n;l+=1)for(h=0;h<e.length;h+=1)l<s[h].length&&(v[_]=s[h][l],_+=1);return v}(n,r)};v.addData=function(t,e){var i=null;switch(e=e||"Byte"){case"Numeric":i=l(t);break;case"Alphanumeric":i=g(t);break;case"Byte":i=f(t);break;case"Kanji":i=w(t);break;default:throw"mode:"+e}p.push(i),h=null},v.isDark=function(t,e){if(t<0||o<=t||e<0||o<=e)throw t+","+e;return n[t][e]},v.getModuleCount=function(){return o},v.make=function(){if(i<1){for(var t=1;t<40;t++){for(var e=u.getRSBlocks(t,r),n=c(),o=0;o<p.length;o++){var s=p[o];n.put(s.getMode(),4),n.put(s.getLength(),a.getLengthInBits(s.getMode(),t)),s.write(n)}var h=0;for(o=0;o<e.length;o++)h+=e[o].dataCount;if(n.getLengthInBits()<=8*h)break}i=t}m(!1,function(){for(var t=0,e=0,i=0;i<8;i+=1){m(!0,i);var r=a.getLostPoint(v);(0==i||t>r)&&(t=r,e=i)}return e}())},v.createTableTag=function(t,e){t=t||2;var i="";i+='<table style="',i+=" border-width: 0px; border-style: none;",i+=" border-collapse: collapse;",i+=" padding: 0px; margin: "+(e=void 0===e?4*t:e)+"px;",i+='">',i+="<tbody>";for(var r=0;r<v.getModuleCount();r+=1){i+="<tr>";for(var n=0;n<v.getModuleCount();n+=1)i+='<td style="',i+=" border-width: 0px; border-style: none;",i+=" border-collapse: collapse;",i+=" padding: 0px; margin: 0px;",i+=" width: "+t+"px;",i+=" height: "+t+"px;",i+=" background-color: ",i+=v.isDark(r,n)?"#000000":"#ffffff",i+=";",i+='"/>';i+="</tr>"}return(i+="</tbody>")+"</table>"},v.createSvgTag=function(t,e,i,r){var n={};"object"==typeof arguments[0]&&(t=(n=arguments[0]).cellSize,e=n.margin,i=n.alt,r=n.title),t=t||2,e=void 0===e?4*t:e,(i="string"==typeof i?{text:i}:i||{}).text=i.text||null,i.id=i.text?i.id||"qrcode-description":null,(r="string"==typeof r?{text:r}:r||{}).text=r.text||null,r.id=r.text?r.id||"qrcode-title":null;var o,s,a,h,d=v.getModuleCount()*t+2*e,u="";for(h="l"+t+",0 0,"+t+" -"+t+",0 0,-"+t+"z ",u+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',u+=n.scalable?"":' width="'+d+'px" height="'+d+'px"',u+=' viewBox="0 0 '+d+" "+d+'" ',u+=' preserveAspectRatio="xMinYMin meet"',u+=r.text||i.text?' role="img" aria-labelledby="'+$([r.id,i.id].join(" ").trim())+'"':"",u+=">",u+=r.text?'<title id="'+$(r.id)+'">'+$(r.text)+"</title>":"",u+=i.text?'<description id="'+$(i.id)+'">'+$(i.text)+"</description>":"",u+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',u+='<path d="',s=0;s<v.getModuleCount();s+=1)for(a=s*t+e,o=0;o<v.getModuleCount();o+=1)v.isDark(s,o)&&(u+="M"+(o*t+e)+","+a+h);return(u+='" stroke="transparent" fill="black"/>')+"</svg>"},v.createDataURL=function(t,e){t=t||2,e=void 0===e?4*t:e;var i=v.getModuleCount()*t+2*e,r=e,n=i-e;return _(i,i,(function(e,i){if(r<=e&&e<n&&r<=i&&i<n){var o=Math.floor((e-r)/t),s=Math.floor((i-r)/t);return v.isDark(s,o)?0:1}return 1}))},v.createImgTag=function(t,e,i){t=t||2,e=void 0===e?4*t:e;var r=v.getModuleCount()*t+2*e,n="";return n+="<img",n+=' src="',n+=v.createDataURL(t,e),n+='"',n+=' width="',n+=r,n+='"',n+=' height="',n+=r,n+='"',i&&(n+=' alt="',n+=$(i),n+='"'),n+"/>"};var $=function(t){for(var e="",i=0;i<t.length;i+=1){var r=t.charAt(i);switch(r){case"<":e+="<";break;case">":e+=">";break;case"&":e+="&";break;case'"':e+=""";break;default:e+=r}}return e};return v.createASCII=function(t,e){if((t=t||1)<2)return function(t){t=void 0===t?2:t;var e,i,r,n,o,s=1*v.getModuleCount()+2*t,a=t,h=s-t,d={"██":"█","█ ":"▀"," █":"▄"," ":" "},u={"██":"▀","█ ":"▀"," █":" "," ":" "},c="";for(e=0;e<s;e+=2){for(r=Math.floor((e-a)/1),n=Math.floor((e+1-a)/1),i=0;i<s;i+=1)o="█",a<=i&&i<h&&a<=e&&e<h&&v.isDark(r,Math.floor((i-a)/1))&&(o=" "),a<=i&&i<h&&a<=e+1&&e+1<h&&v.isDark(n,Math.floor((i-a)/1))?o+=" ":o+="█",c+=t<1&&e+1>=h?u[o]:d[o];c+="\n"}return s%2&&t>0?c.substring(0,c.length-s-1)+Array(s+1).join("▀"):c.substring(0,c.length-1)}(e);t-=1,e=void 0===e?2*t:e;var i,r,n,o,s=v.getModuleCount()*t+2*e,a=e,h=s-e,d=Array(t+1).join("██"),u=Array(t+1).join(" "),c="",l="";for(i=0;i<s;i+=1){for(n=Math.floor((i-a)/t),l="",r=0;r<s;r+=1)o=1,a<=r&&r<h&&a<=i&&i<h&&v.isDark(n,Math.floor((r-a)/t))&&(o=0),l+=o?d:u;for(n=0;n<t;n+=1)c+=l+"\n"}return c.substring(0,c.length-1)},v.renderTo2dContext=function(t,e){e=e||2;for(var i=v.getModuleCount(),r=0;r<i;r++)for(var n=0;n<i;n++)t.fillStyle=v.isDark(r,n)?"black":"white",t.fillRect(r*e,n*e,e,e)},v};t.stringToBytes=(t.stringToBytesFuncs={default:function(t){for(var e=[],i=0;i<t.length;i+=1){var r=t.charCodeAt(i);e.push(255&r)}return e}}).default,t.createStringToBytes=function(t,e){var i=function(){for(var i=v(t),r=function(){var t=i.read();if(-1==t)throw"eof";return t},n=0,o={};;){var s=i.read();if(-1==s)break;var a=r(),h=r()<<8|r();o[String.fromCharCode(s<<8|a)]=h,n+=1}if(n!=e)throw n+" != "+e;return o}(),r="?".charCodeAt(0);return function(t){for(var e=[],n=0;n<t.length;n+=1){var o=t.charCodeAt(n);if(o<128)e.push(o);else{var s=i[t.charAt(n)];"number"==typeof s?(255&s)==s?e.push(s):(e.push(s>>>8),e.push(255&s)):e.push(r)}}return e}};var e,i,r,n,o,s={L:1,M:0,Q:3,H:2},a=(e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],i=1335,r=7973,o=function(t){for(var e=0;0!=t;)e+=1,t>>>=1;return e},(n={}).getBCHTypeInfo=function(t){for(var e=t<<10;o(e)-o(i)>=0;)e^=i<<o(e)-o(i);return 21522^(t<<10|e)},n.getBCHTypeNumber=function(t){for(var e=t<<12;o(e)-o(r)>=0;)e^=r<<o(e)-o(r);return t<<12|e},n.getPatternPosition=function(t){return e[t-1]},n.getMaskFunction=function(t){switch(t){case 0:return function(t,e){return(t+e)%2==0};case 1:return function(t,e){return t%2==0};case 2:return function(t,e){return e%3==0};case 3:return function(t,e){return(t+e)%3==0};case 4:return function(t,e){return(Math.floor(t/2)+Math.floor(e/3))%2==0};case 5:return function(t,e){return t*e%2+t*e%3==0};case 6:return function(t,e){return(t*e%2+t*e%3)%2==0};case 7:return function(t,e){return(t*e%3+(t+e)%2)%2==0};default:throw"bad maskPattern:"+t}},n.getErrorCorrectPolynomial=function(t){for(var e=d([1],0),i=0;i<t;i+=1)e=e.multiply(d([1,h.gexp(i)],0));return e},n.getLengthInBits=function(t,e){if(1<=e&&e<10)switch(t){case 1:return 10;case 2:return 9;case 4:case 8:return 8;default:throw"mode:"+t}else if(e<27)switch(t){case 1:return 12;case 2:return 11;case 4:return 16;case 8:return 10;default:throw"mode:"+t}else{if(!(e<41))throw"type:"+e;switch(t){case 1:return 14;case 2:return 13;case 4:return 16;case 8:return 12;default:throw"mode:"+t}}},n.getLostPoint=function(t){for(var e=t.getModuleCount(),i=0,r=0;r<e;r+=1)for(var n=0;n<e;n+=1){for(var o=0,s=t.isDark(r,n),a=-1;a<=1;a+=1)if(!(r+a<0||e<=r+a))for(var h=-1;h<=1;h+=1)n+h<0||e<=n+h||0==a&&0==h||s==t.isDark(r+a,n+h)&&(o+=1);o>5&&(i+=3+o-5)}for(r=0;r<e-1;r+=1)for(n=0;n<e-1;n+=1){var d=0;t.isDark(r,n)&&(d+=1),t.isDark(r+1,n)&&(d+=1),t.isDark(r,n+1)&&(d+=1),t.isDark(r+1,n+1)&&(d+=1),0!=d&&4!=d||(i+=3)}for(r=0;r<e;r+=1)for(n=0;n<e-6;n+=1)t.isDark(r,n)&&!t.isDark(r,n+1)&&t.isDark(r,n+2)&&t.isDark(r,n+3)&&t.isDark(r,n+4)&&!t.isDark(r,n+5)&&t.isDark(r,n+6)&&(i+=40);for(n=0;n<e;n+=1)for(r=0;r<e-6;r+=1)t.isDark(r,n)&&!t.isDark(r+1,n)&&t.isDark(r+2,n)&&t.isDark(r+3,n)&&t.isDark(r+4,n)&&!t.isDark(r+5,n)&&t.isDark(r+6,n)&&(i+=40);var u=0;for(n=0;n<e;n+=1)for(r=0;r<e;r+=1)t.isDark(r,n)&&(u+=1);return i+Math.abs(100*u/e/e-50)/5*10},n),h=function(){for(var t=new Array(256),e=new Array(256),i=0;i<8;i+=1)t[i]=1<<i;for(i=8;i<256;i+=1)t[i]=t[i-4]^t[i-5]^t[i-6]^t[i-8];for(i=0;i<255;i+=1)e[t[i]]=i;return{glog:function(t){if(t<1)throw"glog("+t+")";return e[t]},gexp:function(e){for(;e<0;)e+=255;for(;e>=256;)e-=255;return t[e]}}}();function d(t,e){if(void 0===t.length)throw t.length+"/"+e;var i=function(){for(var i=0;i<t.length&&0==t[i];)i+=1;for(var r=new Array(t.length-i+e),n=0;n<t.length-i;n+=1)r[n]=t[n+i];return r}(),r={getAt:function(t){return i[t]},getLength:function(){return i.length},multiply:function(t){for(var e=new Array(r.getLength()+t.getLength()-1),i=0;i<r.getLength();i+=1)for(var n=0;n<t.getLength();n+=1)e[i+n]^=h.gexp(h.glog(r.getAt(i))+h.glog(t.getAt(n)));return d(e,0)},mod:function(t){if(r.getLength()-t.getLength()<0)return r;for(var e=h.glog(r.getAt(0))-h.glog(t.getAt(0)),i=new Array(r.getLength()),n=0;n<r.getLength();n+=1)i[n]=r.getAt(n);for(n=0;n<t.getLength();n+=1)i[n]^=h.gexp(h.glog(t.getAt(n))+e);return d(i,0).mod(t)}};return r}var u=function(){var t=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],e=function(t,e){var i={};return i.totalCount=t,i.dataCount=e,i},i={getRSBlocks:function(i,r){var n=function(e,i){switch(i){case s.L:return t[4*(e-1)+0];case s.M:return t[4*(e-1)+1];case s.Q:return t[4*(e-1)+2];case s.H:return t[4*(e-1)+3];default:return}}(i,r);if(void 0===n)throw"bad rs block @ typeNumber:"+i+"/errorCorrectionLevel:"+r;for(var o=n.length/3,a=[],h=0;h<o;h+=1)for(var d=n[3*h+0],u=n[3*h+1],c=n[3*h+2],l=0;l<d;l+=1)a.push(e(u,c));return a}};return i}(),c=function(){var t=[],e=0,i={getBuffer:function(){return t},getAt:function(e){var i=Math.floor(e/8);return 1==(t[i]>>>7-e%8&1)},put:function(t,e){for(var r=0;r<e;r+=1)i.putBit(1==(t>>>e-r-1&1))},getLengthInBits:function(){return e},putBit:function(i){var r=Math.floor(e/8);t.length<=r&&t.push(0),i&&(t[r]|=128>>>e%8),e+=1}};return i},l=function(t){var e=t,i={getMode:function(){return 1},getLength:function(t){return e.length},write:function(t){for(var i=e,n=0;n+2<i.length;)t.put(r(i.substring(n,n+3)),10),n+=3;n<i.length&&(i.length-n==1?t.put(r(i.substring(n,n+1)),4):i.length-n==2&&t.put(r(i.substring(n,n+2)),7))}},r=function(t){for(var e=0,i=0;i<t.length;i+=1)e=10*e+n(t.charAt(i));return e},n=function(t){if("0"<=t&&t<="9")return t.charCodeAt(0)-"0".charCodeAt(0);throw"illegal char :"+t};return i},g=function(t){var e=t,i={getMode:function(){return 2},getLength:function(t){return e.length},write:function(t){for(var i=e,n=0;n+1<i.length;)t.put(45*r(i.charAt(n))+r(i.charAt(n+1)),11),n+=2;n<i.length&&t.put(r(i.charAt(n)),6)}},r=function(t){if("0"<=t&&t<="9")return t.charCodeAt(0)-"0".charCodeAt(0);if("A"<=t&&t<="Z")return t.charCodeAt(0)-"A".charCodeAt(0)+10;switch(t){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+t}};return i},f=function(e){var i=t.stringToBytes(e);return{getMode:function(){return 4},getLength:function(t){return i.length},write:function(t){for(var e=0;e<i.length;e+=1)t.put(i[e],8)}}},w=function(e){var i=t.stringToBytesFuncs.SJIS;if(!i)throw"sjis not supported.";!function(){var t=i("友");if(2!=t.length||38726!=(t[0]<<8|t[1]))throw"sjis not supported."}();var r=i(e),n={getMode:function(){return 8},getLength:function(t){return~~(r.length/2)},write:function(t){for(var e=r,i=0;i+1<e.length;){var n=(255&e[i])<<8|255&e[i+1];if(33088<=n&&n<=40956)n-=33088;else{if(!(57408<=n&&n<=60351))throw"illegal char at "+(i+1)+"/"+n;n-=49472}n=192*(n>>>8&255)+(255&n),t.put(n,13),i+=2}if(i<e.length)throw"illegal char at "+(i+1)}};return n},p=function(){var t=[],e={writeByte:function(e){t.push(255&e)},writeShort:function(t){e.writeByte(t),e.writeByte(t>>>8)},writeBytes:function(t,i,r){i=i||0,r=r||t.length;for(var n=0;n<r;n+=1)e.writeByte(t[n+i])},writeString:function(t){for(var i=0;i<t.length;i+=1)e.writeByte(t.charCodeAt(i))},toByteArray:function(){return t},toString:function(){var e="";e+="[";for(var i=0;i<t.length;i+=1)i>0&&(e+=","),e+=t[i];return e+"]"}};return e},v=function(t){var e=t,i=0,r=0,n=0,o={read:function(){for(;n<8;){if(i>=e.length){if(0==n)return-1;throw"unexpected end of file./"+n}var t=e.charAt(i);if(i+=1,"="==t)return n=0,-1;t.match(/^\s$/)||(r=r<<6|s(t.charCodeAt(0)),n+=6)}var o=r>>>n-8&255;return n-=8,o}},s=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw"c:"+t};return o},_=function(t,e,i){for(var r=function(t,e){var i=t,r=e,n=new Array(t*e),o={setPixel:function(t,e,r){n[e*i+t]=r},write:function(t){t.writeString("GIF87a"),t.writeShort(i),t.writeShort(r),t.writeByte(128),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(255),t.writeByte(255),t.writeByte(255),t.writeString(","),t.writeShort(0),t.writeShort(0),t.writeShort(i),t.writeShort(r),t.writeByte(0);var e=s(2);t.writeByte(2);for(var n=0;e.length-n>255;)t.writeByte(255),t.writeBytes(e,n,255),n+=255;t.writeByte(e.length-n),t.writeBytes(e,n,e.length-n),t.writeByte(0),t.writeString(";")}},s=function(t){for(var e=1<<t,i=1+(1<<t),r=t+1,o=a(),s=0;s<e;s+=1)o.add(String.fromCharCode(s));o.add(String.fromCharCode(e)),o.add(String.fromCharCode(i));var h,d,u,c=p(),l=(h=c,d=0,u=0,{write:function(t,e){if(t>>>e!=0)throw"length over";for(;d+e>=8;)h.writeByte(255&(t<<d|u)),e-=8-d,t>>>=8-d,u=0,d=0;u|=t<<d,d+=e},flush:function(){d>0&&h.writeByte(u)}});l.write(e,r);var g=0,f=String.fromCharCode(n[g]);for(g+=1;g<n.length;){var w=String.fromCharCode(n[g]);g+=1,o.contains(f+w)?f+=w:(l.write(o.indexOf(f),r),o.size()<4095&&(o.size()==1<<r&&(r+=1),o.add(f+w)),f=w)}return l.write(o.indexOf(f),r),l.write(i,r),l.flush(),c.toByteArray()},a=function(){var t={},e=0,i={add:function(r){if(i.contains(r))throw"dup key:"+r;t[r]=e,e+=1},size:function(){return e},indexOf:function(e){return t[e]},contains:function(e){return void 0!==t[e]}};return i};return o}(t,e),n=0;n<e;n+=1)for(var o=0;o<t;o+=1)r.setPixel(o,n,i(o,n));var s=p();r.write(s);for(var a=function(){var t=0,e=0,i=0,r="",n={},o=function(t){r+=String.fromCharCode(s(63&t))},s=function(t){if(t<0);else{if(t<26)return 65+t;if(t<52)return t-26+97;if(t<62)return t-52+48;if(62==t)return 43;if(63==t)return 47}throw"n:"+t};return n.writeByte=function(r){for(t=t<<8|255&r,e+=8,i+=1;e>=6;)o(t>>>e-6),e-=6},n.flush=function(){if(e>0&&(o(t<<6-e),t=0,e=0),i%3!=0)for(var n=3-i%3,s=0;s<n;s+=1)r+="="},n.toString=function(){return r},n}(),h=s.toByteArray(),d=0;d<h.length;d+=1)a.writeByte(h[d]);return a.flush(),"data:image/gif;base64,"+a};return t}();n.stringToBytesFuncs["UTF-8"]=function(t){return function(t){for(var e=[],i=0;i<t.length;i++){var r=t.charCodeAt(i);r<128?e.push(r):r<2048?e.push(192|r>>6,128|63&r):r<55296||r>=57344?e.push(224|r>>12,128|r>>6&63,128|63&r):(i++,r=65536+((1023&r)<<10|1023&t.charCodeAt(i)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}(t)},void 0===(r="function"==typeof(i=function(){return n})?i.apply(e,[]):i)||(t.exports=r)}},e={};function i(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,i),o.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};return(()=>{"use strict";i.d(r,{default:()=>$});const t=t=>!!t&&"object"==typeof t&&!Array.isArray(t);function e(i,...r){if(!r.length)return i;const n=r.shift();return void 0!==n&&t(i)&&t(n)?(i=Object.assign({},i),Object.keys(n).forEach((r=>{const o=i[r],s=n[r];Array.isArray(o)&&Array.isArray(s)?i[r]=s:t(o)&&t(s)?i[r]=e(Object.assign({},o),s):i[r]=s})),e(i,...r)):i}function n(t,e){const i=document.createElement("a");i.download=e,i.href=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}const o={L:.07,M:.15,Q:.25,H:.3};class s{constructor({svg:t,type:e,window:i}){this._svg=t,this._type=e,this._window=i}draw(t,e,i,r){let n;switch(this._type){case"dots":n=this._drawDot;break;case"classy":n=this._drawClassy;break;case"classy-rounded":n=this._drawClassyRounded;break;case"rounded":n=this._drawRounded;break;case"extra-rounded":n=this._drawExtraRounded;break;default:n=this._drawSquare}n.call(this,{x:t,y:e,size:i,getNeighbor:r})}_rotateFigure({x:t,y:e,size:i,rotation:r=0,draw:n}){var o;const s=t+i/2,a=e+i/2;n(),null===(o=this._element)||void 0===o||o.setAttribute("transform",`rotate(${180*r/Math.PI},${s},${a})`)}_basicDot(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","circle"),this._element.setAttribute("cx",String(i+e/2)),this._element.setAttribute("cy",String(r+e/2)),this._element.setAttribute("r",String(e/2))}}))}_basicSquare(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","rect"),this._element.setAttribute("x",String(i)),this._element.setAttribute("y",String(r)),this._element.setAttribute("width",String(e)),this._element.setAttribute("height",String(e))}}))}_basicSideRounded(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("d",`M ${i} ${r}v ${e}h `+e/2+`a ${e/2} ${e/2}, 0, 0, 0, 0 ${-e}`)}}))}_basicCornerRounded(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("d",`M ${i} ${r}v ${e}h ${e}v `+-e/2+`a ${e/2} ${e/2}, 0, 0, 0, ${-e/2} ${-e/2}`)}}))}_basicCornerExtraRounded(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("d",`M ${i} ${r}v ${e}h ${e}a ${e} ${e}, 0, 0, 0, ${-e} ${-e}`)}}))}_basicCornersRounded(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("d",`M ${i} ${r}v `+e/2+`a ${e/2} ${e/2}, 0, 0, 0, ${e/2} ${e/2}h `+e/2+"v "+-e/2+`a ${e/2} ${e/2}, 0, 0, 0, ${-e/2} ${-e/2}`)}}))}_drawDot({x:t,y:e,size:i}){this._basicDot({x:t,y:e,size:i,rotation:0})}_drawSquare({x:t,y:e,size:i}){this._basicSquare({x:t,y:e,size:i,rotation:0})}_drawRounded({x:t,y:e,size:i,getNeighbor:r}){const n=r?+r(-1,0):0,o=r?+r(1,0):0,s=r?+r(0,-1):0,a=r?+r(0,1):0,h=n+o+s+a;if(0!==h)if(h>2||n&&o||s&&a)this._basicSquare({x:t,y:e,size:i,rotation:0});else{if(2===h){let r=0;return n&&s?r=Math.PI/2:s&&o?r=Math.PI:o&&a&&(r=-Math.PI/2),void this._basicCornerRounded({x:t,y:e,size:i,rotation:r})}if(1===h){let r=0;return s?r=Math.PI/2:o?r=Math.PI:a&&(r=-Math.PI/2),void this._basicSideRounded({x:t,y:e,size:i,rotation:r})}}else this._basicDot({x:t,y:e,size:i,rotation:0})}_drawExtraRounded({x:t,y:e,size:i,getNeighbor:r}){const n=r?+r(-1,0):0,o=r?+r(1,0):0,s=r?+r(0,-1):0,a=r?+r(0,1):0,h=n+o+s+a;if(0!==h)if(h>2||n&&o||s&&a)this._basicSquare({x:t,y:e,size:i,rotation:0});else{if(2===h){let r=0;return n&&s?r=Math.PI/2:s&&o?r=Math.PI:o&&a&&(r=-Math.PI/2),void this._basicCornerExtraRounded({x:t,y:e,size:i,rotation:r})}if(1===h){let r=0;return s?r=Math.PI/2:o?r=Math.PI:a&&(r=-Math.PI/2),void this._basicSideRounded({x:t,y:e,size:i,rotation:r})}}else this._basicDot({x:t,y:e,size:i,rotation:0})}_drawClassy({x:t,y:e,size:i,getNeighbor:r}){const n=r?+r(-1,0):0,o=r?+r(1,0):0,s=r?+r(0,-1):0,a=r?+r(0,1):0;0!==n+o+s+a?n||s?o||a?this._basicSquare({x:t,y:e,size:i,rotation:0}):this._basicCornerRounded({x:t,y:e,size:i,rotation:Math.PI/2}):this._basicCornerRounded({x:t,y:e,size:i,rotation:-Math.PI/2}):this._basicCornersRounded({x:t,y:e,size:i,rotation:Math.PI/2})}_drawClassyRounded({x:t,y:e,size:i,getNeighbor:r}){const n=r?+r(-1,0):0,o=r?+r(1,0):0,s=r?+r(0,-1):0,a=r?+r(0,1):0;0!==n+o+s+a?n||s?o||a?this._basicSquare({x:t,y:e,size:i,rotation:0}):this._basicCornerExtraRounded({x:t,y:e,size:i,rotation:Math.PI/2}):this._basicCornerExtraRounded({x:t,y:e,size:i,rotation:-Math.PI/2}):this._basicCornersRounded({x:t,y:e,size:i,rotation:Math.PI/2})}}const a={dot:"dot",square:"square",extraRounded:"extra-rounded"},h=Object.values(a);class d{constructor({svg:t,type:e,window:i}){this._svg=t,this._type=e,this._window=i}draw(t,e,i,r){let n;switch(this._type){case a.square:n=this._drawSquare;break;case a.extraRounded:n=this._drawExtraRounded;break;default:n=this._drawDot}n.call(this,{x:t,y:e,size:i,rotation:r})}_rotateFigure({x:t,y:e,size:i,rotation:r=0,draw:n}){var o;const s=t+i/2,a=e+i/2;n(),null===(o=this._element)||void 0===o||o.setAttribute("transform",`rotate(${180*r/Math.PI},${s},${a})`)}_basicDot(t){const{size:e,x:i,y:r}=t,n=e/7;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("clip-rule","evenodd"),this._element.setAttribute("d",`M ${i+e/2} ${r}a ${e/2} ${e/2} 0 1 0 0.1 0zm 0 ${n}a ${e/2-n} ${e/2-n} 0 1 1 -0.1 0Z`)}}))}_basicSquare(t){const{size:e,x:i,y:r}=t,n=e/7;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("clip-rule","evenodd"),this._element.setAttribute("d",`M ${i} ${r}v ${e}h ${e}v `+-e+"z"+`M ${i+n} ${r+n}h `+(e-2*n)+"v "+(e-2*n)+"h "+(2*n-e)+"z")}}))}_basicExtraRounded(t){const{size:e,x:i,y:r}=t,n=e/7;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","path"),this._element.setAttribute("clip-rule","evenodd"),this._element.setAttribute("d",`M ${i} ${r+2.5*n}v `+2*n+`a ${2.5*n} ${2.5*n}, 0, 0, 0, ${2.5*n} ${2.5*n}h `+2*n+`a ${2.5*n} ${2.5*n}, 0, 0, 0, ${2.5*n} ${2.5*-n}v `+-2*n+`a ${2.5*n} ${2.5*n}, 0, 0, 0, ${2.5*-n} ${2.5*-n}h `+-2*n+`a ${2.5*n} ${2.5*n}, 0, 0, 0, ${2.5*-n} ${2.5*n}`+`M ${i+2.5*n} ${r+n}h `+2*n+`a ${1.5*n} ${1.5*n}, 0, 0, 1, ${1.5*n} ${1.5*n}v `+2*n+`a ${1.5*n} ${1.5*n}, 0, 0, 1, ${1.5*-n} ${1.5*n}h `+-2*n+`a ${1.5*n} ${1.5*n}, 0, 0, 1, ${1.5*-n} ${1.5*-n}v `+-2*n+`a ${1.5*n} ${1.5*n}, 0, 0, 1, ${1.5*n} ${1.5*-n}`)}}))}_drawDot({x:t,y:e,size:i,rotation:r}){this._basicDot({x:t,y:e,size:i,rotation:r})}_drawSquare({x:t,y:e,size:i,rotation:r}){this._basicSquare({x:t,y:e,size:i,rotation:r})}_drawExtraRounded({x:t,y:e,size:i,rotation:r}){this._basicExtraRounded({x:t,y:e,size:i,rotation:r})}}const u={dot:"dot",square:"square"},c=Object.values(u);class l{constructor({svg:t,type:e,window:i}){this._svg=t,this._type=e,this._window=i}draw(t,e,i,r){let n;n=this._type===u.square?this._drawSquare:this._drawDot,n.call(this,{x:t,y:e,size:i,rotation:r})}_rotateFigure({x:t,y:e,size:i,rotation:r=0,draw:n}){var o;const s=t+i/2,a=e+i/2;n(),null===(o=this._element)||void 0===o||o.setAttribute("transform",`rotate(${180*r/Math.PI},${s},${a})`)}_basicDot(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","circle"),this._element.setAttribute("cx",String(i+e/2)),this._element.setAttribute("cy",String(r+e/2)),this._element.setAttribute("r",String(e/2))}}))}_basicSquare(t){const{size:e,x:i,y:r}=t;this._rotateFigure(Object.assign(Object.assign({},t),{draw:()=>{this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","rect"),this._element.setAttribute("x",String(i)),this._element.setAttribute("y",String(r)),this._element.setAttribute("width",String(e)),this._element.setAttribute("height",String(e))}}))}_drawDot({x:t,y:e,size:i,rotation:r}){this._basicDot({x:t,y:e,size:i,rotation:r})}_drawSquare({x:t,y:e,size:i,rotation:r}){this._basicSquare({x:t,y:e,size:i,rotation:r})}}const g="circle",f=[[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]],w=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,1,1,1,0,0],[0,0,1,1,1,0,0],[0,0,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]];class p{constructor(t,e){this._roundSize=t=>this._options.dotsOptions.roundSize?Math.floor(t):t,this._window=e,this._element=this._window.document.createElementNS("http://www.w3.org/2000/svg","svg"),this._element.setAttribute("width",String(t.width)),this._element.setAttribute("height",String(t.height)),this._element.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),t.dotsOptions.roundSize||this._element.setAttribute("shape-rendering","crispEdges"),this._element.setAttribute("viewBox",`0 0 ${t.width} ${t.height}`),this._defs=this._window.document.createElementNS("http://www.w3.org/2000/svg","defs"),this._element.appendChild(this._defs),this._imageUri=t.image,this._instanceId=p.instanceCount++,this._options=t}get width(){return this._options.width}get height(){return this._options.height}getElement(){return this._element}async drawQR(t){const e=t.getModuleCount(),i=Math.min(this._options.width,this._options.height)-2*this._options.margin,r=this._options.shape===g?i/Math.sqrt(2):i,n=this._roundSize(r/e);let s={hideXDots:0,hideYDots:0,width:0,height:0};if(this._qr=t,this._options.image){if(await this.loadImage(),!this._image)return;const{imageOptions:t,qrOptions:i}=this._options,r=t.imageSize*o[i.errorCorrectionLevel],a=Math.floor(r*e*e);s=function({originalHeight:t,originalWidth:e,maxHiddenDots:i,maxHiddenAxisDots:r,dotSize:n}){const o={x:0,y:0},s={x:0,y:0};if(t<=0||e<=0||i<=0||n<=0)return{height:0,width:0,hideYDots:0,hideXDots:0};const a=t/e;return o.x=Math.floor(Math.sqrt(i/a)),o.x<=0&&(o.x=1),r&&r<o.x&&(o.x=r),o.x%2==0&&o.x--,s.x=o.x*n,o.y=1+2*Math.ceil((o.x*a-1)/2),s.y=Math.round(s.x*a),(o.y*o.x>i||r&&r<o.y)&&(r&&r<o.y?(o.y=r,o.y%2==0&&o.x--):o.y-=2,s.y=o.y*n,o.x=1+2*Math.ceil((o.y/a-1)/2),s.x=Math.round(s.y/a)),{height:s.y,width:s.x,hideYDots:o.y,hideXDots:o.x}}({originalWidth:this._image.width,originalHeight:this._image.height,maxHiddenDots:a,maxHiddenAxisDots:e-14,dotSize:n})}this.drawBackground(),this.drawDots(((t,i)=>{var r,n,o,a,h,d;return!(this._options.imageOptions.hideBackgroundDots&&t>=(e-s.hideYDots)/2&&t<(e+s.hideYDots)/2&&i>=(e-s.hideXDots)/2&&i<(e+s.hideXDots)/2||(null===(r=f[t])||void 0===r?void 0:r[i])||(null===(n=f[t-e+7])||void 0===n?void 0:n[i])||(null===(o=f[t])||void 0===o?void 0:o[i-e+7])||(null===(a=w[t])||void 0===a?void 0:a[i])||(null===(h=w[t-e+7])||void 0===h?void 0:h[i])||(null===(d=w[t])||void 0===d?void 0:d[i-e+7]))})),this.drawCorners(),this._options.image&&await this.drawImage({width:s.width,height:s.height,count:e,dotSize:n})}drawBackground(){var t,e,i;const r=this._element,n=this._options;if(r){const r=null===(t=n.backgroundOptions)||void 0===t?void 0:t.gradient,o=null===(e=n.backgroundOptions)||void 0===e?void 0:e.color;let s=n.height,a=n.width;if(r||o){const t=this._window.document.createElementNS("http://www.w3.org/2000/svg","rect");this._backgroundClipPath=this._window.document.createElementNS("http://www.w3.org/2000/svg","clipPath"),this._backgroundClipPath.setAttribute("id",`clip-path-background-color-${this._instanceId}`),this._defs.appendChild(this._backgroundClipPath),(null===(i=n.backgroundOptions)||void 0===i?void 0:i.round)&&(s=a=Math.min(n.width,n.height),t.setAttribute("rx",String(s/2*n.backgroundOptions.round))),t.setAttribute("x",String(this._roundSize((n.width-a)/2))),t.setAttribute("y",String(this._roundSize((n.height-s)/2))),t.setAttribute("width",String(a)),t.setAttribute("height",String(s)),this._backgroundClipPath.appendChild(t),this._createColor({options:r,color:o,additionalRotation:0,x:0,y:0,height:n.height,width:n.width,name:`background-color-${this._instanceId}`})}}}drawDots(t){var e,i;if(!this._qr)throw"QR code is not defined";const r=this._options,n=this._qr.getModuleCount();if(n>r.width||n>r.height)throw"The canvas is too small.";const o=Math.min(r.width,r.height)-2*r.margin,a=r.shape===g?o/Math.sqrt(2):o,h=this._roundSize(a/n),d=this._roundSize((r.width-n*h)/2),u=this._roundSize((r.height-n*h)/2),c=new s({svg:this._element,type:r.dotsOptions.type,window:this._window});this._dotsClipPath=this._window.document.createElementNS("http://www.w3.org/2000/svg","clipPath"),this._dotsClipPath.setAttribute("id",`clip-path-dot-color-${this._instanceId}`),this._defs.appendChild(this._dotsClipPath),this._createColor({options:null===(e=r.dotsOptions)||void 0===e?void 0:e.gradient,color:r.dotsOptions.color,additionalRotation:0,x:0,y:0,height:r.height,width:r.width,name:`dot-color-${this._instanceId}`});for(let e=0;e<n;e++)for(let r=0;r<n;r++)t&&!t(e,r)||(null===(i=this._qr)||void 0===i?void 0:i.isDark(e,r))&&(c.draw(d+r*h,u+e*h,h,((i,o)=>!(r+i<0||e+o<0||r+i>=n||e+o>=n)&&!(t&&!t(e+o,r+i))&&!!this._qr&&this._qr.isDark(e+o,r+i))),c._element&&this._dotsClipPath&&this._dotsClipPath.appendChild(c._element));if(r.shape===g){const t=this._roundSize((o/h-n)/2),e=n+2*t,i=d-t*h,r=u-t*h,s=[],a=this._roundSize(e/2);for(let i=0;i<e;i++){s[i]=[];for(let r=0;r<e;r++)i>=t-1&&i<=e-t&&r>=t-1&&r<=e-t||Math.sqrt((i-a)*(i-a)+(r-a)*(r-a))>a?s[i][r]=0:s[i][r]=this._qr.isDark(r-2*t<0?r:r>=n?r-2*t:r-t,i-2*t<0?i:i>=n?i-2*t:i-t)?1:0}for(let t=0;t<e;t++)for(let n=0;n<e;n++)s[t][n]&&(c.draw(i+n*h,r+t*h,h,((e,i)=>{var r;return!!(null===(r=s[t+i])||void 0===r?void 0:r[n+e])})),c._element&&this._dotsClipPath&&this._dotsClipPath.appendChild(c._element))}}drawCorners(){if(!this._qr)throw"QR code is not defined";const t=this._element,e=this._options;if(!t)throw"Element code is not defined";const i=this._qr.getModuleCount(),r=Math.min(e.width,e.height)-2*e.margin,n=e.shape===g?r/Math.sqrt(2):r,o=this._roundSize(n/i),a=7*o,u=3*o,p=this._roundSize((e.width-i*o)/2),v=this._roundSize((e.height-i*o)/2);[[0,0,0],[1,0,Math.PI/2],[0,1,-Math.PI/2]].forEach((([t,r,n])=>{var g,_,m,b,y,x,S,C,A,M,$,O,D,k;const z=p+t*o*(i-7),B=v+r*o*(i-7);let P=this._dotsClipPath,I=this._dotsClipPath;if(((null===(g=e.cornersSquareOptions)||void 0===g?void 0:g.gradient)||(null===(_=e.cornersSquareOptions)||void 0===_?void 0:_.color))&&(P=this._window.document.createElementNS("http://www.w3.org/2000/svg","clipPath"),P.setAttribute("id",`clip-path-corners-square-color-${t}-${r}-${this._instanceId}`),this._defs.appendChild(P),this._cornersSquareClipPath=this._cornersDotClipPath=I=P,this._createColor({options:null===(m=e.cornersSquareOptions)||void 0===m?void 0:m.gradient,color:null===(b=e.cornersSquareOptions)||void 0===b?void 0:b.color,additionalRotation:n,x:z,y:B,height:a,width:a,name:`corners-square-color-${t}-${r}-${this._instanceId}`})),(null===(y=e.cornersSquareOptions)||void 0===y?void 0:y.type)&&h.includes(e.cornersSquareOptions.type)){const t=new d({svg:this._element,type:e.cornersSquareOptions.type,window:this._window});t.draw(z,B,a,n),t._element&&P&&P.appendChild(t._element)}else{const t=new s({svg:this._element,type:(null===(x=e.cornersSquareOptions)||void 0===x?void 0:x.type)||e.dotsOptions.type,window:this._window});for(let e=0;e<f.length;e++)for(let i=0;i<f[e].length;i++)(null===(S=f[e])||void 0===S?void 0:S[i])&&(t.draw(z+i*o,B+e*o,o,((t,r)=>{var n;return!!(null===(n=f[e+r])||void 0===n?void 0:n[i+t])})),t._element&&P&&P.appendChild(t._element))}if(((null===(C=e.cornersDotOptions)||void 0===C?void 0:C.gradient)||(null===(A=e.cornersDotOptions)||void 0===A?void 0:A.color))&&(I=this._window.document.createElementNS("http://www.w3.org/2000/svg","clipPath"),I.setAttribute("id",`clip-path-corners-dot-color-${t}-${r}-${this._instanceId}`),this._defs.appendChild(I),this._cornersDotClipPath=I,this._createColor({options:null===(M=e.cornersDotOptions)||void 0===M?void 0:M.gradient,color:null===($=e.cornersDotOptions)||void 0===$?void 0:$.color,additionalRotation:n,x:z+2*o,y:B+2*o,height:u,width:u,name:`corners-dot-color-${t}-${r}-${this._instanceId}`})),(null===(O=e.cornersDotOptions)||void 0===O?void 0:O.type)&&c.includes(e.cornersDotOptions.type)){const t=new l({svg:this._element,type:e.cornersDotOptions.type,window:this._window});t.draw(z+2*o,B+2*o,u,n),t._element&&I&&I.appendChild(t._element)}else{const t=new s({svg:this._element,type:(null===(D=e.cornersDotOptions)||void 0===D?void 0:D.type)||e.dotsOptions.type,window:this._window});for(let e=0;e<w.length;e++)for(let i=0;i<w[e].length;i++)(null===(k=w[e])||void 0===k?void 0:k[i])&&(t.draw(z+i*o,B+e*o,o,((t,r)=>{var n;return!!(null===(n=w[e+r])||void 0===n?void 0:n[i+t])})),t._element&&I&&I.appendChild(t._element))}}))}loadImage(){return new Promise(((t,e)=>{var i;const r=this._options;if(!r.image)return e("Image is not defined");if(null===(i=r.nodeCanvas)||void 0===i?void 0:i.loadImage)r.nodeCanvas.loadImage(r.image).then((e=>{var i,n;if(this._image=e,this._options.imageOptions.saveAsBlob){const t=null===(i=r.nodeCanvas)||void 0===i?void 0:i.createCanvas(this._image.width,this._image.height);null===(n=null==t?void 0:t.getContext("2d"))||void 0===n||n.drawImage(e,0,0),this._imageUri=null==t?void 0:t.toDataURL()}t()})).catch(e);else{const e=new this._window.Image;"string"==typeof r.imageOptions.crossOrigin&&(e.crossOrigin=r.imageOptions.crossOrigin),this._image=e,e.onload=async()=>{this._options.imageOptions.saveAsBlob&&(this._imageUri=await async function(t,e){return new Promise((i=>{const r=new e.XMLHttpRequest;r.onload=function(){const t=new e.FileReader;t.onloadend=function(){i(t.result)},t.readAsDataURL(r.response)},r.open("GET",t),r.responseType="blob",r.send()}))}(r.image||"",this._window)),t()},e.src=r.image}}))}async drawImage({width:t,height:e,count:i,dotSize:r}){const n=this._options,o=this._roundSize((n.width-i*r)/2),s=this._roundSize((n.height-i*r)/2),a=o+this._roundSize(n.imageOptions.margin+(i*r-t)/2),h=s+this._roundSize(n.imageOptions.margin+(i*r-e)/2),d=t-2*n.imageOptions.margin,u=e-2*n.imageOptions.margin,c=this._window.document.createElementNS("http://www.w3.org/2000/svg","image");c.setAttribute("href",this._imageUri||""),c.setAttribute("xlink:href",this._imageUri||""),c.setAttribute("x",String(a)),c.setAttribute("y",String(h)),c.setAttribute("width",`${d}px`),c.setAttribute("height",`${u}px`),this._element.appendChild(c)}_createColor({options:t,color:e,additionalRotation:i,x:r,y:n,height:o,width:s,name:a}){const h=s>o?s:o,d=this._window.document.createElementNS("http://www.w3.org/2000/svg","rect");if(d.setAttribute("x",String(r)),d.setAttribute("y",String(n)),d.setAttribute("height",String(o)),d.setAttribute("width",String(s)),d.setAttribute("clip-path",`url('#clip-path-${a}')`),t){let e;if("radial"===t.type)e=this._window.document.createElementNS("http://www.w3.org/2000/svg","radialGradient"),e.setAttribute("id",a),e.setAttribute("gradientUnits","userSpaceOnUse"),e.setAttribute("fx",String(r+s/2)),e.setAttribute("fy",String(n+o/2)),e.setAttribute("cx",String(r+s/2)),e.setAttribute("cy",String(n+o/2)),e.setAttribute("r",String(h/2));else{const h=((t.rotation||0)+i)%(2*Math.PI),d=(h+2*Math.PI)%(2*Math.PI);let u=r+s/2,c=n+o/2,l=r+s/2,g=n+o/2;d>=0&&d<=.25*Math.PI||d>1.75*Math.PI&&d<=2*Math.PI?(u-=s/2,c-=o/2*Math.tan(h),l+=s/2,g+=o/2*Math.tan(h)):d>.25*Math.PI&&d<=.75*Math.PI?(c-=o/2,u-=s/2/Math.tan(h),g+=o/2,l+=s/2/Math.tan(h)):d>.75*Math.PI&&d<=1.25*Math.PI?(u+=s/2,c+=o/2*Math.tan(h),l-=s/2,g-=o/2*Math.tan(h)):d>1.25*Math.PI&&d<=1.75*Math.PI&&(c+=o/2,u+=s/2/Math.tan(h),g-=o/2,l-=s/2/Math.tan(h)),e=this._window.document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),e.setAttribute("id",a),e.setAttribute("gradientUnits","userSpaceOnUse"),e.setAttribute("x1",String(Math.round(u))),e.setAttribute("y1",String(Math.round(c))),e.setAttribute("x2",String(Math.round(l))),e.setAttribute("y2",String(Math.round(g)))}t.colorStops.forEach((({offset:t,color:i})=>{const r=this._window.document.createElementNS("http://www.w3.org/2000/svg","stop");r.setAttribute("offset",100*t+"%"),r.setAttribute("stop-color",i),e.appendChild(r)})),d.setAttribute("fill",`url('#${a}')`),this._defs.appendChild(e)}else e&&d.setAttribute("fill",e);this._element.appendChild(d)}}p.instanceCount=0;const v=p,_="canvas",m={};for(let t=0;t<=40;t++)m[t]=t;const b={type:_,shape:"square",width:300,height:300,data:"",margin:0,qrOptions:{typeNumber:m[0],mode:void 0,errorCorrectionLevel:"Q"},imageOptions:{saveAsBlob:!0,hideBackgroundDots:!0,imageSize:.4,crossOrigin:void 0,margin:0},dotsOptions:{type:"square",color:"#000",roundSize:!0},backgroundOptions:{round:0,color:"#fff"}};function y(t){const e=Object.assign({},t);if(!e.colorStops||!e.colorStops.length)throw"Field 'colorStops' is required in gradient";return e.rotation?e.rotation=Number(e.rotation):e.rotation=0,e.colorStops=e.colorStops.map((t=>Object.assign(Object.assign({},t),{offset:Number(t.offset)}))),e}function x(t){const e=Object.assign({},t);return e.width=Number(e.width),e.height=Number(e.height),e.margin=Number(e.margin),e.imageOptions=Object.assign(Object.assign({},e.imageOptions),{hideBackgroundDots:Boolean(e.imageOptions.hideBackgroundDots),imageSize:Number(e.imageOptions.imageSize),margin:Number(e.imageOptions.margin)}),e.margin>Math.min(e.width,e.height)&&(e.margin=Math.min(e.width,e.height)),e.dotsOptions=Object.assign({},e.dotsOptions),e.dotsOptions.gradient&&(e.dotsOptions.gradient=y(e.dotsOptions.gradient)),e.cornersSquareOptions&&(e.cornersSquareOptions=Object.assign({},e.cornersSquareOptions),e.cornersSquareOptions.gradient&&(e.cornersSquareOptions.gradient=y(e.cornersSquareOptions.gradient))),e.cornersDotOptions&&(e.cornersDotOptions=Object.assign({},e.cornersDotOptions),e.cornersDotOptions.gradient&&(e.cornersDotOptions.gradient=y(e.cornersDotOptions.gradient))),e.backgroundOptions&&(e.backgroundOptions=Object.assign({},e.backgroundOptions),e.backgroundOptions.gradient&&(e.backgroundOptions.gradient=y(e.backgroundOptions.gradient))),e}var S=i(873),C=i.n(S);function A(t){if(!t)throw new Error("Extension must be defined");"."===t[0]&&(t=t.substring(1));const e={bmp:"image/bmp",gif:"image/gif",ico:"image/vnd.microsoft.icon",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",webp:"image/webp",pdf:"application/pdf"}[t.toLowerCase()];if(!e)throw new Error(`Extension "${t}" is not supported`);return e}class M{constructor(t){(null==t?void 0:t.jsdom)?this._window=new t.jsdom("",{resources:"usable"}).window:this._window=window,this._options=t?x(e(b,t)):b,this.update()}static _clearContainer(t){t&&(t.innerHTML="")}_setupSvg(){if(!this._qr)return;const t=new v(this._options,this._window);this._svg=t.getElement(),this._svgDrawingPromise=t.drawQR(this._qr).then((()=>{var e;this._svg&&(null===(e=this._extension)||void 0===e||e.call(this,t.getElement(),this._options))}))}_setupCanvas(){var t,e;this._qr&&((null===(t=this._options.nodeCanvas)||void 0===t?void 0:t.createCanvas)?(this._nodeCanvas=this._options.nodeCanvas.createCanvas(this._options.width,this._options.height),this._nodeCanvas.width=this._options.width,this._nodeCanvas.height=this._options.height):(this._domCanvas=document.createElement("canvas"),this._domCanvas.width=this._options.width,this._domCanvas.height=this._options.height),this._setupSvg(),this._canvasDrawingPromise=null===(e=this._svgDrawingPromise)||void 0===e?void 0:e.then((()=>{var t;if(!this._svg)return;const e=this._svg,i=(new this._window.XMLSerializer).serializeToString(e),r=btoa(i),n=`data:${A("svg")};base64,${r}`;if(null===(t=this._options.nodeCanvas)||void 0===t?void 0:t.loadImage)return this._options.nodeCanvas.loadImage(n).then((t=>{var e,i;t.width=this._options.width,t.height=this._options.height,null===(i=null===(e=this._nodeCanvas)||void 0===e?void 0:e.getContext("2d"))||void 0===i||i.drawImage(t,0,0)}));{const t=new this._window.Image;return new Promise((e=>{t.onload=()=>{var i,r;null===(r=null===(i=this._domCanvas)||void 0===i?void 0:i.getContext("2d"))||void 0===r||r.drawImage(t,0,0),e()},t.src=n}))}})))}async _getElement(t="png"){if(!this._qr)throw"QR code is empty";return"svg"===t.toLowerCase()?(this._svg&&this._svgDrawingPromise||this._setupSvg(),await this._svgDrawingPromise,this._svg):((this._domCanvas||this._nodeCanvas)&&this._canvasDrawingPromise||this._setupCanvas(),await this._canvasDrawingPromise,this._domCanvas||this._nodeCanvas)}update(t){M._clearContainer(this._container),this._options=t?x(e(this._options,t)):this._options,this._options.data&&(this._qr=C()(this._options.qrOptions.typeNumber,this._options.qrOptions.errorCorrectionLevel),this._qr.addData(this._options.data,this._options.qrOptions.mode||function(t){switch(!0){case/^[0-9]*$/.test(t):return"Numeric";case/^[0-9A-Z $%*+\-./:]*$/.test(t):return"Alphanumeric";default:return"Byte"}}(this._options.data)),this._qr.make(),this._options.type===_?this._setupCanvas():this._setupSvg(),this.append(this._container))}append(t){if(t){if("function"!=typeof t.appendChild)throw"Container should be a single DOM node";this._options.type===_?this._domCanvas&&t.appendChild(this._domCanvas):this._svg&&t.appendChild(this._svg),this._container=t}}applyExtension(t){if(!t)throw"Extension function should be defined.";this._extension=t,this.update()}deleteExtension(){this._extension=void 0,this.update()}async getRawData(t="png"){if(!this._qr)throw"QR code is empty";const e=await this._getElement(t),i=A(t);if(!e)return null;if("svg"===t.toLowerCase()){const t=`<?xml version="1.0" standalone="no"?>\r\n${(new this._window.XMLSerializer).serializeToString(e)}`;return"undefined"==typeof Blob||this._options.jsdom?Buffer.from(t):new Blob([t],{type:i})}return new Promise((t=>{const r=e;if("toBuffer"in r)if("image/png"===i)t(r.toBuffer(i));else if("image/jpeg"===i)t(r.toBuffer(i));else{if("application/pdf"!==i)throw Error("Unsupported extension");t(r.toBuffer(i))}else"toBlob"in r&&r.toBlob(t,i,1)}))}async download(t){if(!this._qr)throw"QR code is empty";if("undefined"==typeof Blob)throw"Cannot download in Node.js, call getRawData instead.";let e="png",i="qr";"string"==typeof t?(e=t,console.warn("Extension is deprecated as argument for 'download' method, please pass object { name: '...', extension: '...' } as argument")):"object"==typeof t&&null!==t&&(t.name&&(i=t.name),t.extension&&(e=t.extension));const r=await this._getElement(e);if(r)if("svg"===e.toLowerCase()){let t=(new XMLSerializer).serializeToString(r);t='<?xml version="1.0" standalone="no"?>\r\n'+t,n(`data:${A(e)};charset=utf-8,${encodeURIComponent(t)}`,`${i}.svg`)}else n(r.toDataURL(A(e)),`${i}.${e}`)}}const $=M})(),r.default})()));
|
|
2
|
+
//# sourceMappingURL=qr-code-styling.js.map
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_fs_1 = require("node:fs");
|
|
4
|
-
const node_os_1 = require("node:os");
|
|
5
4
|
const node_path_1 = require("node:path");
|
|
6
5
|
const commander_1 = require("commander");
|
|
7
6
|
const console_log_colors_1 = require("console-log-colors");
|
|
@@ -32,10 +31,11 @@ commander_1.program
|
|
|
32
31
|
.option('--localsend-dir <dir>', 'localsend 文件存储目录。默认 ~/.static-server/localsend,可用环境变量 SS_LOCALSEND_DIR 覆盖')
|
|
33
32
|
.option('--debug', `开启调试模式。`, false)
|
|
34
33
|
.action(async (opts) => {
|
|
34
|
+
// opts.ssl 默认为 undefined,需先构造对象再赋值
|
|
35
35
|
if (opts.cert)
|
|
36
|
-
opts.ssl
|
|
36
|
+
opts.ssl = { ...opts.ssl, cert: opts.cert };
|
|
37
37
|
if (opts.key)
|
|
38
|
-
opts.ssl
|
|
38
|
+
opts.ssl = { ...opts.ssl, key: opts.key };
|
|
39
39
|
if (opts.debug) {
|
|
40
40
|
get_logger_1.logger.updateOptions({ levelType: 'debug' });
|
|
41
41
|
get_logger_1.logger.debug(opts);
|
|
@@ -54,8 +54,10 @@ commander_1.program
|
|
|
54
54
|
commander_1.program
|
|
55
55
|
.command('init [destination]')
|
|
56
56
|
.description('初始化一个 ss.config.js 文件至指定的目录。默认为当前目录')
|
|
57
|
-
.
|
|
58
|
-
|
|
57
|
+
.option('-g, --global', '初始化到用户级配置目录 ~/.static-server,作为所有目录的兜底配置')
|
|
58
|
+
.action((destination, opts) => {
|
|
59
|
+
const dir = opts.global ? (0, config_1.getUserConfigDir)() : destination || process.cwd();
|
|
60
|
+
const confFile = (0, node_path_1.resolve)(dir, config_1.CONFIG_FILE_NAME);
|
|
59
61
|
if ((0, node_fs_1.existsSync)(confFile)) {
|
|
60
62
|
get_logger_1.logger.warn('配置文件已存在,请确认:', console_log_colors_1.color.cyanBright(confFile));
|
|
61
63
|
return;
|
|
@@ -65,6 +67,7 @@ commander_1.program
|
|
|
65
67
|
get_logger_1.logger.error('未找到配置文件模板:', console_log_colors_1.color.red(tplFile));
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
70
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
68
71
|
(0, node_fs_1.writeFileSync)(confFile, (0, node_fs_1.readFileSync)(tplFile));
|
|
69
72
|
get_logger_1.logger.info('已生成配置文件:', console_log_colors_1.color.greenBright(confFile));
|
|
70
73
|
});
|
|
@@ -75,7 +78,7 @@ commander_1.program
|
|
|
75
78
|
.action(async (opts) => {
|
|
76
79
|
const config = await (0, config_1.getConfig)(false, opts.localsendDir ? { localsend: { enabled: true, dir: opts.localsendDir } } : {});
|
|
77
80
|
const ls = typeof config.localsend === 'object' && config.localsend ? config.localsend : {};
|
|
78
|
-
const dir = opts.localsendDir || ls.dir || process.env.SS_LOCALSEND_DIR || (0, node_path_1.resolve)((0,
|
|
81
|
+
const dir = opts.localsendDir || ls.dir || process.env.SS_LOCALSEND_DIR || (0, node_path_1.resolve)((0, config_1.getUserConfigDir)(), 'localsend');
|
|
79
82
|
const renamed = (0, localsend_1.repairLocalsendNames)(dir);
|
|
80
83
|
if (!renamed.length) {
|
|
81
84
|
get_logger_1.logger.info('未发现乱码文件名。目录:', console_log_colors_1.color.cyanBright(dir));
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Stats } from 'node:fs';
|
|
2
2
|
import type { ServerOptions } from 'node:https';
|
|
3
|
-
import {
|
|
3
|
+
import type { color, NLogger } from '@lzwme/fe-utils';
|
|
4
4
|
import type { Express, Response } from 'express';
|
|
5
5
|
import type { Options } from 'http-proxy-middleware';
|
|
6
6
|
export interface LocalSendConfig {
|
|
@@ -10,6 +10,33 @@ export interface LocalSendConfig {
|
|
|
10
10
|
dir?: string;
|
|
11
11
|
/** 单个文件上传大小限制(字节)。默认 1GB */
|
|
12
12
|
maxSize?: number;
|
|
13
|
+
/** 存储目录总容量上限(字节)。超出后拒绝新的上传。默认不限制 */
|
|
14
|
+
maxTotalSize?: number;
|
|
15
|
+
/** 访问令牌。设置后,页面与所有接口都需要携带(?key=xxx 或 X-Localsend-Key 请求头) */
|
|
16
|
+
token?: string;
|
|
17
|
+
/** 管理员口令。设置后删除文件、整理目录、撤销分享等危险操作需要登录 */
|
|
18
|
+
password?: string;
|
|
19
|
+
/** 访客口令(可选)。设置后访客可上传下载,但不能删除与整理 */
|
|
20
|
+
visitorPassword?: string;
|
|
21
|
+
/** 登录会话有效期(毫秒)。默认 24 小时 */
|
|
22
|
+
sessionTtl?: number;
|
|
23
|
+
/** 单个 IP 的最大并发上传数。默认 3 */
|
|
24
|
+
maxConcurrent?: number;
|
|
25
|
+
/** 单个 IP 的请求频率限制。默认 120 次 / 60 秒 */
|
|
26
|
+
rateLimit?: {
|
|
27
|
+
windowMs?: number;
|
|
28
|
+
max?: number;
|
|
29
|
+
};
|
|
30
|
+
/** 禁止上传的文件扩展名列表(如 ['.php', '.phtml'])。默认禁止常见服务端脚本 */
|
|
31
|
+
blockExtensions?: string[];
|
|
32
|
+
/** 自动清理:文件的保留天数,超过后自动删除 */
|
|
33
|
+
autoCleanDays?: number;
|
|
34
|
+
/** 自动清理:存储目录容量上限(字节),超出后自动删除最旧的文件 */
|
|
35
|
+
autoCleanMaxSize?: number;
|
|
36
|
+
/** 回收站保留天数。删除的文件在保留期内可还原,默认 1 天 */
|
|
37
|
+
trashDays?: number;
|
|
38
|
+
/** 是否开启 WebDAV 挂载接口(/localsend/dav),可把存储目录挂载为网络盘。默认开启 */
|
|
39
|
+
webdav?: boolean;
|
|
13
40
|
}
|
|
14
41
|
export interface SSConfig {
|
|
15
42
|
/** 是否开启目录列表 */
|
|
@@ -56,4 +83,14 @@ export interface SSConfig {
|
|
|
56
83
|
/** 按请求自定义 headers。返回结果与 headers 内容合并 */
|
|
57
84
|
setHeaders?: (res: Response<any, Record<string, any>>, path: string, stat: Stats) => Record<string, string | string[] | undefined>;
|
|
58
85
|
}
|
|
86
|
+
/** 用户级配置目录名。默认位于用户主目录下 */
|
|
87
|
+
export declare const USER_CONFIG_DIR = ".static-server";
|
|
88
|
+
/** 配置文件名 */
|
|
89
|
+
export declare const CONFIG_FILE_NAME = "ss.config.js";
|
|
90
|
+
/** 用户级配置目录:~/.static-server */
|
|
91
|
+
export declare function getUserConfigDir(): string;
|
|
92
|
+
/** 用户级配置文件:~/.static-server/ss.config.js */
|
|
93
|
+
export declare function getUserConfigFile(): string;
|
|
94
|
+
/** 当前工作目录下的配置文件:./ss.config.js */
|
|
95
|
+
export declare function getCwdConfigFile(): string;
|
|
59
96
|
export declare function getConfig(useCache?: boolean, cfg?: SSConfig): Promise<SSConfig>;
|
package/dist/config.js
CHANGED
|
@@ -1,12 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONFIG_FILE_NAME = exports.USER_CONFIG_DIR = void 0;
|
|
4
|
+
exports.getUserConfigDir = getUserConfigDir;
|
|
5
|
+
exports.getUserConfigFile = getUserConfigFile;
|
|
6
|
+
exports.getCwdConfigFile = getCwdConfigFile;
|
|
3
7
|
exports.getConfig = getConfig;
|
|
4
8
|
const node_fs_1 = require("node:fs");
|
|
5
9
|
const node_os_1 = require("node:os");
|
|
6
10
|
const node_path_1 = require("node:path");
|
|
7
|
-
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
8
11
|
const get_logger_1 = require("./get-logger");
|
|
9
12
|
const get_cert_1 = require("./lib/get-cert");
|
|
13
|
+
const merge_config_1 = require("./lib/merge-config");
|
|
14
|
+
/** 用户级配置目录名。默认位于用户主目录下 */
|
|
15
|
+
exports.USER_CONFIG_DIR = '.static-server';
|
|
16
|
+
/** 配置文件名 */
|
|
17
|
+
exports.CONFIG_FILE_NAME = 'ss.config.js';
|
|
18
|
+
/** 用户级配置目录:~/.static-server */
|
|
19
|
+
function getUserConfigDir() {
|
|
20
|
+
return (0, node_path_1.resolve)((0, node_os_1.homedir)(), exports.USER_CONFIG_DIR);
|
|
21
|
+
}
|
|
22
|
+
/** 用户级配置文件:~/.static-server/ss.config.js */
|
|
23
|
+
function getUserConfigFile() {
|
|
24
|
+
return (0, node_path_1.resolve)(getUserConfigDir(), exports.CONFIG_FILE_NAME);
|
|
25
|
+
}
|
|
26
|
+
/** 当前工作目录下的配置文件:./ss.config.js */
|
|
27
|
+
function getCwdConfigFile() {
|
|
28
|
+
return (0, node_path_1.resolve)(process.cwd(), exports.CONFIG_FILE_NAME);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 加载配置文件。
|
|
32
|
+
* 文件不存在时返回 undefined;加载失败时输出错误提示并忽略该文件,避免整个服务启动失败。
|
|
33
|
+
*/
|
|
34
|
+
function loadConfigFile(file) {
|
|
35
|
+
if (!(0, node_fs_1.existsSync)(file))
|
|
36
|
+
return undefined;
|
|
37
|
+
try {
|
|
38
|
+
const mod = require(file);
|
|
39
|
+
const cfg = mod && typeof mod === 'object' && mod.__esModule && mod.default ? mod.default : mod;
|
|
40
|
+
return (0, merge_config_1.isPlainObject)(cfg) ? cfg : undefined;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
get_logger_1.logger.error(`配置文件加载失败,已忽略该文件:${file}`, e);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** 归一化单个配置文件的内容,使其可与其它配置深度合并 */
|
|
48
|
+
function normalizeConfig(cfg) {
|
|
49
|
+
if (!cfg)
|
|
50
|
+
return undefined;
|
|
51
|
+
// localsend 支持布尔值,归一化为对象后再合并,避免布尔值覆盖掉对象配置
|
|
52
|
+
if (typeof cfg.localsend === 'boolean')
|
|
53
|
+
return { ...cfg, localsend: { enabled: cfg.localsend } };
|
|
54
|
+
return cfg;
|
|
55
|
+
}
|
|
10
56
|
const ssConfig = {
|
|
11
57
|
log: false,
|
|
12
58
|
open: false,
|
|
@@ -26,18 +72,18 @@ const ssConfig = {
|
|
|
26
72
|
async function getConfig(useCache = true, cfg) {
|
|
27
73
|
if (ssConfig.port && useCache)
|
|
28
74
|
return ssConfig;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
75
|
+
// 配置优先级:内置默认值 < 用户级配置(~/.static-server/ss.config.js) < 当前目录配置(./ss.config.js) < 运行时参数
|
|
76
|
+
(0, merge_config_1.mergeConfig)(ssConfig, normalizeConfig(loadConfigFile(getUserConfigFile())));
|
|
77
|
+
(0, merge_config_1.mergeConfig)(ssConfig, normalizeConfig(loadConfigFile(getCwdConfigFile())));
|
|
32
78
|
if (cfg)
|
|
33
|
-
(0,
|
|
79
|
+
(0, merge_config_1.mergeConfig)(ssConfig, cfg);
|
|
34
80
|
ssConfig.rootDir = (0, node_path_1.resolve)(process.cwd(), typeof ssConfig.rootDir === 'string' ? ssConfig.rootDir : '.');
|
|
35
81
|
// localsend 配置归一化:支持 true / 配置对象,支持环境变量 SS_LOCALSEND_DIR 指定存储目录
|
|
36
82
|
if (ssConfig.localsend) {
|
|
37
83
|
const localsend = typeof ssConfig.localsend === 'boolean' ? { enabled: ssConfig.localsend } : { ...ssConfig.localsend };
|
|
38
84
|
localsend.enabled = typeof ssConfig.localsend === 'boolean' ? ssConfig.localsend : localsend.enabled !== false;
|
|
39
|
-
localsend.dir = process.env.SS_LOCALSEND_DIR || localsend.dir || (0, node_path_1.resolve)((
|
|
40
|
-
localsend.maxSize = localsend.maxSize
|
|
85
|
+
localsend.dir = process.env.SS_LOCALSEND_DIR || localsend.dir || (0, node_path_1.resolve)(getUserConfigDir(), 'localsend');
|
|
86
|
+
localsend.maxSize = localsend.maxSize ?? 1024 * 1024 * 1024;
|
|
41
87
|
ssConfig.localsend = localsend;
|
|
42
88
|
}
|
|
43
89
|
if (ssConfig.log) {
|
|
@@ -45,7 +91,6 @@ async function getConfig(useCache = true, cfg) {
|
|
|
45
91
|
}
|
|
46
92
|
if (ssConfig.cors) {
|
|
47
93
|
Object.assign(ssConfig.headers, {
|
|
48
|
-
'Access-Control-Allow-Credentials': 'true',
|
|
49
94
|
'Access-Control-Allow-Headers': '*',
|
|
50
95
|
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS',
|
|
51
96
|
'Access-Control-Allow-Origin': '*',
|
|
@@ -58,7 +103,7 @@ async function getConfig(useCache = true, cfg) {
|
|
|
58
103
|
const info = await (0, get_cert_1.getCert)(ssConfig.host, ssConfig.sslCache || '');
|
|
59
104
|
ssl.key = Buffer.from(info.certKey);
|
|
60
105
|
ssl.cert = Buffer.from(info.certCrt);
|
|
61
|
-
ssl.ca = Buffer.from(info.
|
|
106
|
+
ssl.ca = Buffer.from(info.caCrt);
|
|
62
107
|
}
|
|
63
108
|
for (const key of ['key', 'cert', 'ca']) {
|
|
64
109
|
const val = ssl[key];
|
package/dist/lib/get-cert.js
CHANGED
|
@@ -22,7 +22,7 @@ async function getCert(host = 'localhost', cacheDir = '') {
|
|
|
22
22
|
};
|
|
23
23
|
if (cacheDir) {
|
|
24
24
|
if (!(0, node_fs_1.existsSync)(cacheDir))
|
|
25
|
-
(0, promises_1.mkdir)(cacheDir, { recursive: true });
|
|
25
|
+
await (0, promises_1.mkdir)(cacheDir, { recursive: true });
|
|
26
26
|
for (const [key, filepath] of Object.entries(dirs)) {
|
|
27
27
|
if ((0, node_fs_1.existsSync)(filepath))
|
|
28
28
|
result[key] = await (0, promises_1.readFile)(filepath, 'utf8');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function isPlainObject(value: unknown): value is Record<string, any>;
|
|
2
|
+
/**
|
|
3
|
+
* 将 source 深度合并到 target。
|
|
4
|
+
* - 普通对象:递归合并
|
|
5
|
+
* - 数组:按 ARRAY_MERGE_KEYS 中指定的 key 合并,否则整体覆盖
|
|
6
|
+
* - 函数等非对象值:直接覆盖
|
|
7
|
+
* - undefined 值:忽略,不覆盖已有配置
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeConfig<T extends Record<string, any>>(target: T, source?: Record<string, any> | null): T;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlainObject = isPlainObject;
|
|
4
|
+
exports.mergeConfig = mergeConfig;
|
|
5
|
+
/**
|
|
6
|
+
* 配置文件合并策略。
|
|
7
|
+
* 数组类型的配置项在合并时,按指定 key 匹配已有项并深度合并,而不是整体替换。
|
|
8
|
+
* 未列出的数组配置项,由后加载的配置整体覆盖先加载的。
|
|
9
|
+
*/
|
|
10
|
+
const ARRAY_MERGE_KEYS = {
|
|
11
|
+
proxyConfig: 'api',
|
|
12
|
+
};
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
15
|
+
return false;
|
|
16
|
+
if (value instanceof RegExp || value instanceof Date)
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 将 source 深度合并到 target。
|
|
22
|
+
* - 普通对象:递归合并
|
|
23
|
+
* - 数组:按 ARRAY_MERGE_KEYS 中指定的 key 合并,否则整体覆盖
|
|
24
|
+
* - 函数等非对象值:直接覆盖
|
|
25
|
+
* - undefined 值:忽略,不覆盖已有配置
|
|
26
|
+
*/
|
|
27
|
+
function mergeConfig(target, source) {
|
|
28
|
+
const t = target;
|
|
29
|
+
if (!isPlainObject(source))
|
|
30
|
+
return target;
|
|
31
|
+
for (const [key, value] of Object.entries(source)) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
continue;
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
const mergeKey = ARRAY_MERGE_KEYS[key];
|
|
36
|
+
const prev = t[key];
|
|
37
|
+
t[key] = mergeKey && Array.isArray(prev) ? mergeArrayByKey(prev, value, mergeKey) : value;
|
|
38
|
+
}
|
|
39
|
+
else if (isPlainObject(value)) {
|
|
40
|
+
if (!isPlainObject(t[key]))
|
|
41
|
+
t[key] = {};
|
|
42
|
+
mergeConfig(t[key], value);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
t[key] = value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return target;
|
|
49
|
+
}
|
|
50
|
+
/** 按 key 合并数组:同 key 的项深度合并,后者覆盖前者;新项追加到末尾 */
|
|
51
|
+
function mergeArrayByKey(prev, next, key) {
|
|
52
|
+
const result = [...prev];
|
|
53
|
+
for (const item of next) {
|
|
54
|
+
const index = result.findIndex((it) => isPlainObject(it) && isPlainObject(item) && it[key] === item[key]);
|
|
55
|
+
if (index < 0) {
|
|
56
|
+
result.push(item);
|
|
57
|
+
}
|
|
58
|
+
else if (isPlainObject(result[index]) && isPlainObject(item)) {
|
|
59
|
+
result[index] = mergeConfig({ ...result[index] }, item);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
result[index] = item;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/** 一个可用的本机地址及其所属网卡 */
|
|
2
|
+
export interface IpCandidate {
|
|
3
|
+
/** IPv4 地址 */
|
|
4
|
+
address: string;
|
|
5
|
+
/** 网卡名称(用于展示,帮助用户判断该选哪一个) */
|
|
6
|
+
iface: string;
|
|
7
|
+
}
|
|
8
|
+
/** 是否为私网地址(含回环) */
|
|
9
|
+
export declare function isPrivateAddress(address: string): boolean;
|
|
10
|
+
/** 是否为回环地址(IPv4 / IPv6 / IPv4-mapped) */
|
|
11
|
+
export declare function isLoopbackAddress(address: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 按「可达概率」排序候选地址。
|
|
14
|
+
*
|
|
15
|
+
* 物理网卡优先、私网段优先,同级按地址排序保证结果稳定。
|
|
16
|
+
* 纯函数,便于单测。
|
|
17
|
+
*/
|
|
18
|
+
export declare function rankIpCandidates(list: IpCandidate[]): IpCandidate[];
|
|
19
|
+
/** 收集本机全部非回环 IPv4 地址(已按可达概率排序,去重) */
|
|
20
|
+
export declare function getIpCandidates(): IpCandidate[];
|
|
21
|
+
/**
|
|
22
|
+
* 取最可能被局域网其它设备访问的地址。
|
|
23
|
+
*
|
|
24
|
+
* 只用于启动日志这类「给个大概」的场景;页面上的二维码应使用
|
|
25
|
+
* `/localsend/api/network` 返回的完整候选列表,让用户自己选。
|
|
26
|
+
*/
|
|
27
|
+
export declare function getIp(): string | undefined;
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,22 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPrivateAddress = isPrivateAddress;
|
|
4
|
+
exports.isLoopbackAddress = isLoopbackAddress;
|
|
5
|
+
exports.rankIpCandidates = rankIpCandidates;
|
|
6
|
+
exports.getIpCandidates = getIpCandidates;
|
|
3
7
|
exports.getIp = getIp;
|
|
4
8
|
const node_os_1 = require("node:os");
|
|
5
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 虚拟网卡 / 容器网卡的特征。
|
|
11
|
+
*
|
|
12
|
+
* 这些网卡上的地址通常只有本机或虚拟网络内部可达:
|
|
13
|
+
* 手机扫码拿到 WSL、Docker、VMware 的地址只会得到「无法访问此网站」。
|
|
14
|
+
*/
|
|
15
|
+
const VIRTUAL_IFACE_RE = /(vethernet|wsl|docker|br-|vmnet|vmware|vbox|virtualbox|hyper-v|tailscale|zerotier|utun|tun\d|tap\d|ppp|loopback|npcap|openvpn|wireguard|vpn)/i;
|
|
16
|
+
/**
|
|
17
|
+
* 私网段优先级(数值越小越优先)。
|
|
18
|
+
*
|
|
19
|
+
* 家用/办公路由器最常见的是 192.168.x.x,其次是 10.x.x.x;
|
|
20
|
+
* 172.16-31 更多出现在 Docker / WSL / 企业内网,因此排在其后。
|
|
21
|
+
* 169.254(APIPA)说明没拿到 DHCP,基本不可用,排在最后。
|
|
22
|
+
*/
|
|
23
|
+
function privateRank(address) {
|
|
24
|
+
if (address.startsWith('192.168.'))
|
|
25
|
+
return 0;
|
|
26
|
+
if (address.startsWith('10.'))
|
|
27
|
+
return 1;
|
|
28
|
+
const matched = /^172\.(\d{1,3})\./.exec(address);
|
|
29
|
+
if (matched) {
|
|
30
|
+
const second = Number(matched[1]);
|
|
31
|
+
if (second >= 16 && second <= 31)
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
// 没拿到 DHCP 的自动地址:对其它设备一定不可达,无条件排最后
|
|
35
|
+
if (address.startsWith('169.254.'))
|
|
36
|
+
return 30;
|
|
37
|
+
// 100.64/10(CGNAT)常见于 Tailscale 等组网工具
|
|
38
|
+
if (/^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./.test(address))
|
|
39
|
+
return 7;
|
|
40
|
+
return 5;
|
|
41
|
+
}
|
|
42
|
+
/** 是否为私网地址(含回环) */
|
|
43
|
+
function isPrivateAddress(address) {
|
|
44
|
+
if (!address)
|
|
45
|
+
return false;
|
|
46
|
+
if (address === '127.0.0.1' || address === '::1')
|
|
47
|
+
return true;
|
|
48
|
+
if (address.startsWith('192.168.') || address.startsWith('10.') || address.startsWith('127.'))
|
|
49
|
+
return true;
|
|
50
|
+
const matched = /^172\.(\d{1,3})\./.exec(address);
|
|
51
|
+
if (matched) {
|
|
52
|
+
const second = Number(matched[1]);
|
|
53
|
+
return second >= 16 && second <= 31;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/** 是否为回环地址(IPv4 / IPv6 / IPv4-mapped) */
|
|
58
|
+
function isLoopbackAddress(address) {
|
|
59
|
+
return address === '127.0.0.1' || address === '::1' || address === '::ffff:127.0.0.1';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 按「可达概率」排序候选地址。
|
|
63
|
+
*
|
|
64
|
+
* 物理网卡优先、私网段优先,同级按地址排序保证结果稳定。
|
|
65
|
+
* 纯函数,便于单测。
|
|
66
|
+
*/
|
|
67
|
+
function rankIpCandidates(list) {
|
|
68
|
+
return list.slice().sort((a, b) => {
|
|
69
|
+
const rankA = privateRank(a.address) + (VIRTUAL_IFACE_RE.test(a.iface) ? 10 : 0);
|
|
70
|
+
const rankB = privateRank(b.address) + (VIRTUAL_IFACE_RE.test(b.iface) ? 10 : 0);
|
|
71
|
+
if (rankA !== rankB)
|
|
72
|
+
return rankA - rankB;
|
|
73
|
+
return a.address.localeCompare(b.address);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** 收集本机全部非回环 IPv4 地址(已按可达概率排序,去重) */
|
|
77
|
+
function getIpCandidates() {
|
|
6
78
|
const nif = (0, node_os_1.networkInterfaces)();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
79
|
+
const list = [];
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
for (const iface of Object.keys(nif)) {
|
|
82
|
+
const items = nif[iface] || [];
|
|
83
|
+
for (const item of items) {
|
|
84
|
+
if (item.internal || !item.address || item.family !== 'IPv4')
|
|
85
|
+
continue;
|
|
86
|
+
if (item.address.startsWith('127.') || seen.has(item.address))
|
|
87
|
+
continue;
|
|
88
|
+
seen.add(item.address);
|
|
89
|
+
list.push({ address: item.address, iface });
|
|
12
90
|
}
|
|
13
91
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
92
|
+
return rankIpCandidates(list);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 取最可能被局域网其它设备访问的地址。
|
|
96
|
+
*
|
|
97
|
+
* 只用于启动日志这类「给个大概」的场景;页面上的二维码应使用
|
|
98
|
+
* `/localsend/api/network` 返回的完整候选列表,让用户自己选。
|
|
99
|
+
*/
|
|
100
|
+
function getIp() {
|
|
101
|
+
return getIpCandidates()[0]?.address;
|
|
21
102
|
}
|
|
22
|
-
// console.log(getIp());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** 一条审计记录 */
|
|
2
|
+
export interface AuditEntry {
|
|
3
|
+
/** 时间戳(毫秒) */
|
|
4
|
+
ts: number;
|
|
5
|
+
/** 来源 IP */
|
|
6
|
+
ip: string;
|
|
7
|
+
/** 操作者角色:admin / visitor / guest / open */
|
|
8
|
+
role: string;
|
|
9
|
+
/** 动作标识,如 file.rename、settings.update */
|
|
10
|
+
action: string;
|
|
11
|
+
/** 操作对象(文件相对路径、配置项名等) */
|
|
12
|
+
target?: string;
|
|
13
|
+
/** 补充信息(数量、来源等) */
|
|
14
|
+
extra?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface AuditOptions {
|
|
17
|
+
/** 日志文件路径 */
|
|
18
|
+
file: string;
|
|
19
|
+
/** 单文件大小上限,超过后轮转,默认 5MB */
|
|
20
|
+
maxBytes?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface AuditLog {
|
|
23
|
+
/** 日志文件路径 */
|
|
24
|
+
readonly file: string;
|
|
25
|
+
/** 追加一条记录 */
|
|
26
|
+
record: (entry: Omit<AuditEntry, 'ts'> & {
|
|
27
|
+
ts?: number;
|
|
28
|
+
}) => void;
|
|
29
|
+
/** 最近的记录(从新到旧) */
|
|
30
|
+
recent: (limit?: number) => AuditEntry[];
|
|
31
|
+
/** 当前文件大小(诊断用) */
|
|
32
|
+
size: () => number;
|
|
33
|
+
}
|
|
34
|
+
/** 默认单文件上限:5MB 约可容纳数万条记录 */
|
|
35
|
+
export declare const AUDIT_MAX_BYTES: number;
|
|
36
|
+
export declare function createAuditLog(options: AuditOptions): AuditLog;
|