file_explorer.html 214 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760
  1. <html>
  2. <head>
  3. <title>File Manager</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/tocas/tocas.css">
  7. <link rel="icon" type="image/png" href="./img/small_icon.png">
  8. <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
  9. <script type="text/javascript" src="../../script/tocas/tocas.js"></script>
  10. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  11. <script type="text/javascript" src="../../script/ao_module.js"></script>
  12. <script type="text/javascript" src="../../script/forge-sha256.min.js"></script>
  13. <script type="text/javascript" src="../../script/qrcode.min.js"></script>
  14. <script>
  15. window.mobilecheck = function() {
  16. var check = false;
  17. (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
  18. return check;
  19. };
  20. </script>
  21. <style>
  22. body{
  23. color:black;
  24. height:100%;
  25. }
  26. @font-face {
  27. font-family: 'TaipeiSansTCBeta-Regular';
  28. src: url('../../script/font/TaipeiSansTCBeta-Regular.ttf');
  29. }
  30. h1, h2, h3, p, span, div,span { font-family: 'TaipeiSansTCBeta-Regular',"Lucida Console", "Courier New", monospace;}
  31. html{
  32. height:100%;
  33. overflow:hidden;
  34. }
  35. body.whiteTheme{
  36. background-color:rgb(250, 250, 250);
  37. }
  38. .darkTheme{
  39. background-color:#242330 !important;
  40. color:white;
  41. }
  42. .whiteTheme{
  43. color:#0d0d0d
  44. }
  45. .navibar{
  46. position:fixed;
  47. width:100%;
  48. padding-left:12px;
  49. padding-right:12px;
  50. padding-top:6px;
  51. padding-bottom:3px;
  52. z-index: 99;
  53. }
  54. .navibar.darkTheme{
  55. background-color:#17161f !important;
  56. border-bottom:2px solid #34b7eb;
  57. }
  58. .navibar.whiteTheme{
  59. /*box-shadow: 0 2px 4px 2px rgb(224, 224, 224);*/
  60. background-color:#fcfcfc;
  61. border-bottom:2px solid #34b7eb;
  62. }
  63. .whiteTheme .button.standard{
  64. box-shadow: 0 1px 1px 0px rgb(190, 190, 190);
  65. border: 0px;
  66. }
  67. .whiteTheme .button.standard:hover{
  68. background-color:#82c2f0 !important;
  69. color:white !important;
  70. }
  71. .ts.button{
  72. margin-bottom:2px;
  73. }
  74. .ts.button.darkTheme{
  75. background-color:#17161f !important;
  76. border: 1px solid #262533;
  77. color:white;
  78. }
  79. .ts.button.active.darkTheme{
  80. background-color:#312f42 !important;
  81. border: 1px solid #262533;
  82. color:white;
  83. }
  84. .ts.button.darkTheme:hover{
  85. background-color:#312f42 !important;
  86. color:white !important;
  87. }
  88. .rightPad{
  89. margin-right:40px;
  90. }
  91. .addressBar{
  92. width:100%;
  93. padding:3px;
  94. min-height: 35px;
  95. padding-top:6px;
  96. }
  97. .breadcrumb.darkTheme{
  98. background-color:transparent;
  99. }
  100. .section.darkTheme{
  101. color:white !important;
  102. background-color:transparent;
  103. }
  104. .selectable{
  105. cursor:pointer;
  106. }
  107. .rightAlign{
  108. position:absolute;
  109. right:0px;
  110. top:3px;
  111. }
  112. .addressText{
  113. padding:5px;
  114. border-radius: 3px;
  115. }
  116. .addressText.darkTheme{
  117. border: 1px solid #262533;
  118. }
  119. .addressText.whiteTheme{
  120. border: 1px solid #cfcfcf;
  121. }
  122. .divider.whiteTheme{
  123. color:#262533 !important;
  124. background-color:transparent;
  125. }
  126. .divider.darkTheme{
  127. background-color:transparent;
  128. color: white !important;
  129. }
  130. #directorySidebar{
  131. padding:12px;
  132. overflow-y:auto;
  133. padding-bottom:20px;
  134. }
  135. #directorySidebar.darkTheme{
  136. border-right:2px solid rgb(25, 24, 31);
  137. color:white;
  138. position:absolute;
  139. }
  140. #directorySidebar.whiteTheme{
  141. border-right:2px solid rgba(219, 226, 241, 0.7);
  142. background-color:#f5f5f5;
  143. color:rgb(44, 44, 44);
  144. position:absolute;
  145. }
  146. #folderView{
  147. position:absolute;
  148. padding-left:2em;
  149. padding-right:2em;
  150. padding-top:2em;
  151. overflow-y:auto;
  152. }
  153. #folderView.whiteTheme{
  154. background-color:white;
  155. }
  156. .item.darkTheme{
  157. color:white;
  158. }
  159. .rightmargin.icon{
  160. margin-right:8px !important;
  161. }
  162. .dir{
  163. cursor:pointer;
  164. }
  165. .dir:hover{
  166. color:#d1d1d1 !important;
  167. }
  168. .dir.item.whiteTheme{
  169. color:rgb(78, 78, 78);
  170. }
  171. .device{
  172. cursor:pointer;
  173. }
  174. .device:hover{
  175. color:#d1d1d1;
  176. }
  177. .accordion.darkTheme{
  178. color:white !important;
  179. }
  180. .accordion.whiteTheme{
  181. background-color:transparent !important;
  182. }
  183. .fileObject{
  184. display:block !important;
  185. cursor:pointer;
  186. overflow-wrap: break-word !important;
  187. -webkit-touch-callout: none;
  188. -webkit-user-select: none;
  189. -khtml-user-select: none;
  190. -moz-user-select: none;
  191. -ms-user-select: none;
  192. user-select: none;
  193. }
  194. .fileObject.darkTheme{
  195. border:1px solid rgb(72, 69, 88) !important;
  196. }
  197. .segmented.list.darkTheme{
  198. border:1px solid rgb(8, 8, 10) !important;
  199. box-shadow: 0 0 0 0;
  200. border-radius: 0px;
  201. }
  202. .fileObject.darkTheme:hover{
  203. background-color:#17161f !important;
  204. }
  205. .fileObject.darkTheme:hover span{
  206. background-color:#17161f !important;
  207. }
  208. .fileObject.whiteTheme:hover{
  209. background-color:#f2f2f2 !important;
  210. }
  211. .fileObject.darkTheme.selected{
  212. background-color:#100f16 !important;
  213. }
  214. .fileObject.darkTheme.selected span{
  215. background-color:#100f16 !important;
  216. }
  217. .fileObject.whiteTheme.selected{
  218. background-color:#d2f2f7 !important;
  219. color:black !important;
  220. }
  221. .mobilePathDisplayWrapper{
  222. width:100%;
  223. margin-bottom:5px;
  224. }
  225. .ts.card.darkTheme{
  226. border:1px solid rgb(72, 69, 88) !important;
  227. box-shadow: 0 0 0 0 transparent;
  228. }
  229. .darkTheme.header{
  230. color:white !important;
  231. background-color:transparent !important;
  232. }
  233. .darkTheme.meta{
  234. color:rgba(255, 255, 255, 0.836) !important;
  235. background-color:transparent !important;
  236. }
  237. .darkTheme.description{
  238. color:white !important;
  239. background-color:transparent !important;
  240. }
  241. .whiteTheme.header{
  242. background-color:transparent;
  243. }
  244. .whiteTheme.meta{
  245. background-color:transparent;
  246. }
  247. .whiteTheme.description{
  248. background-color:transparent;
  249. }
  250. #folderList{
  251. margin-bottom:16px;
  252. }
  253. .msgbox{
  254. padding:3px;
  255. }
  256. .closeMsgButton{
  257. position:absolute;
  258. top:8px;
  259. right:12px;
  260. }
  261. .closeMsgButton{
  262. cursor:pointer;
  263. }
  264. .popup{
  265. position:fixed;
  266. top:30px;
  267. z-index:110;
  268. left:34%;
  269. right:34%;
  270. bottom:30px;
  271. padding-bottom:24px;
  272. border: 0px solid transparent !important;
  273. }
  274. .popup.wide{
  275. left:24%;
  276. right:24%;
  277. }
  278. .popup.darkTheme{
  279. -webkit-box-shadow: 3px 4px 5px 0px rgb(35, 33, 46) ;
  280. -moz-box-shadow: 3px 4px 5px 0px rgb(35, 33, 46);
  281. box-shadow: 3px 4px 5px 0px rgb(35, 33, 46) ;
  282. border: 1px solid rgb(22, 21, 29);
  283. }
  284. .popup.whiteTheme{
  285. -webkit-box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  286. -moz-box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  287. box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  288. border: 1px solid rgb(226, 226, 226);
  289. background-color:white;
  290. }
  291. @media only screen and (max-width: 1920px) {
  292. .popup{
  293. left:35em;
  294. right:35em;
  295. }
  296. .popup.wide{
  297. left:20em;
  298. right:20em;
  299. }
  300. }
  301. @media only screen and (max-width: 1500px) {
  302. .popup{
  303. left:20em;
  304. right:20em;
  305. }
  306. .popup.wide{
  307. left:14em;
  308. right:14em;
  309. }
  310. }
  311. @media only screen and (max-width: 1200px) {
  312. .popup{
  313. left:14em;
  314. right:14em;
  315. }
  316. .popup.wide{
  317. left:5em;
  318. right:5em;
  319. }
  320. }
  321. @media only screen and (max-width: 800px) {
  322. .popup{
  323. left:5em;
  324. right:5em;
  325. }
  326. .popup.wide{
  327. left:2em;
  328. right:2em;
  329. }
  330. }
  331. @media only screen and (max-width: 600px) {
  332. .popup{
  333. position:fixed;
  334. top:5%;
  335. z-index:100;
  336. left:1em;
  337. right:1em;
  338. }
  339. }
  340. .popupheader{
  341. width:100%;
  342. padding:3px;
  343. padding-left:12px;
  344. border-bottom:2px solid #34b7eb;
  345. background-color: #171719;
  346. color: white;
  347. height:29px;
  348. }
  349. .popupcontent{
  350. height: calc(100% - 29px);
  351. overflow:auto;
  352. }
  353. /*
  354. .popupheader.whiteTheme{
  355. background-color:#eee;
  356. color: #232322;
  357. }
  358. .popupheader.darkTheme{
  359. background-color:#111017 !important;
  360. color: white;
  361. }
  362. */
  363. .popupcloser{
  364. position:absolute;
  365. top:5px;
  366. right:0px;
  367. font-size: 120%;
  368. cursor:pointer;
  369. }
  370. .popupbuttons{
  371. cursor:pointer;
  372. padding:5px;
  373. padding-left:12px;
  374. margin-bottom:4px;
  375. border: 1px solid #dedede;
  376. border-radius: 4px;
  377. }
  378. .popupbuttons.primary.whiteTheme{
  379. background-color:#51aded;
  380. box-shadow: 0 2px 1px 0px #34a2ee !important;
  381. border: 1px solid transparent;
  382. color:white;
  383. }
  384. .popupbuttons.negative{
  385. background-color:#ed5151;
  386. box-shadow: 0 2px 1px 0px #ee3434 !important;
  387. border: 1px solid transparent;
  388. color:white;
  389. }
  390. .popupbuttons.primary.darkTheme{
  391. background-color:#413f57 !important;
  392. box-shadow: 0 2px 1px 0px #3c3b50 !important;
  393. border: 1px solid transparent;
  394. color:white;
  395. }
  396. .popupbuttons.negative.darkTheme{
  397. background-color:#ed5151 !important;
  398. }
  399. .popupbuttons.disabled{
  400. opacity: 0.4;
  401. pointer-events: none;
  402. }
  403. .popupbuttons.primary.disabled{
  404. opacity: 0.4;
  405. pointer-events: none;
  406. }
  407. .whiteTheme.allowHover:hover{
  408. background-color:rgba(238, 238, 238, 0.932);
  409. }
  410. .whiteTheme.allowHover.primary:hover{
  411. background-color:#76c0f5;
  412. }
  413. .allowHover.negative:hover{
  414. background-color:#f57676;
  415. }
  416. .allowHover.negative.darkTheme:hover{
  417. background-color:#f57676 !important;
  418. }
  419. .darkTheme.allowHover:hover{
  420. background-color:#111017 !important;
  421. }
  422. .ts.list.darkTheme{
  423. background-color:#464457 !important;
  424. }
  425. input.darkTheme{
  426. color:white !important;
  427. }
  428. .ts.segmented.list.darkTheme .item{
  429. color:white !important;
  430. }
  431. .newFileFormat{
  432. cursor:pointer;
  433. }
  434. .popupWrapper{
  435. position:fixed;
  436. top:0px;
  437. left:0px;
  438. width:100%;
  439. height:100%;
  440. z-index:99;
  441. background-color:rgba(27,27,27,0.5);
  442. display:none;
  443. }
  444. @supports (backdrop-filter: none) {
  445. .popupWrapper {
  446. backdrop-filter: blur(5px);
  447. }
  448. }
  449. .breadcrumb.whiteTheme{
  450. background-color:white;
  451. }
  452. #openWithModuleList{
  453. height:250px;
  454. overflow-y:auto;
  455. }
  456. #openWith .segment.darkTheme{
  457. color:white !important;
  458. }
  459. #openWithModuleList .item{
  460. padding:8px;
  461. padding-left:22px;
  462. border-radius: 2px;
  463. display: flex;
  464. flex-wrap: wrap;
  465. }
  466. #openWithModuleList.darkTheme .item.selected{
  467. background-color:#100f16 !important;
  468. }
  469. #openWithModuleList.whiteTheme .item.selected{
  470. background-color:#51aded !important;
  471. color:white;
  472. }
  473. #openWithModuleList.darkTheme .item.selectable:hover{
  474. background-color:rgba(250,250,250,0.05);
  475. }
  476. #openWithModuleList.whiteTheme .item.selectable:hover{
  477. background-color:rgba(35,35,35,0.14);
  478. }
  479. .contextmenu.darkTheme .item{
  480. color:white !important;
  481. }
  482. .contextmenu .item{
  483. font-size:90% !important;
  484. }
  485. #uploadTab{
  486. position:fixed;
  487. right:0px;
  488. bottom: 0px;
  489. width:300px;
  490. margin-bottom:0px !important;
  491. padding:0px !important;
  492. }
  493. #uploadTab.darkTheme{
  494. color:white;
  495. background-color:rgba(35,35,35,0.14);
  496. border: 1px solid #17161f !important;
  497. box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75);
  498. }
  499. .statusBar{
  500. height:32px;
  501. background-color:#f5f5f5;
  502. padding:8px;
  503. }
  504. .statusBar.whiteTheme{
  505. color:rgb(78, 78, 78);
  506. }
  507. .statusBar.darkTheme{
  508. background-color:#181720 !important;
  509. }
  510. .hideUploadButton{
  511. float: right;
  512. cursor:pointer;
  513. }
  514. .uploadList{
  515. margin:8px;
  516. padding-bottom:3px;
  517. margin-bottom:0px;
  518. max-height: 250px;
  519. overflow-y:auto;
  520. }
  521. .uploadTask{
  522. margin-top:6px;
  523. }
  524. .uploadTaskRemoveIcon{
  525. position:absolute;
  526. top:0px;
  527. right:0px;
  528. cursor:pointer;
  529. }
  530. .clearallButton{
  531. padding:8px;
  532. cursor:pointer;
  533. }
  534. .normal.object.whiteTheme{
  535. color:#303030;
  536. }
  537. .normal.object.darkTheme{
  538. color:white;
  539. }
  540. .sub.header.darkTheme{
  541. color:rgb(190, 190, 190) !important;
  542. }
  543. .hex.foldername{
  544. color:#2b9447 !important;
  545. }
  546. .um.filename{
  547. color: #69aaff !important;
  548. }
  549. .dropdown.inverted{
  550. background-color: #17161f !important;
  551. }
  552. .sharebtn{
  553. cursor: pointer;
  554. }
  555. .sharebtn.darkTheme {
  556. color: white !important;
  557. background-color: transparent !important;
  558. }
  559. .sharebtn.whiteTheme:hover{
  560. opacity: 0.5;
  561. }
  562. .sharebtn.darkTheme:hover{
  563. opacity: 0.5;
  564. }
  565. </style>
  566. </head>
  567. <body class="whiteTheme">
  568. <div id="navibar" class="navibar whiteTheme">
  569. <!-- Directoy navigations -->
  570. <button id="backbtn" class="ts icon tiny button standard whiteTheme" onclick="previosPath();" title="Back"><i class="left arrow icon"></i></button>
  571. <button id="ppbtn" class="ts icon tiny button standard whiteTheme rightPad" onclick="parentDir();" title="Parent Folder"><i class="up arrow icon"></i></button>
  572. <!-- File Read Operations -->
  573. <button class="ts icon tiny button standard whiteTheme" title="Open" onclick="openViaButton();"><i class="folder open icon"></i></button>
  574. <button class="ts icon tiny button standard whiteTheme" title="Open with" onclick="openWith();"><i class="external icon"></i></button>
  575. <button class="ts icon tiny button standard whiteTheme singleObjectOnly" title="Share File" onclick="shareFile();"><i class="share alternate icon"></i></button>
  576. <button class="ts labeled icon tiny button standard whiteTheme" style="width:154px;" title="Download" onclick="downloadFile();">
  577. <i class="download icon"></i>
  578. Download
  579. </button>
  580. <!-- File Edit Operations -->
  581. <button class="ts icon tiny button standard whiteTheme" title="Copy" onclick="copy();"><i class="copy icon"></i></button>
  582. <button class="ts icon tiny button standard whiteTheme" title="Paste" onclick="paste();"><i class="paste icon"></i></button>
  583. <button class="ts icon tiny button standard whiteTheme" title="Cut" onclick="cut();"><i class="cut icon"></i></button>
  584. <button class="ts icon tiny button standard whiteTheme" title="New File" onclick="newfile();"><i class="file outline icon"></i></button>
  585. <button class="ts icon tiny button standard whiteTheme" title="New Folder" onclick="newFolder();"><i class="folder outline icon"></i></button>
  586. <button class="ts icon tiny button standard whiteTheme" title="Upload" onclick="upload();"><i class="upload icon"></i></button>
  587. <button class="ts icon tiny button standard whiteTheme" title="Create Zip" onclick="zipFile();"><i class="zip file icon"></i></button>
  588. <button class="ts icon tiny button standard whiteTheme" title="Rename" onclick="rename();"><i class="i cursor icon"></i></button>
  589. <button class="ts icon tiny negative button" title="Delete" onclick="deleteFile();"><i class="trash outline icon"></i></button>
  590. <button class="ts icon tiny button standard whiteTheme" title="Refresh" onclick="refreshList();"><i class="refresh icon"></i></button>
  591. <button class="ts icon tiny button standard whiteTheme" title="File Info" onclick="showFileProperties();"><i class="notice icon"></i></button>
  592. <button class="ts icon tiny button standard whiteTheme" title="Help"><i class="help icon"></i></button>
  593. <div class="addressBar">
  594. <button class="ts icon tiny button standard whiteTheme" onclick="toggleSidebar();" title="Toggle Folder List"><i class="content icon"></i></button>
  595. <button class="ts icon tiny button inverted" title="Dark Theme" onclick="toggleDarkTheme();"><i class="moon icon" id="darkthemebtn"></i></button>
  596. <div class="ts breadcrumb whiteTheme addressText pathDisplay desktopOnly">
  597. <div class="section whiteTheme selectable"><i class="folder icon"></i> user</div>
  598. <div class="divider whiteTheme">:/</div>
  599. <div class="section whiteTheme selectable">Desktop</div>
  600. </div>
  601. <div class="rightAlign">
  602. <select id="sortingMethodSelector" title="Sorting Method" class="ts basic borderless mini dropdown" onchange="updateSortingMethods();" autocomplete="off">
  603. <option value="default">Ascending</option>
  604. <option value="reverse">Descending</option>
  605. <option value="smallToLarge">Smallest</option>
  606. <option value="largeToSmall"> Largest</option>
  607. <option value="mostRecent">Most Recent</option>
  608. <option value="leastRecent">Least Recent</option>
  609. </select>
  610. <button id="searhbtn" class="ts icon tiny button standard whiteTheme" title="Search" onclick="toggleSearch();"><i class="search icon"></i></button>
  611. <button class="ts icon tiny button standard whiteTheme videmode" mode="grid" title="Block View" onclick="changeViewMode(this);"><i class="block layout icon"></i></button>
  612. <button class="ts icon tiny button standard whiteTheme videmode" mode="list" title="List View" onclick="changeViewMode(this);"><i class="align justify icon"></i></button>
  613. </div>
  614. </div>
  615. <div class="mobilePathDisplayWrapper">
  616. <div style="width:100%;" class="ts pathDisplay breadcrumb whiteTheme addressText mobileOnly">
  617. <div class="section whiteTheme selectable"><i class="folder icon"></i> user</div>
  618. <div class="divider whiteTheme">:/</div>
  619. <div class="section whiteTheme selectable">Desktop</div>
  620. </div>
  621. </div>
  622. <div class="searchbar" style="z-index:999; display:none;">
  623. <div style="width: 80%; display:inline-block; margin-top:-4px;">
  624. <div class="ts mini fluid input">
  625. <input autocomplete="off" id="searchInput" type="text" class="whiteTheme" placeholder="File Search (Start wildcard search with / , e.g. /*.mp3)" onkeypress="handleSearchBarPress(event);">
  626. </div>
  627. </div>
  628. <button class="ts icon tiny button standard whiteTheme" title="Case Sensitive" onclick="toggleCaseSensitive(this);">Aa</button>
  629. <button class="ts icon tiny button standard whiteTheme" title="Search" onclick="handleSearch();"><i class="search icon"></i></button>
  630. <button class="ts icon tiny button standard whiteTheme" title="Clear Search" onclick="hideSearchBar();"><i class="remove icon"></i></button>
  631. </div>
  632. <div class="msgbox" style="z-index:999; display:none;">
  633. <i class="checkmark icon"></i> <span>No Message</span>
  634. <div class="closeMsgButton" onclick="$(this).parent().slideUp('fast');"><i class="remove icon"></i></div>
  635. </div>
  636. </div>
  637. <div id="mainWindow">
  638. <div id="directorySidebar" class="whiteTheme">
  639. <div class="ts list">
  640. <details class="ts accordion fluid whiteTheme" open>
  641. <summary>
  642. <i class="dropdown icon"></i> User
  643. </summary>
  644. <div id="userroot" class="ts list" style="padding-top:0px !important;">
  645. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  646. </div>
  647. </details>
  648. <details class="ts accordion fluid whiteTheme" open>
  649. <summary>
  650. <i class="dropdown icon"></i> Storage
  651. </summary>
  652. <div id="storageroot" class="ts list" style="padding-top:0px !important;">
  653. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  654. </div>
  655. </details>
  656. <!--
  657. <details class="ts accordion fluid whiteTheme" open>
  658. <summary>
  659. <i class="caret down icon"></i>Disks
  660. </summary>
  661. <div id="deviceList" class="ts list" style="padding-top:0px !important;">
  662. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  663. </div>
  664. </details>
  665. -->
  666. <!-- >
  667. <div class="item fluid whiteTheme">
  668. <i class="world icon"></i>Network
  669. </div>
  670. -->
  671. <br>
  672. </div>
  673. </div>
  674. <div id="folderView" class="whiteTheme" ondrop="drop(event)" ondragover="allowDrop(event)">
  675. <div id="folderList">
  676. </div>
  677. <div id="fileList">
  678. </div>
  679. <br>
  680. </div>
  681. </div>
  682. <!-- Other popup windows -->
  683. <div class="popupWrapper"></div>
  684. <!-- Overwrite Selection Box-->
  685. <div id="overwriteModeSelection" class="popup whiteTheme" style="display:none;">
  686. <div class="popupheader whiteTheme">
  687. <i class="paste icon"></i> Replace, Keep or Skip Files
  688. <div class="popupcloser" onclick="hideAllPopupWindows();">
  689. <i class="remove icon"></i>
  690. </div>
  691. </div>
  692. <div class="popupcontent" style="padding:12px;">
  693. <small style="font-size:80%;">Copying <span class="owm-fc"></span> files from <span class="owm-srcdir"></span> to <span class="owm-destdir"></span>.</small>
  694. <p>The destination has <span class="owm-fc"></span> files with the same names.</p>
  695. <div class="popupbuttons whiteTheme allowHover primary" onclick="changeOverwriteRule(0,true);">
  696. <i class="checkmark icon"></i> Replace the files in the destination
  697. </div>
  698. <div class="popupbuttons whiteTheme allowHover" onclick="changeOverwriteRule(1,true);">
  699. <i class="reply icon"></i> Skip these files
  700. </div>
  701. <div class="popupbuttons whiteTheme allowHover" onclick="changeOverwriteRule(2,true);">
  702. <i class="undo icon"></i> Rename and keep the files
  703. </div>
  704. </div>
  705. </div>
  706. <!-- Force delete confirmation box -->
  707. <div id="forceDeleteConfirmBox" class="popup whiteTheme" style="display:none;">
  708. <div class="popupheader whiteTheme">
  709. <i class="trash icon"></i> Permanently Remove Files
  710. <div class="popupcloser" onclick="hideAllPopupWindows();">
  711. <i class="remove icon"></i>
  712. </div>
  713. </div>
  714. <div class="popupcontent" style="padding:12px;">
  715. <p>Are you sure you want to remove these files <u>permanently?</u><br>This action is <u>irreversible</u>.</p>
  716. <div class="ts list whiteTheme deleteFilelist" style="max-height:350px;overflow-y:auto; ">
  717. </div>
  718. <div class="popupbuttons whiteTheme allowHover" style="background-color: #eb4034 !important;" onclick="forceDelete(true);";>
  719. <i class="trash icon"></i> Confirm
  720. </div>
  721. <div class="popupbuttons whiteTheme allowHover" onclick="cancelForceDelete();hideAllPopupWindows();">
  722. <i class="remove icon"></i> Cancel
  723. </div>
  724. </div>
  725. </div>
  726. <!-- Delete confirm box -->
  727. <div id="deleteConfirmBox" class="popup whiteTheme" style="display:none;">
  728. <div class="popupheader whiteTheme">
  729. <i class="recycle icon"></i> Move files to Trash Bin
  730. <div class="popupcloser" onclick="hideAllPopupWindows();">
  731. <i class="remove icon"></i>
  732. </div>
  733. </div>
  734. <div class="popupcontent" style="padding:12px;">
  735. <p>Are you sure you want to move these files to trash bin?</p>
  736. <div class="ts list whiteTheme deleteFilelist" style="max-height:350px;overflow-y:auto; ">
  737. </div>
  738. <div class="popupbuttons whiteTheme allowHover" style="color: #2bbbdf !important;" onclick="deleteFile(true);";>
  739. <i class="recycle icon"></i> Move to Trash
  740. </div>
  741. <div class="popupbuttons whiteTheme allowHover" onclick="cancelDelete();hideAllPopupWindows();">
  742. <i class="remove icon"></i> Cancel
  743. </div>
  744. </div>
  745. </div>
  746. <!-- Rename tool box -->
  747. <div id="renameBox" class="popup whiteTheme" style="display:none;">
  748. <div class="popupheader whiteTheme">
  749. <i class="text cursor icon"></i> Rename Files
  750. <div class="popupcloser" onclick="hideAllPopupWindows();">
  751. <i class="remove icon"></i>
  752. </div>
  753. </div>
  754. <div class="popupcontent" style="padding:12px;">
  755. <p>Enter the new filename for renaming. </p>
  756. <p class="multifileWarning"><i class="notice icon"></i> Other files will be named as file(#)</p>
  757. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  758. <input type="text" class="whiteTheme orgfn" placeholder="Original Filename" readonly="true">
  759. <i class="minus square icon" style="color:rgb(122, 176, 247)"></i>
  760. </div>
  761. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  762. <input type="text" class="whiteTheme newfn" placeholder="New Filename" onkeydown="handleEnterKeyDown(event, function(){confirmRename(true);})">
  763. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  764. </div>
  765. <div class="popupbuttons whiteTheme allowHover primary" onclick="confirmRename(true);";>
  766. <i class="checkmark icon"></i> OK
  767. </div>
  768. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  769. <i class="remove icon"></i> Cancel
  770. </div>
  771. </div>
  772. </div>
  773. <!-- New File Dialog-->
  774. <div id="newFile" class="popup whiteTheme" style="display:none;">
  775. <div class="popupheader whiteTheme">
  776. <i class="add icon"></i> New File
  777. <div class="popupcloser" onclick="hideAllPopupWindows();">
  778. <i class="remove icon"></i>
  779. </div>
  780. </div>
  781. <div class="popupcontent" style="padding:12px;">
  782. <p>Please select a type of file to be created.</p>
  783. <div class="ts segmented list whiteTheme newfilelist" style="max-height:18em; overflow-y:scroll">
  784. <div class="item newFileFormat" ext="php">No Item</div>
  785. </div>
  786. <p>Or create an empty file with given filename:</p>
  787. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  788. <input id="createNewFileName" type="text" class="whiteTheme" placeholder="New Filename" onkeydown="handleEnterKeyDown(event, confirmNewFile);">
  789. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  790. </div>
  791. <p class="duplicateWarning" style="color:#CE5F58; display:none;"><i class="caution sign icon"></i> The given filename already exist.</p>
  792. <div class="popupbuttons whiteTheme allowHover primary" onclick="confirmNewFile();";>
  793. <i class="add icon"></i> Create
  794. </div>
  795. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  796. <i class="remove icon"></i> Cancel
  797. </div>
  798. </div>
  799. </div>
  800. <!-- New Folder Dialog-->
  801. <div id="newFolder" class="popup whiteTheme" style="display:none;">
  802. <div class="popupheader whiteTheme">
  803. <i class="folder icon"></i> New Folder
  804. <div class="popupcloser" onclick="hideAllPopupWindows();">
  805. <i class="remove icon"></i>
  806. </div>
  807. </div>
  808. <div class="popupcontent" style="padding:12px;">
  809. <p>Please enter the new folder name to be created.</p>
  810. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  811. <input id="createNewFolder" type="text" class="whiteTheme" placeholder="New Folder Name" onkeydown="handleEnterKeyDown(event, function(){newFolder(true);});">
  812. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  813. </div>
  814. <p class="duplicateWarning" style="color:#CE5F58; display:none;"><i class="caution sign icon"></i> The given folder already exist.</p>
  815. <div class="popupbuttons whiteTheme allowHover primary" onclick="newFolder(true);";>
  816. <i class="add icon"></i> Create
  817. </div>
  818. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  819. <i class="remove icon"></i> Cancel
  820. </div>
  821. </div>
  822. </div>
  823. <!-- Share File Dialog-->
  824. <div id="shareFile" class="popup wide whiteTheme" style="display:none;">
  825. <div class="popupheader whiteTheme">
  826. <i class="external icon"></i> Share File
  827. <div class="popupcloser" onclick="hideAllPopupWindows();">
  828. <i class="remove icon"></i>
  829. </div>
  830. </div>
  831. <div class="popupcontent" style="padding:12px;">
  832. <div class="ts stackable grid">
  833. <div class="eight wide column">
  834. <div class="width: 100%; ">
  835. <div style="display: block; margin-left: auto; margin-right: auto;" align="center">
  836. <div id="qrcode" style="border: 10px solid white; background-color: white;"></div>
  837. </div>
  838. <a id="sharelink" href="" target="_blank" style="margin-top:8px; font-size: 120%; padding-left: 20px; padding-right: 20px; word-break: break-all;">Scan this QR Code to copy the share link</a>
  839. </div>
  840. </div>
  841. <div class="eight wide column" style="padding-left: 12px;">
  842. <div class="ts header whiteTheme">
  843. Share Settings
  844. <div class="sub header whiteTheme">Change who can see this file</div>
  845. </div>
  846. <div id="shareSettingForm" class="ts form">
  847. <div class="field">
  848. <label><p class="whiteTheme">Visable options:</p></label>
  849. <div class="ts checkboxes">
  850. <div class="ts radio checkbox">
  851. <input id="anyone" type="radio" class="shareoption" name="shareopt" value="anyone" checked="true">
  852. <label for="anyone">
  853. <div class="ts header">
  854. <div class="content whiteTheme">
  855. <i class="globe icon"></i> Anyone with the link
  856. <div class="sub header whiteTheme">Anyone who has the link can access this file</div>
  857. </div>
  858. </div>
  859. </label>
  860. </div>
  861. <div class="ts radio disabled checkbox">
  862. <input id="signedin" type="radio" class="shareoption" value="signedin" name="shareopt">
  863. <label for="signedin">
  864. <div class="ts header">
  865. <div class="content whiteTheme">
  866. <i class="user circle outline icon"></i> Anyone signed in
  867. <div class="sub header whiteTheme">Anyone who has signed in can access this file</div>
  868. </div>
  869. </div>
  870. </label>
  871. </div>
  872. <div class="ts radio disabled checkbox">
  873. <input id="samegroup" type="radio" class="shareoption" value="samegroup" name="shareopt">
  874. <label for="samegroup">
  875. <div class="ts header">
  876. <div class="content whiteTheme">
  877. <i class="users icon"></i> Users in the same group
  878. <div class="sub header whiteTheme">Anyone who is in the same group as you do</div>
  879. </div>
  880. </div>
  881. </label>
  882. </div>
  883. <br>
  884. <button class="ts small button" onclick="updateShareSettings(this)" style="border: 0px solid transparent;">Update</button>
  885. </div>
  886. </div>
  887. </div>
  888. </div>
  889. </div>
  890. <div class="ts divider"></div>
  891. <div id="sharingRemoveBtn" class="popupbuttons negative whiteTheme allowHover" onclick="removeSharing()">
  892. <i class="remove icon"></i> Remove Sharing
  893. </div>
  894. <div class="popupbuttons whiteTheme allowHover" onclick="hideShare()">
  895. <i class="checkmark icon"></i> OK
  896. </div>
  897. </div>
  898. </div>
  899. <!-- Open With Dialog-->
  900. <div id="openWith" class="popup whiteTheme" style="display:none;">
  901. <div class="popupheader whiteTheme">
  902. <i class="external icon"></i> Open File With
  903. <div class="popupcloser" onclick="hideAllPopupWindows();">
  904. <i class="remove icon"></i>
  905. </div>
  906. </div>
  907. <div class="popupcontent" style="padding:12px;">
  908. <p>Select a module from the list below:</p>
  909. <div id="openWithModuleList" class="ts segment whiteTheme" style="padding:0px;">
  910. <div class="item selectable">
  911. <div class="content" style="padding-left:12px;">
  912. <div class="header">Loading...</div>
  913. </div>
  914. </div>
  915. </div>
  916. <div class="openWithModule popupbuttons whiteTheme allowHover primary" onclick="openWithSelectedModule(this);";>
  917. <i class="external icon"></i> Open with Selected Module
  918. </div>
  919. <div class="openWithModule popupbuttons whiteTheme allowHover" onclick="openFileWithModuleInNewTab(this);">
  920. <i class="add icon"></i> Open in new tab
  921. </div>
  922. <div class="popupbuttons whiteTheme allowHover vdonly" onclick="openRawFileInFloatWindow(this);">
  923. <i class="window restore outline icon"></i> Open File directly in floatWindow
  924. </div>
  925. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  926. <i class="remove icon"></i> Cancel
  927. </div>
  928. </div>
  929. </div>
  930. <!-- Context Menu -->
  931. <div id="contextmenu" class="ts small contextmenu visible whiteTheme" style="min-width:250px;">
  932. <div class="item" onclick="openViaButton();">
  933. <i class="folder open icon"></i> Open
  934. </div>
  935. <div class="item fileonly" onclick="openWith();">
  936. <i class="external icon"></i> Open With
  937. </div>
  938. <div class="item folderonly" onclick="openSelectedFolderInNewWindow();">
  939. <i class="external icon"></i> Open In New Window
  940. </div>
  941. <!-- This is the vroot alternative new windows-->
  942. <div class="item vrootonly" onclick="openSelectedVroot();">
  943. <i class="external icon"></i> Open In New Window
  944. </div>
  945. <div class="item shareonly" onclick="openFileLocation();">
  946. <i class="folder outline icon"></i> Open File Location
  947. </div>
  948. <div class="item singleObjectOnlyHide" onclick="shareFile();">
  949. <i class="share alternate icon"></i> Share
  950. </div>
  951. <div class="item mobileonly" onclick="toggleCtrl();">
  952. <i class="mouse pointer icon"></i> Multi-select
  953. </div>
  954. <div class="item" onclick="copy();">
  955. <i class="copy icon"></i> Copy
  956. <span class="description">Ctrl + C</span>
  957. </div>
  958. <div class="item allowNoSelection" onclick="paste();">
  959. <i class="paste icon"></i> Paste
  960. <span class="description">Ctrl + V</span>
  961. </div>
  962. <div class="item" onclick="cut();">
  963. <i class="cut icon"></i> Cut
  964. <span class="description">Ctrl + X</span>
  965. </div>
  966. <div class="divider noSelectionOnly"></div>
  967. <div class="item noSelectionOnly" onclick="newfile();">
  968. <i class="file outline icon"></i> New File
  969. </div>
  970. <div class="item noSelectionOnly" onclick="newFolder();">
  971. <i class="folder outline icon"></i> New Folder
  972. </div>
  973. <div class="divider"></div>
  974. <div class="item noSelectionOnly" onclick="upload();">
  975. <i class="upload icon"></i> Upload
  976. </div>
  977. <div class="item" onclick="zipFile();">
  978. <i class="zip file icon"></i> Create Zip
  979. </div>
  980. <div class="item" onclick="rename();">
  981. <i class="i cursor icon"></i> Rename
  982. </div>
  983. <div class="item" onclick="deleteFile();">
  984. <i class="trash icon"></i> Delete
  985. </div>
  986. <div class="item backuponly" onclick="openBackupManager();">
  987. <i class="block layout icon"></i> Backup & Restore
  988. </div>
  989. <div class="item divider"></div>
  990. <div class="item noSelectionOnly" onclick="refreshList();">
  991. <i class="refresh icon"></i> Refresh
  992. </div>
  993. <div class="item" onclick="downloadFile();">
  994. <i class="download icon"></i> Download
  995. </div>
  996. <div class="item" onclick="showFileProperties();">
  997. <i class="notice icon"></i> Properties
  998. </div>
  999. <!-- This properties shows the currentDirectory properties instead of the selected file properties-->
  1000. <div class="item noSelectionOnly" onclick="showCurrentDirectoryProperties();">
  1001. <i class="notice icon"></i> Properties
  1002. </div>
  1003. <!-- This properties show the vroot properties -->
  1004. <!-- This properties shows the currentDirectory properties instead of the selected file properties-->
  1005. <div class="item vrootonly" onclick="showVrootProperties();">
  1006. <i class="notice icon"></i> Properties
  1007. </div>
  1008. </div>
  1009. <!-- Upload Progress Bars-->
  1010. <div id="uploadTab" class="ts segment whiteTheme" style="display:none;">
  1011. <div class="statusBar whiteTheme">
  1012. <i class="upload icon"></i><span id="uploadCount">0</span> Files / <i class="wait icon"></i> <span id="waitingCount">0</span> Files
  1013. <div class="hideUploadButton" onclick="toggleUploadList();">
  1014. <i class="caret down icon"></i>
  1015. </div>
  1016. </div>
  1017. <div class="uploadList" id="uploadProgressList">
  1018. </div>
  1019. <div class="clearallButton">
  1020. <a onclick="clearAllUploadTask();">Clear All</a>
  1021. </div>
  1022. </div>
  1023. <script>
  1024. let directorySidebarWidth = 250; //Width of the sidebar
  1025. let sideBarShown = true; //Indicate if sidebar is shown
  1026. let rootDirs = []; //Storage location for rootDirs
  1027. let currentTheme = "whiteTheme"; //Default theme
  1028. let viewMode = "list"; //Viewmode, support {list, grid, detail}
  1029. let sortMode = "default"; //Sortmode, support {default, reverse, smallToLarge, largeToSmall, mostRecent, leastRecent}
  1030. let currentPath = "user:/"
  1031. let viewHistory = []; //View history
  1032. let enableBetaFilename = false; //Enable beta filename conversion from "inith..." to "normal"
  1033. let currentFilelist = []; //The current file list in the currentPath
  1034. let currentPathHash = ""; //The folder content hash
  1035. let enableAutoRefresh = true; //Enable directory updates on file change
  1036. let filesIconTheme = "default";
  1037. //File operations
  1038. let clipboard = []; //System clipboard
  1039. let cutMode = false; //If set to true, this is cut mode. Else copy mode
  1040. let useLocalstorage = lscheck();
  1041. let overwriteMode = "keep"; //Overwrite mode, support {skip, overwrite, keep}
  1042. let thumbRenderWebSocket = null;
  1043. let searchCaseSensitive = false;
  1044. //Keypress listeners
  1045. let ctrlHold = false;
  1046. let shiftHold = false;
  1047. //Upload related
  1048. let uploadingFileCount = 0;
  1049. let maxConcurrentUpload = 4; //Maxmium number of oncurrent upload
  1050. let uploadPendingList = []; //Upload pending queue for mass upoad
  1051. let lowMemoryMode = true; //Upload with low memory mode channel
  1052. let uploadFileChunkSize = 1024 * 512; //512KB, 4MB not working quite well on slow network
  1053. //File Sharing related
  1054. let shareEditingObject = "";
  1055. let shareEditingUUID = "";
  1056. //System Information
  1057. let systemUUID = "";
  1058. let systemIP = "";
  1059. //Browser detection
  1060. let isMobile = window.mobilecheck();
  1061. let isChromium = window.chrome;
  1062. let isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  1063. let isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  1064. let isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  1065. //Intiiation functions
  1066. initRootDirs();
  1067. initSystemInfo();
  1068. initUploadMode();
  1069. if (isMobile){
  1070. //Mobile css adjustment
  1071. sideBarShown = false;
  1072. $("#directorySidebar").hide();
  1073. $("#directorySidebar").css("width",window.innerWidth + "px");
  1074. $("body").css("overflow","hidden");
  1075. directorySidebarWidth = window.innerWidth;
  1076. $("#folderView").css({
  1077. "padding-right":"1em",
  1078. "padding-left":"1em",
  1079. "padding-top":"1em",
  1080. });
  1081. $(".desktopOnly").hide();
  1082. $(".mobileOnly").show();
  1083. }else{
  1084. $(".mobileOnly").hide();
  1085. $(".desktopOnly").show();
  1086. }
  1087. //Initialize view mode buttons
  1088. updateViewmodeButtons();
  1089. loadListModeFromDB();
  1090. //Initialize system theme
  1091. loadPreference("file_explorer/theme",function(data){
  1092. if (data.error === undefined){
  1093. if (data == "darkTheme"){
  1094. toggleDarkTheme();
  1095. }else{
  1096. //White theme
  1097. }
  1098. }
  1099. });
  1100. if (window.location.hash != ""){
  1101. //Check if the hash is standard open protocol. If yes, translate it
  1102. if (ao_module_loadInputFiles() === null){
  1103. //Window location hash set. List the desire directory
  1104. currentPath = window.location.hash.substring(1,window.location.hash.length);
  1105. if (currentPath.substring(currentPath.length -1) != "/"){
  1106. currentPath = currentPath + "/";
  1107. }
  1108. currentPath = decodeURIComponent(currentPath);
  1109. loadListModeFromDB(function(){
  1110. listDirectory(currentPath);
  1111. });
  1112. }else{
  1113. //This is ao_module load file input. Handle the file opening
  1114. var filelist = ao_module_loadInputFiles();
  1115. if (filelist.length > 0){
  1116. filelist = filelist[0];
  1117. //Check if this is folder or file. Only opendir when it is folder
  1118. //Updates 27-12-2020: Open folder and highlight the file if it is file
  1119. if (filelist.filename.includes(".") == false){
  1120. //Try to open it and overwrite the hash to filesystem hash
  1121. loadListModeFromDB(function(){
  1122. listDirectory(filelist.filepath);
  1123. });
  1124. }else{
  1125. //File. Open its parent folder and highlight the target file if exists
  1126. var parentdir = filelist.filepath.split("/");
  1127. let focusFilename = JSON.parse(JSON.stringify(filelist.filename));
  1128. parentdir.pop();
  1129. parentdir = parentdir.join("/");
  1130. loadListModeFromDB(function(){
  1131. listDirectory(parentdir, function(){
  1132. focusFileObject(focusFilename);
  1133. });
  1134. });
  1135. }
  1136. }
  1137. }
  1138. }else{
  1139. //Initialized directory views
  1140. loadListModeFromDB(function(){
  1141. listDirectory(currentPath);
  1142. });
  1143. }
  1144. //Create a timer to check change in current folder
  1145. setInterval(function(){
  1146. if (enableAutoRefresh == false){
  1147. return;
  1148. }
  1149. getDirHash(function(hash){
  1150. if (hash.error !== undefined){
  1151. //Something went wrong. Ignore this request
  1152. console.log(hash.error)
  1153. }else{
  1154. //Check if the hash match with the last hash.
  1155. if (hash != currentPathHash){
  1156. //console.log(currentPathHash, hash);
  1157. refreshList();
  1158. currentPathHash = hash;
  1159. if (currentPath == "user:/"){
  1160. //Reload the User root folder list
  1161. initRootDirs();
  1162. }
  1163. }
  1164. }
  1165. });
  1166. }, 5000)
  1167. //END OF INIT FUNCTIONS
  1168. //Get the system ID and ip address from the system id services
  1169. function initSystemInfo(){
  1170. $.get("../../system/id/requestInfo",function(data){
  1171. if (data.error !== undefined){
  1172. msgbox("remove", data.error);
  1173. }else{
  1174. systemUUID = data.SystemUUID;
  1175. systemIP = data.IpAddress;
  1176. }
  1177. });
  1178. }
  1179. //Initiate the sidebar contents
  1180. function initRootDirs(){
  1181. //Load user directories
  1182. $.ajax({
  1183. url:"../../system/file_system/listRoots?user=true",
  1184. success: function(data){
  1185. $("#userroot").html("");
  1186. for (var i =0; i < data.length; i++){
  1187. var thisRootObject = data[i];
  1188. if (thisRootObject.IsDir == true && !(thisRootObject.Filename == ".cache" || thisRootObject.Filename == ".trash")){
  1189. //Files will not be listed in the root directory list
  1190. var icon = getUserRootIcons(thisRootObject.Filename);
  1191. var displayName = thisRootObject.Filename;
  1192. var vpath = thisRootObject.Filepath;
  1193. $("#userroot").append(`<div class="dir item ${currentTheme}" filepath="${vpath}" type="folder" onclick="openthis(this);"><i class="${icon} rightmargin icon"></i> ${displayName}</div>`);
  1194. }
  1195. }
  1196. }
  1197. });
  1198. //Load other storage devices
  1199. $.ajax({
  1200. url:"../../system/file_system/listRoots",
  1201. success: function(data){
  1202. $("#storageroot").html("");
  1203. for (var i =0; i < data.length; i++){
  1204. var thisRoot = data[i];
  1205. var displayName = thisRoot.RootName;
  1206. var rootPath = thisRoot.RootPath;
  1207. var containBackup = thisRoot.RootBackups;
  1208. $("#storageroot").append(`<div class="dir item ${currentTheme}" contain-backup="${containBackup}" filepath="${rootPath}" type="folder" rootname="${displayName}" onclick="openthis(this);"><i class="disk outline rightmargin icon"></i> ${displayName} (${rootPath})</div>`);
  1209. }
  1210. }
  1211. });
  1212. //Initial Host device drives
  1213. /*
  1214. $.ajax({
  1215. url: "../../system/file_system/listDrives",
  1216. success: function(data){
  1217. $("#deviceList").html("");
  1218. for (var i =0; i < data.length; i++){
  1219. var drivePath = data[i].Drivepath;
  1220. var usagePercentage = ((data[i].DriveTotalSpace - data[i].DriveFreeSpace) / data[i].DriveTotalSpace) * 100;
  1221. var className = "primary";
  1222. if (usagePercentage > 90){
  1223. className = "negative";
  1224. }
  1225. $("#deviceList").append(`<div class="dir item ${currentTheme}" filepath="${drivePath}" ><i class="disk outline rightmargin icon"></i> ${drivePath}
  1226. <div style="width:100px;height:15px !important; position:absolute;right:3px;top:6px;"">
  1227. <div class="ts ${className} tiny progress">
  1228. <div class="bar" style="width: ${usagePercentage}%"></div>
  1229. </div>
  1230. </div>
  1231. </div>`);
  1232. }
  1233. }
  1234. });
  1235. */
  1236. }
  1237. function getUserRootIcons(foldername){
  1238. var icon = "folder open";
  1239. foldername = foldername.toLowerCase();
  1240. if (foldername == "desktop"){
  1241. icon = "computer";
  1242. }else if (foldername == "document"){
  1243. icon = "file text outline";
  1244. }else if (foldername == "music" || foldername == "audio"){
  1245. icon = "music";
  1246. }else if (foldername == "photo" || foldername == "picture"){
  1247. icon = "image";
  1248. }else if (foldername == "video" || foldername == "film"){
  1249. icon = "video";
  1250. }else if (foldername == "trash" || foldername == "bin" || foldername == "rubbish"){
  1251. icon = "trash"
  1252. }else if (foldername == "download"){
  1253. icon = "download"
  1254. }else if (foldername == "www" || foldername == "web" || foldername == "mysite"){
  1255. icon = "globe"
  1256. }else if (foldername == "model"){
  1257. icon = "cube"
  1258. }else if (foldername == "appdata"){
  1259. icon = "code"
  1260. }
  1261. return icon;
  1262. }
  1263. // ============================== FOLDER LISTING FUNCTIONS ====================
  1264. function listDirectory(path, callback=undefined, recordUndo=true){
  1265. //If current mode is search mode, hide the serach bar
  1266. if (searchMode == true){
  1267. //Hide searchbar and skip refresh list
  1268. hideSearchBar(true);
  1269. }
  1270. var recordPreviousPage = true;
  1271. if (recordUndo == false){
  1272. recordPreviousPage = false;
  1273. }
  1274. //Backup the current selected files if it is an refresh operation
  1275. let selectedFiles = [];
  1276. if (path == currentPath){
  1277. $(".fileObject.item.selected").each(function(){
  1278. selectedFiles.push($(this).attr("filename"));
  1279. });
  1280. //Set record histroy to false on refresh
  1281. recordPreviousPage = false;
  1282. }
  1283. //Always pad slash to the end of path
  1284. if (path.substring(path.length - 1) != "/"){
  1285. path = path + "/";
  1286. }
  1287. //Clean the path if there are any malformat
  1288. if (path.indexOf("//") != -1){
  1289. path = path.split("//").join("/");
  1290. }
  1291. if (recordPreviousPage){
  1292. viewHistory.push(currentPath);
  1293. }
  1294. window.location.hash = path;
  1295. updatePathDisplay(path);
  1296. currentPath = path;
  1297. //Update floatWindow title if exists
  1298. if (ao_module_virtualDesktop){
  1299. var tmp = path.split("/");
  1300. tmp.pop();
  1301. ao_module_setWindowTitle("File Manager - " + tmp.pop());
  1302. }
  1303. //Check if there are parent path for curret path
  1304. if (checkIfParentDirExists(currentPath)){
  1305. $("#ppbtn").removeClass("disabled");
  1306. }else{
  1307. $("#ppbtn").addClass("disabled");
  1308. }
  1309. if (viewHistory.length < 1){
  1310. $("#backbtn").addClass("disabled");
  1311. }else{
  1312. $("#backbtn").removeClass("disabled");
  1313. }
  1314. //Add loading screen to the folderlists and fileList
  1315. $("#fileList").html("");
  1316. if (currentTheme == "darkTheme"){
  1317. $("#folderList").html(`<div style="height: 100px;">
  1318. <div class="ts active dimmer">
  1319. <div class="ts text loader">Loading</div>
  1320. </div>
  1321. </div>`);
  1322. }else{
  1323. $("#folderList").html(`<div style="height: 100px;">
  1324. <div class="ts active inverted dimmer">
  1325. <div class="ts text loader">Loading</div>
  1326. </div>
  1327. </div>`);
  1328. }
  1329. $.ajax({
  1330. url: "../../system/file_system/listDir",
  1331. method: "POST",
  1332. data: {dir: decodeURIComponent(path), sort: sortMode},
  1333. success: function(data){
  1334. //Parse the filelist into global variable
  1335. currentFilelist = [];
  1336. if (data === null){
  1337. //There is nothing is this folder.
  1338. $("#folderList").hide();
  1339. $("#fileList").hide();
  1340. return;
  1341. }
  1342. if (data.error !== undefined){
  1343. //Parse path error. Try to refresh the page
  1344. console.log("Path prase error! Redirecting to parent directory.", data.error);
  1345. var pdir = currentPath.split("/");
  1346. pdir.pop(); pdir.pop();
  1347. pdir = pdir.join("/");
  1348. currentPath = pdir;
  1349. //Check if it is already rooted and no more parent ahead
  1350. if (currentPath == ""){
  1351. currentPath = "user:/";
  1352. }
  1353. //listDirectory(currentPath, function(){
  1354. // window.location.reload();
  1355. //});
  1356. return;
  1357. }else{
  1358. //Filelist returned. Render it
  1359. renderDirectory(data,function(){
  1360. //Restore the selected file list
  1361. $(".fileObject.item").each(function(){
  1362. for (var i = 0; i < selectedFiles.length; i++){
  1363. var thisFilename = selectedFiles[i];
  1364. if (thisFilename == $(this).attr("filename")){
  1365. $(this).addClass("selected");
  1366. }
  1367. }
  1368. });
  1369. //Perform the callback
  1370. if (callback !== undefined){
  1371. callback();
  1372. }
  1373. });
  1374. }
  1375. }
  1376. });
  1377. }
  1378. //Render filelist --> Convert a file list object into the visable form of file list
  1379. function renderDirectory(filelist, callback=undefined){
  1380. var data = filelist;
  1381. $("#fileList").html("");
  1382. $("#folderList").html("");
  1383. //Build the css strcture of the list
  1384. if (viewMode == "list"){
  1385. $("#fileList").attr("class",`ts segmented fluid list ${currentTheme}`);
  1386. $("#folderList").attr("class",`ts segmented fluid list ${currentTheme}`);
  1387. }else if (viewMode == "details"){
  1388. }else if (viewMode == "grid"){
  1389. $("#fileList").attr("class",`${currentTheme}`).css("vertical-align","top");
  1390. $("#folderList").attr("class",`${currentTheme}`).css("vertical-align","top");
  1391. }
  1392. var files = [];
  1393. var folders = [];
  1394. for (var i =0; i < data.length; i++){
  1395. if (data[i].IsDir == true){
  1396. //This is folder
  1397. folders.push(data[i]);
  1398. }else{
  1399. //This is file
  1400. files.push(data[i]);
  1401. }
  1402. currentFilelist.push(JSON.parse(JSON.stringify(data[i].Filename)));
  1403. }
  1404. //Define the grid size for the interface
  1405. var gridSize = 150 ;
  1406. if (isMobile){
  1407. //Update 3/5/2021: Optimize the width calculation method to best fit
  1408. /*
  1409. if (window.innerWidth > window.innerHeight){
  1410. //Screen using in horizontal mode
  1411. gridSize = window.innerWidth /4 - 20 ;
  1412. }else{
  1413. //Screen using in vertical mode
  1414. gridSize = window.innerWidth /2 - 20 ;
  1415. }
  1416. */
  1417. //A hack to align the divs to center of the container
  1418. $("#folderView").attr("align", "center");
  1419. $("#folderList").attr("align", "left");
  1420. $("#fileList").attr("align", "left");
  1421. //Calculate the best width to fit all the grids
  1422. var bestCount = Math.floor(parseFloat($("#folderView").width()) / parseFloat(gridSize));
  1423. var bestOffset = $("#folderView").width() % gridSize;
  1424. gridSize = gridSize + (bestOffset / bestCount) - (window.innerWidth - $("#folderView").width()) / bestCount;
  1425. }
  1426. //List all folders
  1427. for (var i =0; i < folders.length; i++){
  1428. var filename = folders[i].Filename;
  1429. var filepath = folders[i].Filepath;
  1430. var realpath = folders[i].Realpath;
  1431. var isDir = folders[i].IsDir;
  1432. var filesize = folders[i].Filesize;
  1433. var Displaysize = folders[i].Displaysize;
  1434. var isShared = folders[i].IsShared;
  1435. var ext = getExtFromPath(filepath);
  1436. //var icon = ao_module_utils.getIconFromExt(ext);
  1437. var icon = "folder";
  1438. var shareicon = "";
  1439. if (isShared == true){
  1440. shareicon = `<button class="sharebtn ${currentTheme}" onclick='handleShareFilebuttonClick(event, this);' style="margin-left: 4px; height: 16px;">
  1441. <i class='share alternate icon'></i>
  1442. </button>`
  1443. }
  1444. if (viewMode == "list"){
  1445. var textclass = "normal object";
  1446. if (currentTheme == "darkTheme"){
  1447. textclass += " darkTheme";
  1448. }
  1449. var displayName = filename;
  1450. try{
  1451. //Try to decode it using ArozOS Beta naming scheme
  1452. if (enableBetaFilename && ao_module_codec.decodeHexFoldername(displayName) != displayName){
  1453. displayName = ao_module_codec.decodeHexFoldername(displayName, false);
  1454. textclass = "hex foldername";
  1455. }
  1456. }catch(ex){
  1457. //Codec decode failed. Fallback to default name
  1458. }
  1459. $("#folderList").append(`<div class="fileObject item ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" ondrop="dropToFolder(event)" ondragover="allowDrop(event)" fileID="${i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="folder">
  1460. <span style="display:inline-block !important;word-break: break-all;" class="${textclass}">
  1461. <i class="${icon} icon" style="margin-right:12px; color:#eab54e;"></i> ${displayName} ${shareicon}
  1462. </span></div>`);
  1463. }else if (viewMode == "grid"){
  1464. var displayName = JSON.parse(JSON.stringify(filename));
  1465. var textclass = "normal object";
  1466. try{
  1467. //Try to decode it using ArozOS Beta naming scheme
  1468. if (enableBetaFilename && ao_module_codec.decodeHexFoldername(displayName) != displayName){
  1469. displayName = ao_module_codec.decodeHexFoldername(displayName, false);
  1470. textclass = "hex foldername";
  1471. }
  1472. }catch(ex){
  1473. //Codec decode failed. Fallback to default name
  1474. }
  1475. if (displayName.length > 16){
  1476. displayName = displayName.substring(0,16) + "...";
  1477. }
  1478. $("#folderList").append(`
  1479. <div class="ts card fileObject ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" ondrop="dropToFolder(event)" ondragover="allowDrop(event)" fileID="${i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="folder" style="width:${gridSize}px; display:inline-block !important;vertical-align:top; height:15em; margin-top:0px !important; overflow:hidden;">
  1480. <div class="image" style="text-align: center;">
  1481. <img draggable="true"ondragstart="disableDrag(event);" src="../../../img/desktop/files_icon/${filesIconTheme}/folder.png" style="height: 148px; width: 148px; display: inline-block;">
  1482. </div>
  1483. <div class="content" style="font-size: 12px;">
  1484. <div class="header ${currentTheme} ${textclass}" title="${filename}">${displayName} ${shareicon}</div>
  1485. </div>
  1486. </div>`);
  1487. }
  1488. }
  1489. if (folders.length == 0){
  1490. $("#folderList").hide();
  1491. }else{
  1492. $("#folderList").show();
  1493. }
  1494. //List all files
  1495. var fl = folders.length;
  1496. for (var i =0; i < files.length; i++){
  1497. var filename = files[i].Filename;
  1498. var filepath = files[i].Filepath;
  1499. var realpath = files[i].Realpath;
  1500. var filesize = files[i].Filesize;
  1501. var Displaysize = files[i].Displaysize;
  1502. var isShared = files[i].IsShared;
  1503. var ext = getExtFromPath(filepath);
  1504. if (ext == ""){
  1505. var icon = "file outline";
  1506. }else{
  1507. var icon = ao_module_utils.getIconFromExt(ext);
  1508. }
  1509. var shareicon = "";
  1510. if (isShared){
  1511. shareicon = `<button class="sharebtn ${currentTheme}" onclick='handleShareFilebuttonClick(event, this);' style="margin-left: 4px; height: 16px;">
  1512. <i class='share alternate icon'></i>
  1513. </button>`
  1514. }
  1515. var fileType = "file";
  1516. if (ext == "shortcut"){
  1517. fileType = "shortcut";
  1518. }
  1519. if (viewMode == "list"){
  1520. var displayName = filename;
  1521. var textclass = "normal object";
  1522. if (currentTheme == "darkTheme"){
  1523. textclass += " darkTheme";
  1524. }
  1525. if (enableBetaFilename){
  1526. decodedName = ao_module_codec.decodeUmFilename(displayName);
  1527. if (decodedName != displayName){
  1528. displayName = decodedName;
  1529. textclass = "um filename";
  1530. }
  1531. filename = ao_module_codec.decodeUmFilename(filename);
  1532. }
  1533. $("#fileList").append(`<div class="fileObject item ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" fileID="${fl + i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="${fileType}" filesize="${filesize}" displaysize="${Displaysize}">
  1534. <span style="display:inline-block !important;word-break: break-all;text-overflow: ellipsis !important;overflow: hidden;" class="${textclass}">
  1535. <i class="${icon} icon" style="margin-right:12px;"></i>
  1536. ${displayName} ${shareicon}
  1537. </span>
  1538. </div>`);
  1539. }else if (viewMode == "grid"){
  1540. var imagePath = "../../../img/desktop/files_icon/" + filesIconTheme + "/" + icon + ".png";
  1541. var displayName = JSON.parse(JSON.stringify(filename));
  1542. var textclass = "normal object";
  1543. if (enableBetaFilename){
  1544. decodedName = ao_module_codec.decodeUmFilename(displayName);
  1545. if (decodedName != displayName){
  1546. textclass = "um filename";
  1547. displayName = decodedName;
  1548. }
  1549. filename = ao_module_codec.decodeUmFilename(filename);
  1550. }
  1551. if (displayName.length > 20){
  1552. displayName = displayName.substring(0,20) + "...";
  1553. }
  1554. $("#fileList").append(`
  1555. <div class="ts card fileObject ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" fileID="${fl + i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="${fileType}" style="width:${gridSize}px; display:inline-block !important;vertical-align:top; height:20em; margin-top:0px !important; overflow:hidden;">
  1556. <div class="image" style="text-align: center !important;">
  1557. <img draggable="true"ondragstart="disableDrag(event);" style="height: 148px; width: 148px; display:inline-block;" src="${imagePath}">
  1558. </div>
  1559. <div class="content">
  1560. <div class="header ${currentTheme} ${textclass}" title="${filename}" style="text-overflow: ellipsis; font-size: 100%">${displayName} ${shareicon}</div>
  1561. <div class="meta ${currentTheme}">
  1562. <div>.${ext}</div>
  1563. </div>
  1564. <div class="description ${currentTheme}">
  1565. ${Displaysize}
  1566. </div>
  1567. </div>
  1568. </div>
  1569. `);
  1570. }
  1571. }
  1572. if (files.length == 0){
  1573. $("#fileList").hide();
  1574. }else{
  1575. $("#fileList").show();
  1576. }
  1577. bindFileObjectEvents();
  1578. currentFilelist.sort();
  1579. //Update the filelist hash
  1580. enableAutoRefresh = false;
  1581. getDirHash(function(hash){
  1582. currentPathHash = hash;
  1583. enableAutoRefresh = true;
  1584. });
  1585. //If viewmode is grid, load file thumbnails
  1586. if (viewMode == "grid"){
  1587. startThumbnailLoader();
  1588. }
  1589. if (callback !== undefined){
  1590. callback();
  1591. }
  1592. }
  1593. function startThumbnailLoader(){
  1594. let path = currentPath;
  1595. let protocol = "wss://";
  1596. if (location.protocol !== 'https:') {
  1597. protocol = "ws://";
  1598. }
  1599. var port = window.location.port;
  1600. if (window.location.port == ""){
  1601. port = "80";
  1602. }
  1603. thumbRenderWebSocket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/handleCacheRender?folder=" + path);
  1604. thumbRenderWebSocket.onopen = function(e) {
  1605. };
  1606. thumbRenderWebSocket.onmessage = function(event) {
  1607. //Find the correct file in the current directory and place its image
  1608. if (path == currentPath){
  1609. var thumbData = JSON.parse(event.data);
  1610. $(".fileObject").each(function(){
  1611. if (thumbData[1].length > 0){
  1612. if ($(this).attr("filename") == thumbData[0]){
  1613. $(this).find("img").attr("src","data:image/jpg;base64," + thumbData[1]);
  1614. }
  1615. }
  1616. });
  1617. }
  1618. };
  1619. thumbRenderWebSocket.onclose = function(event) {
  1620. //Transfer ended
  1621. };
  1622. thumbRenderWebSocket.onerror = function(error) {
  1623. console.log(error);
  1624. };
  1625. }
  1626. //Make an div not draggable
  1627. function disableDrag(event){
  1628. event.preventDefault();
  1629. event.stopPropagation();
  1630. }
  1631. //Make fileObject draggable
  1632. function onFileObjectDragStart(object, event){
  1633. if ((ctrlHold) && $(object).hasClass("selected") == false){
  1634. $(object).addClass("selected");
  1635. }else if ($(object).hasClass("selected") == false){
  1636. $(".fileObject.selected").removeClass("selected");
  1637. $(object).addClass("selected");
  1638. }
  1639. var fileList = [];
  1640. $(".selected.fileObject").each(function(){
  1641. var filename = $(this).attr('filename');
  1642. var filepath = $(this).attr('filepath');
  1643. var sourceSystemUUID = systemUUID;
  1644. //Extra information is passed in due to the need for cross cluster communication in the future
  1645. fileList.push({
  1646. filename: filename,
  1647. filepath: filepath,
  1648. hostUUID: sourceSystemUUID
  1649. });
  1650. });
  1651. event.dataTransfer.setData("filedata", JSON.stringify(fileList));
  1652. }
  1653. //Bind onclicke events for fileObjects
  1654. var lastClickedFileID = 0;
  1655. function bindFileObjectEvents(){
  1656. $(".fileObject").off("click").on('click',function(evt){
  1657. if (!ctrlHold && isMobile){
  1658. //If on mobile, click means open
  1659. openthis(this,evt);
  1660. return
  1661. }
  1662. if (ctrlHold == true){
  1663. if ($(this).hasClass("selected")){
  1664. $(this).removeClass("selected");
  1665. }else{
  1666. $(this).addClass("selected");
  1667. }
  1668. lastClickedFileID = parseInt($(this).attr("fileid"));
  1669. }else if (shiftHold == true){
  1670. //Select everything in range lastClicked to this
  1671. var thisFileID = $(this).attr("fileid");
  1672. let start = parseInt(thisFileID);
  1673. let end = parseInt(lastClickedFileID);
  1674. if (start > end){
  1675. start = parseInt(lastClickedFileID);
  1676. end = parseInt(thisFileID);
  1677. }
  1678. //Select all fileObject in range.
  1679. $(".fileObject").each(function(){
  1680. let currentItemFileID = $(this).attr('fileid');
  1681. currentItemFileID = currentItemFileID - 0;
  1682. if (currentItemFileID >= start && currentItemFileID <= end){
  1683. $(this).addClass("selected");
  1684. }
  1685. });
  1686. }else{
  1687. //Nothing is pressed. Deselect everything and add this only
  1688. $(".fileObject.selected").removeClass("selected");
  1689. $(this).addClass("selected");
  1690. lastClickedFileID = $(this).attr("fileID");
  1691. }
  1692. if ($(".fileObject.selected").length != 1){
  1693. $(".singleObjectOnly").addClass("disabled");
  1694. $(".singleObjectOnlyHide").hide();
  1695. }else{
  1696. $(".singleObjectOnly").removeClass("disabled");
  1697. $(".singleObjectOnlyHide").show();
  1698. }
  1699. });
  1700. //Bind right click select on items
  1701. $(".fileObject").off("mousedown").on("mousedown",function(evt){
  1702. if (evt.which == 3){
  1703. //Right click on this file
  1704. if ($(this).hasClass('selected') == false){
  1705. $(".fileObject.selected").removeClass("selected");
  1706. $(this).addClass("selected");
  1707. }
  1708. }
  1709. });
  1710. //This function calculate and offset the context menu to not go out of the window area
  1711. function calculateContextMenuOffsets(evt){
  1712. var defaultLeftPost = evt.pageX;
  1713. var defaultTopPost =evt.pageY;
  1714. if (evt.pageX > window.innerWidth / 2){
  1715. defaultLeftPost = evt.pageX - $("#contextmenu").width() + "px";
  1716. }
  1717. if (evt.pageY > window.innerHeight / 2){
  1718. defaultTopPost = evt.pageY - $("#contextmenu").height() + "px";
  1719. }
  1720. $("#contextmenu").css({
  1721. left: defaultLeftPost,
  1722. top: defaultTopPost
  1723. });
  1724. }
  1725. //Rightclick on a file object
  1726. $(".fileObject").off("contextmenu").on("contextmenu", function(evt){
  1727. evt.preventDefault();
  1728. if (isMobile){
  1729. //Firefox Mobile. Fix select with context menu not working bug
  1730. var selectedObject = $(evt.target);
  1731. if ($(selectedObject).hasClass("fileObject")){
  1732. if (!ctrlHold){
  1733. $(".fileObject.selected").removeClass("selected");
  1734. }
  1735. $(selectedObject).addClass("selected");
  1736. }else{
  1737. //Uptrace 5 layers for fileObject
  1738. for (var i = 0; i < 5; i++){
  1739. if ($(selectedObject).hasClass("fileObject") == false){
  1740. selectedObject = $(selectedObject).parent();
  1741. }else{
  1742. break;
  1743. }
  1744. }
  1745. if (!ctrlHold){
  1746. $(".fileObject.selected").removeClass("selected");
  1747. }
  1748. $(selectedObject).addClass("selected");
  1749. }
  1750. }
  1751. calculateContextMenuOffsets(evt);
  1752. //Show all options by defaults
  1753. $("#contextmenu").find(".item").show();
  1754. $("#contextmenu").find(".noSelectionOnly").hide();
  1755. //Check if this is folder or file. Replace the suitable selections
  1756. if ($(this).attr("type") == "folder"){
  1757. //Use folder mode
  1758. $("#contextmenu").find(".folderonly").show();
  1759. $("#contextmenu").find(".fileonly").hide();
  1760. }else{
  1761. //Use file mode
  1762. $("#contextmenu").find(".folderonly").hide();
  1763. $("#contextmenu").find(".fileonly").show();
  1764. }
  1765. if (searchMode == true){
  1766. $("#contextmenu").find(".shareonly").show();
  1767. }else{
  1768. $("#contextmenu").find(".shareonly").hide();
  1769. }
  1770. $("#contextmenu").addClass("visible");
  1771. //Handle CSS offset of the contextmenu
  1772. if ($("#contextmenu").offset().top < 0){
  1773. $("#contextmenu").css("top","0px");
  1774. }else if($("#contextmenu").offset().top + $("#contextmenu").height() > window.innerHeight){
  1775. $("#contextmenu").css("top",window.innerHeight - $("#contextmenu").height() + "px");
  1776. }
  1777. if (isMobile){
  1778. $("#contextmenu").find(".mobileonly").show();
  1779. }else{
  1780. $("#contextmenu").find(".mobileonly").hide();
  1781. }
  1782. });
  1783. //Right click on empty space of the file selector
  1784. $("#folderView").off("contextmenu").on("contextmenu", function(e){
  1785. if ($(e.target).attr("id") == "folderView" || $(e.target).attr("id") == "fileList" || $(e.target).attr("id") == "folderList"){
  1786. //Context menu on the empty space of the folder / file list
  1787. e.preventDefault();
  1788. $("#contextmenu").find(".item").hide();
  1789. $("#contextmenu").find(".noSelectionOnly").show();
  1790. $("#contextmenu").find(".allowNoSelection").show();
  1791. //Calculate the position of the context menu
  1792. calculateContextMenuOffsets(e);
  1793. //Show context menu
  1794. $("#contextmenu").addClass("visible");
  1795. //Handle CSS offset of the contextmenu
  1796. if ($("#contextmenu").offset().top < 0){
  1797. $("#contextmenu").css("top","0px");
  1798. }else if($("#contextmenu").offset().top + $("#contextmenu").height() > window.innerHeight){
  1799. $("#contextmenu").css("top",window.innerHeight - $("#contextmenu").height() + "px");
  1800. }
  1801. }
  1802. });
  1803. //Handle right click on storage roots
  1804. $("#storageroot").off("contextmenu").on("contextmenu", function(e){
  1805. if ($(e.target).is("i")){
  1806. e.target = e.target.parentElement;
  1807. }
  1808. $("#storageroot").find(".dir.item").each(function(){
  1809. if ($(this).attr("rootname") != undefined){
  1810. $(this).removeClass("active");
  1811. }
  1812. });
  1813. if ($(e.target).attr("rootname") != undefined){
  1814. //Correct one. Show vroot functions
  1815. e.preventDefault();
  1816. var rootname = $(e.target).attr("rootname");
  1817. var containBackup = $(e.target).attr("contain-backup") == "true";
  1818. $(e.target).addClass("active");
  1819. $("#contextmenu").find(".item").hide();
  1820. $("#contextmenu").find(".vrootonly").show();
  1821. //Check if this is a backup drive
  1822. if (containBackup == true){
  1823. $("#contextmenu").find(".backuponly").show();
  1824. }
  1825. //Show context menu
  1826. calculateContextMenuOffsets(e);
  1827. $("#contextmenu").addClass("visible");
  1828. //Handle CSS offset of the contextmenu
  1829. if ($("#contextmenu").offset().top < 0){
  1830. $("#contextmenu").css("top","0px");
  1831. }else if($("#contextmenu").offset().top + $("#contextmenu").height() > window.innerHeight){
  1832. $("#contextmenu").css("top",window.innerHeight - $("#contextmenu").height() + "px");
  1833. }
  1834. }
  1835. });
  1836. $(document).on("click",function(evt){
  1837. $(".contextmenu").removeClass("visible");
  1838. });
  1839. }
  1840. //Change the current view mode
  1841. function changeViewMode(object){
  1842. var targetMode = $(object).attr("mode");
  1843. viewMode = targetMode;
  1844. listDirectory(currentPath);
  1845. updateViewmodeButtons();
  1846. setPreference("file_explorer/listmode",targetMode)
  1847. }
  1848. function updateViewmodeButtons(){
  1849. $(".videmode").removeClass('disabled');
  1850. $(".videmode").each(function(){
  1851. if ($(this).attr("mode") == viewMode){
  1852. $(this).addClass("disabled");
  1853. }
  1854. });
  1855. }
  1856. function previosPath(){
  1857. //Remove the current directory from history
  1858. if (viewHistory.length == 0){
  1859. //This is already the first page
  1860. return;
  1861. }
  1862. var previousPath = viewHistory.pop();
  1863. listDirectory(previousPath, undefined, false);
  1864. }
  1865. function parentDir(){
  1866. //If under searchmode, parentDir go back to the currentPath
  1867. if (searchMode){
  1868. hideSearchBar();
  1869. return;
  1870. }
  1871. //Check if there are any parent dir for this path
  1872. if (checkIfParentDirExists(currentPath)){
  1873. //There are parent path. Get it from currentPath
  1874. pathInfo = currentPath.split("/");
  1875. pathInfo.pop();
  1876. var parentFolderName = pathInfo.pop();
  1877. parentPath = pathInfo.join("/") + "/"
  1878. //List the parentDir
  1879. listDirectory(parentPath, function(){
  1880. focusFileObject(parentFolderName);
  1881. });
  1882. }
  1883. }
  1884. //Move the page focus to the given fileobject
  1885. function focusFileObject(targetFileName){
  1886. $(".fileObject").each(function(){
  1887. if ($(this).attr("filename") == targetFileName){
  1888. $(this).addClass("selected");
  1889. //Trying to vertically align the directory from its parent list
  1890. $("#folderView").stop().finish().animate({
  1891. scrollTop: $(this).offset().top - $("#folderView").offset().top - (window.innerHeight - $("#navibar").height())/2 + $(this).height()
  1892. }, 300);
  1893. }
  1894. });
  1895. }
  1896. function loadListModeFromDB(callback = undefined){
  1897. //Get list mode from storage
  1898. loadPreference("file_explorer/listmode",function(data){
  1899. if (data != "" && data.error === undefined){
  1900. viewMode = data;
  1901. updateViewmodeButtons();
  1902. }
  1903. if (callback !== undefined){
  1904. callback();
  1905. }
  1906. });
  1907. }
  1908. function rootDir(){
  1909. //Go to the root dir of the current path
  1910. var rootDir = currentPath.split("/").shift();
  1911. rootDir = rootDir + "/";
  1912. listDirectory(rootDir);
  1913. }
  1914. function checkIfParentDirExists(path){
  1915. if (path.includes("/")){
  1916. pathInfo = path.split("/");
  1917. if (pathInfo[1] == ""){
  1918. return false;
  1919. }else{
  1920. return true;
  1921. }
  1922. }else{
  1923. return false;
  1924. }
  1925. }
  1926. function getDirHash(callback){
  1927. $.ajax({
  1928. url: "../../system/file_system/listDirHash",
  1929. data: {dir: currentPath},
  1930. success: function(data){
  1931. if (data.error !== undefined){
  1932. if (data.error == "Invalid dir given"){
  1933. //Storage has been unmounted. Back to parent
  1934. var pdir = currentPath.split("/");
  1935. pdir.pop();pdir.pop();
  1936. pdir = pdir.join("/");
  1937. currentPath = pdir;
  1938. listDirectory(currentPath, function(){
  1939. window.location.reload();
  1940. });
  1941. return;
  1942. }
  1943. }
  1944. callback(data);
  1945. }
  1946. })
  1947. }
  1948. //=================================== FILE OPERATIONS ========================
  1949. function refreshList(){
  1950. shiftHold = false;
  1951. ctrlHold = false;
  1952. let currentScrollTop = JSON.parse(JSON.stringify($("#folderView").scrollTop()));
  1953. listDirectory(currentPath, function(){
  1954. //Scroll back to the original height
  1955. $("#folderView").scrollTop(currentScrollTop);
  1956. });
  1957. }
  1958. function zipFile(){
  1959. $(".popup").fadeOut('fast');
  1960. var zippingFiles = [];
  1961. $(".fileObject.selected").each(function(){
  1962. var filepath = $(this).attr("filepath");
  1963. zippingFiles.push(filepath);
  1964. });
  1965. console.log(zippingFiles);
  1966. //Request to create a zip file, named with the parent dir name
  1967. var oprConfig = {
  1968. opr: "zip",
  1969. src: zippingFiles,
  1970. dest: currentPath,
  1971. overwriteMode: "overwrite",
  1972. callbackWindowID: ao_module_windowID,
  1973. callbackFunction: `callRefresh("${currentPath}")`
  1974. }
  1975. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  1976. var title = "Zipping " + zippingFiles.length;
  1977. if (fileList.length > 1){
  1978. title += " files";
  1979. }else{
  1980. title += " file";
  1981. }
  1982. parent.newFloatWindow({
  1983. url: "SystemAO/file_system/file_operation.html#" + configHash,
  1984. width: 400,
  1985. height: 220,
  1986. appicon: "SystemAO/file_system/img/selector.png",
  1987. title: title
  1988. });
  1989. }
  1990. let renameFileObjects = [];
  1991. function rename(){
  1992. $(".popup").fadeOut('fast');
  1993. renameFileObjects = [];
  1994. var filenames = [];
  1995. $(".fileObject.selected").each(function(){
  1996. var fileObjectType = $(this).attr("type");
  1997. let fileObject = {
  1998. filename: $(this).attr('filename'),
  1999. filepath: $(this).attr("filepath"),
  2000. filetype: fileObjectType
  2001. }
  2002. renameFileObjects.push(JSON.parse(JSON.stringify(fileObject)));
  2003. filenames.push($(this).attr('filename'));
  2004. });
  2005. var oldname = "unknown file.txt";
  2006. if (renameFileObjects.length == 0){
  2007. return;
  2008. }else if (renameFileObjects.length > 0){
  2009. $("#renameBox").find(".multifileWarning").hide();
  2010. oldname = filenames[0];
  2011. }
  2012. $("#renameBox").find(".orgfn").val(oldname);
  2013. $("#renameBox").find(".newfn").val(oldname);
  2014. showPopupWrapper();
  2015. $("#renameBox").fadeIn(100);
  2016. }
  2017. function confirmRename(){
  2018. var oldName = $("#renameBox").find(".orgfn").val();
  2019. var newName = $("#renameBox").find(".newfn").val();
  2020. if (newName == oldName){
  2021. msgbox("remove","New filename is identical to the original filename.")
  2022. $("#renameBox").fadeOut(100);
  2023. return;
  2024. }
  2025. var newNameWithoutExt = newName;
  2026. var newnameExt = "";
  2027. if (newName.includes(".")){
  2028. tmp = newName.split(".");
  2029. newnameExt = tmp.pop();
  2030. newNameWithoutExt = tmp.join(".");
  2031. }
  2032. var counter = 0;
  2033. var srclist = [];
  2034. var newnamelist = [];
  2035. for (var i =0; i < renameFileObjects.length; i++){
  2036. var thisFilepath = renameFileObjects[i].filepath;
  2037. var thisFiletype = renameFileObjects[i].filetype;
  2038. var thisFilename = renameFileObjects[i].filename;
  2039. var newFilename = newName;
  2040. if ( i > 0){
  2041. if (thisFiletype == "file"){
  2042. var thisFileExt = thisFilename.split(".").pop();
  2043. newFilename = newNameWithoutExt + "(" + i + ")." + thisFileExt;
  2044. }else if (thisFiletype == "folder"){
  2045. newFilename = newNameWithoutExt + "(" + i + ")";
  2046. }
  2047. }
  2048. srclist.push(thisFilepath);
  2049. newnamelist.push(newFilename);
  2050. }
  2051. console.log(srclist, newnamelist);
  2052. //Send the request to serverside
  2053. requestCSRFToken(function(token){
  2054. $.ajax({
  2055. url: "../../system/file_system/fileOpr",
  2056. method: "POST",
  2057. data: {opr: "rename", src: JSON.stringify(srclist), new: JSON.stringify(newnamelist), csrft: token},
  2058. success: function(data){
  2059. if (data.error !== undefined){
  2060. msgbox("remove",data.error);
  2061. $("#renameBox").fadeOut(100);
  2062. }else{
  2063. refreshList();
  2064. msgbox("checkmark","Rename suceed");
  2065. $("#renameBox").fadeOut(100);
  2066. }
  2067. }
  2068. });
  2069. renameFileObjects = [];
  2070. });
  2071. hideAllPopupWindows();
  2072. }
  2073. function changeOverwriteRule(mode, doPasteAgain=false){
  2074. switch (mode){
  2075. case 0:
  2076. overwriteMode = "overwrite";
  2077. break;
  2078. case 1:
  2079. overwriteMode = "skip";
  2080. break;
  2081. case 2:
  2082. overwriteMode = "keep";
  2083. break;
  2084. default:
  2085. overwriteMode = "keep";
  2086. }
  2087. if (doPasteAgain){
  2088. //Initiate paste without checking and close the overwritemode selector
  2089. paste(undefined, true);
  2090. $("#overwriteModeSelection").fadeOut(100);
  2091. }
  2092. }
  2093. function copy(){
  2094. cutMode = false;
  2095. clipboard = [];
  2096. if ($(".fileObject.selected").length == 0){
  2097. return;
  2098. }
  2099. $(".fileObject.selected").each(function(){
  2100. var thisFilepath = $(this).attr("filepath");
  2101. clipboard.push(thisFilepath);
  2102. });
  2103. if (useLocalstorage){
  2104. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  2105. localStorage.setItem("ao/file_system/cutmode","false");
  2106. }
  2107. msgbox("copy",clipboard.length + " objects copied.")
  2108. }
  2109. function cut(){
  2110. cutMode = true;
  2111. clipboard = [];
  2112. if ($(".fileObject.selected").length == 0){
  2113. return;
  2114. }
  2115. $(".fileObject.selected").each(function(){
  2116. var thisFilepath = $(this).attr("filepath");
  2117. clipboard.push(thisFilepath);
  2118. });
  2119. if (useLocalstorage){
  2120. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  2121. localStorage.setItem("ao/file_system/cutmode","true");
  2122. }
  2123. msgbox("cut",clipboard.length + " objects ready to be moved.")
  2124. }
  2125. function paste(redirectPasteTarget="", nocheck=false){
  2126. let thisOprCutMode = cutMode;
  2127. let fileList = clipboard;
  2128. let targetDir = currentPath;
  2129. if (redirectPasteTarget != ""){
  2130. //Allow redirection of paste target if necessary
  2131. targetDir = redirectPasteTarget;
  2132. }
  2133. if (useLocalstorage){
  2134. //There are localStorage. Always use localStorage if exists.
  2135. var crossFrameClipboard = localStorage.getItem("ao/file_system/clipboard");
  2136. var useCutMode = localStorage.getItem("ao/file_system/cutmode");
  2137. if (crossFrameClipboard !== "" && crossFrameClipboard !== undefined && crossFrameClipboard !== null){
  2138. fileList = JSON.parse(crossFrameClipboard);
  2139. }
  2140. if (useCutMode !== "" && useCutMode !== undefined && useCutMode !== null){
  2141. thisOprCutMode = (useCutMode == "true");
  2142. }
  2143. }
  2144. if (fileList.length == 0){
  2145. //There are nothing to paste
  2146. msgbox("question","There are nothing to paste.")
  2147. return;
  2148. }
  2149. //console.log(fileList,JSON.stringify(fileList));
  2150. if (thisOprCutMode == true){
  2151. //Cut and paste
  2152. $.ajax({
  2153. type: 'POST',
  2154. url: `../../system/file_system/validateFileOpr`,
  2155. data: {src: JSON.stringify(fileList), dest: targetDir},
  2156. success: function(data){
  2157. if (!nocheck && data !== null){
  2158. //There are problem with the copy target. Pop up overwrite rule selector
  2159. showDuplicateHandler(data);
  2160. }else{
  2161. //OK!
  2162. //Clear clipboard settings
  2163. localStorage.setItem("ao/file_system/clipboard", "");
  2164. clipboard = "";
  2165. //Stsart operations
  2166. if (!ao_module_virtualDesktop){
  2167. //Not under desktop mode. Use direct copy API
  2168. requestCSRFToken(function(token){
  2169. $.ajax({
  2170. type: 'POST',
  2171. url: `../../system/file_system/fileOpr`,
  2172. data: {opr: "move" ,src: JSON.stringify(fileList), dest: targetDir,existsresp: overwriteMode, csrft: token},
  2173. success: function(data){
  2174. if (data.error !== undefined){
  2175. msgbox("remove",data.error);
  2176. }else{
  2177. //OK
  2178. msgbox("checkmark",fileList.length + " objects moved.")
  2179. refreshList();
  2180. }
  2181. hideAllPopupWindows();
  2182. }
  2183. });
  2184. });
  2185. }else{
  2186. //Pass the request to operation handler
  2187. var oprConfig = {
  2188. opr: "move",
  2189. src: fileList,
  2190. dest: targetDir,
  2191. overwriteMode: overwriteMode,
  2192. callbackWindowID: ao_module_windowID,
  2193. callbackFunction: `callRefresh("${targetDir}")`
  2194. }
  2195. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2196. var title = "Moving " + fileList.length;
  2197. if (fileList.length > 1){
  2198. title += " files";
  2199. }else{
  2200. title += " file";
  2201. }
  2202. parent.newFloatWindow({
  2203. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2204. width: 400,
  2205. height: 220,
  2206. appicon: "SystemAO/file_system/img/selector.png",
  2207. title: title
  2208. });
  2209. hideAllPopupWindows();
  2210. }
  2211. }
  2212. }
  2213. });
  2214. }else{
  2215. //Copy and paste
  2216. //Check if the file list is OK for continue without the need for overwrite
  2217. $.ajax({
  2218. type: 'POST',
  2219. url: `../../system/file_system/validateFileOpr`,
  2220. data: {src: JSON.stringify(fileList), dest: targetDir},
  2221. success: function(data){
  2222. if (!nocheck && data !== null){
  2223. //There are problem with the copy target. Pop up overwrite rule selector
  2224. showDuplicateHandler(data);
  2225. }else{
  2226. //OK!
  2227. if (!ao_module_virtualDesktop){
  2228. requestCSRFToken(function(token){
  2229. $.ajax({
  2230. type: 'POST',
  2231. url: `../../system/file_system/fileOpr`,
  2232. data: {opr: "copy" ,src: JSON.stringify(fileList), dest: targetDir,existsresp: overwriteMode, csrft: token},
  2233. success: function(data){
  2234. if (data.error !== undefined){
  2235. msgbox("remove",data.error);
  2236. }else{
  2237. //OK
  2238. msgbox("checkmark",fileList.length + " objects copied.")
  2239. refreshList();
  2240. }
  2241. hideAllPopupWindows();
  2242. }
  2243. });
  2244. });
  2245. }else{
  2246. //Pass the request to operation handler
  2247. var oprConfig = {
  2248. opr: "copy",
  2249. src: fileList,
  2250. dest: targetDir,
  2251. overwriteMode: overwriteMode,
  2252. callbackWindowID: ao_module_windowID,
  2253. callbackFunction: `callRefresh("${targetDir}")`
  2254. }
  2255. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2256. var title = "Copying " + fileList.length;
  2257. if (fileList.length > 1){
  2258. title += " files";
  2259. }else{
  2260. title += " file";
  2261. }
  2262. parent.newFloatWindow({
  2263. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2264. width: 400,
  2265. height: 220,
  2266. appicon: "SystemAO/file_system/img/selector.png",
  2267. title: title
  2268. });
  2269. hideAllPopupWindows();
  2270. }
  2271. }
  2272. }
  2273. });
  2274. }
  2275. }
  2276. //Callback function for file operation display
  2277. window.callRefresh = function(targetdir){
  2278. console.log(currentPath, targetdir);
  2279. if (currentPath == targetdir){
  2280. refreshList();
  2281. }
  2282. }
  2283. //This action may duplicate files. Show handler
  2284. function showDuplicateHandler(duplicateFileList){
  2285. $(".popup").fadeOut(100);
  2286. var duplicatedFileCounts = duplicateFileList.length;
  2287. showPopupWrapper();
  2288. $("#overwriteModeSelection").fadeIn(100);
  2289. $("#overwriteModeSelection").find(".owm-fc").text(duplicatedFileCounts);
  2290. var srcpath = duplicateFileList[0];
  2291. srcpath = srcpath.split("/");
  2292. srcpath.pop();
  2293. srcpath = srcpath.join("/");
  2294. $("#overwriteModeSelection").find(".owm-srcdir").text(srcpath);
  2295. $("#overwriteModeSelection").find(".owm-destdir").text(currentPath);
  2296. }
  2297. //Force delete. Use normal delete fucntion if you want to move things to recycle bin instead.
  2298. let forceDeleteList = [];
  2299. function forceDelete(confirmed=false){
  2300. if (confirmed == false){
  2301. //Show confirm box
  2302. let deletePendingList = [];
  2303. var listObject = $("#forceDeleteConfirmBox").find(".deleteFilelist")[0];
  2304. $(listObject).html("");
  2305. $(".selected.fileObject").each(function(data){
  2306. var thispath = $(this).attr("filepath");
  2307. var thisfilename = $(this).attr("filename");
  2308. var ext = thisfilename.split(".").pop();
  2309. var icon = ao_module_utils.getIconFromExt(ext);
  2310. deletePendingList.push(thispath);
  2311. $(listObject).append(`<div class="item ${currentTheme}" ><span style="display:inline-block;">${thisfilename}</span></div>`);
  2312. });
  2313. showPopupWrapper();
  2314. $("#forceDeleteConfirmBox").fadeIn(100);
  2315. forceDeleteList = deletePendingList;
  2316. }else{
  2317. //Start force delete function
  2318. $("#forceDeleteConfirmBox").fadeOut(100);
  2319. let fdlistLength = forceDeleteList.length;
  2320. requestCSRFToken(function(token){
  2321. $.ajax({
  2322. url: "../../system/file_system/fileOpr",
  2323. method:"POST",
  2324. data: {opr: "delete", src: JSON.stringify(forceDeleteList), csrft: token},
  2325. success: function(data){
  2326. if (data.error !== undefined){
  2327. msgbox("caution",data.error);
  2328. }else{
  2329. refreshList();
  2330. msgbox("checkmark",fdlistLength + " objects removed.")
  2331. }
  2332. hideAllPopupWindows();
  2333. }
  2334. });
  2335. //Finishing up delete sequence
  2336. forceDeleteList = [];
  2337. });
  2338. }
  2339. }
  2340. let deleteFileList = [];
  2341. function deleteFile(confirmed = false){
  2342. if (!confirmed){
  2343. //Show the confirm dialog
  2344. $("#deleteConfirmBox").find(".deleteFilelist").html("");
  2345. $(".fileObject.selected").each(function(data){
  2346. var thisfilename = $(this).attr('filename');
  2347. var thisFilepath = $(this).attr('filepath');
  2348. deleteFileList.push(thisFilepath);
  2349. $("#deleteConfirmBox").find(".deleteFilelist").append(`<div class="item ${currentTheme}" ><span style="display:inline-block;">${thisfilename}</span></div>`);
  2350. });
  2351. if (deleteFileList.length == 0){
  2352. //No files selected
  2353. return;
  2354. }else{
  2355. //File selected. Continue to delete
  2356. showPopupWrapper();
  2357. $("#deleteConfirmBox").fadeIn(100);
  2358. }
  2359. }else{
  2360. //Continue to delete files
  2361. let fdlistLength = deleteFileList.length;
  2362. requestCSRFToken(function(token){
  2363. $.ajax({
  2364. url: "../../system/file_system/fileOpr",
  2365. method:"POST",
  2366. data: {opr: "recycle", src: JSON.stringify(deleteFileList), csrft: token},
  2367. success: function(data){
  2368. if (data.error !== undefined){
  2369. msgbox("caution",data.error);
  2370. }else{
  2371. refreshList();
  2372. msgbox("checkmark",fdlistLength + " objects moved to trash bin.")
  2373. }
  2374. if (currentPath == "user:/"){
  2375. //Reload the User root folder list
  2376. initRootDirs();
  2377. }
  2378. }
  2379. });
  2380. console.log(deleteFileList);
  2381. deleteFileList = [];
  2382. hideAllPopupWindows();
  2383. });
  2384. }
  2385. }
  2386. function cancelDelete(){
  2387. deleteFileList=[];
  2388. }
  2389. function cancelForceDelete(){
  2390. $("#forceDeleteConfirmBox").fadeOut(100);
  2391. forceDeleteList = [];
  2392. }
  2393. function upload(){
  2394. var input = document.createElement('input');
  2395. input.type = 'file';
  2396. input.multiple = true;
  2397. input.onchange = e => {
  2398. var files = e.target.files;
  2399. msgbox("upload","Upload Started");
  2400. for (var i = 0; i < files.length; i++){
  2401. uploadFile(files[i]);
  2402. }
  2403. }
  2404. input.click();
  2405. }
  2406. function updatePathDisplay(path){
  2407. var pathInfo = path.split("/");
  2408. var vdID = pathInfo[0];
  2409. //As path always end with /, pop the empty pathinfo from array
  2410. pathInfo.pop();
  2411. var l = pathInfo.length;
  2412. //Append the starting vdir
  2413. $(".pathDisplay").html("");
  2414. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="rootDir();"><i class="folder icon"></i> ${vdID}</div>`);
  2415. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2416. //console.log(pathInfo);
  2417. if (l > 3){
  2418. //E.g. user:/Desktop/test/boo/ => Display as user:/.../test/boo/
  2419. $(".pathDisplay").append(`<div class="section ${currentTheme}">...</div>`);
  2420. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2421. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="parentDir();">${shortenLongFoldername(pathInfo[l-2], 40)}</div>`);
  2422. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2423. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[l-1], 60)}</div>`);
  2424. }else if (l == 3){
  2425. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="parentDir();">${shortenLongFoldername(pathInfo[l-2], 40)}</div>`);
  2426. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2427. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[l-1], 60)}</div>`);
  2428. }else if (l == 2){
  2429. //E.g. user:/Desktop or user:/
  2430. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[1], 80)}</div>`);
  2431. }
  2432. }
  2433. function shortenLongFoldername(name, maxchar = 20){
  2434. var resultname = name;
  2435. if (name.length > maxchar){
  2436. //Shorten it
  2437. var offset = parseInt((maxchar - 2) / 2);
  2438. resultname = name.substr(0, offset) + "..." + name.substr(name.length - offset)
  2439. }
  2440. return resultname
  2441. }
  2442. function getExtFromPath(path){
  2443. if (path.includes(".") == false){
  2444. return "";
  2445. }
  2446. return path.split(".").pop();
  2447. }
  2448. function getFileObjectFromFID(fid){
  2449. var targetFileObject = null;
  2450. $(".fileObject").each(function(){
  2451. if ($(this).attr("fileid") == fid){
  2452. targetFileObject = $(this);
  2453. }
  2454. });
  2455. return targetFileObject;
  2456. }
  2457. function openViaButton(){
  2458. let fileOpenList = [];
  2459. let foldersToBeOpened=[];
  2460. $(".fileObject.selected").each(function(){
  2461. let type = $(this).attr("type");
  2462. let filepath = $(this).attr("filepath");
  2463. if (type == "file"){
  2464. fileOpenList.push(filepath);
  2465. }else if (type == "folder"){
  2466. foldersToBeOpened.push(filepath);
  2467. }
  2468. });
  2469. //Open files
  2470. openPathWithDefaultOpener(fileOpenList);
  2471. //Open folders
  2472. openFolderInNewWindow(foldersToBeOpened);
  2473. }
  2474. function openthis(object,evt=null){
  2475. if (evt !== null){
  2476. evt.preventDefault();
  2477. }
  2478. var objType = $(object).attr("type");
  2479. if ( objType == "file"){
  2480. //Open this file. Generate the access path from filepath
  2481. var filepath = $(object).attr("filepath");
  2482. //Only one path to be opened. Pass in as a single object array
  2483. openPathWithDefaultOpener([filepath]);
  2484. }else if (objType == "folder"){
  2485. //Open this folder
  2486. var folderPath = $(object).attr('filepath');
  2487. listDirectory(folderPath, function(){
  2488. //Scroll to top of the list
  2489. $("#folderView").stop().finish().animate({
  2490. scrollTop: 0
  2491. }, 300);
  2492. if ($(object).hasClass('dir') && isMobile){
  2493. toggleSidebar();
  2494. }
  2495. });
  2496. }else if (objType == "shortcut"){
  2497. //Load the shortcut information
  2498. getShortcutInfo($(object).attr('filepath'), function(shortcutInfo){
  2499. /*
  2500. Shortcut Info format
  2501. 0: Shortcut type
  2502. 1: Shortcut Name
  2503. 2: Shortcut target
  2504. 3: Shortcut icon image
  2505. */
  2506. if (shortcutInfo[0] == "module"){
  2507. //This is a module
  2508. if (ao_module_virtualDesktop){
  2509. //Open Module with VDI API
  2510. parent.openModule(shortcutInfo[2]);
  2511. }else{
  2512. //Open module in new tab
  2513. $.get("../../system/modules/getLaunchPara?module=" + shortcutInfo[2], function(data) {
  2514. window.open("../../" + data.StartDir);
  2515. });
  2516. }
  2517. }else if (shortcutInfo[0] == "folder"){
  2518. //This is a folder
  2519. listDirectory(shortcutInfo[2]);
  2520. }else if (shortcutInfo[0] == "url"){
  2521. //This is a url shortcut
  2522. window.open(shortcutInfo[2]);
  2523. }
  2524. console.log(shortcutInfo);
  2525. });
  2526. }
  2527. //Check if this opened in sidebar and in mobile mode. Close sidebar if yes
  2528. }
  2529. /*
  2530. Shortcut Info format
  2531. 0: Shortcut type
  2532. 1: Shortcut Name
  2533. 2: Shortcut target
  2534. 3: Shortcut icon image
  2535. */
  2536. function getShortcutInfo(filepath, callback){
  2537. $.get("../../media?file=" + filepath, function(data){
  2538. //This return the shortcut information. Split it and see what shortcut is this
  2539. data = data.split("\r\n").join("\n");
  2540. var shortcutInfo = data.trim().split("\n");
  2541. callback(shortcutInfo);
  2542. });
  2543. }
  2544. //Download the selected files.
  2545. function downloadFile(){
  2546. var fileList = [];
  2547. if ($(".fileObject.selected").length == 1 && $(".fileObject.selected").attr("type") == "file"){
  2548. //One file. Download directly.
  2549. var downloadURL = "/media?file=" + encodeURIComponent($(".fileObject.selected").attr("filepath")) + "&download=true";
  2550. var filename = $(".fileObject.selected").attr("filename");
  2551. generateDownloadFromURL(downloadURL,escape(filename));
  2552. }else if ($(".fileObject.selected").length > 1 || ($(".fileObject.selected").length == 1 && $(".fileObject.selected").attr("type") == "folder")){
  2553. //Do zip and download for multiple files
  2554. $(".fileObject.selected").each(function(){
  2555. fileList.push($(this).attr("filepath"));
  2556. });
  2557. console.log(fileList);
  2558. //Zip the file or folder
  2559. $.ajax({
  2560. url: "../../system/file_system/zipHandler",
  2561. data: {opr: "tmpzip", src: JSON.stringify(fileList), dest: ""},
  2562. method: "POST",
  2563. success: function(data){
  2564. if (data.error !== undefined){
  2565. alert(data.error);
  2566. }else{
  2567. //Zip completed.
  2568. window.open("../../media?file=" + data + "&download=true");
  2569. }
  2570. }
  2571. });
  2572. }else{
  2573. alert("No file selected!")
  2574. }
  2575. }
  2576. //Create a new file
  2577. function newfile(){
  2578. $(".popup").fadeOut('fast');
  2579. showPopupWrapper();
  2580. $("#newFile").fadeIn('fast');
  2581. $("#newFile").find(".duplicateWarning").hide();
  2582. $("#createNewFileName").parent().removeClass("error");
  2583. //Update the newfile list
  2584. $("#newFile").find(".newfilelist").html("");
  2585. $.ajax({
  2586. url: "../../system/file_system/newItem",
  2587. success: function(data){
  2588. if (data.error !== undefined){
  2589. return;
  2590. }
  2591. for (var i =0; i < data.length; i++){
  2592. var desc = data[i].Desc;
  2593. var ext = data[i].Ext;
  2594. var icon = ao_module_utils.getIconFromExt(ext);
  2595. $("#newFile").find(".newfilelist").append(`<div class="item newFileFormat" ext="${ext}"><i class="${icon} icon" style="margin-right:12px;"></i> ${desc}</div>`);
  2596. }
  2597. //Initialize the new file as txt
  2598. var filename = "newfile";
  2599. var finalFilename = filename;
  2600. var i = 0;
  2601. while (currentFilelist.includes(finalFilename)){
  2602. finalFilename = finalFilename + "(" + i + ")";
  2603. i++;
  2604. }
  2605. $("#createNewFileName").val(finalFilename + ".txt");
  2606. //Hook events for on click
  2607. $(".newFileFormat").off("click").on("click",function(data){
  2608. $(".newFileFormat").removeClass("selected");
  2609. $(this).addClass("selected");
  2610. //Parse the newfilename
  2611. var selectedExt = $(this).attr("ext");
  2612. var filename = "newfile";
  2613. var finalFilename = filename;
  2614. var i = 0;
  2615. while (currentFilelist.includes(finalFilename)){
  2616. finalFilename = finalFilename + "(" + i + ")";
  2617. i++;
  2618. }
  2619. $("#createNewFileName").val(filename + "." + selectedExt);
  2620. });
  2621. }
  2622. });
  2623. }
  2624. function filePermission(){
  2625. //Open file permission window
  2626. if ($(".fileObject.selected").length > 0){
  2627. //Build the filelist
  2628. var fileList = [];
  2629. $(".fileObject.selected").each(function(){
  2630. var filepath = $(this).attr("filepath");
  2631. fileList.push(filepath);
  2632. });
  2633. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  2634. ao_module_newfw({
  2635. url: "SystemAO/file_system/file_permission.html#" + hashPassthrough,
  2636. width: 340,
  2637. height: 480,
  2638. appicon: "SystemAO/file_system/img/properties.png",
  2639. title: "File Permissions",
  2640. })
  2641. }
  2642. }
  2643. function newFolder(confirmed = false){
  2644. if (confirmed == false){
  2645. //Launch the dialog for newFolder
  2646. $(".popup").fadeOut(100);
  2647. $("#createNewFolder").val("");
  2648. $("#createNewFolder").parent().removeClass("error").removeClass("success");
  2649. $("#newFolder").find(".duplicateWarning").hide();
  2650. showPopupWrapper();
  2651. $("#newFolder").fadeIn(100);
  2652. }else{
  2653. //Create new folder
  2654. var newFoldername = $("#createNewFolder").val();
  2655. if (newFoldername == ""){
  2656. $("#createNewFolder").parent().addClass("error");
  2657. return;
  2658. }
  2659. if (currentFilelist.includes(newFoldername)){
  2660. //Current filelist already contain a folder with the same name
  2661. $("#createNewFolder").parent().addClass("error");
  2662. $("#newFolder").find(".duplicateWarning").show();
  2663. return;
  2664. }
  2665. //OK to proceed.
  2666. $("#createNewFolder").parent().removeClass("error").addClass("success");
  2667. $("#newFolder").find(".duplicateWarning").hide();
  2668. $.ajax({
  2669. url: "../../system/file_system/newItem",
  2670. data: {type: "folder", src: currentPath, filename: newFoldername},
  2671. success: function(data){
  2672. if (data.error !== undefined){
  2673. msgbox("remove", data.error);
  2674. }else{
  2675. msgbox("checkmark","New folder created.");
  2676. refreshList();
  2677. }
  2678. $("#newFolder").fadeOut('fast');
  2679. hideAllPopupWindows();
  2680. if (currentPath == "user:/"){
  2681. //Reload the User root folder list
  2682. initRootDirs();
  2683. }
  2684. }
  2685. });
  2686. }
  2687. }
  2688. function confirmNewFile(){
  2689. var filename = $("#createNewFileName").val();
  2690. if (filename == ""){
  2691. //Filename not set
  2692. $("#createNewFileName").parent().addClass("error");
  2693. return;
  2694. }else if(currentFilelist.includes(filename)){
  2695. //File with this name already exists
  2696. $("#createNewFileName").parent().addClass("error");
  2697. $("#newFile").find(".duplicateWarning").show();
  2698. return;
  2699. }
  2700. $("#createNewFileName").parent().removeClass("error");
  2701. //Ok to proceed
  2702. $.ajax({
  2703. url: "../../system/file_system/newItem",
  2704. data: {type: "file", src: currentPath, filename:filename},
  2705. success: function(data){
  2706. if (data.error !== undefined){
  2707. msgbox("remove",data.error);
  2708. }else{
  2709. msgbox("checkmark",filename + " created.");
  2710. refreshList();
  2711. }
  2712. }
  2713. });
  2714. hideAllPopupWindows();
  2715. $("#newFile").fadeOut('fast');
  2716. }
  2717. //Open File Location
  2718. function openFileLocation(){
  2719. var folders = [];
  2720. $(".selected.fileObject").each(function(){
  2721. var thisFilepath = $(this).attr('filepath');
  2722. var thisFilename = $(this).attr('filename');
  2723. openPathInNewWindow(encodeURIComponent(JSON.stringify([{
  2724. filename: thisFilename,
  2725. filepath: thisFilepath
  2726. }])))
  2727. });
  2728. }
  2729. //OpenWith dialog
  2730. function openWith(){
  2731. if ($(".selected.fileObject").length == 0){
  2732. msgbox("question","No file selected");
  2733. return;
  2734. }
  2735. //Get a list of modules and append it into the selection list
  2736. $.get("../../system/modules/list",function(data){
  2737. if (data.error !== undefined){
  2738. console.log(data.error);
  2739. }else{
  2740. $("#openWithModuleList").html("");
  2741. for (var i =0; i < data.length; i++){
  2742. var thisModule = data[i];
  2743. var supportFW = `<div class="ts horizontal mini label"><i class="checkmark icon"></i>floatWindow Window</div>`;
  2744. var supportEmb = `<div class="ts horizontal mini label"><i class="checkmark icon"></i>Embedded Window</div>`;
  2745. if (!thisModule.SupportFW){
  2746. supportFW = "";
  2747. }
  2748. if (!thisModule.LaunchEmb){
  2749. supportEmb = "";
  2750. }
  2751. var launchInfo = encodeURIComponent(JSON.stringify(thisModule));
  2752. $("#openWithModuleList").append(`<div class="item selectable openWithModule" launchInfo="${launchInfo}" onclick="selectOpenWithModule(this, event);" ondblclick="selectOpenWithModule(this, event); openWithSelectedModule();">
  2753. <img class="ts avatar image" src="../../${thisModule.IconPath}">
  2754. <div class="content" style="padding-left:12px;">
  2755. <div class="header">${thisModule.Name}</div>
  2756. <div class="description">
  2757. ${supportFW}
  2758. ${supportEmb}
  2759. </div>
  2760. </div>
  2761. </div>`);
  2762. }
  2763. }
  2764. });
  2765. $(".openWithModule.popupbuttons").addClass("disabled");
  2766. if (!ao_module_virtualDesktop){
  2767. $("#openWith").find(".vdonly").hide();
  2768. }
  2769. showPopupWrapper();
  2770. $("#openWith").fadeIn('fast');
  2771. }
  2772. //Functions for handling open with module selection and file opening
  2773. function selectOpenWithModule(object, event){
  2774. event.preventDefault();
  2775. $(".openWithModule.popupbuttons").removeClass("disabled");
  2776. $(".openWithModule.selected").removeClass("selected");
  2777. $(object).addClass("selected");
  2778. }
  2779. function openWithSelectedModule(btn){
  2780. if ($(btn).hasClass("disabled")){
  2781. return false;
  2782. }
  2783. var targetModuleInfo = JSON.parse(decodeURIComponent($(".openWithModule.selected").attr("launchInfo")));
  2784. var targetObjects = $(".selected.fileObject");
  2785. console.log(targetModuleInfo);
  2786. //Phrase launch mode from the module info
  2787. var launchURL = targetModuleInfo.StartDir
  2788. var launchSize = [undefined, undefined];
  2789. var iconPath = targetModuleInfo.IconPath;
  2790. var title = targetModuleInfo.Name;
  2791. if (targetModuleInfo.SupportEmb){
  2792. //Launch with embedded mode
  2793. launchURL = targetModuleInfo.LaunchEmb;
  2794. if (targetModuleInfo.InitEmbSize !== null){
  2795. launchSize = targetModuleInfo.InitEmbSize
  2796. }
  2797. }else if (targetModuleInfo.SupportFW){
  2798. //Launch with floatWindow mode
  2799. launchURL = targetModuleInfo.LaunchFWDir;
  2800. if (targetModuleInfo.InitFWSize !== null){
  2801. launchSize = targetModuleInfo.InitFWSize
  2802. }
  2803. }else if (targetModuleInfo.StartDir !== ""){
  2804. //Launch with default mode
  2805. }else{
  2806. msgbox("remove","This module has no endpoint for opening a file.");
  2807. return;
  2808. }
  2809. //Parse the filelist
  2810. var filelist = [];
  2811. $(targetObjects).each(function(){
  2812. var filename = $(this).attr("filename");
  2813. var filepath = $(this).attr("filepath");
  2814. filelist.push({
  2815. filename: filename,
  2816. filepath: filepath
  2817. });
  2818. });
  2819. fileHash = encodeURIComponent(JSON.stringify(filelist));
  2820. if (ao_module_virtualDesktop){
  2821. //Open the target module in a new fw
  2822. parent.newFloatWindow({
  2823. url: launchURL + "#" + fileHash,
  2824. width: launchSize[0],
  2825. height: launchSize[1],
  2826. appicon: iconPath,
  2827. title: title
  2828. });
  2829. }else{
  2830. //Redirect current window to the target module
  2831. window.location.href = "../../" + launchURL + "#" + fileHash;
  2832. }
  2833. hideAllPopupWindows();
  2834. }
  2835. function openFileWithModuleInNewTab(btn){
  2836. if ($(btn).hasClass("disabled")){
  2837. return false;
  2838. }
  2839. var targetModuleInfo = JSON.parse(decodeURIComponent($(".openWithModule.selected").attr("launchInfo")));
  2840. var targetObjects = $(".selected.fileObject");
  2841. //Parse the filelist
  2842. var filelist = [];
  2843. $(targetObjects).each(function(){
  2844. var filename = $(this).attr("filename");
  2845. var filepath = $(this).attr("filepath");
  2846. filelist.push({
  2847. filename: filename,
  2848. filepath: filepath
  2849. });
  2850. });
  2851. //Directly passing the file information to the startdir
  2852. fileHash = encodeURIComponent(JSON.stringify(filelist));
  2853. window.open("../../" + targetModuleInfo.StartDir + "#" + fileHash);
  2854. hideAllPopupWindows();
  2855. }
  2856. function openRawFileInFloatWindow(btn){
  2857. //Directly open this (or more than one) files / folder in floatWindow
  2858. var targetObjects = $(".selected.fileObject");
  2859. $(targetObjects).each(function(){
  2860. if ($(this).attr("type") == "file"){
  2861. var launchURL = "media?file=" + $(this).attr('filepath');
  2862. parent.newFloatWindow({
  2863. url: launchURL,
  2864. appicon: "img/system/file.png",
  2865. title: $(this).attr('filename'),
  2866. "background-color": "#1f1f1f"
  2867. });
  2868. }else if ($(this).attr("type") == "folder"){
  2869. var launchURL = "SystemAO/file_system/file_explorer.html#" + $(this).attr("filepath");
  2870. parent.newFloatWindow({
  2871. url: launchURL,
  2872. appicon: "SystemAO/file_system/img/small_icon.png",
  2873. title: "File Manager - " + $(this).attr('filename'),
  2874. });
  2875. }else{
  2876. //Not supported openeing type.
  2877. console.log("Failed to open file " + $(this).attr('filepath') + " . WIP")
  2878. }
  2879. });
  2880. hideAllPopupWindows();
  2881. }
  2882. //Open the filepaths in the given paramters
  2883. function openPathWithDefaultOpener(filepaths){
  2884. console.log("Opening: ", filepaths);
  2885. for (var i =0; i < filepaths.length; i++){
  2886. let filepath = JSON.parse(JSON.stringify(filepaths[i]));
  2887. var ext = "." + filepath.split(".").pop();
  2888. $.ajax({
  2889. url: "../../system/modules/getDefault",
  2890. method: "GET",
  2891. data: {opr: "launch", ext: ext, mode: "launch"},
  2892. success: function(data){
  2893. if (data.error !== undefined){
  2894. //No default opener assigned. Launch it with opener selector
  2895. var url = "SystemAO/file_system/defaultOpener.html";
  2896. var icon = "SystemAO/file_system/img/opener.png";
  2897. var title = "Select an opener WebApp: "
  2898. var openFileList = [];
  2899. var openFileObject = {
  2900. filepath: filepath,
  2901. filename: filepath.split("/").pop()
  2902. }
  2903. openFileList.push(openFileObject);
  2904. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  2905. var ao_module_virtualDesktop = !(!parent.isDesktopMode);
  2906. console.log(window.innerHeight/2 - 510/20);
  2907. if (ao_module_virtualDesktop){
  2908. parent.newFloatWindow({
  2909. url: url + "#" + openParamter,
  2910. width: 320,
  2911. height: 510,
  2912. appicon: icon,
  2913. title: title
  2914. });
  2915. }else{
  2916. url = "defaultOpener.html";
  2917. window.open(url + "#" + openParamter);
  2918. }
  2919. }else{
  2920. //Assigned. Launch with given paramter
  2921. var url = data["StartDir"];
  2922. var size = [undefined, undefined];
  2923. var title = data["Name"];
  2924. var icon = "img/system/favicon.png";
  2925. if (data["IconPath"] != ""){
  2926. icon = data["IconPath"];
  2927. }
  2928. //Use floatWindow if exists
  2929. if (data["SupportFW"] == true && data["LaunchFWDir"] != ""){
  2930. url = data["LaunchFWDir"];
  2931. if (data["InitFWSize"] !== null){
  2932. size = data["InitFWSize"]
  2933. }
  2934. }
  2935. //Use embedded mode if exists
  2936. if (data["SupportEmb"] == true && data["LaunchEmb"] != ""){
  2937. url = data["LaunchEmb"];
  2938. if (data["InitEmbSize"] !== null){
  2939. size = data["InitEmbSize"]
  2940. }
  2941. }
  2942. //Build open File Hash Data Format
  2943. var openFileList = [];
  2944. var openFileObject = {
  2945. filepath: filepath,
  2946. filename: filepath.split("/").pop()
  2947. }
  2948. openFileList.push(openFileObject);
  2949. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2950. //Add launch files info and launch floatWindow
  2951. var ao_module_virtualDesktop = !(!parent.isDesktopMode);
  2952. if (ao_module_virtualDesktop){
  2953. parent.newFloatWindow({
  2954. url: url + "#" + openParamter,
  2955. width: size[0],
  2956. height: size[1],
  2957. appicon: icon,
  2958. title: title
  2959. });
  2960. }else{
  2961. window.open("../../" + url + "#" + openParamter);
  2962. }
  2963. }
  2964. }
  2965. });
  2966. }
  2967. }
  2968. function openSelectedFolderInNewWindow(){
  2969. $(".fileObject.selected").each(function(){
  2970. if ($(this).attr("type") == "folder"){
  2971. console.log($(this).attr('filepath'));
  2972. openPathInNewWindow([$(this).attr('filepath')]);
  2973. }
  2974. })
  2975. }
  2976. function openSelectedVroot(){
  2977. $("#storageroot").find(".dir.item").each(function(){
  2978. if ($(this).hasClass("active")){
  2979. var thisRootPath = $(this).attr('filepath');
  2980. openPathInNewWindow([$(this).attr('filepath')]);
  2981. }
  2982. });
  2983. }
  2984. //Always open the first object locally, and open others in new floatWindows
  2985. function openFolderInNewWindow(paths){
  2986. if (paths.length > 0){
  2987. listDirectory(paths[0]);
  2988. for (var i = 1; i < paths.length; i++){
  2989. //newFloatWindow(location.href.replace(location.hash,"") + "#" + path[i])
  2990. openPathInNewWindow(paths[i]);
  2991. }
  2992. }
  2993. }
  2994. function openPathInNewWindow(path){
  2995. console.log("Opening in new File Maanger: ", window.location.pathname + "#" + path);
  2996. ao_module_newfw({
  2997. url: window.location.pathname + "#" + path,
  2998. appicon: "SystemAO/file_system/img/small_icon.png",
  2999. title: "File Manager",
  3000. width: 1080,
  3001. height: 580,
  3002. parent: ao_module_windowID,
  3003. });
  3004. }
  3005. //Preference setting and loading functions.
  3006. function setPreference(key, value){
  3007. $.ajax({
  3008. url:"../../system/file_system/preference?key=" + key + "&value=" + value,
  3009. success: function(data){
  3010. if (data.error !== undefined){
  3011. console.log(data);
  3012. }
  3013. }
  3014. });
  3015. }
  3016. function loadPreference(key, callback){
  3017. $.get("../../system/file_system/preference?key=" + key,function(data){
  3018. callback(data);
  3019. });
  3020. }
  3021. // ============================== WINDOW RESIZE FUNCTIONS =====================
  3022. $(document).ready(function(data){
  3023. if (window.innerWidth < 620 && !isMobile){
  3024. toggleSidebar(false);
  3025. }
  3026. initWindowSizes(false);
  3027. });
  3028. $(window).on("resize",function(){
  3029. initWindowSizes(false);
  3030. if (!isMobile && window.innerWidth < 620 && sideBarShown == true){
  3031. toggleSidebar(false);
  3032. }else if (!isMobile && window.innerWidth > 650 && sideBarShown == false){
  3033. toggleSidebar(false);
  3034. }
  3035. if (isMobile){
  3036. refreshList();
  3037. }
  3038. });
  3039. function handleShareFilebuttonClick(event, object){
  3040. event.preventDefault();
  3041. event.stopImmediatePropagation();
  3042. $(".fileObject.selected").removeClass("selected");
  3043. if (viewMode == "list"){
  3044. $(object).parent().parent().addClass("selected");
  3045. }else if (viewMode == "grid"){
  3046. $(object).parent().parent().parent().addClass("selected");
  3047. }
  3048. shareFile();
  3049. }
  3050. function shareFile(){
  3051. var selectedFiles = [];
  3052. $(".fileObject.selected").each(function(){
  3053. var thisFilepath = $(this).attr("filepath");
  3054. selectedFiles.push(thisFilepath);
  3055. });
  3056. if (selectedFiles.length != 1){
  3057. //Try to share more than 1 files, which is not supported
  3058. console.log("Multi share is current not supported");
  3059. return
  3060. }
  3061. //OK! Continue to generate link
  3062. var selectedFile = selectedFiles[0];
  3063. shareEditingObject = selectedFile;
  3064. $.ajax({
  3065. url: "../../system/file_system/share/new",
  3066. data: {path: selectedFile},
  3067. success: function(data){
  3068. if (data.error !== undefined){
  3069. alert(data.error);
  3070. }else{
  3071. //Build the predicted share endpoint
  3072. let protocol = "https://";
  3073. if (location.protocol !== 'https:') {
  3074. protocol = "http://";
  3075. }
  3076. //Continue to render QR Code and UI contents
  3077. $("#qrcode").html("");
  3078. var shareURL = protocol + window.location.hostname + ":" + window.location.port + "/share?id=" + data.UUID;
  3079. shareEditingUUID = data.UUID;
  3080. new QRCode(document.getElementById("qrcode"), shareURL);
  3081. $("#sharelink").text(shareURL);
  3082. $("#sharelink").attr("href", shareURL);
  3083. $(".shareoption").parent().removeClass("disabled");
  3084. $("#sharingRemoveBtn").show();
  3085. //Check the correct checkbox
  3086. var tagetCheckbox = data.Permission;
  3087. if (tagetCheckbox == "anyone"){
  3088. $("#anyone")[0].checked = true;
  3089. }else if (tagetCheckbox == "signedin"){
  3090. $("#signedin")[0].checked = true;
  3091. }else if (tagetCheckbox == "samegroup"){
  3092. $("#samegroup")[0].checked = true;
  3093. }
  3094. //Show the share file interface
  3095. $(".popup").fadeOut('fast');
  3096. showPopupWrapper();
  3097. $("#shareFile").fadeIn("fast");
  3098. //Reload the list
  3099. listDirectory(currentPath);
  3100. }
  3101. }
  3102. });
  3103. }
  3104. function removeSharing(){
  3105. if (shareEditingObject == ""){
  3106. return
  3107. }
  3108. //The target file to remove
  3109. var selectedFile = shareEditingObject;
  3110. $.ajax({
  3111. url: "../../system/file_system/share/delete",
  3112. data: {path: selectedFile},
  3113. success: function(data){
  3114. console.log(data);
  3115. $("#qrcode").html(`<img src="img/private.png">`);
  3116. $(".shareoption").parent().addClass("disabled");
  3117. $("#sharelink").text("(Sharing Removed)");
  3118. $("#sharelink").removeAttr("href");
  3119. $("#sharingRemoveBtn").hide();
  3120. //Reload the current filelist and hide the share interface
  3121. listDirectory(currentPath);
  3122. //Reset sharing file settings
  3123. shareEditingObject = ""
  3124. shareEditingUUID = ""
  3125. }
  3126. });
  3127. }
  3128. function updateShareSettings(object){
  3129. $(object).addClass("loading");
  3130. var shareMode = $("#shareSettingForm [name='shareopt']:checked").val();
  3131. $.ajax({
  3132. url: "../../system/file_system/share/edit",
  3133. data: {uuid: shareEditingUUID, mode: shareMode},
  3134. success: function(data){
  3135. if (data.error !== undefined){
  3136. alert(data.error);
  3137. }
  3138. $(object).removeClass("loading");
  3139. $(object).html(`<i class="checkmark icon"></i> Updated`);
  3140. $(object).addClass("positive");
  3141. setTimeout(function(){
  3142. $(object).html("Update");
  3143. $(object).removeClass("positive");
  3144. }, 3000);
  3145. }
  3146. })
  3147. }
  3148. function hideShare(){
  3149. hideAllPopupWindows();
  3150. }
  3151. function toggleSidebar(useAnimation=true){
  3152. //Fixing desktop bugs on showing the sidebar
  3153. if (isMobile){
  3154. $("#directorySidebar").stop().finish().animate({left: "toggle"},200);
  3155. }else{
  3156. if ($("#directorySidebar").offset().left < 0){
  3157. $("#directorySidebar").stop().finish().animate({left: 0},200);
  3158. }else{
  3159. $("#directorySidebar").stop().finish().animate({left: -1 * directorySidebarWidth},200);
  3160. }
  3161. }
  3162. sideBarShown = !sideBarShown;
  3163. initWindowSizes(useAnimation);
  3164. }
  3165. function initWindowSizes(animate=true){
  3166. var h = $("#navibar").css("height");
  3167. var hint = $("#navibar").height();
  3168. //$("#mainWindow").css("padding-top",h);
  3169. var windowHeight = window.innerHeight - hint - 12;
  3170. //console.log(windowHeight);
  3171. if (sideBarShown){
  3172. //Resize the sidebar
  3173. $("#directorySidebar").css("top",h);
  3174. $("#directorySidebar").css("width",directorySidebarWidth);
  3175. $("#directorySidebar").css("height",windowHeight + "px");
  3176. //Resize the file viewer
  3177. $("#folderView").css("top",h);
  3178. if (window.innerWidth > 650){
  3179. if (animate){
  3180. $("#folderView").stop().finish().animate({
  3181. left: directorySidebarWidth + 'px',
  3182. width: window.innerWidth - directorySidebarWidth - 2 + "px"
  3183. },200);
  3184. }else{
  3185. $("#folderView").css({
  3186. left: directorySidebarWidth + 'px',
  3187. width: window.innerWidth - directorySidebarWidth - 2 + "px"
  3188. });
  3189. }
  3190. }else{
  3191. //Window width too small to allow resizing sidebar shown. Overlap it
  3192. if (animate){
  3193. $("#folderView").stop().finish().animate({
  3194. left: directorySidebarWidth + 'px',
  3195. width: window.innerWidth + "px"
  3196. },200);
  3197. }else{
  3198. $("#folderView").css({
  3199. left: directorySidebarWidth + 'px',
  3200. width: window.innerWidth + "px"
  3201. });
  3202. }
  3203. }
  3204. if (isChromium){
  3205. //$("#mainWindow").css("height", window.innerWidth);
  3206. }
  3207. //$("#folderView").css("left",directorySidebarWidth + "px");
  3208. $("#folderView").css("height",windowHeight + "px");
  3209. }else{
  3210. $("#folderView").css("top",h);
  3211. if (animate){
  3212. $("#folderView").stop().finish().animate({
  3213. left:'0px',
  3214. width:(window.innerWidth - 2 + "px")
  3215. },200);
  3216. }else{
  3217. $("#folderView").css({
  3218. left:'0px',
  3219. width:(window.innerWidth - 2 + "px")
  3220. });
  3221. }
  3222. $("#folderView").css("height",windowHeight + "px");
  3223. }
  3224. }
  3225. function toggleDarkTheme(){
  3226. if ($(".darkTheme").length > 0){
  3227. //Set To Whitetheme
  3228. $(".darkTheme").removeClass("darkTheme").addClass("whiteTheme");
  3229. currentTheme = "whiteTheme";
  3230. $("#darkthemebtn").attr("class","moon icon");
  3231. $("#darkthemebtn").parent().addClass("inverted");
  3232. $(".dropdown").removeClass("inverted");
  3233. setPreference("file_explorer/theme","whiteTheme");
  3234. //If in vdi mode, update desktop's listMenu as well
  3235. if (ao_module_virtualDesktop){
  3236. parent.initTheme("whiteTheme");
  3237. }
  3238. }else{
  3239. //Set to DarkTheme
  3240. $(".whiteTheme").removeClass("whiteTheme").addClass("darkTheme");
  3241. currentTheme = "darkTheme";
  3242. $("#darkthemebtn").attr("class","sun icon");
  3243. $("#darkthemebtn").parent().removeClass("inverted");
  3244. $(".dropdown").addClass("inverted");
  3245. setPreference("file_explorer/theme","darkTheme");
  3246. //If in vdi mode, update desktop's listMenu as well
  3247. if (ao_module_virtualDesktop){
  3248. parent.initTheme("darkTheme");
  3249. }
  3250. }
  3251. }
  3252. function msgbox(icon, text){
  3253. $($(".msgbox").find("span")[0]).text(text);
  3254. $($(".msgbox").find("i")[0]).attr("class", icon + " icon");
  3255. $(".msgbox").stop().finish().slideDown('fast').delay(3000).slideUp('fast');
  3256. }
  3257. //Keyboard hotkey events
  3258. $(document).keydown(function(event){
  3259. if ($(':focus').is("input")){
  3260. //Do not block operations on input fields.
  3261. return;
  3262. }
  3263. if(event.which==17 || event.which == 91){
  3264. ctrlHold = true;
  3265. }else if (event.which == 16){
  3266. shiftHold = true;
  3267. }else if (event.which == 67 && ctrlHold == true){
  3268. //Ctrl + C
  3269. if (!$(".popup").is(":visible")){
  3270. event.preventDefault();
  3271. copy();
  3272. }
  3273. }else if (event.which == 88 && ctrlHold == true){
  3274. //Ctrl + X
  3275. if (!$(".popup").is(":visible")){
  3276. event.preventDefault();
  3277. cut();
  3278. }
  3279. }else if (event.which == 65 && ctrlHold == true){
  3280. //Ctrl + A
  3281. event.preventDefault();
  3282. $(".fileObject").addClass("selected");
  3283. }else if (event.which == 78 && shiftHold == true){
  3284. //Shift + N, Open new file manager window with current path
  3285. event.preventDefault();
  3286. openPathInNewWindow(currentPath);
  3287. }else if (event.which == 86 && ctrlHold == true){
  3288. if (!$(".popup").is(":visible")){
  3289. paste();
  3290. }
  3291. }else if (event.which == 46 && shiftHold == true){
  3292. //Shift + delete
  3293. forceDelete();
  3294. }else if (event.which == 46){
  3295. //Delete
  3296. deleteFile();
  3297. }else if (event.which == 38){
  3298. //Up Arrow
  3299. if ($(".popup:visible").length == 0){
  3300. //No popup visiable
  3301. if (ctrlHold == true){
  3302. //Parenet path
  3303. parentDir();
  3304. }else{
  3305. //Select the file on the upper
  3306. selectPreviousFile(event);
  3307. }
  3308. }
  3309. }else if (event.which == 40){
  3310. //Down arrow
  3311. if ($(".popup:visible").length == 0){
  3312. //No popup visiable
  3313. selectNextFile(event);
  3314. }
  3315. }else if (event.which == 39){
  3316. //Right arrow
  3317. if ($(".popup:visible").length == 0 && viewMode == "grid"){
  3318. //No popup visiable and grid mode
  3319. selectRightFile(event);
  3320. }
  3321. }else if (event.which == 37){
  3322. //Left arrow
  3323. if ($(".popup:visible").length == 0 && viewMode == "grid"){
  3324. //No popup visiable and grid mode
  3325. selectLeftFile(event);
  3326. }
  3327. }else if (event.which == 13){
  3328. //Enter key
  3329. if ($(".fileObject.selected").length > 0){
  3330. openViaButton();
  3331. }
  3332. }else if (event.which == 27){
  3333. //Esc key
  3334. hideAllPopupWindows();
  3335. $(".fileObject.selected").removeClass("selected");
  3336. }else{
  3337. //console.log(event.which);
  3338. }
  3339. });
  3340. $(document).keyup(function(event){
  3341. if(event.which==17 || event.which == 91){
  3342. ctrlHold = false;
  3343. }else if (event.which == 16){
  3344. shiftHold = false;
  3345. }
  3346. });
  3347. $("#directorySidebar").on("click",function(evt){
  3348. //Clear the button holding
  3349. $(".fileObject.selected").removeClass("selected");
  3350. shiftHold = false;
  3351. ctrlHold = false;
  3352. });
  3353. //Check if localstorage is availble
  3354. function lscheck(){
  3355. var test = 'test';
  3356. try {
  3357. localStorage.setItem(test, test);
  3358. localStorage.removeItem(test);
  3359. return true;
  3360. } catch(e) {
  3361. return false;
  3362. }
  3363. }
  3364. function selectNextFile(e){
  3365. e.preventDefault();
  3366. //Check if there are no selection. If yes, select the first file object
  3367. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3368. //Select the first file object
  3369. $($(".fileObject")[0]).addClass("selected");
  3370. return
  3371. }else if ( $(".fileObject").length == 0){
  3372. //No file in this folder
  3373. return
  3374. }
  3375. //Already contain selected file on the interface. Seleect it
  3376. var baseObject = $($(".fileObject.selected")[0]);
  3377. if ($(".fileObject.selected").length > 1){
  3378. $(".fileObject.selected").removeClass("selected");
  3379. }
  3380. if (viewMode == "list"){
  3381. //Select the next file
  3382. var nextObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) + 1 );
  3383. if (nextObject.length > 0){
  3384. nextObject.addClass("selected");
  3385. scrollToFileObject(nextObject);
  3386. $(baseObject).removeClass("selected");
  3387. }
  3388. }else if (viewMode == "grid"){
  3389. var colobj = getFileObjectInTheSameCol(baseObject);
  3390. var nextObject = baseObject;
  3391. for (var i = 0; i < colobj.length; i++){
  3392. if ($(colobj[i]).hasClass("selected") && i != colobj.length - 1){
  3393. nextObject = colobj[i + 1];
  3394. }
  3395. }
  3396. $(baseObject).removeClass("selected");
  3397. nextObject.addClass("selected");
  3398. scrollToFileObject(nextObject);
  3399. }
  3400. }
  3401. function selectPreviousFile(e){
  3402. e.preventDefault();
  3403. //Check if there are no selection. If yes, select the first file object
  3404. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3405. //Select the first file object
  3406. $($(".fileObject")[$(".fileObject").length - 1]).addClass("selected");
  3407. return
  3408. }else if ( $(".fileObject").length == 0){
  3409. //No file in this folder
  3410. return
  3411. }
  3412. var baseObject = $($(".fileObject.selected")[0]);
  3413. if ($(".fileObject.selected").length > 1){
  3414. $(".fileObject.selected").removeClass("selected");
  3415. }
  3416. if (viewMode == "list"){
  3417. //Select the previous file
  3418. if ($(".fileObject").index( $(baseObject) ) -1 < 0){
  3419. return;
  3420. }
  3421. var previousObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) -1 );
  3422. if (previousObject.length > 0){
  3423. previousObject.addClass("selected");
  3424. scrollToFileObject(previousObject);
  3425. $(baseObject).removeClass("selected");
  3426. }
  3427. }else if (viewMode == "grid"){
  3428. var colobj = getFileObjectInTheSameCol(baseObject);
  3429. var prevObj = baseObject;
  3430. for (var i = 0; i < colobj.length; i++){
  3431. if ($(colobj[i]).hasClass("selected") && i > 0){
  3432. prevObj = colobj[i - 1];
  3433. }
  3434. }
  3435. $(baseObject).removeClass("selected");
  3436. prevObj.addClass("selected");
  3437. scrollToFileObject(prevObj);
  3438. }
  3439. }
  3440. function scrollToFileObject(fileObject){
  3441. if (viewMode == "grid"){
  3442. $('#folderView').scrollTop($(fileObject)[0].offsetTop - ($("#directorySidebar").height()/2 - 340));
  3443. }else{
  3444. $('#folderView').scrollTop($(fileObject)[0].offsetTop - ($("#directorySidebar").height()/2 - 140));
  3445. }
  3446. }
  3447. //Grid mode left right opr
  3448. function selectLeftFile(e){
  3449. e.preventDefault();
  3450. if (viewMode != "grid"){
  3451. return;
  3452. }
  3453. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3454. //Select the first file object
  3455. $($(".fileObject")[$(".fileObject").length - 1]).addClass("selected");
  3456. return
  3457. }else if ( $(".fileObject").length == 0){
  3458. //No file in this folder
  3459. return
  3460. }
  3461. var baseObject = $($(".fileObject.selected")[0]);
  3462. if ($(".fileObject").index( $(baseObject) ) -1 < 0){
  3463. return;
  3464. }
  3465. var previousObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) -1 );
  3466. if (previousObject.length > 0){
  3467. previousObject.addClass("selected");
  3468. scrollToFileObject(previousObject);
  3469. $(baseObject).removeClass("selected");
  3470. }
  3471. }
  3472. function selectRightFile(e){
  3473. e.preventDefault();
  3474. if (viewMode != "grid"){
  3475. return;
  3476. }
  3477. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3478. //Select the first file object
  3479. $($(".fileObject")[0]).addClass("selected");
  3480. return
  3481. }else if ( $(".fileObject").length == 0){
  3482. //No file in this folder
  3483. return
  3484. }
  3485. var baseObject = $($(".fileObject.selected")[0]);
  3486. var nextObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) + 1 );
  3487. if (nextObject.length > 0){
  3488. nextObject.addClass("selected");
  3489. scrollToFileObject(nextObject);
  3490. $(baseObject).removeClass("selected");
  3491. }
  3492. }
  3493. //Functions for getting file objects in the same collume
  3494. function getFileObjectInTheSameCol(baseFileObject){
  3495. if (viewMode != "grid"){
  3496. return;
  3497. }
  3498. var baseOffset = $(baseFileObject).offset().left;
  3499. var fileObjectInTheSameCol = [];
  3500. $(".fileObject").each(function(){
  3501. if ($(this).offset().left == baseOffset){
  3502. let thisFileObject = $(this);
  3503. fileObjectInTheSameCol.push(thisFileObject);
  3504. }
  3505. });
  3506. return fileObjectInTheSameCol;
  3507. }
  3508. //Function for getting file objects in the same row
  3509. function getFileObjectInTheSameRow(baseFileObject){
  3510. if (viewMode != "grid"){
  3511. return;
  3512. }
  3513. var baseOffset = $(baseFileObject).offset().top;
  3514. var fileObjectInTheSameRow = [];
  3515. $(".fileObject").each(function(){
  3516. if ($(this).offset().top == baseOffset){
  3517. let thisFileObject = $(this);
  3518. fileObjectInTheSameRow.push(thisFileObject);
  3519. }
  3520. });
  3521. return fileObjectInTheSameRow;
  3522. }
  3523. //Handle drag drop upload
  3524. function drop(event){
  3525. event.preventDefault();
  3526. console.log(event, event.target)
  3527. //Check if this is file upload or file move / copy function
  3528. let dt = event.dataTransfer
  3529. let files = dt.files
  3530. if (files.length > 0){
  3531. //Upload file via dragdrop
  3532. msgbox("upload","Upload Started");
  3533. let items = event.dataTransfer.items;
  3534. for (let i=0; i<items.length; i++) {
  3535. let item = items[i].webkitGetAsEntry();
  3536. if (item) {
  3537. recursiveScanFilesUpload(item);
  3538. }
  3539. }
  3540. }else{
  3541. //File transfer within system
  3542. let filedata = event.dataTransfer.getData("filedata");
  3543. if (filedata != ""){
  3544. try{
  3545. let fileList = JSON.parse(filedata);
  3546. //Check if the file objects are from the same host
  3547. let localFiles = [];
  3548. let remoteFiles = [];
  3549. fileList.forEach(file => {
  3550. if (file.hostUUID == systemUUID){
  3551. //Local file
  3552. localFiles.push(file);
  3553. }else{
  3554. //Remote files
  3555. remoteFiles.push(file);
  3556. }
  3557. });
  3558. //Start processing the local files
  3559. let currentVroot = currentPath.split(":/").shift();
  3560. clipboard = [];
  3561. //Assume all files are from the same directory
  3562. if (localFiles.length > 0){
  3563. //Check if drag drop from the same directory
  3564. let currentDirname = currentPath.split("/")
  3565. currentDirname.pop();
  3566. currentDirname = currentDirname.join("/");
  3567. let firstFileDirname = localFiles[0].filepath.split("/")
  3568. firstFileDirname.pop();
  3569. firstFileDirname = firstFileDirname.join("/");
  3570. if (currentDirname == firstFileDirname){
  3571. //Drag start and drop location are the same directory
  3572. msgbox("remove","Source and destination file names are the same")
  3573. return;
  3574. }
  3575. let fileVroot = localFiles[0].filepath.split(":/").shift();
  3576. if (currentVroot == fileVroot){
  3577. //Same device same root. Move the file
  3578. cutMode = true;
  3579. }else{
  3580. //Same device differnet root. Copy the file
  3581. cutMode = false;
  3582. }
  3583. //Move all localFiles into clipboard
  3584. localFiles.forEach(file => {
  3585. clipboard.push(file.filepath);
  3586. });
  3587. if (useLocalstorage){
  3588. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  3589. if (cutMode){
  3590. localStorage.setItem("ao/file_system/cutmode","true");
  3591. }else{
  3592. localStorage.setItem("ao/file_system/cutmode","false");
  3593. }
  3594. }
  3595. //Paste all the files to the current path
  3596. console.log(clipboard);
  3597. paste();
  3598. }
  3599. }catch(ex){
  3600. console.log(ex);
  3601. msgbox("remove","File drop failed. Unable to decode filelist.");
  3602. }
  3603. }
  3604. }
  3605. }
  3606. function recursiveScanFilesUpload(item, rootpath="", base=""){
  3607. var filesInside = [];
  3608. if (item.isDirectory) {
  3609. //This is a directory
  3610. let directoryReader = item.createReader();
  3611. directoryReader.readEntries(function(entries) {
  3612. entries.forEach(function(entry) {
  3613. recursiveScanFilesUpload(entry, rootpath + item.name + "/", base);
  3614. });
  3615. });
  3616. }else{
  3617. //This is a file. Upload it
  3618. item.file(function(fileObject){
  3619. if (isChrome || isSafari){
  3620. //WebKits
  3621. console.log("Upload Target", fileObject, rootpath);
  3622. uploadFile(fileObject, undefined, currentPath + rootpath);
  3623. }else{
  3624. //Firefox. Special handling for root path.
  3625. //Updates for Firefox 84.0.2 (64-bit), which changed minor implementation on relative path in folder updates
  3626. //This section of code is deprecated since then
  3627. /*
  3628. //As firefox will keep its file input relative path, we need to remove the root folder
  3629. //name from the rootpath passed in by the webkit API
  3630. if (rootpath.substr(rootpath.length - 1, 1) == "/"){
  3631. rootpath = rootpath.substr(0, rootpath.length - 1);
  3632. }
  3633. var rootpathInfo = rootpath.split("/");
  3634. if (rootpathInfo.length > 1){
  3635. //Uploading folder to folder. Extract the folder root name
  3636. rootpathInfo.pop();
  3637. }else{
  3638. //Uploading file to folder. Do nothing
  3639. }
  3640. rootpath = rootpathInfo.join("/") + "/";
  3641. console.log("Upload Target", fileObject, rootpath);
  3642. uploadFile(fileObject, undefined, currentPath + rootpath);
  3643. */
  3644. console.log(currentPath + rootpath);
  3645. uploadFile(fileObject, undefined, currentPath + base);
  3646. }
  3647. });
  3648. }
  3649. return filesInside;
  3650. }
  3651. function showCurrentDirectoryProperties(){
  3652. var fileList = [currentPath];
  3653. console.log(fileList);
  3654. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  3655. ao_module_newfw({
  3656. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3657. width: 340,
  3658. height: 480,
  3659. appicon: "SystemAO/file_system/img/properties.png",
  3660. title: "File Properties",
  3661. });
  3662. }
  3663. function showVrootProperties(){
  3664. var rootname = [$("#storageroot").find(".dir.item.active").attr("filepath")];
  3665. var hashPassthrough = encodeURIComponent(JSON.stringify(rootname));
  3666. ao_module_newfw({
  3667. url: "SystemAO/disk/diskprop.html#" + hashPassthrough,
  3668. width: 410,
  3669. height: 580,
  3670. appicon: "img/system/drive.svg",
  3671. title: "Disk Properties",
  3672. });
  3673. }
  3674. function showFileProperties(){
  3675. //Show the file list of the selected files
  3676. if ($(".fileObject.selected").length > 0){
  3677. //Build the filelist
  3678. var fileList = [];
  3679. $(".fileObject.selected").each(function(){
  3680. var filepath = $(this).attr("filepath");
  3681. fileList.push(filepath);
  3682. });
  3683. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  3684. ao_module_newfw({
  3685. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3686. width: 340,
  3687. height: 480,
  3688. appicon: "SystemAO/file_system/img/properties.png",
  3689. title: "File Properties",
  3690. });
  3691. }
  3692. }
  3693. function initUploadMode(){
  3694. //Get the amount of RAM on the server side to check if low memory mode should be used.
  3695. $.ajax({
  3696. url: "../../system/info/getRAMinfo",
  3697. success: function(data){
  3698. if (data.error !== undefined){
  3699. //Permission denied or other reasons that cannot access harwdare info. Use default mode
  3700. lowMemoryMode = true;
  3701. }else{
  3702. //Check if ramsize > 1.8 GB (2GB). If yes, switch to large memory upload mode
  3703. var memsize = JSON.parse(data);
  3704. if (parseFloat(memsize)/ 1024 / 1024 / 1024 >= 3.8){
  3705. console.log("[File Explorer] Entering large memory upload mode")
  3706. lowMemoryMode = false;
  3707. }
  3708. }
  3709. },
  3710. error: function(){
  3711. //Hardware mode disabled. Always use low memory upload mode instead
  3712. lowMemoryMode = true;
  3713. }
  3714. });
  3715. }
  3716. let uploadBufferedRefreshTimer;
  3717. function uploadFile(file, uuid=undefined, targetDir=undefined) {
  3718. if (lowMemoryMode){
  3719. /*
  3720. Low Memory Upload Mode (Experimental)
  3721. (For host with less than 2GB RAM)
  3722. */
  3723. var filename = encodeURIComponent(file.name);
  3724. var filesize = file.size;
  3725. //Generate a new file item
  3726. let taskUUID = uuid; //For queueing objects
  3727. if (taskUUID == undefined){
  3728. //If this is a new file to be uploaded
  3729. taskUUID = appendUploadFileItem(file.name, file.size);
  3730. }
  3731. //Push to upload pending list if the max concurrent upload is reached
  3732. if (uploadingFileCount >= maxConcurrentUpload){
  3733. let uploadDir = currentPath;
  3734. if (targetDir !== undefined){
  3735. uploadDir = targetDir;
  3736. }else if (isFirefox && uploadDir == currentPath && file.webkitRelativePath != ""){
  3737. //Use the webkitRelativePath instead of the name, this is a folder upload
  3738. //Deprecated for Firefox 84.0.2 updates
  3739. /*
  3740. let pathinfo = file.webkitRelativePath.split("/");
  3741. pathinfo.pop();
  3742. let subpath = pathinfo.join("/");
  3743. uploadDir = uploadDir + subpath;
  3744. */
  3745. uploadDir = targetDir;
  3746. }
  3747. uploadPendingList.push({
  3748. File: file,
  3749. UUID: taskUUID,
  3750. TargetDir: JSON.parse(JSON.stringify(uploadDir)),
  3751. });
  3752. return
  3753. }
  3754. function updateProgressForWebSocketUpload(uuid, progress){
  3755. $(".uploadTask").each(function(){
  3756. if ($(this).attr("taskID") == uuid){
  3757. //Update this progress bar
  3758. $(this).find(".bar").css("width",progress + "%");
  3759. if (progress == 100){
  3760. //When progress = 100 and the server is not response with 200,
  3761. //That means the upload has finish and server is processing the upload
  3762. $(this).find(".progress").addClass("indeterminate");
  3763. }
  3764. }
  3765. });
  3766. }
  3767. //Open the websocket
  3768. let path = currentPath;
  3769. let protocol = "wss://";
  3770. if (location.protocol !== 'https:') {
  3771. protocol = "ws://";
  3772. }
  3773. var port = window.location.port;
  3774. if (window.location.port == ""){
  3775. port = "80";
  3776. }
  3777. let uploadDir = currentPath;
  3778. if (targetDir !== undefined){
  3779. //Not uploading to current directory. Change upload path to target
  3780. uploadDir = targetDir;
  3781. }
  3782. //Fixing Firefox path issues on or above FF48.0
  3783. if (isFirefox && file.webkitRelativePath != ""){
  3784. //Use the webkitRelativePath instead of the name, this is a folder upload
  3785. let pathinfo = file.webkitRelativePath.split("/");
  3786. pathinfo.pop();
  3787. let subpath = pathinfo.join("/");
  3788. uploadDir = uploadDir + subpath;
  3789. //console.log("Firefox Mode: ", uploadDir, "Target Dir", targetDir)
  3790. }
  3791. let socket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/lowmemUpload?filename=" + filename + "&path=" + uploadDir);
  3792. let currentSendingIndex = 0;
  3793. let chunks = Math.ceil(file.size/uploadFileChunkSize,uploadFileChunkSize);
  3794. //Define a function for sending a particular chunk
  3795. function sendChunk(id){
  3796. var offsetStart = id*uploadFileChunkSize;
  3797. var offsetEnd = id*uploadFileChunkSize + uploadFileChunkSize;
  3798. var thisblob = file.slice(offsetStart,offsetEnd);
  3799. socket.send(thisblob);
  3800. //console.log(id + "/" + chunks);
  3801. //Update progress to first percentage
  3802. var progress = id / (chunks-1) * 100.0;
  3803. if (progress > 100){
  3804. progress = 100;
  3805. }
  3806. updateProgressForWebSocketUpload(taskUUID, progress)
  3807. }
  3808. //Update all UI elements
  3809. updateUploadFileCount();
  3810. uploadingFileCount++;
  3811. //Start sending
  3812. socket.onopen = function(e) {
  3813. if (filesize < uploadFileChunkSize){
  3814. //This file is smaller than chunk size, set it to somwhere within 10% - 20% so it doesn't look like it is stuck
  3815. updateProgressForWebSocketUpload(taskUUID, 10 + Math.floor(Math.random() * Math.floor(10)))
  3816. }
  3817. //Send the first chunk
  3818. sendChunk(0);
  3819. currentSendingIndex++;
  3820. };
  3821. socket.onmessage = function(event) {
  3822. //Append to the send index
  3823. var incomingValue = event.data;
  3824. if (incomingValue == "next"){
  3825. if (currentSendingIndex == chunks + 1){
  3826. //Already finished
  3827. socket.send("done");
  3828. }else{
  3829. //Send next chunk
  3830. sendChunk(currentSendingIndex);
  3831. currentSendingIndex++;
  3832. }
  3833. }else if (incomingValue == "OK"){
  3834. //Merge completed
  3835. $(".uploadTask").each(function(){
  3836. if ($(this).attr("taskID") == taskUUID){
  3837. //Update this progress bar to completed
  3838. $(this).find(".bar").css("width","100%");
  3839. $(this).find(".progress").attr("class","ts tiny positive progress");
  3840. $(this).find(".uploadTaskRemoveIcon").show();
  3841. $(this).addClass("ended");
  3842. $.when($(this).delay(1000).fadeOut("fast")).then(function(){
  3843. $(this).remove();
  3844. updateUploadFileCount();
  3845. });
  3846. }
  3847. });
  3848. }else{
  3849. //Try to parse it as JSON
  3850. try{
  3851. var resp = JSON.parse(incomingValue.split('\\' + '"').join("\""));
  3852. console.log(resp);
  3853. if (resp.error !== undefined){
  3854. //This is an error message
  3855. msgbox("remove",resp.error);
  3856. //Update the progress bar to error
  3857. $(".uploadTask").each(function(){
  3858. if ($(this).attr("taskID") == taskUUID){
  3859. //Update this progress bar to completed
  3860. $(this).find(".bar").css("width","100%");
  3861. $(this).find(".progress").attr("class","ts tiny negative progress");
  3862. $(this).find(".uploadTaskRemoveIcon").show();
  3863. $(this).addClass("ended");
  3864. }
  3865. });
  3866. }
  3867. }catch(ex){
  3868. //Something else
  3869. console.log(incomingValue);
  3870. console.log(ex);
  3871. }
  3872. }
  3873. };
  3874. socket.onclose = function(event) {
  3875. uploadingFileCount--;
  3876. updateUploadFileCount();
  3877. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  3878. setTimeout(function(){
  3879. if (uploadPendingList.length > 0){
  3880. let nextFile = uploadPendingList.shift();
  3881. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  3882. }
  3883. }, 100)
  3884. };
  3885. socket.onerror = function(error) {
  3886. console.log(error.message);
  3887. console.log("Unable to open WebSocket connection. Fall back to FORM POST upload mode. (Check your nginx / reverse proxy settings!!!)")
  3888. //Try to fallback to FORM POST upload mode
  3889. lowMemoryMode = false;
  3890. uploadPendingList.push({
  3891. File: file,
  3892. UUID: taskUUID,
  3893. TargetDir: JSON.parse(JSON.stringify(targetDir)),
  3894. });
  3895. return
  3896. /*
  3897. msgbox("caution","Upload failed due to unknown reason");
  3898. //Something went wrong. Set the color to red
  3899. $(".uploadTask").each(function(){
  3900. if ($(this).attr("taskID") == taskUUID){
  3901. //Update this progress bar to completed
  3902. $(this).find(".bar").css("width","100%");
  3903. $(this).find(".progress").attr("class","ts tiny negative progress");
  3904. $(this).find(".uploadTaskRemoveIcon").show();
  3905. $(this).addClass("ended");
  3906. }
  3907. });
  3908. */
  3909. };
  3910. }else{
  3911. /*
  3912. Standard Upload Mode
  3913. (For host with RAM >= 2GB)
  3914. */
  3915. //Create the task progress Object
  3916. let taskUUID = uuid; //For queueing objects
  3917. if (taskUUID == undefined){
  3918. //If this is a new file to be uploaded
  3919. taskUUID = appendUploadFileItem(file.name, file.size);
  3920. }
  3921. //Updates 22-10-2020
  3922. //Added file upload queuing system to prevent too many request on-the-fly at the same time
  3923. if (uploadingFileCount >= maxConcurrentUpload){
  3924. //Push to upload pending list
  3925. //Sometime files will be recursively uploaded (aka retry multiple time), hence the targetDir needed to be copied as well
  3926. let uploadDir = currentPath;
  3927. if (targetDir !== undefined){
  3928. uploadDir = targetDir;
  3929. }
  3930. uploadPendingList.push({
  3931. File: file,
  3932. UUID: taskUUID,
  3933. TargetDir: JSON.parse(JSON.stringify(uploadDir)),
  3934. });
  3935. return
  3936. }
  3937. //Prase upload Form
  3938. let uploadCurrentPath = JSON.parse(JSON.stringify(currentPath));
  3939. if (targetDir !== undefined){
  3940. //The upload paramter supplied targetDir
  3941. uploadCurrentPath = targetDir;
  3942. }
  3943. let url = '../../system/file_system/upload?path=' + uploadCurrentPath
  3944. //console.log("Uploading To => ", uploadCurrentPath, targetDir, currentPath);
  3945. let formData = new FormData()
  3946. let xhr = new XMLHttpRequest()
  3947. formData.append('file', file);
  3948. formData.append('path', uploadCurrentPath);
  3949. xhr.open('POST', url, true)
  3950. xhr.upload.addEventListener("progress", function(e) {
  3951. var progress = (e.loaded * 100.0 / e.total) || 100;
  3952. $(".uploadTask").each(function(){
  3953. if ($(this).attr("taskID") == taskUUID){
  3954. //Update this progress bar
  3955. $(this).find(".bar").css("width",progress + "%");
  3956. if (progress == 100){
  3957. //When progress = 100 and the server is not response with 200,
  3958. //That means the upload has finish and server is processing the upload
  3959. $(this).find(".progress").addClass("indeterminate");
  3960. }
  3961. }
  3962. });
  3963. })
  3964. xhr.addEventListener('readystatechange', function(e) {
  3965. if (xhr.readyState == 4 && xhr.status == 200) {
  3966. //Upload process ended
  3967. //Update task status
  3968. $(".uploadTask").each(function(){
  3969. if ($(this).attr("taskID") == taskUUID){
  3970. //Update this progress bar to completed
  3971. $(this).find(".bar").css("width","100%");
  3972. $(this).find(".progress").attr("class","ts tiny positive progress");
  3973. $(this).find(".uploadTaskRemoveIcon").show();
  3974. $(this).addClass("ended");
  3975. //Update 15-11-2020
  3976. //Remove this taskbar after 3 secounds to prevent lags during > 2000 uploads
  3977. $.when($(this).delay(1000).fadeOut("fast")).then(function(){
  3978. $(this).remove();
  3979. updateUploadFileCount();
  3980. });
  3981. }
  3982. });
  3983. var resp = JSON.parse(e.target.response);
  3984. if (resp.error !== undefined){
  3985. msgbox("caution",resp.error);
  3986. //Something went wrong. Set the color to red
  3987. $(".uploadTask").each(function(){
  3988. if ($(this).attr("taskID") == taskUUID){
  3989. //Update this progress bar to completed
  3990. $(this).find(".bar").css("width","100%");
  3991. $(this).find(".progress").attr("class","ts tiny negative progress");
  3992. $(this).find(".uploadTaskRemoveIcon").show();
  3993. $(this).addClass("ended");
  3994. }
  3995. });
  3996. }
  3997. uploadingFileCount--;
  3998. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  3999. setTimeout(function(){
  4000. if (uploadPendingList.length > 0){
  4001. let nextFile = uploadPendingList.shift();
  4002. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  4003. }
  4004. }, 100)
  4005. }else if (xhr.readyState == 4 && xhr.status != 200) {
  4006. msgbox("remove","File too big or the target disk is fulled");
  4007. console.log(xhr);
  4008. $(".uploadTask").each(function(){
  4009. if ($(this).attr("taskID") == taskUUID){
  4010. //Upload screwed up. Show negative
  4011. $(this).find(".progress").attr("class","ts tiny negative progress");
  4012. $(this).find(".uploadTaskRemoveIcon").show();
  4013. $(this).addClass("ended");
  4014. }
  4015. });
  4016. uploadingFileCount--;
  4017. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  4018. setTimeout(function(){
  4019. if (uploadPendingList.length > 0){
  4020. let nextFile = uploadPendingList.shift();
  4021. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  4022. }
  4023. }, 100)
  4024. }
  4025. updateUploadFileCount();
  4026. })
  4027. xhr.send(formData);
  4028. uploadingFileCount++;
  4029. updateUploadFileCount();
  4030. }
  4031. }
  4032. //Clear all finished upload tasks
  4033. function clearAllUploadTask(){
  4034. $(".uploadTask.ended").slideUp('300',function(){
  4035. $(this).remove();
  4036. updateUploadFileCount();
  4037. });
  4038. }
  4039. var searchMode = false;
  4040. function toggleSearch(){
  4041. //Start search mode
  4042. $(".searchbar").slideDown("fast", function(){
  4043. initWindowSizes(true);
  4044. });
  4045. $("#searhbtn").addClass("disabled");
  4046. //Force videmode to list
  4047. viewMode = "list"
  4048. $(".videmode.button").each(function(){
  4049. $(this).addClass('disabled');
  4050. });
  4051. searchMode = true;
  4052. //Clear current folderlist
  4053. $("#folderList").show();
  4054. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  4055. <div class="ts header">
  4056. <i class="arrow up icon ${currentTheme}"></i> <span class="${currentTheme}">Type to Start Search</span>
  4057. <div class="sub header ${currentTheme}" style="margin-top:12px;">Type something in the search bar to start searching.<br>
  4058. Start wildcard matching with "/" (slash) and your wildcard string (e.g. /*.mp3)</div>
  4059. </div>
  4060. </div>`);
  4061. $("#fileList").hide();
  4062. }
  4063. function hideSearchBar(skipFilelistRefresh = false){
  4064. $(".searchbar").slideUp("fast", function(){
  4065. initWindowSizes(true);
  4066. });
  4067. $("#searchInput").val("");
  4068. $("#searhbtn").removeClass("disabled");
  4069. $(".videmode.button").each(function(){
  4070. if ($(this).attr("mode") != "list"){
  4071. $(this).removeClass('disabled');
  4072. }
  4073. });
  4074. if (skipFilelistRefresh == false){
  4075. listDirectory(currentPath);
  4076. }
  4077. searchMode = false;
  4078. }
  4079. //Handle case sensitive in keyword searching
  4080. function toggleCaseSensitive(btn){
  4081. if ($(btn).hasClass("active")){
  4082. $(btn).removeClass("active");
  4083. searchCaseSensitive = false;
  4084. }else{
  4085. $(btn).addClass("active");
  4086. searchCaseSensitive = true;
  4087. }
  4088. }
  4089. function handleSearch(){
  4090. var keyword = $("#searchInput").val();
  4091. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  4092. <i class="loading spinner icon ${currentTheme}"></i> <span class="${currentTheme}">Searching</span>
  4093. </div>`);
  4094. $("#fileList").hide();
  4095. $("#fileList").html("");
  4096. $.ajax({
  4097. url: "../../system/file_system/search",
  4098. data: {path: currentPath, keyword: keyword, casesensitive: searchCaseSensitive},
  4099. success: function(data){
  4100. if (data.error !== undefined){
  4101. msgbox("remove", data.error);
  4102. }else{
  4103. //Render the filelist
  4104. console.log(data);
  4105. if (data.length == 0){
  4106. $("#folderList").show();
  4107. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  4108. <div class="ts header ${currentTheme}">
  4109. <i class="question icon" ${currentTheme}></i> <span class="${currentTheme}">No Matching Results</span>
  4110. <div class="sub header ${currentTheme}">The host return no matching results for your keyword "${keyword}". <br>Check your spelling and if your wildcard are valid.</div>
  4111. </div>
  4112. </div>`);
  4113. }else{
  4114. renderDirectory(data);
  4115. }
  4116. }
  4117. }, error: function(){
  4118. $("#folderList").html(`<div class="ts basic segment">
  4119. <div class="ts header">
  4120. <i class="remove icon"></i> Search Error
  4121. <div class="sub header">Search timeout has occurred during file searching.</div>
  4122. </div>
  4123. </div>`);
  4124. }
  4125. })
  4126. }
  4127. function handleSearchBarPress(e){
  4128. if (e.keyCode == 13){
  4129. e.preventDefault();
  4130. handleSearch();
  4131. }
  4132. }
  4133. function toggleCtrl(){
  4134. ctrlHold = !ctrlHold;
  4135. }
  4136. function appendUploadFileItem(filename, filesize){
  4137. var newuuid = uuidv4();
  4138. var humanReadableFilesize = bytesToSize(filesize);
  4139. $("#uploadProgressList").append(`<div class="uploadTask" taskID="${newuuid}">
  4140. <p style="width: calc(100% - 15px);">${filename} (${humanReadableFilesize})</p>
  4141. <div class="ts tiny primary progress" style="margin-top:-12px;">
  4142. <div class="bar" style="width: 0%"></div>
  4143. </div>
  4144. <div class="uploadTaskRemoveIcon" onclick="removeThisTask(this);" style="display:none;">
  4145. <i class="remove icon"></i>
  4146. </div>
  4147. </div>`);
  4148. return newuuid;
  4149. }
  4150. function removeThisTask(object){
  4151. $(object).parent().fadeOut('fast',
  4152. function(){
  4153. $(this).remove();
  4154. updateUploadFileCount();
  4155. }
  4156. );
  4157. }
  4158. function toggleUploadList(){
  4159. $("#uploadProgressList").toggle();
  4160. if ($("#uploadProgressList").is(":visible")){
  4161. $("#hideUploadButton").html('<i class="caret down icon"></i>');
  4162. }else{
  4163. $("#hideUploadButton").html('<i class="caret up icon"></i>');
  4164. }
  4165. }
  4166. function updateUploadFileCount(){
  4167. $("#uploadCount").text(uploadingFileCount);
  4168. $("#waitingCount").text(uploadPendingList.length);
  4169. if (uploadingFileCount == 0 && $(".uploadTask").length == 0){
  4170. $("#uploadTab").hide();
  4171. }else{
  4172. $("#uploadTab").show();
  4173. }
  4174. }
  4175. function bytesToSize(bytes) {
  4176. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  4177. if (bytes == 0) return '0 Byte';
  4178. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  4179. return Math.round(bytes / Math.pow(1024, i) * 100, 2) / 100 + ' ' + sizes[i];
  4180. }
  4181. function uuidv4() {
  4182. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  4183. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  4184. return v.toString(16);
  4185. });
  4186. }
  4187. function dropToFolder(event){
  4188. event.preventDefault();
  4189. event.stopImmediatePropagation();
  4190. console.log("Drop to folder detected");
  4191. //Extract target folder path from object
  4192. var targetPath = $(event.target).attr("filepath");
  4193. if (targetPath == ""){
  4194. return
  4195. }
  4196. //Check if this is upload or file move drag
  4197. var files = event.dataTransfer.files;
  4198. if (files.length > 0){
  4199. //Upload mode. Extract the target folder basename from path
  4200. if (targetPath.substr(targetPath.length -1,1) == "/"){
  4201. targetPath = targetPath.substr(0, targetPath.length-1);
  4202. }
  4203. var folderBase = targetPath.split("/").pop() + "/";
  4204. var items = event.dataTransfer.items;
  4205. for (let i=0; i<items.length; i++) {
  4206. let item = items[i].webkitGetAsEntry();
  4207. if (item) {
  4208. recursiveScanFilesUpload(item, folderBase, folderBase);
  4209. }
  4210. }
  4211. }else if (event.dataTransfer.getData("filedata") != ""){
  4212. var targetVroot = targetPath.split(":/").shift();
  4213. //Get the source files
  4214. var filelist = JSON.parse(event.dataTransfer.getData("filedata"));
  4215. if (filelist.length > 0){
  4216. var srcVroot = filelist[0].filepath.split(":/").shift();
  4217. if (srcVroot == targetVroot){
  4218. //Use move mode
  4219. cutMode = true;
  4220. }else{
  4221. //Use copy mode
  4222. cutMode = false;
  4223. }
  4224. //Parse the filelist
  4225. clipboard = [];
  4226. filelist.forEach(file=>{
  4227. clipboard.push(file.filepath);
  4228. });
  4229. if (useLocalstorage){
  4230. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  4231. localStorage.setItem("ao/file_system/cutmode","true");
  4232. }
  4233. //Perform operations
  4234. paste(targetPath, false)
  4235. }
  4236. }
  4237. }
  4238. function allowDrop(event){
  4239. event.preventDefault();
  4240. }
  4241. $(".popupWrapper").on("click",function(){
  4242. hideAllPopupWindows();
  4243. });
  4244. function hideAllPopupWindows(){
  4245. $(".popup").fadeOut(100);
  4246. $(".popupWrapper").fadeOut(100);
  4247. $('body').css("overflow","");
  4248. }
  4249. function showPopupWrapper(){
  4250. $(".popupWrapper").fadeIn('fast');
  4251. $('body').css("overflow","hidden");
  4252. }
  4253. //Handle keydown of enter on certain input boxes
  4254. function handleEnterKeyDown(event, handler){
  4255. if (event.which == 13){
  4256. handler();
  4257. }
  4258. }
  4259. //Generate a download link and press it
  4260. function generateDownloadFromURL(url, filename){
  4261. let a = document.createElement('a')
  4262. a.href = url;
  4263. a.download = filename;
  4264. document.body.appendChild(a)
  4265. a.click()
  4266. document.body.removeChild(a)
  4267. }
  4268. //Update sorting method for file listing
  4269. function updateSortingMethods(){
  4270. var method = $("#sortingMethodSelector").val();
  4271. sortMode = method;
  4272. refreshList();
  4273. }
  4274. function requestCSRFToken(callback){
  4275. $.ajax({
  4276. url: "../../system/csrf/new",
  4277. success: function(token){
  4278. callback(token);
  4279. }
  4280. })
  4281. }
  4282. </script>
  4283. </body>
  4284. </html>