Commit 974cac47 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js putAttachment method redesigned

parent 0747228c
......@@ -130,17 +130,45 @@ var newLocalStorage = function (spec, my) {
/**
* Add an attachment to a document
* @method _putAttachment
* @method putAttachment
* @param {object} command The JIO command
*
* Available options:
* - {boolean} conflicts Add a conflicts object to the response
* - {boolean} revs Add the revisions history of the document
* - {boolean} revs_info Add revisions informations
*/
that._putAttachment = function (command) {
that.putAttachment = function (command) {
setTimeout(function () {
that.success(priv.setDocument(command, 'put');
var doc;
doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId());
if (typeof doc === "undefined") {
// the document does not exists
that.error({
"status": 404,
"statusText": "Not Found",
"error": "not_found",
"message": "Impossible to add attachment",
"reason": "Document not found"
});
return;
} else {
// the document already exists
doc["_attachments"] = doc["_attachments"] || {};
doc["_attachments"][command.getAttachmentId()] = {
"content_type": command.getAttachmentMimeType(),
"digest": "md5-"+command.md5SumAttachmentData(),
"length": command.getAttachmentLength()
};
}
// upload data
localstorage.setItem(
priv.localpath + "/" + command.getAttachmentId(),
command.getAttachmentData());
// write document
localstorage.setItem(
priv.localpath + "/" + command.getDocId(),
doc);
that.success({
"ok":true,
"_id":command.getDocId()+"/"+command.getAttachmentId()
});
});
};
......
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