Skip to content

Commit

Permalink
BUG: Use network resource for sample data with production builds
Browse files Browse the repository at this point in the history
CDN does not support the large file.

Also fix progress bar value (max is fixed to 100).
  • Loading branch information
thewtex committed Jul 27, 2023
1 parent e72b860 commit 186bc96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"version": "0.1.0",
"description": "Convert and calibrate Scanco microCT volume .isq and .aim files.",
"scripts": {
"start": "npm run copyShoelaceAssets && npm run downloadSampleData && vite -c vite.config.js",
"start": "pnpm copyShoelaceAssets && pnpm downloadSampleData && vite",
"preview": "pnpm copyShoelaceAssets && pnpm downloadSampleData && vite build && vite preview",
"test": "echo \"tests are not configured\" && exit 1",
"downloadSampleData": "dam download -v public/sample-data public/sample-data.tar.gz bafybeiepwh5ppaeaja7q6kqc25tvzfpkygqomxzqq4csnjfntoxarqtdiq https://w3s.link/ipfs/bafybeihiuinvftya2jqrr7fhdrdf4a5zhx7gnmawwf45mid7j2s5zcn6xi",
"copyShoelaceAssets": "shx mkdir -p public/shoelace && shx cp -r node_modules/@shoelace-style/shoelace/dist/assets public/",
"build": "npm run copyShoelaceAssets && npm run downloadSampleData && vite -c vite.config.js build"
"build": "pnpm copyShoelaceAssets && pnpm downloadSampleData && vite build"
},
"keywords": [
"itk",
Expand Down
11 changes: 6 additions & 5 deletions app/src/conversion-load-sample-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default async function conversionLoadSampleInputs (model) {

const inputVolumeElement = document.querySelector("#conversionInputs sl-input[name=input-volume]")

const response = await fetch('/sample-data/AIMIOTestImage.AIM')
const contentLength = +response.headers.get('Content-Length');
const url = import.meta.env.DEV ? '/sample-data/AIMIOTestImage.AIM' : 'https://itk.mypinata.cloud/ipfs/QmPaZBXqb99fsKQi28tCuGpW1LgiVrBYKRimY28nA9mYgE'
const response = await fetch(url)
const contentLength = parseInt(response.headers.get('Content-Length'))
inputVolumeElement.helpText = 'Input volume size: ' + contentLength + ' bytes'
progressBar.max = contentLength

const reader = response.body.getReader()

Expand All @@ -23,8 +23,9 @@ export default async function conversionLoadSampleInputs (model) {

chunks.push(value)
receivedLength += value.length
progressBar.value = receivedLength
progressBar.textContent = `${receivedLength.toString()} / ${contentLength.toString()} bytes`
const percent = receivedLength / contentLength * 100
progressBar.value = percent
progressBar.textContent = `${percent.toFixed(2)}%`
}

let inputVolume = new Uint8Array(receivedLength)
Expand Down

0 comments on commit 186bc96

Please sign in to comment.