file_explorer.html 251 KB

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