From 01aaa07e87e33736370101fe0ef0fa961dbda552 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:41:45 +0530 Subject: [PATCH 01/33] added zip progress counter configurations --- src/gui/src/globals.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/src/globals.js b/src/gui/src/globals.js index ae544148..7813b51f 100644 --- a/src/gui/src/globals.js +++ b/src/gui/src/globals.js @@ -109,6 +109,7 @@ window.taskbar_height = window.default_taskbar_height; window.upload_progress_hide_delay = 500; window.active_uploads = {}; window.copy_progress_hide_delay = 1000; +window.zip_progress_hide_delay = 2000; window.busy_indicator_hide_delay = 600; window.global_element_id = 0; window.operation_id = 0; @@ -126,6 +127,17 @@ window.watchItems = []; window.appdata_signatures = {}; window.appCallbackFunctions = []; +// Defines how much weight each operation has in the zipping progress +window.zippingProgressConfig = { + TOTAL: 100 +} +//Assuming uInt8Array conversion a file takes betwneen 45% to 60% of the total progress +window.zippingProgressConfig.SEQUENCING = Math.floor(Math.random() * (60 - 45 + 1)) + 45, +//Assuming zipping up uInt8Arrays takes betwneen 23% to 20% of the total progress +window.zippingProgressConfig.ZIPPING = Math.floor(Math.random() * (23 - 20 + 1)) + 20, +//Assuming writing a zip file takes betwneen 14% to 10% of the total progress +window.zippingProgressConfig.WRITING = Math.floor(Math.random() * (14 - 10 + 1)) + 14, + // 'Launch' apps window.launch_apps = []; window.launch_apps.recent = [] From 1929aaf5ef2df90f285bb0a3755db5fb4eb91d59 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:42:43 +0530 Subject: [PATCH 02/33] added fflate on libPath on puter-gui --- src/gui/puter-gui.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/puter-gui.json b/src/gui/puter-gui.json index 97e52025..ef505266 100644 --- a/src/gui/puter-gui.json +++ b/src/gui/puter-gui.json @@ -14,7 +14,8 @@ "/lib/timeago.min.js", "/lib/iro.min.js", "/lib/isMobile.min.js", - "/lib/jszip-3.10.1.min.js" + "/lib/jszip-3.10.1.min.js", + "/lib/fflate-0.8.2.min.js" ], "css_paths": [ "/css/normalize.css", From 4c7b75ed678eb5bbac55573bdd3e2cbbf96a7a1d Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:43:15 +0530 Subject: [PATCH 03/33] added fflate on static asset and libPath --- src/gui/src/static-assets.js | 1 + src/gui/webpack/libPaths.cjs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/src/static-assets.js b/src/gui/src/static-assets.js index b6fc5677..aed11a13 100644 --- a/src/gui/src/static-assets.js +++ b/src/gui/src/static-assets.js @@ -32,6 +32,7 @@ const lib_paths =[ `/lib/iro.min.js`, `/lib/isMobile.min.js`, `/lib/jszip-3.10.1.min.js`, + `/lib/fflate-0.8.2.min.js`, ] // Ordered list of CSS stylesheets diff --git a/src/gui/webpack/libPaths.cjs b/src/gui/webpack/libPaths.cjs index f822a6f3..aea7f05f 100644 --- a/src/gui/webpack/libPaths.cjs +++ b/src/gui/webpack/libPaths.cjs @@ -11,5 +11,6 @@ module.exports = [ "timeago.min.js", "iro.min.js", "isMobile.min.js", - "jszip-3.10.1.min.js" + "jszip-3.10.1.min.js", + "fflate-0.8.2.min.js" ]; \ No newline at end of file From f3625ed907a704ff074ed485b0aa21fdb663a582 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:43:43 +0530 Subject: [PATCH 04/33] added terms for status message on zip operation --- src/gui/src/i18n/translations/en.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/src/i18n/translations/en.js b/src/gui/src/i18n/translations/en.js index d653bb4e..afb7e6f3 100644 --- a/src/gui/src/i18n/translations/en.js +++ b/src/gui/src/i18n/translations/en.js @@ -226,7 +226,8 @@ const en = { publish: "Publish", publish_as_website: 'Publish as website', puter_description: `Puter is a privacy-first personal cloud to keep all your files, apps, and games in one secure place, accessible from anywhere at any time.`, - reading_file: "Reading %strong%", + reading: "Reading %strong%", + writing: "Writing %strong%", recent: "Recent", recommended: "Recommended", recover_password: "Recover Password", @@ -316,7 +317,8 @@ const en = { yes_release_it: 'Yes, Release It', you_have_been_referred_to_puter_by_a_friend: "You have been referred to Puter by a friend!", zip: "Zip", - zipping_file: "Zipping %strong%", + sequencing: "Sequencing %strong%", + zipping: "Zipping %strong%", // === 2FA Setup === setup2fa_1_step_heading: 'Open your authenticator app', From 582c411c0061db977909ff0eb2c1d833033d07e3 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:44:04 +0530 Subject: [PATCH 05/33] added fflate min js to the library --- src/gui/src/lib/fflate-0.8.2.min.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/gui/src/lib/fflate-0.8.2.min.js diff --git a/src/gui/src/lib/fflate-0.8.2.min.js b/src/gui/src/lib/fflate-0.8.2.min.js new file mode 100644 index 00000000..3b6382d1 --- /dev/null +++ b/src/gui/src/lib/fflate-0.8.2.min.js @@ -0,0 +1,9 @@ +/*! + +fflate v0.8.2 - High performance (de)compression in an 8kB package + + +*/ + + +!function(f){typeof module!='undefined'&&typeof exports=='object'?module.exports=f():typeof define!='undefined'&&define.amd?define(f):(typeof self!='undefined'?self:this).fflate=f()}(function(){var _e={};"use strict";var t=(typeof module!='undefined'&&typeof exports=='object'?function(_f){"use strict";var e,t=";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";try{e=require("worker_threads").Worker}catch(e){}exports.default=e?function(r,n,o,a,s){var u=!1,i=new e(r+t,{eval:!0}).on("error",(function(e){return s(e,null)})).on("message",(function(e){return s(null,e)})).on("exit",(function(e){e&&!u&&s(Error("exited with code "+e),null)}));return i.postMessage(o,a),i.terminate=function(){return u=!0,e.prototype.terminate.call(i)},i}:function(e,t,r,n,o){setImmediate((function(){return o(Error("async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)"),null)}));var a=function(){};return{terminate:a,postMessage:a}};return _f}:function(_f){"use strict";var e={};_f.default=function(r,t,s,a,n){var o=new Worker(e[t]||(e[t]=URL.createObjectURL(new Blob([r+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(e){var r=e.data,t=r.$e$;if(t){var s=Error(t[0]);s.code=t[1],s.stack=t[2],n(s,null)}else n(null,r)},o.postMessage(s,a),o};return _f})({}),n=Uint8Array,r=Uint16Array,e=Int32Array,i=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),o=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),s=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),a=function(t,n){for(var i=new r(31),o=0;o<31;++o)i[o]=n+=1<>1|(21845&d)<<1;v[d]=((65280&(g=(61680&(g=(52428&g)>>2|(13107&g)<<2))>>4|(3855&g)<<4))>>8|(255&g)<<8)>>1}var y=function(t,n,e){for(var i=t.length,o=0,s=new r(n);o>h]=f}else for(a=new r(i),o=0;o>15-t[o]);return a},m=new n(288);for(d=0;d<144;++d)m[d]=8;for(d=144;d<256;++d)m[d]=9;for(d=256;d<280;++d)m[d]=7;for(d=280;d<288;++d)m[d]=8;var b=new n(32);for(d=0;d<32;++d)b[d]=5;var w=y(m,9,0),x=y(m,9,1),z=y(b,5,0),k=y(b,5,1),M=function(t){for(var n=t[0],r=1;rn&&(n=t[r]);return n},S=function(t,n,r){var e=n/8|0;return(t[e]|t[e+1]<<8)>>(7&n)&r},A=function(t,n){var r=n/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(7&n)},T=function(t){return(t+7)/8|0},D=function(t,r,e){return(null==r||r<0)&&(r=0),(null==e||e>t.length)&&(e=t.length),new n(t.subarray(r,e))};_e.FlateErrorCode={UnexpectedEOF:0,InvalidBlockType:1,InvalidLengthLiteral:2,InvalidDistance:3,StreamFinished:4,NoStreamHandler:5,InvalidHeader:6,NoCallback:7,InvalidUTF8:8,ExtraFieldTooLong:9,InvalidDate:10,FilenameTooLong:11,StreamFinishing:12,InvalidZipData:13,UnknownCompressionMethod:14};var C=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],I=function(t,n,r){var e=Error(n||C[t]);if(e.code=t,Error.captureStackTrace&&Error.captureStackTrace(e,I),!r)throw e;return e},U=function(t,r,e,a){var u=t.length,f=a?a.length:0;if(!u||r.f&&!r.l)return e||new n(0);var l=!e,p=l||2!=r.i,v=r.i;l&&(e=new n(3*u));var d=function(t){var r=e.length;if(t>r){var i=new n(Math.max(2*r,t));i.set(e),e=i}},g=r.f||0,m=r.p||0,b=r.b||0,w=r.l,z=r.d,C=r.m,U=r.n,F=8*u;do{if(!w){g=S(t,m,1);var E=S(t,m+1,3);if(m+=3,!E){var Z=t[(J=T(m)+4)-4]|t[J-3]<<8,q=J+Z;if(q>u){v&&I(0);break}p&&d(b+Z),e.set(t.subarray(J,q),b),r.b=b+=Z,r.p=m=8*q,r.f=g;continue}if(1==E)w=x,z=k,C=9,U=5;else if(2==E){var O=S(t,m,31)+257,G=S(t,m+10,15)+4,L=O+S(t,m+5,31)+1;m+=14;for(var H=new n(L),j=new n(19),N=0;N>4)<16)H[N++]=J;else{var Q=0,R=0;for(16==J?(R=3+S(t,m,3),m+=2,Q=H[N-1]):17==J?(R=3+S(t,m,7),m+=3):18==J&&(R=11+S(t,m,127),m+=7);R--;)H[N++]=Q}}var V=H.subarray(0,O),W=H.subarray(O);C=M(V),U=M(W),w=y(V,C,1),z=y(W,U,1)}else I(1);if(m>F){v&&I(0);break}}p&&d(b+131072);for(var X=(1<>4;if((m+=15&Q)>F){v&&I(0);break}if(Q||I(2),tt<256)e[b++]=tt;else{if(256==tt){_=m,w=null;break}var nt=tt-254;tt>264&&(nt=S(t,m,(1<<(it=i[N=tt-257]))-1)+h[N],m+=it);var rt=z[A(t,m)&$],et=rt>>4;if(rt||I(3),m+=15&rt,W=c[et],et>3){var it=o[et];W+=A(t,m)&(1<F){v&&I(0);break}p&&d(b+131072);var ot=b+nt;if(b>8},E=function(t,n,r){var e=n/8|0;t[e]|=r<<=7&n,t[e+1]|=r>>8,t[e+2]|=r>>16},Z=function(t,e){for(var i=[],o=0;ov&&(v=a[o].s);var d=new r(v+1),g=q(i[c-1],d,0);if(g>e){o=0;var y=0,m=g-e,b=1<e))break;y+=b-(1<>=m;y>0;){var x=a[o].s;d[x]=0&&y;--o){var z=a[o].s;d[z]==e&&(--d[z],++y)}g=e}return{t:new n(d),l:g}},q=function(t,n,r){return-1==t.s?Math.max(q(t.l,n,r+1),q(t.r,n,r+1)):n[t.s]=r},O=function(t){for(var n=t.length;n&&!t[--n];);for(var e=new r(++n),i=0,o=t[0],s=1,a=function(t){e[i++]=t},u=1;u<=n;++u)if(t[u]==o&&u!=n)++s;else{if(!o&&s>2){for(;s>138;s-=138)a(32754);s>2&&(a(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(a(o),--s;s>6;s-=6)a(8304);s>2&&(a(s-3<<5|8208),s=0)}for(;s--;)a(o);s=1,o=t[u]}return{c:e.subarray(0,i),n:n}},G=function(t,n){for(var r=0,e=0;e>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var o=0;o4&&!N[s[B-1]];--B);var Y,J,K,Q,R=p+5<<3,V=G(u,m)+G(h,b)+f,W=G(u,g)+G(h,M)+f+14+3*B+G(q,N)+2*q[16]+3*q[17]+7*q[18];if(c>=0&&R<=V&&R<=W)return L(n,v,t.subarray(c,c+p));if(F(n,v,1+(W15&&(F(n,v,tt[H]>>5&127),v+=tt[H]>>12)}}else Y=w,J=m,K=z,Q=b;for(H=0;H255){var rt;E(n,v,Y[257+(rt=nt>>18&31)]),v+=J[rt+257],rt>7&&(F(n,v,nt>>23&31),v+=i[rt]);var et=31&nt;E(n,v,K[et]),v+=Q[et],et>3&&(E(n,v,nt>>5&8191),v+=o[et])}else E(n,v,Y[nt]),v+=J[nt]}return E(n,v,Y[256]),v+J[256]},j=new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),N=new n(0),P=function(t,s,a,u,h,l){var c=l.z||t.length,v=new n(u+c+5*(1+Math.ceil(c/7e3))+h),d=v.subarray(u,v.length-h),g=l.l,y=7&(l.r||0);if(s){y&&(d[0]=l.r>>3);for(var m=j[s-1],b=m>>13,w=8191&m,x=(1<7e3||q>24576)&&(Y>423||!g)){y=H(t,d,0,C,I,U,E,q,G,Z-G,y),q=F=E=0,G=Z;for(var J=0;J<286;++J)I[J]=0;for(J=0;J<30;++J)U[J]=0}var K=2,Q=0,R=w,V=P-B&32767;if(Y>2&&N==A(Z-V))for(var W=Math.min(b,Y)-1,X=Math.min(32767,Z),$=Math.min(258,Y);V<=X&&--R&&P!=B;){if(t[Z+K]==t[Z+K-V]){for(var _=0;_<$&&t[Z+_]==t[Z+_-V];++_);if(_>K){if(K=_,Q=V,_>W)break;var tt=Math.min(V,_-2),nt=0;for(J=0;Jnt&&(nt=et,B=rt)}}}V+=(P=B)-(B=z[P])&32767}if(Q){C[q++]=268435456|f[K]<<18|p[Q];var it=31&f[K],ot=31&p[Q];E+=i[it]+o[ot],++I[257+it],++U[ot],O=Z+K,++F}else C[q++]=t[Z],++I[t[Z]]}}for(Z=Math.max(Z,O);Z=c&&(d[y/8|0]=g,st=c),y=L(d,y+1,t.subarray(Z,st))}l.i=c}return D(v,0,u+T(y)+h)},B=function(){for(var t=new Int32Array(256),n=0;n<256;++n){for(var r=n,e=9;--e;)r=(1&r&&-306674912)^r>>>1;t[n]=r}return t}(),Y=function(){var t=-1;return{p:function(n){for(var r=t,e=0;e>>8;t=r},d:function(){return~t}}},J=function(){var t=1,n=0;return{p:function(r){for(var e=t,i=n,o=0|r.length,s=0;s!=o;){for(var a=Math.min(s+2655,o);s>16),i=(65535&i)+15*(i>>16)}t=e,n=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(n%=65521))<<8|n>>8}}},K=function(t,r,e,i,o){if(!o&&(o={l:1},r.dictionary)){var s=r.dictionary.subarray(-32768),a=new n(s.length+t.length);a.set(s),a.set(t,s.length),t=a,o.w=s.length}return P(t,null==r.level?6:r.level,null==r.mem?o.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):20:12+r.mem,e,i,o)},Q=function(t,n){var r={};for(var e in t)r[e]=t[e];for(var e in n)r[e]=n[e];return r},R=function(t,n,r){for(var e=t(),i=""+t,o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},lt=function(t,n){return ft(t,n)+4294967296*ft(t,n+4)},ct=function(t,n,r){for(;r;++n)t[n]=r,r>>>=8},pt=function(t,n){var r=n.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=n.level<2?4:9==n.level?2:0,t[9]=3,0!=n.mtime&&ct(t,4,Math.floor(new Date(n.mtime||Date.now())/1e3)),r){t[3]=8;for(var e=0;e<=r.length;++e)t[e+10]=r.charCodeAt(e)}},vt=function(t){31==t[0]&&139==t[1]&&8==t[2]||I(6,"invalid gzip data");var n=t[3],r=10;4&n&&(r+=2+(t[10]|t[11]<<8));for(var e=(n>>3&1)+(n>>4&1);e>0;e-=!t[r++]);return r+(2&n)},dt=function(t){var n=t.length;return(t[n-4]|t[n-3]<<8|t[n-2]<<16|t[n-1]<<24)>>>0},gt=function(t){return 10+(t.filename?t.filename.length+1:0)},yt=function(t,n){var r=n.level,e=0==r?0:r<6?1:9==r?3:2;if(t[0]=120,t[1]=e<<6|(n.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,n.dictionary){var i=J();i.p(n.dictionary),ct(t,2,i.d())}},mt=function(t,n){return(8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31)&&I(6,"invalid zlib data"),(t[1]>>5&1)==+!n&&I(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)};function bt(t,n){return"function"==typeof t&&(n=t,t={}),this.ondata=n,t}var wt=function(){function t(t,r){if("function"==typeof t&&(r=t,t={}),this.ondata=r,this.o=t||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new n(98304),this.o.dictionary){var e=this.o.dictionary.subarray(-32768);this.b.set(e,32768-e.length),this.s.i=32768-e.length}}return t.prototype.p=function(t,n){this.ondata(K(t,this.o,0,0,this.s),n)},t.prototype.push=function(t,r){this.ondata||I(5),this.s.l&&I(4);var e=t.length+this.s.z;if(e>this.b.length){if(e>2*this.b.length-32768){var i=new n(-32768&e);i.set(this.b.subarray(0,this.s.z)),this.b=i}var o=this.b.length-this.s.z;this.b.set(t.subarray(0,o),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(t.subarray(o),32768),this.s.z=t.length-o+32768,this.s.i=32766,this.s.w=32768}else this.b.set(t,this.s.z),this.s.z+=t.length;this.s.l=1&r,(this.s.z>this.s.w+8191||r)&&(this.p(this.b,r||!1),this.s.w=this.s.i,this.s.i-=2)},t.prototype.flush=function(){this.ondata||I(5),this.s.l&&I(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},t}();_e.Deflate=wt;var xt=function(){return function(t,n){ut([_,function(){return[at,wt]}],this,bt.call(this,t,n),(function(t){var n=new wt(t.data);onmessage=at(n)}),6,1)}}();function zt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_],(function(t){return it(kt(t.data[0],t.data[1]))}),0,r)}function kt(t,n){return K(t,n||{},0,0)}_e.AsyncDeflate=xt,_e.deflate=zt,_e.deflateSync=kt;var Mt=function(){function t(t,r){"function"==typeof t&&(r=t,t={}),this.ondata=r;var e=t&&t.dictionary&&t.dictionary.subarray(-32768);this.s={i:0,b:e?e.length:0},this.o=new n(32768),this.p=new n(0),e&&this.o.set(e)}return t.prototype.e=function(t){if(this.ondata||I(5),this.d&&I(4),this.p.length){if(t.length){var r=new n(this.p.length+t.length);r.set(this.p),r.set(t,this.p.length),this.p=r}}else this.p=t},t.prototype.c=function(t){this.s.i=+(this.d=t||!1);var n=this.s.b,r=U(this.p,this.s,this.o);this.ondata(D(r,n,this.s.b),this.d),this.o=D(r,this.s.b-32768),this.s.b=this.o.length,this.p=D(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(t,n){this.e(t),this.c(n)},t}();_e.Inflate=Mt;var St=function(){return function(t,n){ut([$,function(){return[at,Mt]}],this,bt.call(this,t,n),(function(t){var n=new Mt(t.data);onmessage=at(n)}),7,0)}}();function At(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$],(function(t){return it(Tt(t.data[0],ot(t.data[1])))}),1,r)}function Tt(t,n){return U(t,{i:2},n&&n.out,n&&n.dictionary)}_e.AsyncInflate=St,_e.inflate=At,_e.inflateSync=Tt;var Dt=function(){function t(t,n){this.c=Y(),this.l=0,this.v=1,wt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),this.l+=t.length,wt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=K(t,this.o,this.v&>(this.o),n&&8,this.s);this.v&&(pt(r,this.o),this.v=0),n&&(ct(r,r.length-8,this.c.d()),ct(r,r.length-4,this.l)),this.ondata(r,n)},t.prototype.flush=function(){wt.prototype.flush.call(this)},t}();_e.Gzip=Dt,_e.Compress=Dt;var Ct=function(){return function(t,n){ut([_,tt,function(){return[at,wt,Dt]}],this,bt.call(this,t,n),(function(t){var n=new Dt(t.data);onmessage=at(n)}),8,1)}}();function It(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_,tt,function(){return[Ut]}],(function(t){return it(Ut(t.data[0],t.data[1]))}),2,r)}function Ut(t,n){n||(n={});var r=Y(),e=t.length;r.p(t);var i=K(t,n,gt(n),8),o=i.length;return pt(i,n),ct(i,o-8,r.d()),ct(i,o-4,e),i}_e.AsyncGzip=Ct,_e.AsyncCompress=Ct,_e.gzip=It,_e.compress=It,_e.gzipSync=Ut,_e.compressSync=Ut;var Ft=function(){function t(t,n){this.v=1,this.r=0,Mt.call(this,t,n)}return t.prototype.push=function(t,r){if(Mt.prototype.e.call(this,t),this.r+=t.length,this.v){var e=this.p.subarray(this.v-1),i=e.length>3?vt(e):4;if(i>e.length){if(!r)return}else this.v>1&&this.onmember&&this.onmember(this.r-e.length);this.p=e.subarray(i),this.v=0}Mt.prototype.c.call(this,r),!this.s.f||this.s.l||r||(this.v=T(this.s.p)+9,this.s={i:0},this.o=new n(0),this.push(new n(0),r))},t}();_e.Gunzip=Ft;var Et=function(){return function(t,n){var r=this;ut([$,nt,function(){return[at,Mt,Ft]}],this,bt.call(this,t,n),(function(t){var n=new Ft(t.data);n.onmember=function(t){return postMessage(t)},onmessage=at(n)}),9,0,(function(t){return r.onmember&&r.onmember(t)}))}}();function Zt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$,nt,function(){return[qt]}],(function(t){return it(qt(t.data[0],t.data[1]))}),3,r)}function qt(t,r){var e=vt(t);return e+8>t.length&&I(6,"invalid gzip data"),U(t.subarray(e,-8),{i:2},r&&r.out||new n(dt(t)),r&&r.dictionary)}_e.AsyncGunzip=Et,_e.gunzip=Zt,_e.gunzipSync=qt;var Ot=function(){function t(t,n){this.c=J(),this.v=1,wt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),wt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=K(t,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(yt(r,this.o),this.v=0),n&&ct(r,r.length-4,this.c.d()),this.ondata(r,n)},t.prototype.flush=function(){wt.prototype.flush.call(this)},t}();_e.Zlib=Ot;var Gt=function(){return function(t,n){ut([_,rt,function(){return[at,wt,Ot]}],this,bt.call(this,t,n),(function(t){var n=new Ot(t.data);onmessage=at(n)}),10,1)}}();function Lt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[_,rt,function(){return[Ht]}],(function(t){return it(Ht(t.data[0],t.data[1]))}),4,r)}function Ht(t,n){n||(n={});var r=J();r.p(t);var e=K(t,n,n.dictionary?6:2,4);return yt(e,n),ct(e,e.length-4,r.d()),e}_e.AsyncZlib=Gt,_e.zlib=Lt,_e.zlibSync=Ht;var jt=function(){function t(t,n){Mt.call(this,t,n),this.v=t&&t.dictionary?2:1}return t.prototype.push=function(t,n){if(Mt.prototype.e.call(this,t),this.v){if(this.p.length<6&&!n)return;this.p=this.p.subarray(mt(this.p,this.v-1)),this.v=0}n&&(this.p.length<4&&I(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),Mt.prototype.c.call(this,n)},t}();_e.Unzlib=jt;var Nt=function(){return function(t,n){ut([$,et,function(){return[at,Mt,jt]}],this,bt.call(this,t,n),(function(t){var n=new jt(t.data);onmessage=at(n)}),11,0)}}();function Pt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),st(t,n,[$,et,function(){return[Bt]}],(function(t){return it(Bt(t.data[0],ot(t.data[1])))}),5,r)}function Bt(t,n){return U(t.subarray(mt(t,n&&n.dictionary),-4),{i:2},n&&n.out,n&&n.dictionary)}_e.AsyncUnzlib=Nt,_e.unzlib=Pt,_e.unzlibSync=Bt;var Yt=function(){function t(t,n){this.o=bt.call(this,t,n)||{},this.G=Ft,this.I=Mt,this.Z=jt}return t.prototype.i=function(){var t=this;this.s.ondata=function(n,r){t.ondata(n,r)}},t.prototype.push=function(t,r){if(this.ondata||I(5),this.s)this.s.push(t,r);else{if(this.p&&this.p.length){var e=new n(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length)}else this.p=t;this.p.length>2&&(this.s=31==this.p[0]&&139==this.p[1]&&8==this.p[2]?new this.G(this.o):8!=(15&this.p[0])||this.p[0]>>4>7||(this.p[0]<<8|this.p[1])%31?new this.I(this.o):new this.Z(this.o),this.i(),this.s.push(this.p,r),this.p=null)}},t}();_e.Decompress=Yt;var Jt=function(){function t(t,n){Yt.call(this,t,n),this.queuedSize=0,this.G=Et,this.I=St,this.Z=Nt}return t.prototype.i=function(){var t=this;this.s.ondata=function(n,r,e){t.ondata(n,r,e)},this.s.ondrain=function(n){t.queuedSize-=n,t.ondrain&&t.ondrain(n)}},t.prototype.push=function(t,n){this.queuedSize+=t.length,Yt.prototype.push.call(this,t,n)},t}();function Kt(t,n,r){return r||(r=n,n={}),"function"!=typeof r&&I(7),31==t[0]&&139==t[1]&&8==t[2]?Zt(t,n,r):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?At(t,n,r):Pt(t,n,r)}function Qt(t,n){return 31==t[0]&&139==t[1]&&8==t[2]?qt(t,n):8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31?Tt(t,n):Bt(t,n)}_e.AsyncDecompress=Jt,_e.decompress=Kt,_e.decompressSync=Qt;var Rt=function(t,r,e,i){for(var o in t){var s=t[o],a=r+o,u=i;Array.isArray(s)&&(u=Q(i,s[1]),s=s[0]),s instanceof n?e[a]=[s,u]:(e[a+="/"]=[new n(0),u],Rt(s,a,e,i))}},Vt="undefined"!=typeof TextEncoder&&new TextEncoder,Wt="undefined"!=typeof TextDecoder&&new TextDecoder,Xt=0;try{Wt.decode(N,{stream:!0}),Xt=1}catch(t){}var $t=function(t){for(var n="",r=0;;){var e=t[r++],i=(e>127)+(e>223)+(e>239);if(r+i>t.length)return{s:n,r:D(t,r-1)};i?3==i?(e=((15&e)<<18|(63&t[r++])<<12|(63&t[r++])<<6|63&t[r++])-65536,n+=String.fromCharCode(55296|e>>10,56320|1023&e)):n+=String.fromCharCode(1&i?(31&e)<<6|63&t[r++]:(15&e)<<12|(63&t[r++])<<6|63&t[r++]):n+=String.fromCharCode(e)}},_t=function(){function t(t){this.ondata=t,Xt?this.t=new TextDecoder:this.p=N}return t.prototype.push=function(t,r){if(this.ondata||I(5),r=!!r,this.t)return this.ondata(this.t.decode(t,{stream:!0}),r),void(r&&(this.t.decode().length&&I(8),this.t=null));this.p||I(4);var e=new n(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length);var i=$t(e),o=i.s,s=i.r;r?(s.length&&I(8),this.p=null):this.p=s,this.ondata(o,r)},t}();_e.DecodeUTF8=_t;var tn=function(){function t(t){this.ondata=t}return t.prototype.push=function(t,n){this.ondata||I(5),this.d&&I(4),this.ondata(nn(t),this.d=n||!1)},t}();function nn(t,r){if(r){for(var e=new n(t.length),i=0;i>1)),a=0,u=function(t){s[a++]=t};for(i=0;is.length){var h=new n(a+8+(o-i<<1));h.set(s),s=h}var f=t.charCodeAt(i);f<128||r?u(f):f<2048?(u(192|f>>6),u(128|63&f)):f>55295&&f<57344?(u(240|(f=65536+(1047552&f)|1023&t.charCodeAt(++i))>>18),u(128|f>>12&63),u(128|f>>6&63),u(128|63&f)):(u(224|f>>12),u(128|f>>6&63),u(128|63&f))}return D(s,0,a)}function rn(t,n){if(n){for(var r="",e=0;e65535&&I(9),n+=e+4}return n},hn=function(t,n,r,e,i,o,s,a){var u=e.length,h=r.extra,f=a&&a.length,l=un(h);ct(t,n,null!=s?33639248:67324752),n+=4,null!=s&&(t[n++]=20,t[n++]=r.os),t[n]=20,n+=2,t[n++]=r.flag<<1|(o<0&&8),t[n++]=i&&8,t[n++]=255&r.compression,t[n++]=r.compression>>8;var c=new Date(null==r.mtime?Date.now():r.mtime),p=c.getFullYear()-1980;if((p<0||p>119)&&I(10),ct(t,n,p<<25|c.getMonth()+1<<21|c.getDate()<<16|c.getHours()<<11|c.getMinutes()<<5|c.getSeconds()>>1),n+=4,-1!=o&&(ct(t,n,r.crc),ct(t,n+4,o<0?-o-2:o),ct(t,n+8,r.size)),ct(t,n+12,u),ct(t,n+14,l),n+=16,null!=s&&(ct(t,n,f),ct(t,n+6,r.attrs),ct(t,n+10,s),n+=14),t.set(e,n),n+=u,l)for(var v in h){var d=h[v],g=d.length;ct(t,n,+v),ct(t,n+2,g),t.set(d,n+4),n+=4+g}return f&&(t.set(a,n),n+=f),n},fn=function(t,n,r,e,i){ct(t,n,101010256),ct(t,n+8,r),ct(t,n+10,r),ct(t,n+12,e),ct(t,n+16,i)},ln=function(){function t(t){this.filename=t,this.c=Y(),this.size=0,this.compression=0}return t.prototype.process=function(t,n){this.ondata(null,t,n)},t.prototype.push=function(t,n){this.ondata||I(5),this.c.p(t),this.size+=t.length,n&&(this.crc=this.c.d()),this.process(t,n||!1)},t}();_e.ZipPassThrough=ln;var cn=function(){function t(t,n){var r=this;n||(n={}),ln.call(this,t),this.d=new wt(n,(function(t,n){r.ondata(null,t,n)})),this.compression=8,this.flag=en(n.level)}return t.prototype.process=function(t,n){try{this.d.push(t,n)}catch(t){this.ondata(t,null,n)}},t.prototype.push=function(t,n){ln.prototype.push.call(this,t,n)},t}();_e.ZipDeflate=cn;var pn=function(){function t(t,n){var r=this;n||(n={}),ln.call(this,t),this.d=new xt(n,(function(t,n,e){r.ondata(t,n,e)})),this.compression=8,this.flag=en(n.level),this.terminate=this.d.terminate}return t.prototype.process=function(t,n){this.d.push(t,n)},t.prototype.push=function(t,n){ln.prototype.push.call(this,t,n)},t}();_e.AsyncZipDeflate=pn;var vn=function(){function t(t){this.ondata=t,this.u=[],this.d=1}return t.prototype.add=function(t){var r=this;if(this.ondata||I(5),2&this.d)this.ondata(I(4+8*(1&this.d),0,1),null,!1);else{var e=nn(t.filename),i=e.length,o=t.comment,s=o&&nn(o),a=i!=t.filename.length||s&&o.length!=s.length,u=i+un(t.extra)+30;i>65535&&this.ondata(I(11,0,1),null,!1);var h=new n(u);hn(h,0,t,e,a,-1);var f=[h],l=function(){for(var t=0,n=f;t65535&&M(I(11,0,1),null),k)if(g<16e4)try{M(null,kt(e,h))}catch(t){M(t,null)}else l.push(zt(e,h,M));else M(null,e)},g=0;g65535&&I(11);var y=l?kt(h,f):h,m=y.length,b=Y();b.p(h),i.push(Q(f,{size:h.length,crc:b.d(),c:y,f:M,m:v,u:c!=a.length||v&&p.length!=d,o:o,compression:l})),o+=30+c+g+m,s+=76+2*(c+g)+(d||0)+m}for(var w=new n(s+22),x=o,z=s-o,k=0;k0){var i=Math.min(this.c,t.length),o=t.subarray(0,i);if(this.c-=i,this.d?this.d.push(o,!this.c):this.k[0].push(o),(t=t.subarray(i)).length)return this.push(t,r)}else{var s=0,a=0,u=void 0,h=void 0;this.p.length?t.length?((h=new n(this.p.length+t.length)).set(this.p),h.set(t,this.p.length)):h=this.p:h=t;for(var f=h.length,l=this.c,c=l&&this.d,p=function(){var t,n=ft(h,a);if(67324752==n){s=1,u=a,v.d=null,v.c=0;var r=ht(h,a+6),i=ht(h,a+8),o=2048&r,c=8&r,p=ht(h,a+26),d=ht(h,a+28);if(f>a+30+p+d){var g=[];v.k.unshift(g),s=2;var y,m=ft(h,a+18),b=ft(h,a+22),w=rn(h.subarray(a+30,a+=30+p),!o);4294967295==m?(t=c?[-2]:an(h,a),m=t[0],b=t[1]):c&&(m=-1),a+=d,v.c=m;var x={name:w,compression:i,start:function(){if(x.ondata||I(5),m){var t=e.o[i];t||x.ondata(I(14,"unknown compression type "+i,1),null,!1),(y=m<0?new t(w):new t(w,m,b)).ondata=function(t,n,r){x.ondata(t,n,r)};for(var n=0,r=g;n=0&&(x.size=m,x.originalSize=b),v.onfile(x)}return"break"}if(l){if(134695760==n)return u=a+=12+(-2==l&&8),s=3,v.c=0,"break";if(33639248==n)return u=a-=4,s=3,v.c=0,"break"}},v=this;a65558)return a(I(13,0,1),null),o;var h=ht(t,u+8);if(h){var f=h,l=ft(t,u+16),c=4294967295==l||65535==f;if(c){var p=ft(t,u-12);(c=101075792==ft(t,p))&&(f=h=ft(t,p+32),l=ft(t,p+48))}for(var v=r&&r.filter,d=function(r){var e=sn(t,l,c),u=e[0],f=e[1],p=e[2],d=e[3],g=e[4],y=on(t,e[5]);l=g;var m=function(t,n){t?(o(),a(t,null)):(n&&(s[d]=n),--h||a(null,s))};if(!v||v({name:d,size:f,originalSize:p,compression:u}))if(u)if(8==u){var b=t.subarray(y,y+f);if(p<524288||f>.8*p)try{m(null,Tt(b,{out:new n(p)}))}catch(t){m(t,null)}else i.push(At(b,{size:p},m))}else m(I(14,"unknown compression type "+u,1),null);else m(null,D(t,y,y+f));else m(null,null)},g=0;g65558)&&I(13);var o=ht(t,i+8);if(!o)return{};var s=ft(t,i+16),a=4294967295==s||65535==o;if(a){var u=ft(t,i-12);(a=101075792==ft(t,u))&&(o=ft(t,u+32),s=ft(t,u+48))}for(var h=r&&r.filter,f=0;f Date: Sat, 5 Oct 2024 23:45:54 +0530 Subject: [PATCH 06/33] added helper method to convert binary large object to uInt8Array for zipping operations --- src/gui/src/helpers.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 1ba495e2..18c8a459 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -1959,6 +1959,29 @@ window.checkUserSiteRelationship = async function(origin) { } } +// Converts a Blob to a Uint8Array [local helper module] +let streamToUint8Array = async function(blob) { + const totalLength = blob.size; + const reader = blob.stream().getReader(); + let chunks = []; + let receivedLength = 0; + + while (true) { + const { done, value } = await reader.read(); + if (done) break; + + chunks.push(value); + receivedLength += value.length; + } + let uint8Array = new Uint8Array(receivedLength); + let position = 0; + + for (let chunk of chunks) { + uint8Array.set(chunk, position); + position += chunk.length; + } + return uint8Array; +} window.zipItems = async function(el_items, targetDirPath, download = true) { const zip = new JSZip(); From dfe71d5965b6aa306f3c9ebc54a572542997595a Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 5 Oct 2024 23:47:22 +0530 Subject: [PATCH 07/33] modified zipping operationand integrated fflate --- src/gui/src/helpers.js | 104 +++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 18c8a459..cd92f292 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -1984,7 +1984,9 @@ let streamToUint8Array = async function(blob) { } window.zipItems = async function(el_items, targetDirPath, download = true) { - const zip = new JSZip(); + const zip_operation_id = window.operation_id++; + window.operation_cancelled[zip_operation_id] = false; + let terminateOp = () => {} // if single item, convert to array el_items = Array.isArray(el_items) ? el_items : [el_items]; @@ -1992,44 +1994,70 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { // create progress window let start_ts = Date.now(); let progwin, progwin_timeout; - // only show progress window if it takes longer than 500ms to download + // only show progress window if it takes longer than 500ms progwin_timeout = setTimeout(async () => { - progwin = await UIWindowProgress(); + progwin = await UIWindowProgress({ + title: i18n('zip'), + icon: window.icons[`app-icon-uploader.svg`], + operation_id: zip_operation_id, + show_progress: true, + on_cancel: () => { + window.operation_cancelled[zip_operation_id] = true; + terminateOp(); + }, + }); + progwin?.set_status(i18n('zip', 'Selection(s)')); }, 500); - for (const el_item of el_items) { + let toBeZipped = {}; + + let perItemAdditionProgress = window.zippingProgressConfig.SEQUENCING / el_items.length; + let currentProgress = 0; + for (let idx = 0; idx < el_items.length; idx++) { + const el_item = el_items[idx]; + if(window.operation_cancelled[zip_operation_id]) return; let targetPath = $(el_item).attr('data-path'); + // if directory, zip the directory if($(el_item).attr('data-is_dir') === '1'){ - progwin?.set_status(i18n('reading_file', targetPath)); + progwin?.set_status(i18n('reading', path.basename(targetPath))); // Recursively read the directory let children = await readDirectoryRecursive(targetPath); // Add files to the zip - for (const child of children) { + for (let cIdx = 0; cIdx < children.length; cIdx++) { + const child = children[cIdx]; let relativePath; if(el_items.length === 1) relativePath = child.relativePath; else relativePath = path.basename(targetPath) + '/' + child.relativePath; - - // update progress window - progwin?.set_status(i18n('zipping_file', relativePath)); // read file content + progwin?.set_status(i18n('sequencing', child.relativePath)); let content = await puter.fs.read(child.path); try{ - zip.file(relativePath, content, {binary: true}); + toBeZipped = { + ...toBeZipped, + [relativePath]: [await streamToUint8Array(content), {level: 9}] + } }catch(e){ console.error(e); } + currentProgress += perItemAdditionProgress / children.length; + progwin?.set_progress(currentProgress.toPrecision(2)); } - } - // if item is a file, zip the file + // if item is a file, add the file to be zipped else{ - let content = await puter.fs.read(targetPath); - zip.file(path.basename(targetPath), content, {binary: true}); + progwin?.set_status(i18n('reading', path.basename($(el_items[0]).attr('data-path')))); + let content = await puter.fs.read(targetPath) + toBeZipped = { + ...toBeZipped, + [path.basename(targetPath)]: [await streamToUint8Array(content), {level: 9}] + } + currentProgress += perItemAdditionProgress; + progwin?.set_progress(currentProgress.toPrecision(2)); } } @@ -2040,15 +2068,28 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { else zipName = 'Archive'; - // Generate the zip file - zip.generateAsync({ type: "blob" }) - .then(async function (content) { + progwin?.set_status(i18n('zipping', zipName + ".zip")); + progwin?.set_progress(currentProgress.toPrecision(2)); + terminateOp = fflate.zip(toBeZipped, { level: 9 }, async (err, zippedContents)=>{ + currentProgress += window.zippingProgressConfig.ZIPPING; + if(err) { + // close progress window + clearTimeout(progwin_timeout); + setTimeout(() => { + progwin?.close(); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); + // handle errors + // TODO: Display in progress dialog + console.error("Error in zipping files: ", err); + } else { + let zippedBlob = new Blob([new Uint8Array(zippedContents, zippedContents.byteOffset, zippedContents.length)]); + // Trigger the download if(download){ - const url = URL.createObjectURL(content); + const url = URL.createObjectURL(zippedBlob); const a = document.createElement("a"); a.href = url; - a.download = zipName; + a.download = zipName+".zip"; document.body.appendChild(a); a.click(); @@ -2057,26 +2098,21 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { URL.revokeObjectURL(url); } // save - else - await puter.fs.write(targetDirPath + '/' + zipName + ".zip", content, {overwrite: false, dedupeName: true}) + else { + progwin?.set_status(i18n('writing', zipName + ".zip")); + currentProgress += window.zippingProgressConfig.WRITING; + progwin?.set_progress(currentProgress.toPrecision(2)); + await puter.fs.write(targetDirPath + '/' + zipName + ".zip", zippedBlob, { overwrite: false, dedupeName: true }) + progwin?.set_progress(window.zippingProgressConfig.TOTAL); + } // close progress window clearTimeout(progwin_timeout); setTimeout(() => { progwin?.close(); - }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); - }) - .catch(function (err) { - // close progress window - clearTimeout(progwin_timeout); - setTimeout(() => { - progwin?.close(); - }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); - - // handle errors - // TODO: Display in progress dialog - console.error("Error in zipping files: ", err); - }); + }, Math.max(0, window.zip_progress_hide_delay - (Date.now() - start_ts))); + } + }); } async function readDirectoryRecursive(path, baseDir = '') { From a9bebdd7f07a25f4dbfa61fdd34007d30bf3d6fa Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 15:26:26 +0530 Subject: [PATCH 08/33] fixed typo --- src/gui/src/UI/UIItem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/src/UI/UIItem.js b/src/gui/src/UI/UIItem.js index bac63d01..49adddfd 100644 --- a/src/gui/src/UI/UIItem.js +++ b/src/gui/src/UI/UIItem.js @@ -1201,11 +1201,11 @@ function UIItem(options){ html: i18n('unzip'), onClick: async function(){ const zip = new JSZip(); - let filPath = $(el_item).attr('data-path'); + let filePath = $(el_item).attr('data-path'); let file = puter.fs.read($(el_item).attr('data-path')); zip.loadAsync(file).then(async function (zip) { - const rootdir = await puter.fs.mkdir(path.dirname(filPath) + '/' + path.basename(filPath, '.zip'), {dedupeName: true}); + const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), {dedupeName: true}); Object.keys(zip.files).forEach(async function (filename) { if(filename.endsWith('/')) await puter.fs.mkdir(rootdir.path +'/' + filename, {createMissingParents: true}); From a93236118f04ddb8405081cc85b987d6ab163007 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 15:32:31 +0530 Subject: [PATCH 09/33] redirected unzip to helper method --- src/gui/src/UI/UIItem.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/gui/src/UI/UIItem.js b/src/gui/src/UI/UIItem.js index 49adddfd..c554adb5 100644 --- a/src/gui/src/UI/UIItem.js +++ b/src/gui/src/UI/UIItem.js @@ -1200,24 +1200,8 @@ function UIItem(options){ menu_items.push({ html: i18n('unzip'), onClick: async function(){ - const zip = new JSZip(); let filePath = $(el_item).attr('data-path'); - let file = puter.fs.read($(el_item).attr('data-path')); - - zip.loadAsync(file).then(async function (zip) { - const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), {dedupeName: true}); - Object.keys(zip.files).forEach(async function (filename) { - if(filename.endsWith('/')) - await puter.fs.mkdir(rootdir.path +'/' + filename, {createMissingParents: true}); - zip.files[filename].async('blob').then(async function (fileData) { - await puter.fs.write(rootdir.path +'/' + filename, fileData); - }).catch(function (e) { - // UIAlert(e.message); - }) - }) - }).catch(function (e) { - // UIAlert(e.message); - }) + window.unzipItem(filePath) } }) } From deb8c4e13be22fe96d0c1f7f393d303a3c06000e Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 16:00:01 +0530 Subject: [PATCH 10/33] added status message terms --- src/gui/src/i18n/translations/en.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/src/i18n/translations/en.js b/src/gui/src/i18n/translations/en.js index afb7e6f3..45118267 100644 --- a/src/gui/src/i18n/translations/en.js +++ b/src/gui/src/i18n/translations/en.js @@ -304,6 +304,7 @@ const en = { undo: 'Undo', unlimited: 'Unlimited', unzip: "Unzip", + unzipping: "Unzipping %strong%", upload: 'Upload', upload_here: 'Upload here', usage: 'Usage', From f6541fc7937726a024f5ee08a319629061c3f1c6 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 16:01:18 +0530 Subject: [PATCH 11/33] convention implemented definition header --- src/gui/src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index cd92f292..99c37e19 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -1960,7 +1960,7 @@ window.checkUserSiteRelationship = async function(origin) { } // Converts a Blob to a Uint8Array [local helper module] -let streamToUint8Array = async function(blob) { +async function streamToUint8Array(blob) { const totalLength = blob.size; const reader = blob.stream().getReader(); let chunks = []; From 09d10cb29bdea4a439836596d3888ce39f230172 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 16:03:09 +0530 Subject: [PATCH 12/33] rectified progress window for unzip operation --- src/gui/src/helpers.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 99c37e19..db952a45 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2148,12 +2148,25 @@ window.sleep = function(ms){ } window.unzipItem = async function(itemPath) { + const unzip_operation_id = window.operation_id++; + window.operation_cancelled[unzip_operation_id] = false; + let terminateOp = () => {}; // create progress window let start_ts = Date.now(); let progwin, progwin_timeout; // only show progress window if it takes longer than 500ms to download progwin_timeout = setTimeout(async () => { - progwin = await UIWindowProgress(); + progwin = await UIWindowProgress({ + title: i18n('unzip'), + icon: window.icons[`app-icon-uploader.svg`], + operation_id: unzip_operation_id, + show_progress: true, + on_cancel: () => { + window.operation_cancelled[unzip_operation_id] = true; + terminateOp(); + }, + }); + progwin?.set_status(i18n('unzip', 'Selection')); }, 500); const zip = new JSZip(); From 5b477c2cac8d96155a3710b4eb25034d6f18cfe7 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 16:10:40 +0530 Subject: [PATCH 13/33] fixed module name --- src/gui/src/helpers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index db952a45..950373a0 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -1960,7 +1960,7 @@ window.checkUserSiteRelationship = async function(origin) { } // Converts a Blob to a Uint8Array [local helper module] -async function streamToUint8Array(blob) { +async function blobToUint8Array(blob) { const totalLength = blob.size; const reader = blob.stream().getReader(); let chunks = []; @@ -2039,7 +2039,7 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { try{ toBeZipped = { ...toBeZipped, - [relativePath]: [await streamToUint8Array(content), {level: 9}] + [relativePath]: [await blobToUint8Array(content), {level: 9}] } }catch(e){ console.error(e); @@ -2054,7 +2054,7 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { let content = await puter.fs.read(targetPath) toBeZipped = { ...toBeZipped, - [path.basename(targetPath)]: [await streamToUint8Array(content), {level: 9}] + [path.basename(targetPath)]: [await blobToUint8Array(content), {level: 9}] } currentProgress += perItemAdditionProgress; progwin?.set_progress(currentProgress.toPrecision(2)); From b9b8229099ded82cf9ab179a5e655c196f114455 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 16:19:46 +0530 Subject: [PATCH 14/33] fixed comments phrasing --- src/gui/src/globals.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/src/globals.js b/src/gui/src/globals.js index 7813b51f..7887888e 100644 --- a/src/gui/src/globals.js +++ b/src/gui/src/globals.js @@ -133,9 +133,9 @@ window.zippingProgressConfig = { } //Assuming uInt8Array conversion a file takes betwneen 45% to 60% of the total progress window.zippingProgressConfig.SEQUENCING = Math.floor(Math.random() * (60 - 45 + 1)) + 45, -//Assuming zipping up uInt8Arrays takes betwneen 23% to 20% of the total progress +//Assuming zipping up uInt8Arrays takes betwneen 20% to 23% of the total progress window.zippingProgressConfig.ZIPPING = Math.floor(Math.random() * (23 - 20 + 1)) + 20, -//Assuming writing a zip file takes betwneen 14% to 10% of the total progress +//Assuming writing a zip file takes betwneen 10% to 14% of the total progress window.zippingProgressConfig.WRITING = Math.floor(Math.random() * (14 - 10 + 1)) + 14, // 'Launch' apps From b9d7a1d2a1f9475ad6a284283bff7de0a0ba89b5 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 17:33:30 +0530 Subject: [PATCH 15/33] added zip support for empty directories --- src/gui/src/helpers.js | 58 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 950373a0..a977ebf1 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2027,22 +2027,32 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { // Add files to the zip for (let cIdx = 0; cIdx < children.length; cIdx++) { const child = children[cIdx]; - let relativePath; - if(el_items.length === 1) - relativePath = child.relativePath; - else - relativePath = path.basename(targetPath) + '/' + child.relativePath; - // read file content - progwin?.set_status(i18n('sequencing', child.relativePath)); - let content = await puter.fs.read(child.path); - try{ + if (!child.relativePath) { + // Add empty directiories to the zip toBeZipped = { ...toBeZipped, - [relativePath]: [await blobToUint8Array(content), {level: 9}] + [path.basename(child.path)+"/"]: [await blobToUint8Array(new Blob()), { level: 9 }] + } + } else { + // Add files from directory to the zip + let relativePath; + if (el_items.length === 1) + relativePath = child.relativePath; + else + relativePath = path.basename(targetPath) + '/' + child.relativePath; + + // read file content + progwin?.set_status(i18n('sequencing', child.relativePath)); + let content = await puter.fs.read(child.path); + try { + toBeZipped = { + ...toBeZipped, + [relativePath]: [await blobToUint8Array(content), { level: 9 }] + } + } catch (e) { + console.error(e); } - }catch(e){ - console.error(e); } currentProgress += perItemAdditionProgress / children.length; progwin?.set_progress(currentProgress.toPrecision(2)); @@ -2121,16 +2131,20 @@ async function readDirectoryRecursive(path, baseDir = '') { // Read the directory const entries = await puter.fs.readdir(path); - // Process each entry - for (const entry of entries) { - const fullPath = `${path}/${entry.name}`; - if (entry.is_dir) { - // If entry is a directory, recursively read it - const subDirFiles = await readDirectoryRecursive(fullPath, `${baseDir}${entry.name}/`); - allFiles = allFiles.concat(subDirFiles); - } else { - // If entry is a file, add it to the list - allFiles.push({ path: fullPath, relativePath: `${baseDir}${entry.name}` }); + if (entries.length === 0) { + allFiles.push({ path }); + } else { + // Process each entry + for (const entry of entries) { + const fullPath = `${path}/${entry.name}`; + if (entry.is_dir) { + // If entry is a directory, recursively read it + const subDirFiles = await readDirectoryRecursive(fullPath, `${baseDir}${entry.name}/`); + allFiles = allFiles.concat(subDirFiles); + } else { + // If entry is a file, add it to the list + allFiles.push({ path: fullPath, relativePath: `${baseDir}${entry.name}` }); + } } } From 00f2dbdcf032a854c35e0db72cea11bb1e926f17 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:18:30 +0530 Subject: [PATCH 16/33] added window hide delay config --- src/gui/src/globals.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/src/globals.js b/src/gui/src/globals.js index 7887888e..016976e1 100644 --- a/src/gui/src/globals.js +++ b/src/gui/src/globals.js @@ -110,6 +110,7 @@ window.upload_progress_hide_delay = 500; window.active_uploads = {}; window.copy_progress_hide_delay = 1000; window.zip_progress_hide_delay = 2000; +window.unzip_progress_hide_delay = 2000; window.busy_indicator_hide_delay = 600; window.global_element_id = 0; window.operation_id = 0; From 9a2e7016837fc454db50cd57cc603b7d89c4310d Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:21:29 +0530 Subject: [PATCH 17/33] eleminate JSZip invocation --- src/gui/src/helpers.js | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index a977ebf1..1bab56d8 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2183,35 +2183,8 @@ window.unzipItem = async function(itemPath) { progwin?.set_status(i18n('unzip', 'Selection')); }, 500); - const zip = new JSZip(); - let filPath = itemPath; - let file = puter.fs.read(filPath); - - zip.loadAsync(file).then(async function (zip) { - const rootdir = await puter.fs.mkdir(path.dirname(filPath) + '/' + path.basename(filPath, '.zip'), {dedupeName: true}); - Object.keys(zip.files).forEach(async function (filename) { - if(filename.endsWith('/')) - await puter.fs.mkdir(rootdir.path +'/' + filename, {createMissingParents: true}); - zip.files[filename].async('blob').then(async function (fileData) { - await puter.fs.write(rootdir.path +'/' + filename, fileData); - }).catch(function (e) { - // UIAlert(e.message); - }) - }) - // close progress window - clearTimeout(progwin_timeout); - setTimeout(() => { - progwin?.close(); - }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); - - }).catch(function (e) { - // UIAlert(e.message); - // close progress window - clearTimeout(progwin_timeout); - setTimeout(() => { - progwin?.close(); - }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); - }) + let filePath = itemPath; + } window.rename_file = async(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, is_undo = false)=>{ From e5f0f46633640376b329e83152df16bb045a59d3 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:22:07 +0530 Subject: [PATCH 18/33] added blob to uInt8Array conversion --- src/gui/src/helpers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 1bab56d8..60c090f6 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2184,7 +2184,8 @@ window.unzipItem = async function(itemPath) { }, 500); let filePath = itemPath; - + + let file = await blobToUint8Array(await puter.fs.read(filePath)); } window.rename_file = async(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, is_undo = false)=>{ From a79cc040e812e5663aeae9a586790bc458e68dd5 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:22:50 +0530 Subject: [PATCH 19/33] implemented fflate unzip operation --- src/gui/src/helpers.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 60c090f6..65e0f226 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2185,7 +2185,10 @@ window.unzipItem = async function(itemPath) { let filePath = itemPath; - let file = await blobToUint8Array(await puter.fs.read(filePath)); + let file = await blobToUint8Array(await puter.fs.read(filePath)); + terminateOp = fflate.unzip(file, async (err, unzipped) => { + + }); } window.rename_file = async(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, is_undo = false)=>{ From 2a82579eb8cdfe808181cdb6e1c7fb64b927897d Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:23:10 +0530 Subject: [PATCH 20/33] added unzip error handler --- src/gui/src/helpers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 65e0f226..cd3aa242 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2187,7 +2187,14 @@ window.unzipItem = async function(itemPath) { let file = await blobToUint8Array(await puter.fs.read(filePath)); terminateOp = fflate.unzip(file, async (err, unzipped) => { - + if(err) { + UIAlert(e.message); + // close progress window + clearTimeout(progwin_timeout); + setTimeout(() => { + progwin?.close(); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); + } }); } From e992e4d5d4d913a368dd1c981c4ce3152a5ec4b7 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:25:10 +0530 Subject: [PATCH 21/33] unzipped directory creation --- src/gui/src/helpers.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index cd3aa242..f89b2b59 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2194,6 +2194,18 @@ window.unzipItem = async function(itemPath) { setTimeout(() => { progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); + } else { + const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true }); + Object.keys(unzipped).forEach(async (fileItem) => { + let dirLevel, fileName; + let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); + if (fileItem.includes("/")) { + [dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)] + await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); + } else { + fileName = fileItem; + } + }); } }); } From a09dd2941677bd436078e7163d2a38ffdba5eeed Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:25:40 +0530 Subject: [PATCH 22/33] added empty directory check and file creation --- src/gui/src/helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index f89b2b59..497c3a80 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2205,6 +2205,7 @@ window.unzipItem = async function(itemPath) { } else { fileName = fileItem; } + fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData); }); } }); From f0f8e454f99a79a49cd4d99f5db85fbea7b0aa11 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 20:27:12 +0530 Subject: [PATCH 23/33] added Promises to handle multiple file creation and closing progress dialog --- src/gui/src/helpers.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 497c3a80..97a6a091 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2196,16 +2196,33 @@ window.unzipItem = async function(itemPath) { }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); } else { const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true }); - Object.keys(unzipped).forEach(async (fileItem) => { - let dirLevel, fileName; - let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); - if (fileItem.includes("/")) { - [dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)] - await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); - } else { - fileName = fileItem; - } - fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData); + let queuedFileWrites = [] + Object.keys(unzipped).forEach(fileItem => { + let fileWriteProcess = new Promise(async (resolve, reject) => { + try { + let dirLevel, fileName; + let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); + if (fileItem.includes("/")) { + [dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)] + // await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); + } else { + fileName = fileItem; + } + fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData); + resolve(); + } catch (e) { + UIAlert(e.message); + reject(); + } + }) + queuedFileWrites.push(fileWriteProcess); + }); + Promise.all(queuedFileWrites).then(() => { + // close progress window + clearTimeout(progwin_timeout); + setTimeout(() => { + progwin?.close(); + }, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts))); }); } }); From e252567c889616435863e5e16f3f7c57ba5bb189 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 21:19:42 +0530 Subject: [PATCH 24/33] Added progress dialog details --- src/gui/src/helpers.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 97a6a091..5bc34b82 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2184,9 +2184,16 @@ window.unzipItem = async function(itemPath) { }, 500); let filePath = itemPath; + let currentProgress = window.zippingProgressConfig.SEQUENCING; + progwin?.set_status(i18n('sequencing', path.basename(filePath))); let file = await blobToUint8Array(await puter.fs.read(filePath)); + progwin?.set_progress(currentProgress.toPrecision(2)); + + progwin?.set_status(i18n('unzipping', path.basename(filePath))); terminateOp = fflate.unzip(file, async (err, unzipped) => { + currentProgress += window.zippingProgressConfig.ZIPPING; + progwin?.set_progress(currentProgress.toPrecision(2)); if(err) { UIAlert(e.message); // close progress window @@ -2197,6 +2204,7 @@ window.unzipItem = async function(itemPath) { } else { const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true }); let queuedFileWrites = [] + let perItemProgress = window.zippingProgressConfig.WRITING / Object.keys(unzipped).length; Object.keys(unzipped).forEach(fileItem => { let fileWriteProcess = new Promise(async (resolve, reject) => { try { @@ -2204,11 +2212,14 @@ window.unzipItem = async function(itemPath) { let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); if (fileItem.includes("/")) { [dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)] - // await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); + await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); } else { fileName = fileItem; } + progwin?.set_status(i18n('writing', fileItem)); fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData); + currentProgress += perItemProgress; + progwin?.set_progress(currentProgress.toPrecision(2)); resolve(); } catch (e) { UIAlert(e.message); @@ -2218,6 +2229,7 @@ window.unzipItem = async function(itemPath) { queuedFileWrites.push(fileWriteProcess); }); Promise.all(queuedFileWrites).then(() => { + progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2)); // close progress window clearTimeout(progwin_timeout); setTimeout(() => { From 822d850513a52fc0f54bef65eaf61e8f546be133 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 6 Oct 2024 21:25:46 +0530 Subject: [PATCH 25/33] purge JSZip --- eslint.config.js | 1 - src/gui/puter-gui.json | 1 - src/gui/src/lib/jszip-3.10.1.min.js | 13 ------------- src/gui/src/static-assets.js | 1 - src/gui/webpack/libPaths.cjs | 1 - 5 files changed, 17 deletions(-) delete mode 100644 src/gui/src/lib/jszip-3.10.1.min.js diff --git a/eslint.config.js b/eslint.config.js index 269ef63b..45a9d082 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -72,7 +72,6 @@ export default [ "iro": true, // iro.js color picker "$": true, // jQuery "jQuery": true, // jQuery - "JSZip": true, // JSZip "_": true, // lodash "QRCode": true, // qrcode "io": true, // socket.io diff --git a/src/gui/puter-gui.json b/src/gui/puter-gui.json index ef505266..3f40f762 100644 --- a/src/gui/puter-gui.json +++ b/src/gui/puter-gui.json @@ -14,7 +14,6 @@ "/lib/timeago.min.js", "/lib/iro.min.js", "/lib/isMobile.min.js", - "/lib/jszip-3.10.1.min.js", "/lib/fflate-0.8.2.min.js" ], "css_paths": [ diff --git a/src/gui/src/lib/jszip-3.10.1.min.js b/src/gui/src/lib/jszip-3.10.1.min.js deleted file mode 100644 index ff4cfd5e..00000000 --- a/src/gui/src/lib/jszip-3.10.1.min.js +++ /dev/null @@ -1,13 +0,0 @@ -/*! - -JSZip v3.10.1 - A JavaScript class for generating and reading zip files - - -(c) 2009-2016 Stuart Knightley -Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown. - -JSZip uses the library pako released under the MIT license : -https://github.com/nodeca/pako/blob/main/LICENSE -*/ - -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JSZip=e()}}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h)}return o[r].exports}for(var l="function"==typeof require&&require,e=0;e>2,s=(3&t)<<4|r>>4,a=1>6:64,o=2>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l}},{"./support":30,"./utils":32}],2:[function(e,t,r){"use strict";var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){"use strict";var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){"use strict";var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return-1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t.charCodeAt(a))];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,r){"use strict";r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(e,t,r){"use strict";var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n}},{lie:37}],7:[function(e,t,r){"use strict";var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1)},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(e){t.push({data:e,meta:t.meta})}},r.compressWorker=function(e){return new h("Deflate",e)},r.uncompressWorker=function(){return new h("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,r){"use strict";function A(e,t){var r,n="";for(r=0;r>>=8;return n}function n(e,t,r,n,i,s){var a,o,h=e.file,u=e.compression,l=s!==O.utf8encode,f=I.transformTo("string",s(h.name)),c=I.transformTo("string",O.utf8encode(h.name)),d=h.comment,p=I.transformTo("string",s(d)),m=I.transformTo("string",O.utf8encode(d)),_=c.length!==h.name.length,g=m.length!==d.length,b="",v="",y="",w=h.dir,k=h.date,x={crc32:0,compressedSize:0,uncompressedSize:0};t&&!r||(x.crc32=e.crc32,x.compressedSize=e.compressedSize,x.uncompressedSize=e.uncompressedSize);var S=0;t&&(S|=8),l||!_&&!g||(S|=2048);var z=0,C=0;w&&(z|=16),"UNIX"===i?(C=798,z|=function(e,t){var r=e;return e||(r=t?16893:33204),(65535&r)<<16}(h.unixPermissions,w)):(C=20,z|=function(e){return 63&(e||0)}(h.dosPermissions)),a=k.getUTCHours(),a<<=6,a|=k.getUTCMinutes(),a<<=5,a|=k.getUTCSeconds()/2,o=k.getUTCFullYear()-1980,o<<=4,o|=k.getUTCMonth()+1,o<<=5,o|=k.getUTCDate(),_&&(v=A(1,1)+A(B(f),4)+c,b+="up"+A(v.length,2)+v),g&&(y=A(1,1)+A(B(p),4)+m,b+="uc"+A(y.length,2)+y);var E="";return E+="\n\0",E+=A(S,2),E+=u.magic,E+=A(a,2),E+=A(o,2),E+=A(x.crc32,4),E+=A(x.compressedSize,4),E+=A(x.uncompressedSize,4),E+=A(f.length,2),E+=A(b.length,2),{fileRecord:R.LOCAL_FILE_HEADER+E+f+b,dirRecord:R.CENTRAL_FILE_HEADER+A(C,2)+E+A(p.length,2)+"\0\0\0\0"+A(z,4)+A(n,4)+f+b+p}}var I=e("../utils"),i=e("../stream/GenericWorker"),O=e("../utf8"),B=e("../crc32"),R=e("../signature");function s(e,t,r,n){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=r,this.encodeFileName=n,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}I.inherits(s,i),s.prototype.push=function(e){var t=e.meta.percent||0,r=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,i.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:r?(t+100*(r-n-1))/r:100}}))},s.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var r=n(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:r.fileRecord,meta:{percent:0}})}else this.accumulate=!0},s.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,r=n(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),t)this.push({data:function(e){return R.DATA_DESCRIPTOR+A(e.crc32,4)+A(e.compressedSize,4)+A(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},s.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)r=(r<<8)+this.byteAt(t);return this.index+=e,r},readString:function(e){return n.transformTo("string",this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i},{"../utils":32}],19:[function(e,t,r){"use strict";var n=e("./Uint8ArrayReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,r){"use strict";var n=e("./DataReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,r){"use strict";var n=e("./ArrayReader");function i(e){n.call(this,e)}e("../utils").inherits(i,n),i.prototype.readData=function(e){if(this.checkOffset(e),0===e)return new Uint8Array(0);var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,r){"use strict";var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=e("./Uint8ArrayReader");t.exports=function(e){var t=n.getTypeOf(e);return n.checkSupport(t),"string"!==t||i.uint8array?"nodebuffer"===t?new o(e):i.uint8array?new h(n.transformTo("uint8array",e)):new s(n.transformTo("array",e)):new a(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,r){"use strict";r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\b"},{}],24:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../utils");function s(e){n.call(this,"ConvertWorker to "+e),this.destType=e}i.inherits(s,n),s.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=s},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,r){"use strict";var n=e("./GenericWorker"),i=e("../crc32");function s(){n.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}e("../utils").inherits(s,n),s.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=s},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataLengthProbe for "+e),this.propName=e,this.withStreamInfo(e,0)}n.inherits(s,i),s.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=s},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,r){"use strict";var n=e("../utils"),i=e("./GenericWorker");function s(e){i.call(this,"DataWorker");var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=n.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}n.inherits(s,i),s.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},s.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,n.delay(this._tickAndRepeat,[],this)),!0)},s.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(n.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},s.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":e=this.data.substring(this.index,t);break;case"uint8array":e=this.data.subarray(this.index,t);break;case"array":case"nodebuffer":e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=s},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,r){"use strict";function n(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}n.prototype={push:function(e){this.emit("data",e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(e){this.emit("error",e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var r=0;r "+e:e}},t.exports=n},{}],29:[function(e,t,r){"use strict";var h=e("../utils"),i=e("./ConvertWorker"),s=e("./GenericWorker"),u=e("../base64"),n=e("../support"),a=e("../external"),o=null;if(n.nodestream)try{o=e("../nodejs/NodejsStreamOutputAdapter")}catch(e){}function l(e,o){return new a.Promise(function(t,r){var n=[],i=e._internalType,s=e._outputType,a=e._mimeType;e.on("data",function(e,t){n.push(e),o&&o(t)}).on("error",function(e){n=[],r(e)}).on("end",function(){try{var e=function(e,t,r){switch(e){case"blob":return h.newBlob(h.transformTo("arraybuffer",t),r);case"base64":return u.encode(t);default:return h.transformTo(e,t)}}(s,function(e,t){var r,n=0,i=null,s=0;for(r=0;r>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t}(e)},s.utf8decode=function(e){return h.nodebuffer?o.transformTo("nodebuffer",e).toString("utf-8"):function(e){var t,r,n,i,s=e.length,a=new Array(2*s);for(t=r=0;t>10&1023,a[r++]=56320|1023&n)}return a.length!==r&&(a.subarray?a=a.subarray(0,r):a.length=r),o.applyFromCharCode(a)}(e=o.transformTo(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.uint8array){var r=t;(t=new Uint8Array(r.length+this.leftOver.length)).set(this.leftOver,0),t.set(r,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var n=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({data:s.utf8decode(i),meta:e.meta})},a.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:s.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},s.Utf8DecodeWorker=a,o.inherits(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta})},s.Utf8EncodeWorker=l},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){"use strict";var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r>8;this.dir=!!(16&this.externalFileAttributes),0==e&&(this.dosPermissions=63&this.externalFileAttributes),3==e&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,r,n,i=e.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});e.index+4>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t},r.buf2binstring=function(e){return l(e,e.length)},r.binstring2buf=function(e){for(var t=new h.Buf8(e.length),r=0,n=t.length;r>10&1023,o[n++]=56320|1023&i)}return l(o,n)},r.utf8border=function(e,t){var r;for((t=t||e.length)>e.length&&(t=e.length),r=t-1;0<=r&&128==(192&e[r]);)r--;return r<0?t:0===r?t:r+u[e[r]]>t?r:t}},{"./common":41}],43:[function(e,t,r){"use strict";t.exports=function(e,t,r,n){for(var i=65535&e|0,s=e>>>16&65535|0,a=0;0!==r;){for(r-=a=2e3>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a>>8^i[255&(e^t[a])];return-1^e}},{}],46:[function(e,t,r){"use strict";var h,c=e("../utils/common"),u=e("./trees"),d=e("./adler32"),p=e("./crc32"),n=e("./messages"),l=0,f=4,m=0,_=-2,g=-1,b=4,i=2,v=8,y=9,s=286,a=30,o=19,w=2*s+1,k=15,x=3,S=258,z=S+x+1,C=42,E=113,A=1,I=2,O=3,B=4;function R(e,t){return e.msg=n[t],t}function T(e){return(e<<1)-(4e.avail_out&&(r=e.avail_out),0!==r&&(c.arraySet(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))}function N(e,t){u._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function U(e,t){e.pending_buf[e.pending++]=t}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&sh&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=x&&(e.ins_h=(e.ins_h<=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(j(e),0===e.lookahead&&t===l)return A;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((0===e.strstart||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,N(e,!1),0===e.strm.avail_out))return A;if(e.strstart-e.block_start>=e.w_size-z&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):(e.strstart>e.block_start&&(N(e,!1),e.strm.avail_out),A)}),new M(4,4,8,4,Z),new M(4,5,16,8,Z),new M(4,6,32,32,Z),new M(4,4,16,16,W),new M(8,16,32,32,W),new M(8,16,128,128,W),new M(8,32,128,256,W),new M(32,128,258,1024,W),new M(32,258,258,4096,W)],r.deflateInit=function(e,t){return Y(e,t,v,15,8,0)},r.deflateInit2=Y,r.deflateReset=K,r.deflateResetKeep=G,r.deflateSetHeader=function(e,t){return e&&e.state?2!==e.state.wrap?_:(e.state.gzhead=t,m):_},r.deflate=function(e,t){var r,n,i,s;if(!e||!e.state||5>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=p(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=E);else{var a=v+(n.w_bits-8<<4)<<8;a|=(2<=n.strategy||n.level<2?0:n.level<6?1:6===n.level?2:3)<<6,0!==n.strstart&&(a|=32),a+=31-a%31,n.status=E,P(n,a),0!==n.strstart&&(P(n,e.adler>>>16),P(n,65535&e.adler)),e.adler=1}if(69===n.status)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending!==n.pending_buf_size));)U(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=73)}else n.status=73;if(73===n.status)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.gzindex=0,n.status=91)}else n.status=91;if(91===n.status)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),F(e),i=n.pending,n.pending===n.pending_buf_size)){s=1;break}s=n.gzindexi&&(e.adler=p(e.adler,n.pending_buf,n.pending-i,i)),0===s&&(n.status=103)}else n.status=103;if(103===n.status&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else{if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<>>=y,p-=y),p<15&&(d+=z[n++]<>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<>>=y,p-=y,(y=s-a)>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function s(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new I.Buf16(320),this.work=new I.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function a(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=P,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new I.Buf32(n),t.distcode=t.distdyn=new I.Buf32(i),t.sane=1,t.back=-1,N):U}function o(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,a(e)):U}function h(e,t){var r,n;return e&&e.state?(n=e.state,t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=s.wsize?(I.arraySet(s.window,t,r-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n<(i=s.wsize-s.wnext)&&(i=n),I.arraySet(s.window,t,r-n,i,s.wnext),(n-=i)?(I.arraySet(s.window,t,r-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",r.mode=30;break}if(8!=(15&u)){e.msg="unknown compression method",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>>8&255,r.check=B(r.check,E,2,0)),l=u=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286>>=3,l-=3}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=_,l-=_,r.lens[r.have++]=b;else{if(16===b){for(z=_+2;l>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2}else if(17===b){for(z=_+3;l>>=_)),u>>>=3,l-=3}else{for(z=_+7;l>>=_)),u>>>=7,l-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=k}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=a-r.offset,d=r.length;for(hd?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]]}if(k>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;n++)s[n]=a=a+r[n-1]<<1;for(i=0;i<=t;i++){var o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o))}}function W(e){var t;for(t=0;t>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u>=7;n>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{"../utils/common":41}],53:[function(e,t,r){"use strict";t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,r){(function(e){!function(r,n){"use strict";if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i="[object process]"==={}.toString.call(r.process)?function(e){process.nextTick(function(){c(e)})}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1},r.postMessage("","*"),r.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",d,!1):r.attachEvent("onmessage",d),function(e){r.postMessage(a+e,"*")}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data)},function(e){t.port2.postMessage(e)}):l&&"onreadystatechange"in l.createElement("script")?(s=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null},s.appendChild(t)}):function(e){setTimeout(c,0,e)},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r Date: Sun, 6 Oct 2024 21:27:03 +0530 Subject: [PATCH 26/33] added fflate to lint check --- eslint.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eslint.config.js b/eslint.config.js index 45a9d082..64ffeb03 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -72,6 +72,7 @@ export default [ "iro": true, // iro.js color picker "$": true, // jQuery "jQuery": true, // jQuery + "fflate": true, // fflate "_": true, // lodash "QRCode": true, // qrcode "io": true, // socket.io From d39b7a8972df03836530136b1ede0d3986b6e451 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sat, 19 Oct 2024 23:52:21 +0530 Subject: [PATCH 27/33] record unique directory list --- src/puter-js/src/modules/FileSystem/operations/upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index ab8778ea..17366589 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -130,6 +130,7 @@ const upload = async function(items, dirPath, options = {}){ // Will hold directories and files to be uploaded let dirs = []; + let uniqueDirs = {} let files = []; // Separate files from directories From fc461c87351092842bb9c39cee22561c9e4d8766 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 00:04:36 +0530 Subject: [PATCH 28/33] added absolute file path processing --- src/puter-js/src/modules/FileSystem/operations/upload.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index 17366589..e056a3d7 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -142,8 +142,13 @@ const upload = async function(items, dirPath, options = {}){ if(entries[i].isDirectory) dirs.push({path: path.join(dirPath, entries[i].finalPath ? entries[i].finalPath : entries[i].fullPath)}); // also files - else - files.push(entries[i]) + else{ + // Dragged and dropped files do not have a finalPath property and hence the fileItem will go undefined. + // In such cases, we need default to creating the files as uploaded by the user. + let fileItem = entries[i].finalPath ? entries[i].finalPath : entries[i].fullPath; + let [dirLevel, fileName] = [fileItem?.slice(0, fileItem?.lastIndexOf("/")), fileItem?.slice(fileItem?.lastIndexOf("/") + 1)] + + } // stats about the upload to come if(entries[i].size !== undefined){ total_size += (entries[i].size); From f32b1cfce800764559f6544e82db79c68445c58c Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 00:05:40 +0530 Subject: [PATCH 29/33] added option to create parent directories for programmatic file drops --- .../src/modules/FileSystem/operations/upload.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index e056a3d7..8ed4eae2 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -148,6 +148,17 @@ const upload = async function(items, dirPath, options = {}){ let fileItem = entries[i].finalPath ? entries[i].finalPath : entries[i].fullPath; let [dirLevel, fileName] = [fileItem?.slice(0, fileItem?.lastIndexOf("/")), fileItem?.slice(fileItem?.lastIndexOf("/") + 1)] + // If file name is blank then we need to create only an empty directory. + // On the other hand if the file name is not blank(could be undefined), we need to create the file. + fileName != "" && files.push(entries[i]) + if (options.createFileParent && fileItem.includes('/')) { + let filePath = path.join(dirPath, dirLevel) + // Prevent duplicate parent directory creation + if(!uniqueDirs[filePath]){ + uniqueDirs[filePath] = true; + dirs.push({path: filePath}); + } + } } // stats about the upload to come if(entries[i].size !== undefined){ From 4fdea7db6661282749ea41f6de7eb1ce33177b10 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 00:06:30 +0530 Subject: [PATCH 30/33] offloaded write operations to Upload module --- src/gui/src/helpers.js | 56 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 5bc34b82..dbbd5a11 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2203,39 +2203,35 @@ window.unzipItem = async function(itemPath) { }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); } else { const rootdir = await puter.fs.mkdir(path.dirname(filePath) + '/' + path.basename(filePath, '.zip'), { dedupeName: true }); - let queuedFileWrites = [] let perItemProgress = window.zippingProgressConfig.WRITING / Object.keys(unzipped).length; + let queuedFileWrites = [] Object.keys(unzipped).forEach(fileItem => { - let fileWriteProcess = new Promise(async (resolve, reject) => { - try { - let dirLevel, fileName; - let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); - if (fileItem.includes("/")) { - [dirLevel, fileName] = [fileItem.slice(0, fileItem.lastIndexOf("/")), fileItem.slice(fileItem.lastIndexOf("/") + 1)] - await puter.fs.mkdir(rootdir.path + '/' + dirLevel, { createMissingParents: true }); - } else { - fileName = fileItem; - } - progwin?.set_status(i18n('writing', fileItem)); - fileName != "" && await puter.fs.write(rootdir.path + '/' + fileItem, fileData); - currentProgress += perItemProgress; - progwin?.set_progress(currentProgress.toPrecision(2)); - resolve(); - } catch (e) { - UIAlert(e.message); - reject(); - } - }) - queuedFileWrites.push(fileWriteProcess); - }); - Promise.all(queuedFileWrites).then(() => { - progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2)); - // close progress window - clearTimeout(progwin_timeout); - setTimeout(() => { - progwin?.close(); - }, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts))); + try { + let fileData = new Blob([new Uint8Array(unzipped[fileItem], unzipped[fileItem].byteOffset, unzipped[fileItem].length)]); + progwin?.set_status(i18n('writing', fileItem)); + queuedFileWrites.push(new File([fileData], fileItem)) + currentProgress += perItemProgress; + progwin?.set_progress(currentProgress.toPrecision(2)); + } catch (e) { + UIAlert(e.message); + } }); + queuedFileWrites.length && puter.fs.upload( + // what to upload + queuedFileWrites, + // where to upload + rootdir.path + '/', + // options + { + createFileParent: true + } + ); + progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2)); + // close progress window + clearTimeout(progwin_timeout); + setTimeout(() => { + progwin?.close(); + }, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts))); } }); } From a646b02e45950977aef87f13d55a806568de96aa Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 02:00:35 +0530 Subject: [PATCH 31/33] provide incremental directories to mkdir --- .../src/modules/FileSystem/operations/upload.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index 8ed4eae2..ea2dcbad 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -152,12 +152,16 @@ const upload = async function(items, dirPath, options = {}){ // On the other hand if the file name is not blank(could be undefined), we need to create the file. fileName != "" && files.push(entries[i]) if (options.createFileParent && fileItem.includes('/')) { - let filePath = path.join(dirPath, dirLevel) - // Prevent duplicate parent directory creation - if(!uniqueDirs[filePath]){ - uniqueDirs[filePath] = true; - dirs.push({path: filePath}); - } + let incrementalDir; + dirLevel.split('/').forEach((directory) => { + incrementalDir = incrementalDir ? incrementalDir + '/' + directory : directory; + let filePath = path.join(dirPath, incrementalDir) + // Prevent duplicate parent directory creation + if(!uniqueDirs[filePath]){ + uniqueDirs[filePath] = true; + dirs.push({path: filePath}); + } + }) } } // stats about the upload to come From fabc21ecf7b2addf227b38c2e628371a7229f22f Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 02:00:58 +0530 Subject: [PATCH 32/33] fixed sorting logic on directory list --- src/puter-js/src/modules/FileSystem/operations/upload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/puter-js/src/modules/FileSystem/operations/upload.js b/src/puter-js/src/modules/FileSystem/operations/upload.js index ea2dcbad..8ca19c6d 100644 --- a/src/puter-js/src/modules/FileSystem/operations/upload.js +++ b/src/puter-js/src/modules/FileSystem/operations/upload.js @@ -206,7 +206,7 @@ const upload = async function(items, dirPath, options = {}){ // Generate the requests to create all the // folders in this upload //------------------------------------------------- - dirs.sort(); + dirs.sort((a, b) => b.path.length - a.path.length); let mkdir_requests = []; for(let i=0; i < dirs.length; i++){ From 63b4da5be8faeaca4b2b7f87c6f4105ed9d21bf5 Mon Sep 17 00:00:00 2001 From: 4nshuman Date: Sun, 20 Oct 2024 02:07:07 +0530 Subject: [PATCH 33/33] connected upload's inbuilt progress counter --- src/gui/src/helpers.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index dbbd5a11..99309769 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2223,15 +2223,24 @@ window.unzipItem = async function(itemPath) { rootdir.path + '/', // options { - createFileParent: true + createFileParent: true, + progress: async function(operation_id, op_progress){ + progwin.set_progress(op_progress); + // update title if window is not visible + if(document.visibilityState !== "visible"){ + update_title_based_on_uploads(); + } + }, + success: async function(items){ + progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2)); + // close progress window + clearTimeout(progwin_timeout); + setTimeout(() => { + progwin?.close(); + }, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts))); + } } ); - progwin?.set_progress(window.zippingProgressConfig.TOTAL.toPrecision(2)); - // close progress window - clearTimeout(progwin_timeout); - setTimeout(() => { - progwin?.close(); - }, Math.max(0, window.unzip_progress_hide_delay - (Date.now() - start_ts))); } }); }