Skip to content

Commit c9a27b2

Browse files
Implement custom pdfjs viewer for toolbar modification (#624)
1 parent 4d13809 commit c9a27b2

File tree

24 files changed

+276
-86
lines changed

24 files changed

+276
-86
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ lambdas/tests/unit/helpers/data/pdf/tmp
106106

107107
tests/bulk-upload/output/**
108108
tests/bulk-upload/test_patients_data/**
109-
tests/bulk-upload/scripts/scenario_report.txt
109+
tests/bulk-upload/scripts/scenario_report.txt

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ install:
123123
clean-install:
124124
npm --prefix ./app ci --legacy-peer-deps
125125

126+
install-pdfjs:
127+
mkdir -p ./app/public/pdfjs
128+
wget https://github.com/mozilla/pdf.js/releases/download/v4.10.38/pdfjs-4.10.38-dist.zip -O ./app/public/pdfjs/pdfjs.zip
129+
unzip -o -d ./app/public/pdfjs ./app/public/pdfjs/pdfjs.zip
130+
rm ./app/public/pdfjs/pdfjs.zip
131+
126132
start:
127133
npm --prefix ./app start
128134

app/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/.pnp
66
.pnp.js
77

8+
# ignore setup_pdf.js temp files
9+
/public/pdfjs
10+
811
# testing
912
/coverage
1013
/cypress/results

app/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Build the App
22
FROM node:18-alpine as builder
3+
RUN apk add unzip wget
34
WORKDIR /app
45

56
COPY package.json ./
67
COPY package-lock.json ./
78
COPY ./ ./
89

910
RUN npm install --legacy-peer-deps
11+
RUN mkdir -p ./public/pdfjs
12+
RUN wget https://github.com/mozilla/pdf.js/releases/download/v4.10.38/pdfjs-4.10.38-dist.zip -O ./public/pdfjs/pdfjs.zip
13+
RUN unzip -o -d ./public/pdfjs ./public/pdfjs/pdfjs.zip
14+
RUN rm ./public/pdfjs/pdfjs.zip
1015
RUN npm run build
1116

1217
# Host the App

app/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ To run the UI, the team has created a Makefile in the route directory, on your f
3434
make install
3535
```
3636

37+
After modules have installed you need to install pdfjs with the following command
38+
39+
```bash
40+
make install-pdfjs
41+
```
42+
3743
Once the packages have been installed, you can then run the app through the following command
3844

3945
```bash

app/cypress.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default defineConfig({
2121
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
2222
AWS_REGION: process.env.AWS_REGION ?? 'eu-west-2',
2323
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
24+
ELECTRON_ENABLE_LOGGING: 1,
2425
},
2526
component: {
2627
devServer: {
@@ -41,4 +42,5 @@ export default defineConfig({
4142
runMode: 5,
4243
openMode: 0,
4344
},
45+
chromeWebSecurity: false,
4446
});

app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/download_lloyd_george_workflow.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('GP Workflow: View Lloyd George record', () => {
153153
cy.wait('@stitchJobCompleted', { timeout: 20000 });
154154
cy.title().should('eq', lloydGeorgeRecordPageTitle);
155155

156-
cy.getByTestId('download-all-files-link').should('exist');
156+
cy.getByTestId('download-all-files-link', { timeout: 20000 }).should('exist');
157157
cy.getByTestId('download-all-files-link').click();
158158

159159
// Select documents page
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"jobStatus": "Completed",
3-
"numberOfFiles": 12,
3+
"numberOfFiles": 1,
44
"lastUpdated": "2023-10-09T15:41:38.319508Z",
5-
"presignedUrl": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
5+
"presignedUrl": "http://localhost:3000/dev/testFile.pdf",
66
"totalFileSizeInBytes": 514495
77
}

app/docker/nginx.conf

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,42 @@ events {
22
worker_connections 4096; ## Default: 1024
33
}
44
http {
5-
server_tokens off; # hides server version within headers
5+
6+
include /etc/nginx/mime.types;
7+
default_type application/octet-stream;
8+
9+
types {
10+
application/javascript mjs;
11+
}
12+
server_tokens off;
613
server {
14+
15+
root /usr/share/nginx/html;
16+
717
listen $CONTAINER_PORT;
818
add_header Cache-Control "no-store, no-cache" always;
19+
20+
add_header Cache-Control "no-store" always;
921
add_header Pragma "no-cache" always;
1022
add_header Strict-Transport-Security "max-age=63072000" always;
11-
add_header Content-Security-Policy "frame-ancestors 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'self' https://$CLOUDFRONT_DOMAIN_NAME;" always;
23+
add_header Content-Security-Policy "frame-ancestors 'self'; img-src 'self' blob:; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'self' https://$CLOUDFRONT_DOMAIN_NAME;" always;
1224
add_header Referrer-Policy "no-referrer" always;
13-
add_header Permissions-Policy "Permissions-Policy: accelerometer=(self), ambient-light-sensor=(self), autoplay=(self), battery=(self), camera=(self), cross-origin-isolated=(self), display-capture=(self), document-domain=(self), encrypted-media=(self), execution-while-not-rendered=(self), execution-while-out-of-viewport=(self), fullscreen=(self), geolocation=(self), gyroscope=(self), keyboard-map=(self), magnetometer=(self), microphone=(self), midi=(self), navigation-override=(self), payment=(self), picture-in-picture=(self), publickey-credentials-get=(self), screen-wake-lock=(self), sync-xhr=(self), usb=(self), web-share=(self), xr-spatial-tracking=(self), clipboard-read=(self), clipboard-write=(self), gamepad=(self), speaker-selection=(self), conversion-measurement=(self), focus-without-user-activation=(self), hid=(self), idle-detection=(self), interest-cohort=(self), serial=(self), sync-script=(self), trust-token-redemption=(self), unload=(self), window-placement=(self), vertical-scroll=(self)" always;
25+
add_header Permissions-Policy "accelerometer=(self), autoplay=(self), camera=(self), cross-origin-isolated=(self), display-capture=(self), encrypted-media=(self), fullscreen=(self), geolocation=(self), gyroscope=(self), keyboard-map=(self), magnetometer=(self), microphone=(self), midi=(self), payment=(self), picture-in-picture=(self), publickey-credentials-get=(self), screen-wake-lock=(self), sync-xhr=(self), usb=(self), xr-spatial-tracking=(self), clipboard-read=(self), clipboard-write=(self), gamepad=(self), hid=(self), idle-detection=(self), interest-cohort=(self), serial=(self), unload=(self) " always;
1426
add_header X-Content-Type-Options "nosniff" always;
1527
add_header X-Frame-Options "DENY" always;
1628
add_header X-Permitted-Cross-Domain-Policies "none" always;
29+
1730
location / {
18-
root /usr/share/nginx/html;
1931
index index.html index.htm;
20-
include /etc/nginx/mime.types;
2132
try_files $uri $uri/ /index.html$is_args$args;
2233
}
34+
35+
location /pdfjs/ {
36+
add_header Content-Security-Policy "default-src 'none'; frame-ancestors 'self'; img-src 'self' blob: data:; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self' blob: https:;" always;
37+
add_header Permissions-Policy "fullscreen=()" always;
38+
add_header X-Frame-Options "SAMEORIGIN" always;
39+
try_files $uri $uri/ /index.html$is_args$args;
40+
}
41+
2342
}
2443
}

app/package-lock.json

Lines changed: 20 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)