From cf7db884e61919f1efec92fb3601585c8e3c8f12 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 3 Aug 2015 18:40:27 +0200 Subject: [PATCH] fixes for mac --- src/modules/Directory.js | 6 ++++++ src/server/files.js | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/modules/Directory.js b/src/modules/Directory.js index 6147546..fd04b09 100644 --- a/src/modules/Directory.js +++ b/src/modules/Directory.js @@ -74,17 +74,23 @@ define([ , getContentPs: function(par){ var def = this.def(); + console.log("dir get content"); + var fileName = this.getFileName(par.id); + console.log(fileName); + var result = { children: [] }; files.childrenDef(fileName).then(function(ar){ + console.log("find children"); if (!ar || !ar.length){ def.resolve(result); return; }; files.contentTypesDef(ar).then(function(typesAr){ + console.log("content types"); result.children = array.map(typesAr, function(f){ var r = { type: "file" diff --git a/src/server/files.js b/src/server/files.js index fa3f7bd..f0a6d85 100644 --- a/src/server/files.js +++ b/src/server/files.js @@ -116,8 +116,45 @@ define([ var self = this; var def = new Deferred(); var result = {}; - mimeMagic(parFileNamesAr, function (err, types) { + + var mimeMagicFun = mimeMagic; + var mimeMagicAr = function(parAr, parCB){ + var resAr; + mimeMagicFun(parAr, function(err, types){ + if (!err){ + parCB(undefined, types); + return; + }; + // something went wrong + // lets call mime magic for each entry; + var cnt = parAr.length; + resAr = []; + var getCb = function(parIndex){ + return function(err, type){ + if (err){ + resAr[parIndex] = "application/octet-stream"; + }else{ + resAr[parIndex] = type; + }; + cnt--; + if (!cnt){ + parCB(undefined, resAr); + }; + }; + }; + var i = 0; + for (i = 0; i < parAr.length; ++i){ + mimeMagicFun(parAr[i], getCb(i)); + }; + }); + }; + + + mimeMagicAr(parFileNamesAr, function (err, types) { if (err) { + console.log(err); + console.log("types:"); + console.log(types); def.reject(err); return; };