Browse Source

Disabled chrome temps by default

Improved mime types handling for blobs
master
Igor Zhukov 8 years ago
parent
commit
94a94b864d
  1. 24
      app/js/lib/bin_utils.js
  2. 1
      app/js/lib/config.js
  3. 11
      app/js/lib/ng_utils.js

24
app/js/lib/bin_utils.js

@ -127,18 +127,38 @@ function dataUrlToBlob (url) {
function blobConstruct (blobParts, mimeType) { function blobConstruct (blobParts, mimeType) {
var blob var blob
var safeMimeType = blobSafeMimeType(mimeType)
try { try {
blob = new Blob(blobParts, {type: mimeType}) blob = new Blob(blobParts, {type: safeMimeType})
} catch (e) { } catch (e) {
var bb = new BlobBuilder var bb = new BlobBuilder
angular.forEach(blobParts, function (blobPart) { angular.forEach(blobParts, function (blobPart) {
bb.append(blobPart) bb.append(blobPart)
}) })
blob = bb.getBlob(mimeType) blob = bb.getBlob(safeMimeType)
} }
return blob 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) { function bytesCmp (bytes1, bytes2) {
var len = bytes1.length var len = bytes1.length
if (len != bytes2.length) { if (len != bytes2.length) {

1
app/js/lib/config.js

@ -38,6 +38,7 @@ Config.Modes = {
chrome_packed: window.chrome && chrome.app && chrome.app.window && true || false, chrome_packed: window.chrome && chrome.app && chrome.app.window && true || false,
animations: true, animations: true,
memory_only: false, memory_only: false,
allow_tmpfs: location.search.indexOf('tmpfs=yeahImSureIknowWhatImDoing') > 0 || false,
push_api: location.search.indexOf('push=1') == -1 push_api: location.search.indexOf('push=1') == -1
} }

11
app/js/lib/ng_utils.js

@ -180,14 +180,15 @@ angular.module('izhukov.utils', [])
} }
function getUrl (fileData, mimeType) { function getUrl (fileData, mimeType) {
var safeMimeType = blobSafeMimeType(mimeType)
// console.log(dT(), 'get url', fileData, mimeType, fileData.toURL !== undefined, fileData instanceof Blob) // console.log(dT(), 'get url', fileData, mimeType, fileData.toURL !== undefined, fileData instanceof Blob)
if (fileData.toURL !== undefined) { if (fileData.toURL !== undefined) {
return fileData.toURL(mimeType) return fileData.toURL(safeMimeType)
} }
if (fileData instanceof Blob) { if (fileData instanceof Blob) {
return URL.createObjectURL(fileData) return URL.createObjectURL(fileData)
} }
return 'data:' + mimeType + ';base64,' + bytesToBase64(fileData) return 'data:' + safeMimeType + ';base64,' + bytesToBase64(fileData)
} }
function getByteArray (fileData) { function getByteArray (fileData) {
@ -466,8 +467,8 @@ angular.module('izhukov.utils', [])
return $q.reject() return $q.reject()
} }
if (!(blob instanceof Blob)) { if (!(blob instanceof Blob)) {
var mimeType = blob.type || 'image/jpeg' var safeMimeType = blobSafeMimeType(blob.type || 'image/jpeg')
var address = 'data:' + mimeType + ';base64,' + bytesToBase64(blob) var address = 'data:' + safeMimeType + ';base64,' + bytesToBase64(blob)
return storagePutB64String(db, fileName, address).then(function () { return storagePutB64String(db, fileName, address).then(function () {
return blob return blob
}) })
@ -604,7 +605,7 @@ angular.module('izhukov.utils', [])
} }
function isAvailable () { function isAvailable () {
return storageIsAvailable return Config.allow_tmpfs && storageIsAvailable
} }
function getFile (fileName, size) { function getFile (fileName, size) {

Loading…
Cancel
Save