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
1d7c6302
Commit
1d7c6302
authored
Oct 17, 2013
by
Jonathan Rivalan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation for putAttachment
parent
93888b58
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
56 deletions
+54
-56
src/jio.storage/s3storage.js
src/jio.storage/s3storage.js
+53
-55
test/jio.storage/s3storage.tests.js
test/jio.storage/s3storage.tests.js
+1
-1
No files found.
src/jio.storage/s3storage.js
View file @
1d7c6302
...
...
@@ -20,6 +20,12 @@
var
evt
,
that
,
priv
=
{};
that
=
this
;
//nomenclature param
// param._id,
// ._attachment,
// ._blob
// attributes
priv
.
username
=
spec
.
username
||
''
;
priv
.
AWSIdentifier
=
spec
.
AWSIdentifier
||
''
;
...
...
@@ -33,6 +39,7 @@
authenticated-read,
bucket-owner-read,
bucket-owner-full-control" <||*/
priv
.
acl
=
spec
.
acl
||
''
;
priv
.
actionStatus
=
spec
.
actionStatus
||
''
;
priv
.
contenTType
=
spec
.
contenTType
||
''
;
...
...
@@ -417,30 +424,6 @@
return
doc
;
};
priv
.
createError
=
function
(
status
,
message
,
reason
)
{
var
error
=
{
"
status
"
:
status
,
"
message
"
:
message
,
"
reason
"
:
reason
};
switch
(
status
)
{
case
404
:
error
.
statusText
=
"
Not found
"
;
break
;
case
405
:
error
.
statusText
=
"
Method Not Allowed
"
;
break
;
case
409
:
error
.
statusText
=
"
Conflicts
"
;
break
;
case
24
:
error
.
statusText
=
"
Corrupted Document
"
;
break
;
}
error
.
error
=
error
.
statusText
.
toLowerCase
().
split
(
"
"
).
join
(
"
_
"
);
return
error
;
};
that
.
encodeAuthorization
=
function
(
key
,
mime
)
{
//GET oriented method
var
requestUTC
,
httpVerb
,
StringToSign
,
Signature
;
...
...
@@ -654,28 +637,38 @@
);
};
that
.
putAttachment
=
function
(
command
)
{
var
m
on
_document
,
that
.
putAttachment
=
function
(
command
,
param
,
options
)
{
var
m
y
_document
,
docId
,
attachId
,
mime
,
attachment_id
,
attachment_data
,
attachment_
md5
,
attachment_
digest
,
attachment_mimetype
,
attachment_length
;
m
on
_document
=
null
;
docId
=
command
.
getDocId
()
;
attachId
=
command
.
getAttachmentId
()
||
''
;
m
y
_document
=
null
;
docId
=
param
.
_id
;
attachId
=
param
.
_attachment
;
mime
=
'
text/plain; charset=UTF-8
'
;
//récupération des variables de l'attachement
attachment_id
=
command
.
getAttachmentId
();
attachment_data
=
command
.
getAttachmentData
();
attachment_md5
=
command
.
md5SumAttachmentData
();
attachment_mimetype
=
command
.
getAttachmentMimeType
();
attachment_length
=
command
.
getAttachmentLength
();
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
,
...
...
@@ -689,51 +682,56 @@
function
(
reponse
)
{
command
.
success
({
// response
"
ok
"
:
true
,
"
id
"
:
docId
,
"
attachment
"
:
attachId
//"rev": current_revision
"
digest
"
:
attachment_digest
});
}
);
}
console
.
log
(
'
breakpoint2
'
);
function
putDocument
()
{
console
.
log
(
'
putDoc
'
);
var
attachment_obj
,
data
,
doc
;
attachment_obj
=
{
//"revpos": 3, // optional
"
digest
"
:
attachment_
md5
,
"
digest
"
:
attachment_
digest
,
"
content_type
"
:
attachment_mimetype
,
"
length
"
:
attachment_length
};
data
=
JSON
.
parse
(
m
on
_document
);
data
=
JSON
.
parse
(
m
y
_document
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
add
"
,
attachment_obj
);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
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
'
)
{
return
command
.
error
(
priv
.
createError
(
return
command
.
error
(
404
,
"
Cannot find documen
t
"
,
"
Document does not exis
t
"
)
)
;
"
Document does not exis
t
"
,
"
Cannot find documen
t
"
);
}
m
on
_document
=
reponse
;
m
y
_document
=
reponse
;
putDocument
();
}
);
}
getDocument
();
}).
then
(
console
.
log
,
console
.
error
);
};
/**
...
...
@@ -787,7 +785,7 @@
};
that
.
removeAttachment
=
function
(
command
)
{
var
m
on
_document
,
var
m
y
_document
,
docId
,
attachId
,
mime
,
...
...
@@ -797,7 +795,7 @@
attachment_mimetype
,
attachment_length
;
m
on
_document
=
null
;
m
y
_document
=
null
;
docId
=
command
.
getDocId
();
attachId
=
command
.
getAttachmentId
()
||
''
;
mime
=
'
text/plain; charset=UTF-8
'
;
...
...
@@ -818,7 +816,7 @@
function
putDocument
()
{
var
data
,
doc
;
data
=
JSON
.
parse
(
m
on
_document
);
data
=
JSON
.
parse
(
m
y
_document
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
remove
"
,
''
);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
...
...
@@ -830,7 +828,7 @@
function
getDocument
()
{
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
m
on
_document
=
reponse
;
m
y
_document
=
reponse
;
putDocument
();
}
);
...
...
@@ -845,8 +843,8 @@
**/
that
.
allDocs
=
function
(
command
)
{
var
m
on
_document
,
mime
;
m
on
_document
=
null
;
var
m
y
_document
,
mime
;
m
y
_document
=
null
;
mime
=
'
text/plain; charset=UTF-8
'
;
function
makeJSON
()
{
...
...
@@ -866,7 +864,7 @@
parse
,
checkCounter
;
keys
=
$
(
m
on
_document
).
find
(
'
Key
'
);
keys
=
$
(
m
y
_document
).
find
(
'
Key
'
);
resultTable
=
[];
counter
=
0
;
...
...
@@ -979,7 +977,7 @@
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
that
.
XHRwrapper
(
command
,
''
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
m
on
_document
=
reponse
;
m
y
_document
=
reponse
;
makeJSON
();
}
);
...
...
test/jio.storage/s3storage.tests.js
View file @
1d7c6302
...
...
@@ -940,7 +940,7 @@
// post 409
//then(postSameDocument).then(postSameDocumentTest).
// putA a 204
//
then(createAttachment).then(createAttachmentTest).
then
(
createAttachment
).
then
(
createAttachmentTest
).
// putA a 204
//then(updateAttachment).then(updateAttachmentTest).
// putA b 204
...
...
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