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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaohe Cao
jio
Commits
95d90c8a
Commit
95d90c8a
authored
Oct 18, 2013
by
Jonathan Rivalan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation for the getAttachment and blob type/content unit tests
parent
1d7c6302
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
46 deletions
+56
-46
src/jio.storage/s3storage.js
src/jio.storage/s3storage.js
+52
-42
test/jio.storage/s3storage.tests.js
test/jio.storage/s3storage.tests.js
+4
-4
No files found.
src/jio.storage/s3storage.js
View file @
95d90c8a
...
...
@@ -17,7 +17,7 @@
var
b64_hmac_sha1
=
sha1
.
b64_hmac_sha1
;
jIO
.
addStorage
(
"
s3
"
,
function
(
spec
,
my
)
{
var
evt
,
that
,
priv
=
{};
var
evt
,
that
,
priv
=
{}
,
lastDigest
;
that
=
this
;
//nomenclature param
...
...
@@ -319,24 +319,23 @@
break
;
case
'
GET
'
:
if
(
jio
===
true
)
{
console
.
log
(
http
);
console
.
log
(
obj
);
console
.
log
(
typeof
this
.
responseText
);
if
(
typeof
this
.
responseText
===
'
string
'
)
{
if
(
isAttachment
===
true
)
{
//méthode that.getAttachment
console
.
log
(
this
);
response
=
this
.
response
;
console
.
log
(
response
);
command
.
success
(
this
.
status
,{
'
data
'
:
response
,
'
digest
'
:
lastDigest
});
}
//n'est pas un attachment
else
{
//méthode that.get
response
=
JSON
.
parse
(
this
.
responseText
);
//response._attachments = response._attachments || {};
//delete response._attachments;
command
.
success
(
this
.
status
,{
'
data
'
:
response
});
}
else
{
if
(
isAttachment
===
true
)
{
//command.success(this.responseText);
}
else
{
//command.success(JSON.parse(this.responseText));
}
}
}
else
{
callback
(
this
.
responseText
);
}
break
;
case
'
DELETE
'
:
if
(
jio
===
true
)
{
...
...
@@ -479,7 +478,13 @@
+
"
:
"
+
Signature
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
mime
);
xhr
.
responseType
=
'
text
'
;
if
(
http
==
'
GET
'
&&
jio
==
true
&&
is_attachment
==
true
){
xhr
.
responseType
=
'
blob
'
;
}
else
{
//défaut
xhr
.
responseType
=
'
text
'
;
}
xhr_onreadystatechange
(
docId
,
command
,
...
...
@@ -588,13 +593,35 @@
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
);
};
that
.
getAttachment
=
function
(
command
)
{
that
.
getAttachment
=
function
(
command
,
param
,
option
)
{
var
docId
,
attachId
,
isJIO
,
mime
;
docId
=
command
.
getDocId
();
attachId
=
command
.
getAttachmentId
();
isJIO
=
true
;
mime
=
'
text/plain; charset=UTF-8
'
;
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
true
);
function
getTheAttachment
(){
docId
=
param
.
_id
;
attachId
=
param
.
_attachment
;
isJIO
=
true
;
mime
=
'
text/plain; charset=UTF-8
'
;
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
true
);
}
function
getDoc
(){
docId
=
param
.
_id
;
isJIO
=
false
;
mime
=
'
text/plain; charset=UTF-8
'
;
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
,
function
(
response
)
{
lastDigest
=
JSON
.
parse
(
response
)[
"
_attachments
"
][
param
.
_attachment
][
'
digest
'
];
getTheAttachment
();
});
}
getDoc
();
//docId = param._id;
//attachId = param._attachment;
//isJIO = true;
//mime = 'text/plain; charset=UTF-8';
//that.XHRwrapper(command, docId, attachId, 'GET', mime, '', isJIO, true);
};
/**
...
...
@@ -651,24 +678,15 @@
my_document
=
null
;
docId
=
param
.
_id
;
attachId
=
param
.
_attachment
;
mime
=
'
text/plain; charset=UTF-8
'
;
//récupération des variables de l'attachement
mime
=
param
.
_blob
.
type
;
attachment_id
=
param
.
_attachment
;
attachment_data
=
param
.
_blob
;
console
.
log
(
param
.
_blob
);
jIO
.
util
.
readBlobAsBinaryString
(
param
.
_blob
).
then
(
function
(
e
)
{
console
.
log
(
'
readBlobAsBinaryString
'
);
var
binary_string
=
e
.
target
.
result
;
console
.
log
(
binary_string
);
console
.
dir
(
jIO
.
util
);
attachment_digest
=
jIO
.
util
.
makeBinaryStringDigest
(
binary_string
);
console
.
log
(
attachment_digest
);
//attachment_mimetype = param._blob.type;
//attachment_length = param._blob.size;
function
putAttachment
()
{
that
.
XHRwrapper
(
command
,
...
...
@@ -688,11 +706,7 @@
);
}
console
.
log
(
'
breakpoint2
'
);
function
putDocument
()
{
console
.
log
(
'
putDoc
'
);
var
attachment_obj
,
data
,
doc
;
attachment_obj
=
{
//"revpos": 3, // optional
...
...
@@ -706,32 +720,28 @@
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
response
)
{
console
.
log
(
response
);
putAttachment
();
}
);
}
function
getDocument
()
{
console
.
log
(
'
getDoc
'
);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
if
(
reponse
===
'
404
'
)
{
function
(
re
s
ponse
)
{
if
(
re
s
ponse
===
'
404
'
)
{
return
command
.
error
(
404
,
"
Document does not exist
"
,
"
Cannot find document
"
);
}
my_document
=
reponse
;
my_document
=
re
s
ponse
;
putDocument
();
}
);
}
getDocument
();
}).
then
(
console
.
log
,
console
.
error
);
});
};
/**
...
...
test/jio.storage/s3storage.tests.js
View file @
95d90c8a
...
...
@@ -563,8 +563,8 @@
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
digest
"
:
"
sha256-
38760eabb666e8e61ee628a17c4090cc5
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
digest
"
:
"
sha256-
9834876dcfb05cb167a5c24953eba58c4
"
+
"
ac89b1adf57f28f2f9d09af107ee8f0
"
,
"
id
"
:
"
a
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
...
...
@@ -573,7 +573,7 @@
},
"
Get first attachment
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
deepEqual
(
e
.
target
.
result
,
"
aa
b
"
,
"
Check blob text content
"
);
deepEqual
(
e
.
target
.
result
,
"
aa
a
"
,
"
Check blob text content
"
);
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
...
...
@@ -948,7 +948,7 @@
// put 204
//then(updateLastDocument).then(updateLastDocumentTest).
// getA a 200
//
then(getFirstAttachment).then(getFirstAttachmentTest).
then
(
getFirstAttachment
).
then
(
getFirstAttachmentTest
).
// getA b 200
//then(getSecondAttachment).then(getSecondAttachmentTest).
// get 200
...
...
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