Commit 1e7672c7 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage wrong status returned -> fixed

parent e34cc4eb
...@@ -187,21 +187,23 @@ ...@@ -187,21 +187,23 @@
* @param {Object} options The command options * @param {Object} options The command options
*/ */
LocalStorage.prototype.put = function (command, metadata) { LocalStorage.prototype.put = function (command, metadata) {
var doc, tmp; var doc, tmp, status;
doc = this._storage.getItem(this._localpath + "/" + metadata._id); doc = this._storage.getItem(this._localpath + "/" + metadata._id);
if (doc === null) { if (doc === null) {
// the document does not exist // the document does not exist
doc = jIO.util.deepClone(metadata); doc = jIO.util.deepClone(metadata);
delete doc._attachments; delete doc._attachments;
status = "created";
} else { } else {
// the document already exists // the document already exists
tmp = jIO.util.deepClone(metadata); tmp = jIO.util.deepClone(metadata);
tmp._attachments = doc._attachments; tmp._attachments = doc._attachments;
doc = tmp; doc = tmp;
status = "ok";
} }
// write // write
this._storage.setItem(this._localpath + "/" + metadata._id, doc); this._storage.setItem(this._localpath + "/" + metadata._id, doc);
command.success(); command.success(status);
}; };
/** /**
...@@ -213,7 +215,7 @@ ...@@ -213,7 +215,7 @@
* @param {Object} options The command options * @param {Object} options The command options
*/ */
LocalStorage.prototype.putAttachment = function (command, param) { LocalStorage.prototype.putAttachment = function (command, param) {
var that = this, doc; var that = this, doc, status = "ok";
doc = this._storage.getItem(this._localpath + "/" + param._id); doc = this._storage.getItem(this._localpath + "/" + param._id);
if (doc === null) { if (doc === null) {
// the document does not exist // the document does not exist
...@@ -228,6 +230,9 @@ ...@@ -228,6 +230,9 @@
// download data // download data
jIO.util.readBlobAsBinaryString(param._blob).then(function (e) { jIO.util.readBlobAsBinaryString(param._blob).then(function (e) {
doc._attachments = doc._attachments || {}; doc._attachments = doc._attachments || {};
if (doc._attachments[param._attachment]) {
status = "created";
}
doc._attachments[param._attachment] = { doc._attachments[param._attachment] = {
"content_type": param._blob.type, "content_type": param._blob.type,
"digest": jIO.util.makeBinaryStringDigest(e.target.result), "digest": jIO.util.makeBinaryStringDigest(e.target.result),
...@@ -237,7 +242,8 @@ ...@@ -237,7 +242,8 @@
that._storage.setItem(that._localpath + "/" + param._id + "/" + that._storage.setItem(that._localpath + "/" + param._id + "/" +
param._attachment, e.target.result); param._attachment, e.target.result);
that._storage.setItem(that._localpath + "/" + param._id, doc); that._storage.setItem(that._localpath + "/" + param._id, doc);
command.success({"hash": doc._attachments[param._attachment].digest}); command.success(status,
{"hash": doc._attachments[param._attachment].digest});
}, function (e) { }, function (e) {
command.error( command.error(
"request_timeout", "request_timeout",
......
...@@ -153,8 +153,8 @@ ...@@ -153,8 +153,8 @@
"id": "put1", "id": "put1",
"method": "put", "method": "put",
"result": "success", "result": "success",
"status": 200, "status": 201,
"statusText": "Ok" "statusText": "Created"
}, "Creates a document"); }, "Creates a document");
}).then(function () { }).then(function () {
...@@ -407,8 +407,8 @@ ...@@ -407,8 +407,8 @@
"id": "a", "id": "a",
"method": "removeAttachment", "method": "removeAttachment",
"result": "success", "result": "success",
"status": 200, "status": 204,
"statusText": "Ok" "statusText": "No Content"
}, "Remove existent attachment"); }, "Remove existent attachment");
}).then(function () { }).then(function () {
...@@ -443,8 +443,8 @@ ...@@ -443,8 +443,8 @@
"id": "a", "id": "a",
"method": "remove", "method": "remove",
"result": "success", "result": "success",
"status": 200, "status": 204,
"statusText": "Ok" "statusText": "No Content"
}, "Remove existent document"); }, "Remove existent document");
}).then(function () { }).then(function () {
......
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