Disabled chrome temps by default
Improved mime types handling for blobs
This commit is contained in:
parent
5c9f4b00b7
commit
94a94b864d
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user