Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Yaxel Perez
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 @@
...
@@ -17,7 +17,7 @@
var
b64_hmac_sha1
=
sha1
.
b64_hmac_sha1
;
var
b64_hmac_sha1
=
sha1
.
b64_hmac_sha1
;
jIO
.
addStorage
(
"
s3
"
,
function
(
spec
,
my
)
{
jIO
.
addStorage
(
"
s3
"
,
function
(
spec
,
my
)
{
var
evt
,
that
,
priv
=
{};
var
evt
,
that
,
priv
=
{}
,
lastDigest
;
that
=
this
;
that
=
this
;
//nomenclature param
//nomenclature param
...
@@ -319,24 +319,23 @@
...
@@ -319,24 +319,23 @@
break
;
break
;
case
'
GET
'
:
case
'
GET
'
:
if
(
jio
===
true
)
{
if
(
jio
===
true
)
{
console
.
log
(
http
);
if
(
isAttachment
===
true
)
{
console
.
log
(
obj
);
//méthode that.getAttachment
console
.
log
(
typeof
this
.
responseText
);
console
.
log
(
this
);
if
(
typeof
this
.
responseText
===
'
string
'
)
{
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
=
JSON
.
parse
(
this
.
responseText
);
//response._attachments = response._attachments || {};
//delete response._attachments;
command
.
success
(
this
.
status
,{
'
data
'
:
response
});
command
.
success
(
this
.
status
,{
'
data
'
:
response
});
}
else
{
if
(
isAttachment
===
true
)
{
//command.success(this.responseText);
}
else
{
//command.success(JSON.parse(this.responseText));
}
}
}
}
else
{
}
else
{
callback
(
this
.
responseText
);
callback
(
this
.
responseText
);
}
}
break
;
break
;
case
'
DELETE
'
:
case
'
DELETE
'
:
if
(
jio
===
true
)
{
if
(
jio
===
true
)
{
...
@@ -479,7 +478,13 @@
...
@@ -479,7 +478,13 @@
+
"
:
"
+
"
:
"
+
Signature
);
+
Signature
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
mime
);
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
,
xhr_onreadystatechange
(
docId
,
command
,
command
,
...
@@ -588,13 +593,35 @@
...
@@ -588,13 +593,35 @@
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
isJIO
,
false
);
};
};
that
.
getAttachment
=
function
(
command
)
{
that
.
getAttachment
=
function
(
command
,
param
,
option
)
{
var
docId
,
attachId
,
isJIO
,
mime
;
var
docId
,
attachId
,
isJIO
,
mime
;
docId
=
command
.
getDocId
();
attachId
=
command
.
getAttachmentId
();
function
getTheAttachment
(){
isJIO
=
true
;
docId
=
param
.
_id
;
mime
=
'
text/plain; charset=UTF-8
'
;
attachId
=
param
.
_attachment
;
that
.
XHRwrapper
(
command
,
docId
,
attachId
,
'
GET
'
,
mime
,
''
,
isJIO
,
true
);
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 @@
...
@@ -651,24 +678,15 @@
my_document
=
null
;
my_document
=
null
;
docId
=
param
.
_id
;
docId
=
param
.
_id
;
attachId
=
param
.
_attachment
;
attachId
=
param
.
_attachment
;
mime
=
'
text/plain; charset=UTF-8
'
;
mime
=
param
.
_blob
.
type
;
//récupération des variables de l'attachement
attachment_id
=
param
.
_attachment
;
attachment_id
=
param
.
_attachment
;
attachment_data
=
param
.
_blob
;
attachment_data
=
param
.
_blob
;
console
.
log
(
param
.
_blob
);
console
.
log
(
param
.
_blob
);
jIO
.
util
.
readBlobAsBinaryString
(
param
.
_blob
).
then
(
function
(
e
)
{
jIO
.
util
.
readBlobAsBinaryString
(
param
.
_blob
).
then
(
function
(
e
)
{
console
.
log
(
'
readBlobAsBinaryString
'
);
var
binary_string
=
e
.
target
.
result
;
var
binary_string
=
e
.
target
.
result
;
console
.
log
(
binary_string
);
console
.
dir
(
jIO
.
util
);
attachment_digest
=
jIO
.
util
.
makeBinaryStringDigest
(
binary_string
);
attachment_digest
=
jIO
.
util
.
makeBinaryStringDigest
(
binary_string
);
console
.
log
(
attachment_digest
);
//attachment_mimetype = param._blob.type;
//attachment_length = param._blob.size;
function
putAttachment
()
{
function
putAttachment
()
{
that
.
XHRwrapper
(
command
,
that
.
XHRwrapper
(
command
,
...
@@ -688,11 +706,7 @@
...
@@ -688,11 +706,7 @@
);
);
}
}
console
.
log
(
'
breakpoint2
'
);
function
putDocument
()
{
function
putDocument
()
{
console
.
log
(
'
putDoc
'
);
var
attachment_obj
,
data
,
doc
;
var
attachment_obj
,
data
,
doc
;
attachment_obj
=
{
attachment_obj
=
{
//"revpos": 3, // optional
//"revpos": 3, // optional
...
@@ -706,32 +720,28 @@
...
@@ -706,32 +720,28 @@
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
response
)
{
function
(
response
)
{
console
.
log
(
response
);
putAttachment
();
putAttachment
();
}
}
);
);
}
}
function
getDocument
()
{
function
getDocument
()
{
console
.
log
(
'
getDoc
'
);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
re
s
ponse
)
{
if
(
reponse
===
'
404
'
)
{
if
(
re
s
ponse
===
'
404
'
)
{
return
command
.
error
(
return
command
.
error
(
404
,
404
,
"
Document does not exist
"
,
"
Document does not exist
"
,
"
Cannot find document
"
"
Cannot find document
"
);
);
}
}
my_document
=
reponse
;
my_document
=
re
s
ponse
;
putDocument
();
putDocument
();
}
}
);
);
}
}
getDocument
();
getDocument
();
});
}).
then
(
console
.
log
,
console
.
error
);
};
};
/**
/**
...
...
test/jio.storage/s3storage.tests.js
View file @
95d90c8a
...
@@ -563,8 +563,8 @@
...
@@ -563,8 +563,8 @@
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
aa
"
,
"
attachment
"
:
"
aa
"
,
"
data
"
:
"
<blob>
"
,
"
data
"
:
"
<blob>
"
,
"
digest
"
:
"
sha256-
38760eabb666e8e61ee628a17c4090cc5
"
+
"
digest
"
:
"
sha256-
9834876dcfb05cb167a5c24953eba58c4
"
+
"
0728e095ff24218119d51bd22475363
"
,
"
ac89b1adf57f28f2f9d09af107ee8f0
"
,
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
"
method
"
:
"
getAttachment
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
result
"
:
"
success
"
,
...
@@ -573,7 +573,7 @@
...
@@ -573,7 +573,7 @@
},
"
Get first attachment
"
);
},
"
Get first attachment
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
blob
.
type
,
"
text/plain
"
,
"
Check blob type
"
);
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
)
{
},
function
(
err
)
{
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
deepEqual
(
err
,
"
no error
"
,
"
Check blob text content
"
);
});
});
...
@@ -948,7 +948,7 @@
...
@@ -948,7 +948,7 @@
// put 204
// put 204
//then(updateLastDocument).then(updateLastDocumentTest).
//then(updateLastDocument).then(updateLastDocumentTest).
// getA a 200
// getA a 200
//
then(getFirstAttachment).then(getFirstAttachmentTest).
then
(
getFirstAttachment
).
then
(
getFirstAttachmentTest
).
// getA b 200
// getA b 200
//then(getSecondAttachment).then(getSecondAttachmentTest).
//then(getSecondAttachment).then(getSecondAttachmentTest).
// get 200
// 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