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
Ivan Tyagov
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 @@
...
@@ -20,6 +20,12 @@
var
evt
,
that
,
priv
=
{};
var
evt
,
that
,
priv
=
{};
that
=
this
;
that
=
this
;
//nomenclature param
// param._id,
// ._attachment,
// ._blob
// attributes
// attributes
priv
.
username
=
spec
.
username
||
''
;
priv
.
username
=
spec
.
username
||
''
;
priv
.
AWSIdentifier
=
spec
.
AWSIdentifier
||
''
;
priv
.
AWSIdentifier
=
spec
.
AWSIdentifier
||
''
;
...
@@ -33,6 +39,7 @@
...
@@ -33,6 +39,7 @@
authenticated-read,
authenticated-read,
bucket-owner-read,
bucket-owner-read,
bucket-owner-full-control" <||*/
bucket-owner-full-control" <||*/
priv
.
acl
=
spec
.
acl
||
''
;
priv
.
acl
=
spec
.
acl
||
''
;
priv
.
actionStatus
=
spec
.
actionStatus
||
''
;
priv
.
actionStatus
=
spec
.
actionStatus
||
''
;
priv
.
contenTType
=
spec
.
contenTType
||
''
;
priv
.
contenTType
=
spec
.
contenTType
||
''
;
...
@@ -417,30 +424,6 @@
...
@@ -417,30 +424,6 @@
return
doc
;
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
)
{
that
.
encodeAuthorization
=
function
(
key
,
mime
)
{
//GET oriented method
//GET oriented method
var
requestUTC
,
httpVerb
,
StringToSign
,
Signature
;
var
requestUTC
,
httpVerb
,
StringToSign
,
Signature
;
...
@@ -654,28 +637,38 @@
...
@@ -654,28 +637,38 @@
);
);
};
};
that
.
putAttachment
=
function
(
command
)
{
that
.
putAttachment
=
function
(
command
,
param
,
options
)
{
var
m
on
_document
,
var
m
y
_document
,
docId
,
docId
,
attachId
,
attachId
,
mime
,
mime
,
attachment_id
,
attachment_id
,
attachment_data
,
attachment_data
,
attachment_
md5
,
attachment_
digest
,
attachment_mimetype
,
attachment_mimetype
,
attachment_length
;
attachment_length
;
m
on
_document
=
null
;
m
y
_document
=
null
;
docId
=
command
.
getDocId
()
;
docId
=
param
.
_id
;
attachId
=
command
.
getAttachmentId
()
||
''
;
attachId
=
param
.
_attachment
;
mime
=
'
text/plain; charset=UTF-8
'
;
mime
=
'
text/plain; charset=UTF-8
'
;
//récupération des variables de l'attachement
//récupération des variables de l'attachement
attachment_id
=
command
.
getAttachmentId
();
attachment_data
=
command
.
getAttachmentData
();
attachment_id
=
param
.
_attachment
;
attachment_md5
=
command
.
md5SumAttachmentData
();
attachment_data
=
param
.
_blob
;
attachment_mimetype
=
command
.
getAttachmentMimeType
();
console
.
log
(
param
.
_blob
);
attachment_length
=
command
.
getAttachmentLength
();
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
()
{
function
putAttachment
()
{
that
.
XHRwrapper
(
command
,
that
.
XHRwrapper
(
command
,
...
@@ -689,51 +682,56 @@
...
@@ -689,51 +682,56 @@
function
(
reponse
)
{
function
(
reponse
)
{
command
.
success
({
command
.
success
({
// response
// response
"
ok
"
:
true
,
"
digest
"
:
attachment_digest
"
id
"
:
docId
,
"
attachment
"
:
attachId
//"rev": current_revision
});
});
}
}
);
);
}
}
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
"
digest
"
:
attachment_
md5
,
"
digest
"
:
attachment_
digest
,
"
content_type
"
:
attachment_mimetype
,
"
content_type
"
:
attachment_mimetype
,
"
length
"
:
attachment_length
"
length
"
:
attachment_length
};
};
data
=
JSON
.
parse
(
m
on
_document
);
data
=
JSON
.
parse
(
m
y
_document
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
add
"
,
attachment_obj
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
add
"
,
attachment_obj
);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
function
(
response
)
{
console
.
log
(
response
);
putAttachment
();
putAttachment
();
}
}
);
);
}
}
function
getDocument
()
{
function
getDocument
()
{
console
.
log
(
'
getDoc
'
);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
//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
(
reponse
)
{
if
(
reponse
===
'
404
'
)
{
if
(
reponse
===
'
404
'
)
{
return
command
.
error
(
priv
.
createError
(
return
command
.
error
(
404
,
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
();
putDocument
();
}
}
);
);
}
}
getDocument
();
getDocument
();
}).
then
(
console
.
log
,
console
.
error
);
};
};
/**
/**
...
@@ -787,7 +785,7 @@
...
@@ -787,7 +785,7 @@
};
};
that
.
removeAttachment
=
function
(
command
)
{
that
.
removeAttachment
=
function
(
command
)
{
var
m
on
_document
,
var
m
y
_document
,
docId
,
docId
,
attachId
,
attachId
,
mime
,
mime
,
...
@@ -797,7 +795,7 @@
...
@@ -797,7 +795,7 @@
attachment_mimetype
,
attachment_mimetype
,
attachment_length
;
attachment_length
;
m
on
_document
=
null
;
m
y
_document
=
null
;
docId
=
command
.
getDocId
();
docId
=
command
.
getDocId
();
attachId
=
command
.
getAttachmentId
()
||
''
;
attachId
=
command
.
getAttachmentId
()
||
''
;
mime
=
'
text/plain; charset=UTF-8
'
;
mime
=
'
text/plain; charset=UTF-8
'
;
...
@@ -818,7 +816,7 @@
...
@@ -818,7 +816,7 @@
function
putDocument
()
{
function
putDocument
()
{
var
data
,
doc
;
var
data
,
doc
;
data
=
JSON
.
parse
(
m
on
_document
);
data
=
JSON
.
parse
(
m
y
_document
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
remove
"
,
''
);
doc
=
priv
.
updateMeta
(
data
,
docId
,
attachId
,
"
remove
"
,
''
);
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
PUT
'
,
mime
,
doc
,
false
,
false
,
function
(
reponse
)
{
false
,
false
,
function
(
reponse
)
{
...
@@ -830,7 +828,7 @@
...
@@ -830,7 +828,7 @@
function
getDocument
()
{
function
getDocument
()
{
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
docId
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
m
on
_document
=
reponse
;
m
y
_document
=
reponse
;
putDocument
();
putDocument
();
}
}
);
);
...
@@ -845,8 +843,8 @@
...
@@ -845,8 +843,8 @@
**/
**/
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
m
on
_document
,
mime
;
var
m
y
_document
,
mime
;
m
on
_document
=
null
;
m
y
_document
=
null
;
mime
=
'
text/plain; charset=UTF-8
'
;
mime
=
'
text/plain; charset=UTF-8
'
;
function
makeJSON
()
{
function
makeJSON
()
{
...
@@ -866,7 +864,7 @@
...
@@ -866,7 +864,7 @@
parse
,
parse
,
checkCounter
;
checkCounter
;
keys
=
$
(
m
on
_document
).
find
(
'
Key
'
);
keys
=
$
(
m
y
_document
).
find
(
'
Key
'
);
resultTable
=
[];
resultTable
=
[];
counter
=
0
;
counter
=
0
;
...
@@ -979,7 +977,7 @@
...
@@ -979,7 +977,7 @@
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
//XHRwrapper(command,'PUT','text/plain; charset=UTF-8',true);
that
.
XHRwrapper
(
command
,
''
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
that
.
XHRwrapper
(
command
,
''
,
''
,
'
GET
'
,
mime
,
''
,
false
,
false
,
function
(
reponse
)
{
function
(
reponse
)
{
m
on
_document
=
reponse
;
m
y
_document
=
reponse
;
makeJSON
();
makeJSON
();
}
}
);
);
...
...
test/jio.storage/s3storage.tests.js
View file @
1d7c6302
...
@@ -940,7 +940,7 @@
...
@@ -940,7 +940,7 @@
// post 409
// post 409
//then(postSameDocument).then(postSameDocumentTest).
//then(postSameDocument).then(postSameDocumentTest).
// putA a 204
// putA a 204
//
then(createAttachment).then(createAttachmentTest).
then
(
createAttachment
).
then
(
createAttachmentTest
).
// putA a 204
// putA a 204
//then(updateAttachment).then(updateAttachmentTest).
//then(updateAttachment).then(updateAttachmentTest).
// putA b 204
// 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