Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
f976d3de
Commit
f976d3de
authored
Jun 05, 2014
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix blob storage exception in chrome browser
parent
99971bc2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
37 deletions
+57
-37
src/jio.storage/indexeddbstorage.js
src/jio.storage/indexeddbstorage.js
+55
-37
test/jio.storage/indexeddbstorage.tests.js
test/jio.storage/indexeddbstorage.tests.js
+2
-0
No files found.
src/jio.storage/indexeddbstorage.js
View file @
f976d3de
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
*/
*/
/*jslint indent: 2, maxlen: 80, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, module, require, indexedDB, jIO, RSVP, Blob
*/
/*global define, module, require, indexedDB, jIO, RSVP, Blob*/
(
function
(
dependencies
,
factory
)
{
(
function
(
dependencies
,
factory
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -134,19 +134,28 @@
...
@@ -134,19 +134,28 @@
*@param {Object} metadata The data to put in
*@param {Object} metadata The data to put in
*@return a new promise
*@return a new promise
*/
*/
function
putIndexedDB
(
store
,
metadata
)
{
function
putIndexedDB
(
store
,
metadata
,
readData
)
{
function
resolver
(
resolve
,
reject
)
{
var
request
,
var
request
=
store
.
put
(
metadata
);
resolver
;
try
{
request
=
store
.
put
(
metadata
);
resolver
=
function
(
resolve
,
reject
)
{
request
.
onerror
=
reject
;
request
.
onerror
=
reject
;
request
.
onsuccess
=
function
()
{
request
.
onsuccess
=
function
()
{
resolve
(
metadata
);
resolve
(
metadata
);
};
};
}
};
return
new
RSVP
.
Promise
(
resolver
);
return
new
RSVP
.
Promise
(
resolver
);
}
catch
(
e
)
{
return
putIndexedDB
(
store
,
{
"
_id
"
:
metadata
.
_id
,
"
_attachment
"
:
metadata
.
_attachment
,
"
blob
"
:
readData
});
}
}
}
/**
/**
* get a data from a store object
* get a data from a store object
* @param {ObjectStore} store The objectstore
* @param {ObjectStore} store The objectstore
...
@@ -579,18 +588,20 @@
...
@@ -579,18 +588,20 @@
*
*
* @param {Object} command The JIO command
* @param {Object} command The JIO command
* @param {Object} metadata The data
* @param {Object} metadata The data
*
*/
*/
IndexedDBStorage
.
prototype
.
putAttachment
=
function
(
command
,
metadata
)
{
IndexedDBStorage
.
prototype
.
putAttachment
=
function
(
command
,
metadata
)
{
var
jio_storage
=
this
,
var
jio_storage
=
this
,
transaction
,
transaction
,
global_db
,
global_db
,
BlobInfo
,
BlobInfo
,
digest
;
digest
,
readResult
;
new
RSVP
.
Queue
()
new
RSVP
.
Queue
()
.
push
(
jIO
.
util
.
readBlobAsBinaryString
(
metadata
.
_blob
).
.
push
(
jIO
.
util
.
readBlobAsText
(
metadata
.
_blob
).
then
(
function
(
e
)
{
then
(
function
(
e
)
{
digest
=
jIO
.
util
.
makeBinaryStringDigest
(
e
.
target
.
result
);
digest
=
jIO
.
util
.
makeBinaryStringDigest
(
e
.
target
.
result
);
//xxx
readResult
=
e
.
target
.
result
;
BlobInfo
=
{
BlobInfo
=
{
"
content_type
"
:
metadata
.
_blob
.
type
,
"
content_type
"
:
metadata
.
_blob
.
type
,
"
digest
"
:
digest
,
"
digest
"
:
digest
,
...
@@ -618,7 +629,7 @@
...
@@ -618,7 +629,7 @@
researchResult
.
result
.
_attachment
=
researchResult
.
result
.
_attachment
researchResult
.
result
.
_attachment
=
researchResult
.
result
.
_attachment
||
{};
||
{};
researchResult
.
result
.
_attachment
[
metadata
.
_attachment
]
=
researchResult
.
result
.
_attachment
[
metadata
.
_attachment
]
=
BlobInfo
;
(
BlobInfo
===
undefined
)
?
"
BlobInfo
"
:
BlobInfo
;
return
putIndexedDB
(
researchResult
.
store
,
researchResult
.
result
);
return
putIndexedDB
(
researchResult
.
store
,
researchResult
.
result
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
...
@@ -626,10 +637,10 @@
...
@@ -626,10 +637,10 @@
var
store
=
transaction
.
objectStore
(
"
blob
"
);
var
store
=
transaction
.
objectStore
(
"
blob
"
);
return
putIndexedDB
(
store
,
{
"
_id
"
:
metadata
.
_id
,
return
putIndexedDB
(
store
,
{
"
_id
"
:
metadata
.
_id
,
"
_attachment
"
:
metadata
.
_attachment
,
"
_attachment
"
:
metadata
.
_attachment
,
"
blob
"
:
metadata
.
_blob
}
);
"
blob
"
:
metadata
.
_blob
},
readResult
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
({
"
digest
"
:
digest
});
return
({
"
digest
"
:
digest
});
//xxx
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
// Check if transaction is ongoing, if so, abort it
// Check if transaction is ongoing, if so, abort it
...
@@ -644,6 +655,8 @@
...
@@ -644,6 +655,8 @@
.
push
(
command
.
success
,
command
.
error
,
command
.
notify
);
.
push
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
};
/**
/**
* Retriev a document attachment
* Retriev a document attachment
*
*
...
@@ -675,6 +688,10 @@
...
@@ -675,6 +688,10 @@
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
//get data
//get data
if
(
typeof
result
.
blob
===
"
string
"
)
{
result
.
blob
=
new
Blob
([
result
.
blob
],
{
type
:
"
text/plain
"
});
}
return
({
"
data
"
:
result
.
blob
});
return
({
"
data
"
:
result
.
blob
});
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
...
@@ -690,6 +707,7 @@
...
@@ -690,6 +707,7 @@
.
push
(
command
.
success
,
command
.
error
,
command
.
notify
);
.
push
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
};
/**
/**
* Remove an attachment
* Remove an attachment
*
*
...
...
test/jio.storage/indexeddbstorage.tests.js
View file @
f976d3de
...
@@ -28,12 +28,14 @@
...
@@ -28,12 +28,14 @@
}
}
test
(
"
Scenario
"
,
32
,
function
()
{
test
(
"
Scenario
"
,
32
,
function
()
{
// indexedDB.deleteDatabase("jio:test");
var
server
,
shared
=
{},
jio
=
jIO
.
createJIO
(
var
server
,
shared
=
{},
jio
=
jIO
.
createJIO
(
{
"
type
"
:
"
indexeddb
"
,
{
"
type
"
:
"
indexeddb
"
,
"
database
"
:
"
test
"
"
database
"
:
"
test
"
},
},
{
"
workspace
"
:
{}}
{
"
workspace
"
:
{}}
);
);
stop
();
stop
();
server
=
{
restore
:
function
()
{
server
=
{
restore
:
function
()
{
return
;
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment