Commit 1d7c6302 authored by Jonathan Rivalan's avatar Jonathan Rivalan

Validation for putAttachment

parent 93888b58
...@@ -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 mon_document, var my_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;
mon_document = null; my_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(mon_document); data = JSON.parse(my_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 document", "Document does not exist",
"Document does not exist" "Cannot find document"
)); );
} }
mon_document = reponse; my_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 mon_document, var my_document,
docId, docId,
attachId, attachId,
mime, mime,
...@@ -797,7 +795,7 @@ ...@@ -797,7 +795,7 @@
attachment_mimetype, attachment_mimetype,
attachment_length; attachment_length;
mon_document = null; my_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(mon_document); data = JSON.parse(my_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) {
mon_document = reponse; my_document = reponse;
putDocument(); putDocument();
} }
); );
...@@ -845,8 +843,8 @@ ...@@ -845,8 +843,8 @@
**/ **/
that.allDocs = function (command) { that.allDocs = function (command) {
var mon_document, mime; var my_document, mime;
mon_document = null; my_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 = $(mon_document).find('Key'); keys = $(my_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) {
mon_document = reponse; my_document = reponse;
makeJSON(); makeJSON();
} }
); );
......
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment