file_explorer.html 218 KB

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