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