Commit f4a45ae1 authored by Romain Courteaud's avatar Romain Courteaud

getAttachment: directly returns the blob instead of a JSON object

parent d9e77f60
...@@ -339,7 +339,7 @@ ...@@ -339,7 +339,7 @@
checkId(param, storage, method_name); checkId(param, storage, method_name);
checkAttachmentId(param, storage, method_name); checkAttachmentId(param, storage, method_name);
}, function (argument_list, result) { }, function (argument_list, result) {
if (!(result.data instanceof Blob)) { if (!(result instanceof Blob)) {
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"'getAttachment' (" + argument_list[0]._id + " , " + "'getAttachment' (" + argument_list[0]._id + " , " +
argument_list[0]._attachment + ") on '" + this.__type + argument_list[0]._attachment + ") on '" + this.__type +
......
...@@ -186,11 +186,11 @@ ...@@ -186,11 +186,11 @@
}); });
}) })
.push(function (response) { .push(function (response) {
return {data: new Blob( return new Blob(
[response.target.response || response.target.responseText], [response.target.response || response.target.responseText],
{"type": response.target.getResponseHeader('Content-Type') || {"type": response.target.getResponseHeader('Content-Type') ||
"application/octet-stream"} "application/octet-stream"}
)}; );
}, function (error) { }, function (error) {
if ((error.target !== undefined) && if ((error.target !== undefined) &&
(error.target.status === 404)) { (error.target.status === 404)) {
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"_attachment": getSubAttachmentIdFromParam(param) "_attachment": getSubAttachmentIdFromParam(param)
}) })
.push(function (blob) { .push(function (blob) {
return jIO.util.readBlobAsText(blob.data); return jIO.util.readBlobAsText(blob);
}) })
.push(function (text) { .push(function (text) {
return JSON.parse(text.target.result); return JSON.parse(text.target.result);
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
.push(function (blob) { .push(function (blob) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return jIO.util.readBlobAsText(blob.data); return jIO.util.readBlobAsText(blob);
}) })
.push(function (text) { .push(function (text) {
explicit_document = true; explicit_document = true;
......
...@@ -106,19 +106,19 @@ ...@@ -106,19 +106,19 @@
// if Base_edit, do put URN // if Base_edit, do put URN
// if others, do post URN (ie, unique new attachment name) // if others, do post URN (ie, unique new attachment name)
// XXX Except this attachment name should be generated when // XXX Except this attachment name should be generated when
return {data: new Blob( return new Blob(
[JSON.stringify(result)], [JSON.stringify(result)],
{"type": 'application/hal+json'} {"type": 'application/hal+json'}
)}; );
}); });
} }
if (action === "links") { if (action === "links") {
return getDocumentAndHateoas(this, param) return getDocumentAndHateoas(this, param)
.push(function (response) { .push(function (response) {
return {data: new Blob( return new Blob(
[JSON.stringify(JSON.parse(response.target.responseText))], [JSON.stringify(JSON.parse(response.target.responseText))],
{"type": 'application/hal+json'} {"type": 'application/hal+json'}
)}; );
}); });
} }
if (action.indexOf(this._url) === 0) { if (action.indexOf(this._url) === 0) {
...@@ -135,10 +135,10 @@ ...@@ -135,10 +135,10 @@
.push(function (evt) { .push(function (evt) {
var result = JSON.parse(evt.target.responseText); var result = JSON.parse(evt.target.responseText);
result._id = param._id; result._id = param._id;
return {data: new Blob( return new Blob(
[JSON.stringify(result)], [JSON.stringify(result)],
{"type": evt.target.getResponseHeader("Content-Type")} {"type": evt.target.getResponseHeader("Content-Type")}
)}; );
}); });
} }
throw new jIO.util.jIOError("ERP5: not support get attachment: " + action, throw new jIO.util.jIOError("ERP5: not support get attachment: " + action,
......
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
array_buffer_list.push(result_list[i].blob); array_buffer_list.push(result_list[i].blob);
} }
blob = new Blob(array_buffer_list, {type: "application/octet-stream"}); blob = new Blob(array_buffer_list, {type: "application/octet-stream"});
return {data: blob.slice(start, end)}; return blob.slice(start, end);
}); });
}; };
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
404 404
); );
} }
return {data: dataURItoBlob(textstring)}; return dataURItoBlob(textstring);
}; };
LocalStorage.prototype.putAttachment = function (param) { LocalStorage.prototype.putAttachment = function (param) {
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
404 404
); );
} }
return {data: result}; return result;
} catch (error) { } catch (error) {
if (error instanceof TypeError) { if (error instanceof TypeError) {
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
......
...@@ -858,9 +858,9 @@ ...@@ -858,9 +858,9 @@
Authorization: "Basic login:passwd" Authorization: "Basic login:passwd"
}); });
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
deepEqual(result.data.type, "text/plain", "Check mimetype"); deepEqual(result.type, "text/plain", "Check mimetype");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
equal(result.target.result, "foo\nbaré", equal(result.target.result, "foo\nbaré",
......
...@@ -53,11 +53,11 @@ ...@@ -53,11 +53,11 @@
deepEqual(options, {"_id": "foo", deepEqual(options, {"_id": "foo",
"_attachment": "jio_document/YmFy.json"}, "_attachment": "jio_document/YmFy.json"},
"getAttachment bar"); "getAttachment bar");
return {data: new Blob([JSON.stringify({ return new Blob([JSON.stringify({
title: options._attachment, title: options._attachment,
id: "ID " + options._attachment, id: "ID " + options._attachment,
"another": "property" "another": "property"
})])}; })]);
}; };
StorageGetNoAttachment.prototype.get = function (options) { StorageGetNoAttachment.prototype.get = function (options) {
deepEqual(options, {"_id": "foo"}, "Get foo"); deepEqual(options, {"_id": "foo"}, "Get foo");
...@@ -106,11 +106,11 @@ ...@@ -106,11 +106,11 @@
deepEqual(options, {"_id": "foo", deepEqual(options, {"_id": "foo",
"_attachment": "jio_document/YmFy.json"}, "_attachment": "jio_document/YmFy.json"},
"getAttachment bar"); "getAttachment bar");
return {data: new Blob([JSON.stringify({ return new Blob([JSON.stringify({
title: options._attachment, title: options._attachment,
id: "ID " + options._attachment, id: "ID " + options._attachment,
"another": "property" "another": "property"
})])}; })]);
}; };
StorageGetWithAttachment.prototype.get = function (options) { StorageGetWithAttachment.prototype.get = function (options) {
deepEqual(options, {"_id": "foo"}, "Get foo"); deepEqual(options, {"_id": "foo"}, "Get foo");
...@@ -269,12 +269,12 @@ ...@@ -269,12 +269,12 @@
deepEqual(param, {"_id": "foo", deepEqual(param, {"_id": "foo",
"_attachment": "jio_attachment/YmFy/YmFyMg=="}, "_attachment": "jio_attachment/YmFy/YmFyMg=="},
"getAttachment 200 called"); "getAttachment 200 called");
return {data: blob}; return blob;
}; };
jio.getAttachment({"_id": "bar", "_attachment": "bar2"}) jio.getAttachment({"_id": "bar", "_attachment": "bar2"})
.then(function (result) { .then(function (result) {
equal(result.data, blob); equal(result, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
deepEqual(options, {"_id": "/.jio_documents/", deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"}, "_attachment": "bar.json"},
"getAttachment"); "getAttachment");
return {data: new Blob([JSON.stringify({title: "foo"})])}; return new Blob([JSON.stringify({title: "foo"})]);
}; };
StorageGetOnlyDocument.prototype.get = function (options) { StorageGetOnlyDocument.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document"); deepEqual(options, {"_id": "/"}, "Get document");
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
deepEqual(options, {"_id": "/.jio_documents/", deepEqual(options, {"_id": "/.jio_documents/",
"_attachment": "bar.json"}, "_attachment": "bar.json"},
"getAttachment"); "getAttachment");
return {data: new Blob([JSON.stringify({title: "foo"})])}; return new Blob([JSON.stringify({title: "foo"})]);
}; };
StorageGetBoth.prototype.get = function (options) { StorageGetBoth.prototype.get = function (options) {
deepEqual(options, {"_id": "/"}, "Get document"); deepEqual(options, {"_id": "/"}, "Get document");
...@@ -575,12 +575,12 @@ ...@@ -575,12 +575,12 @@
deepEqual(param, {"_id": "/", deepEqual(param, {"_id": "/",
"_attachment": "bar"}, "_attachment": "bar"},
"getAttachment 200 called"); "getAttachment 200 called");
return {data: blob}; return blob;
}; };
jio.getAttachment({"_id": "bar", "_attachment": "enclosure"}) jio.getAttachment({"_id": "bar", "_attachment": "enclosure"})
.then(function (result) { .then(function (result) {
equal(result.data, blob); equal(result, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
...@@ -299,9 +299,9 @@ ...@@ -299,9 +299,9 @@
equal(server.requests[1].requestBody, undefined); equal(server.requests[1].requestBody, undefined);
equal(server.requests[1].withCredentials, true); equal(server.requests[1].withCredentials, true);
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
deepEqual(result.data.type, "application/hal+json", "Check mimetype"); deepEqual(result.type, "application/hal+json", "Check mimetype");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
var expected = JSON.parse(document_hateoas); var expected = JSON.parse(document_hateoas);
...@@ -359,9 +359,9 @@ ...@@ -359,9 +359,9 @@
equal(server.requests[1].requestBody, undefined); equal(server.requests[1].requestBody, undefined);
equal(server.requests[1].withCredentials, true); equal(server.requests[1].withCredentials, true);
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
deepEqual(result.data.type, "application/hal+json", "Check mimetype"); deepEqual(result.type, "application/hal+json", "Check mimetype");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
var expected = JSON.parse(document_hateoas); var expected = JSON.parse(document_hateoas);
...@@ -409,9 +409,9 @@ ...@@ -409,9 +409,9 @@
equal(server.requests[0].requestBody, undefined); equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].withCredentials, true); equal(server.requests[0].withCredentials, true);
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
deepEqual(result.data.type, "application/json", "Check mimetype"); deepEqual(result.type, "application/json", "Check mimetype");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
var expected = JSON.parse(document_hateoas); var expected = JSON.parse(document_hateoas);
......
...@@ -986,8 +986,8 @@ ...@@ -986,8 +986,8 @@
"_attachment": attachment}); "_attachment": attachment});
}) })
.then(function (result) { .then(function (result) {
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
equal(result.target.result, big_string, equal(result.target.result, big_string,
...@@ -1022,8 +1022,8 @@ ...@@ -1022,8 +1022,8 @@
"_start": 1999995, "_end": 2000005}); "_start": 1999995, "_end": 2000005});
}) })
.then(function (result) { .then(function (result) {
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
var expected = "aaaaaaaaaa"; var expected = "aaaaaaaaaa";
......
...@@ -180,11 +180,11 @@ ...@@ -180,11 +180,11 @@
"_attachment": attachment "_attachment": attachment
}) })
.then(function (result) { .then(function (result) {
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
deepEqual(result.data.type, "text/plain;charset=utf-8", deepEqual(result.type, "text/plain;charset=utf-8",
"Check mimetype"); "Check mimetype");
return jIO.util.readBlobAsText(result.data); return jIO.util.readBlobAsText(result);
}) })
.then(function (result) { .then(function (result) {
equal(result.target.result, value, "Attachment correctly fetched"); equal(result.target.result, value, "Attachment correctly fetched");
...@@ -222,8 +222,8 @@ ...@@ -222,8 +222,8 @@
"_attachment": attachment "_attachment": attachment
}) })
.then(function (result) { .then(function (result) {
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
return jIO.util.readBlobAsDataURL(result.data); return jIO.util.readBlobAsDataURL(result);
}) })
.then(function (result) { .then(function (result) {
equal(result.target.result, data_url, "Attachment correctly fetched"); equal(result.target.result, data_url, "Attachment correctly fetched");
......
...@@ -320,8 +320,8 @@ ...@@ -320,8 +320,8 @@
"_attachment": attachment "_attachment": attachment
}) })
.then(function (result) { .then(function (result) {
ok(result.data instanceof Blob, "Data is Blob"); ok(result instanceof Blob, "Data is Blob");
equal(result.data, blob); equal(result, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
...@@ -185,12 +185,12 @@ ...@@ -185,12 +185,12 @@
Storage200.prototype.getAttachment = function (param) { Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"}, deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"getAttachment 200 called"); "getAttachment 200 called");
return {data: blob}; return blob;
}; };
jio.getAttachment({"_id": "bar", "_attachment": "foo"}) jio.getAttachment({"_id": "bar", "_attachment": "foo"})
.then(function (result) { .then(function (result) {
equal(result.data, blob); equal(result, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
...@@ -199,12 +199,12 @@ ...@@ -199,12 +199,12 @@
Storage200.prototype.getAttachment = function (param) { Storage200.prototype.getAttachment = function (param) {
deepEqual(param, {"_id": "bar", "_attachment": "foo"}, deepEqual(param, {"_id": "bar", "_attachment": "foo"},
"getAttachment 200 called"); "getAttachment 200 called");
return {data: blob}; return blob;
}; };
jio.getAttachment({"_id": "bar", "_attachment": "foo"}) jio.getAttachment({"_id": "bar", "_attachment": "foo"})
.then(function (result) { .then(function (result) {
equal(result.data, blob); equal(result, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
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