diff --git a/app/js/lib/bin_utils.js b/app/js/lib/bin_utils.js index ff05c653..ec36ef04 100644 --- a/app/js/lib/bin_utils.js +++ b/app/js/lib/bin_utils.js @@ -127,18 +127,38 @@ function dataUrlToBlob (url) { function blobConstruct (blobParts, mimeType) { var blob + var safeMimeType = blobSafeMimeType(mimeType) try { - blob = new Blob(blobParts, {type: mimeType}) + blob = new Blob(blobParts, {type: safeMimeType}) } catch (e) { var bb = new BlobBuilder angular.forEach(blobParts, function (blobPart) { bb.append(blobPart) }) - blob = bb.getBlob(mimeType) + blob = bb.getBlob(safeMimeType) } return blob } +function blobSafeMimeType(mimeType) { + if ([ + 'image/jpeg', + 'image/png', + 'image/gif', + 'image/webp', + 'image/bmp', + 'video/mp4', + 'video/webm', + 'video/quicktime', + 'audio/ogg', + 'audio/mpeg', + 'audio/mp4', + ].indexOf(mimeType) == -1) { + return 'application/octet-stream' + } + return mimeType +} + function bytesCmp (bytes1, bytes2) { var len = bytes1.length if (len != bytes2.length) { diff --git a/app/js/lib/config.js b/app/js/lib/config.js index 48b95077..8797077b 100644 --- a/app/js/lib/config.js +++ b/app/js/lib/config.js @@ -38,6 +38,7 @@ Config.Modes = { chrome_packed: window.chrome && chrome.app && chrome.app.window && true || false, animations: true, memory_only: false, + allow_tmpfs: location.search.indexOf('tmpfs=yeahImSureIknowWhatImDoing') > 0 || false, push_api: location.search.indexOf('push=1') == -1 } diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index 6ac60b1c..d9a8e9cc 100755 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -180,14 +180,15 @@ angular.module('izhukov.utils', []) } function getUrl (fileData, mimeType) { + var safeMimeType = blobSafeMimeType(mimeType) // console.log(dT(), 'get url', fileData, mimeType, fileData.toURL !== undefined, fileData instanceof Blob) if (fileData.toURL !== undefined) { - return fileData.toURL(mimeType) + return fileData.toURL(safeMimeType) } if (fileData instanceof Blob) { return URL.createObjectURL(fileData) } - return 'data:' + mimeType + ';base64,' + bytesToBase64(fileData) + return 'data:' + safeMimeType + ';base64,' + bytesToBase64(fileData) } function getByteArray (fileData) { @@ -466,8 +467,8 @@ angular.module('izhukov.utils', []) return $q.reject() } if (!(blob instanceof Blob)) { - var mimeType = blob.type || 'image/jpeg' - var address = 'data:' + mimeType + ';base64,' + bytesToBase64(blob) + var safeMimeType = blobSafeMimeType(blob.type || 'image/jpeg') + var address = 'data:' + safeMimeType + ';base64,' + bytesToBase64(blob) return storagePutB64String(db, fileName, address).then(function () { return blob }) @@ -604,7 +605,7 @@ angular.module('izhukov.utils', []) } function isAvailable () { - return storageIsAvailable + return Config.allow_tmpfs && storageIsAvailable } function getFile (fileName, size) {