aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-07 23:13:15 -0800
committerJose Antonio Marquez2012-02-07 23:13:15 -0800
commit687cfbbae1df2392267e9602f955f6eadd5b339d (patch)
tree6b3a1a0f241bcf42df5d68fdb60af865c99ec9c4 /js/io/system
parentaf58afcffff5ac556d16f050a325ac0406897fcd (diff)
downloadninja-687cfbbae1df2392267e9602f955f6eadd5b339d.tar.gz
Mime type fixes
Trying to fix mime type issues in FileSystem, Chrome does not support reponseType 'blob', so looking at alternatives.
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/chromeapi.js21
-rw-r--r--js/io/system/ninjalibrary.js14
2 files changed, 26 insertions, 9 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
index fc93b22a..c19a7d3b 100644
--- a/js/io/system/chromeapi.js
+++ b/js/io/system/chromeapi.js
@@ -71,7 +71,7 @@ exports.ChromeApi = Montage.create(Object.prototype, {
71 // 71 //
72 f.createWriter(function(writer) { 72 f.createWriter(function(writer) {
73 // 73 //
74 var b, mime, type = filePath.split('.'); 74 var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.');
75 type = type[type.length-1]; 75 type = type[type.length-1];
76 switch (type) { 76 switch (type) {
77 case 'bmp': 77 case 'bmp':
@@ -112,9 +112,8 @@ exports.ChromeApi = Montage.create(Object.prototype, {
112 break; 112 break;
113 } 113 }
114 // 114 //
115 b = new window.WebKitBlobBuilder; 115 blob.append(content);
116 b.append(content); 116 writer.write(blob.getBlob(mime));
117 writer.write(b.getBlob(mime));
118 // 117 //
119 if (callback) callback(true); 118 if (callback) callback(true);
120 }, function (e) {if (callback) callback(false)}); 119 }, function (e) {if (callback) callback(false)});
@@ -137,7 +136,19 @@ exports.ChromeApi = Montage.create(Object.prototype, {
137 // 136 //
138 fileContent: { 137 fileContent: {
139 enumerable: true, 138 enumerable: true,
140 value: function() { 139 value: function(filePath, callback) {
140 //
141 this.fileSystem.root.getFile(filePath, {}, function(f) {
142 f.file(function(file) {
143 var reader = new FileReader();
144 reader.onloadend = function(e) {
145 if (callback) {
146 callback({content: this.result, data: file, file: f, url: f.toURL()});
147 }
148 };
149 reader.readAsText(file);
150 }, function (e) {if (callback) callback(false)});
151 }, function (e) {if (callback) callback(false)});
141 } 152 }
142 }, 153 },
143 //////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index 0ab19401..3914ec29 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -74,7 +74,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
74 //Getting contents of library to be copied 74 //Getting contents of library to be copied
75 this.chromeApi.directoryContents(contents[i], function (lib) { 75 this.chromeApi.directoryContents(contents[i], function (lib) {
76 //Creating directory structure from subfolders 76 //Creating directory structure from subfolders
77 this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); 77 this.copyDirectoryToCloud(path, contents[i], '/'+path, function (status) {console.log(status)});
78 }.bind(this)); 78 }.bind(this));
79 break; 79 break;
80 } 80 }
@@ -89,7 +89,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
89 // 89 //
90 copyDirectoryToCloud: { 90 copyDirectoryToCloud: {
91 enumerable: true, 91 enumerable: true,
92 value: function(root, folder, callback) { 92 value: function(root, folder, fileRoot, callback) {
93 //
93 if (folder.name) { 94 if (folder.name) {
94 var dir; 95 var dir;
95 if (root) { 96 if (root) {
@@ -108,9 +109,14 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
108 this.chromeApi.directoryContents(folder, function (contents) { 109 this.chromeApi.directoryContents(folder, function (contents) {
109 for (var i in contents) { 110 for (var i in contents) {
110 if (contents[i].isDirectory) { 111 if (contents[i].isDirectory) {
111 this.copyDirectoryToCloud(dir, contents[i]); 112 this.copyDirectoryToCloud(dir, contents[i], fileRoot);
112 } else if (contents[i].isFile){ 113 } else if (contents[i].isFile){
113 //File to copy 114 //File to copy
115 this.chromeApi.fileContent(contents[i].fullPath, function (result) {
116 //
117 this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type});
118 //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content});
119 }.bind(this));
114 } 120 }
115 } 121 }
116 }.bind(this)); 122 }.bind(this));
@@ -185,7 +191,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
185 //Checking for status 191 //Checking for status
186 if (xhr.readyState === 4) { //TODO: add check for mime type 192 if (xhr.readyState === 4) { //TODO: add check for mime type
187 //Creating new file from loaded content 193 //Creating new file from loaded content
188 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); 194 //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this));
189 } else { 195 } else {
190 //Error creating single file library 196 //Error creating single file library
191 } 197 }