Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Papermerge.Js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
Papermerge.Js
Commits
34c68e58
Commit
34c68e58
authored
Nov 17, 2021
by
Eugen Ciur
Browse files
Options
Downloads
Patches
Plain Diff
fix: use copy of headers in page adapter
parent
076dbbd9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/adapters/document.js
+1
-1
1 addition, 1 deletion
app/adapters/document.js
app/adapters/page.js
+39
-17
39 additions, 17 deletions
app/adapters/page.js
app/routes/authenticated/document.js
+1
-0
1 addition, 0 deletions
app/routes/authenticated/document.js
with
41 additions
and
18 deletions
app/adapters/document.js
+
1
−
1
View file @
34c68e58
...
...
@@ -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
);
...
...
...
...
This diff is collapsed.
Click to expand it.
app/adapters/page.js
+
39
−
17
View file @
34c68e58
import
ApplicationAdapter
from
'
./application
'
;
export
default
class
Nod
eAdapter
extends
ApplicationAdapter
{
export
default
class
Pag
eAdapter
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
This diff is collapsed.
Click to expand it.
app/routes/authenticated/document.js
+
1
−
0
View file @
34c68e58
...
...
@@ -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
)
{
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment