Skip to content

Commit

Permalink
fix: viewing of pdf in analysis preview
Browse files Browse the repository at this point in the history
also src pdfworker locally
  • Loading branch information
PiTrem committed May 13, 2024
1 parent 5c15533 commit 9e99b03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/packs/src/components/common/ImageModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AttachmentFetcher from 'src/fetchers/AttachmentFetcher';
import { stopEvent } from 'src/utilities/DomHelper';
import { Document, Page, pdfjs } from 'react-pdf';

pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js';

export default class ImageModal extends Component {
constructor(props) {
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class ImageModal extends Component {
}
}

shouldComponentUpdate(nextState) {
shouldComponentUpdate(nextProps, nextState) {
if (
this.state.numOfPages === nextState.numOfPages
&& this.state.numOfPages !== 0
Expand Down
16 changes: 15 additions & 1 deletion config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@

# # Specify URI for violation reports
# # policy.report_uri "/csp-violation-report-endpoint"
policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?

# connect_src for log and webpack-dev-serverwebsockets in development
if Rails.env.development?
url = URI.parse(ENV['PUBLIC_URL'] || '')
scheme = url.scheme || 'http'
host = url.host
port = url.port

src = [:self, :https, 'http://localhost:3035', 'ws://localhost:3035']
src += ["ws://#{host}:3035", "#{scheme}://#{host}:3035"] if host.present?
src += ["#{scheme}://#{host}:#{url.port}"] if host.present? && port.present?
puts "connect_src: #{src}"

policy.connect_src *src
end
end

# If you are using UJS then enable automatic nonce generation
Expand Down
7 changes: 6 additions & 1 deletion package_postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ rm -f ./public/svgedit && ln -s "$node_modules_folder"/svgedit/dist/editor ./pub

yellow "Finished adding symbolic link to svg editor in public folder"

# copy pdfjs worker to public folder
node_modules_folder_pdfjs="$(node -e 'const p = require.resolve("pdfjs-dist/build/pdf.worker"); console.log(p.slice(0, p.indexOf("pdfjs-dist/build/pdf.worker")))')"
rm -f ./public/pdf.worker.min.js && ln -s "$node_modules_folder_pdfjs"pdfjs-dist/build/pdf.worker.min.js ./public/pdf.worker.min.js
yellow "Finished adding symbolic link to pdf worker in public folder"

# d3js source files
src_d3=(
"@complat/react-spectra-editor/dist/components/common/draw.js"
Expand All @@ -54,4 +59,4 @@ for src_file in "${src_d3[@]}"; do
echo -e "\n});" >> "$src"
fi
yellow "Done rewriting import for d3.js in $src"
done
done

0 comments on commit 9e99b03

Please sign in to comment.