From 687cfbbae1df2392267e9602f955f6eadd5b339d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 23:13:15 -0800 Subject: Mime type fixes Trying to fix mime type issues in FileSystem, Chrome does not support reponseType 'blob', so looking at alternatives. --- js/io/system/chromeapi.js | 21 ++++++++++++++++----- js/io/system/ninjalibrary.js | 14 ++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'js/io/system') 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, { // f.createWriter(function(writer) { // - var b, mime, type = filePath.split('.'); + var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.'); type = type[type.length-1]; switch (type) { case 'bmp': @@ -112,9 +112,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { break; } // - b = new window.WebKitBlobBuilder; - b.append(content); - writer.write(b.getBlob(mime)); + blob.append(content); + writer.write(blob.getBlob(mime)); // if (callback) callback(true); }, function (e) {if (callback) callback(false)}); @@ -137,7 +136,19 @@ exports.ChromeApi = Montage.create(Object.prototype, { // fileContent: { enumerable: true, - value: function() { + value: function(filePath, callback) { + // + this.fileSystem.root.getFile(filePath, {}, function(f) { + f.file(function(file) { + var reader = new FileReader(); + reader.onloadend = function(e) { + if (callback) { + callback({content: this.result, data: file, file: f, url: f.toURL()}); + } + }; + reader.readAsText(file); + }, function (e) {if (callback) callback(false)}); + }, function (e) {if (callback) callback(false)}); } }, //////////////////////////////////////////////////////////////////// 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, { //Getting contents of library to be copied this.chromeApi.directoryContents(contents[i], function (lib) { //Creating directory structure from subfolders - this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + this.copyDirectoryToCloud(path, contents[i], '/'+path, function (status) {console.log(status)}); }.bind(this)); break; } @@ -89,7 +89,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // copyDirectoryToCloud: { enumerable: true, - value: function(root, folder, callback) { + value: function(root, folder, fileRoot, callback) { + // if (folder.name) { var dir; if (root) { @@ -108,9 +109,14 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { this.chromeApi.directoryContents(folder, function (contents) { for (var i in contents) { if (contents[i].isDirectory) { - this.copyDirectoryToCloud(dir, contents[i]); + this.copyDirectoryToCloud(dir, contents[i], fileRoot); } else if (contents[i].isFile){ //File to copy + this.chromeApi.fileContent(contents[i].fullPath, function (result) { + // + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + }.bind(this)); } } }.bind(this)); @@ -185,7 +191,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } -- cgit v1.2.3