Skip to content
Snippets Groups Projects
Commit 34c68e58 authored by Eugen Ciur's avatar Eugen Ciur
Browse files

fix: use copy of headers in page adapter

parent 076dbbd9
Branches
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import ApplicationAdapter from './application';
export default class NodeAdapter extends ApplicationAdapter {
getDocumentVersion(document_id) {
async getDocumentVersion(document_id) {
let url, ret;
url = this.buildURL('documents', document_id);
......
......
import ApplicationAdapter from './application';
export default class NodeAdapter extends ApplicationAdapter {
export default class PageAdapter extends ApplicationAdapter {
getBinaryImage(page_id) {
let url, headers;
async getBinaryImage(page_id) {
/*
* Requests binary image/jpeg from backend of the
* page model based on `page_id`
*/
let url, headers_copy = {};
url = this.buildURL('pages', page_id);
headers = this.headers;
headers['Accept'] = 'image/jpeg';
// Important! don't change original this.headers
// otherwise `PageAdapter` will continue
// accepting only 'image/jpeg' content type for all subsequent requests
Object.assign(headers_copy, this.headers); // create a copy of `this.headers`
headers_copy['Accept'] = 'image/jpeg';
return fetch(url, {
method: 'GET',
headers: headers
headers: headers_copy
});
}
async loadBinaryImages(pages) {
let all_proms = pages.map((page) => {
// fetch binary image here
return this.getBinaryImage(page.id).then(
response => response.blob()
).then((image_blob) => {
const image_object_url = URL.createObjectURL(image_blob);
async loadBinaryImage(page) {
/*
* Requests binary image/jpeg from backend and sets `page.url` attribute
* to the `URL` pointing to newly retrieved binary image.
*/
let response,
image_blob,
image_object_url;
response = await this.getBinaryImage(page.id);
image_blob = await response.blob();
image_object_url = URL.createObjectURL(image_blob);
page.url = image_object_url;
});
});
await Promise.all(all_proms);
return pages;
return page;
}
async loadBinaryImages(pages) {
let all_proms,
pages_with_url;
all_proms = pages.map(
(page) => this.loadBinaryImage(page)
);
pages_with_url = await Promise.all(all_proms);
return pages_with_url;
}
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ export default class DocumentRoute extends Route {
document_version = await doc_adapter.getDocumentVersion(params.document_id);
pages = await document_version.pages;
pages_with_url = await page_adapter.loadBinaryImages(pages);
if (params.extradoc_id) {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment