Skip to content

Commit

Permalink
Merge pull request #603 from salimkanoun/0.6.4
Browse files Browse the repository at this point in the history
0.6.4
  • Loading branch information
salimkanoun authored Jun 25, 2021
2 parents 295a047 + 408ac0a commit 3281096
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
mkdir stone
cd stone
wget https://lsb.orthanc-server.com/stone-webviewer/1.0/wasm-binaries.zip
wget https://lsb.orthanc-server.com/stone-webviewer/2.0/wasm-binaries.zip
unzip wasm-binaries.zip -d .
rm wasm-binaries.zip
rm./wasm-binaries/StoneWebViewer/configuration.json
Expand Down
33 changes: 2 additions & 31 deletions FrontEnd/src/components/Export/DownloadDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DropdownButton from "react-bootstrap/DropdownButton"
import { toast } from "react-toastify"

import apis from '../../services/apis'
import MonitorJob from '../../tools/MonitorJob'

export default class DownloadDropdown extends Component {

Expand Down Expand Up @@ -40,44 +39,16 @@ export default class DownloadDropdown extends Component {

handleClickDownload = async (e) => {
e.stopPropagation()

let jobAnswer

try{
if (e.currentTarget.id === 'hirarchical') {
jobAnswer = await apis.exportDicom.exportHirachicalDicoms(this.props.exportIds, this.props.TS)
apis.exportDicom.downloadZipSync(this.props.exportIds, this.props.TS, false)
} else {
jobAnswer = await apis.exportDicom.exportDicomDirDicoms(this.props.exportIds, this.props.TS)
apis.exportDicom.downloadZipSync(this.props.exportIds, this.props.TS, true)
}
} catch (error){
toast.error(error.statusText)
}


let jobMonitoring = new MonitorJob(jobAnswer.ID)
let self = this
jobMonitoring.onUpdate(function (progress) {
self.updateProgress(progress)
})

jobMonitoring.onFinish(async function (state) {
if (state === MonitorJob.Success) {
self.setStatusDownloading()
await apis.exportDicom.downloadZip(jobAnswer.ID)
self.resetProgress()
} else if (state === MonitorJob.Failure) {
console.log('failure')
self.resetProgress()
}
self.job = undefined
})

jobMonitoring.startMonitoringJob()
this.job = jobMonitoring
}

componentWillUnmount = () => {
if (this.job !== undefined) this.job.stopMonitoringJob()
}

render = () => {
Expand Down
54 changes: 45 additions & 9 deletions FrontEnd/src/services/exportDicom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const exportDicom = {
let body = {}
if (TS !== 'None') {
body = {
Synchronous: false,
Synchronous: true,
Resources: OrthancIDsArray,
Transcode: TS
}
Expand All @@ -30,10 +30,7 @@ const exportDicom = {
body: JSON.stringify(body)
}

return fetch('/api/tools/create-archive/', exportHirachicalDicomsOption).then((answer) => {
if (!answer.ok) { throw answer }
return answer.json()
}).catch((error) => {
return fetch('/api/tools/create-archive/', exportHirachicalDicomsOption).catch((error) => {
throw error
})
},
Expand All @@ -42,7 +39,7 @@ const exportDicom = {
let body = {}
if (TS !== 'None') {
body = {
Synchronous: false,
Synchronous: true,
Resources: OrthancIDsArray,
Transcode: TS
}
Expand All @@ -62,12 +59,51 @@ const exportDicom = {
body: JSON.stringify(body)
}

return fetch('/api/tools/create-media-extended/', exportDicomDirDicomsOption).then((answer) => {
if (!answer.ok) { throw answer }
return (answer.json())
return fetch('/api/tools/create-media-extended/', exportDicomDirDicomsOption).catch((error) => {
throw error
})
},


downloadZipSync(orthancIDsArray, TS, dicomDir) {

let fetchPromise = null
if(dicomDir){
fetchPromise = this.exportDicomDirDicoms(orthancIDsArray, TS)
}else{
fetchPromise = this.exportHirachicalDicoms(orthancIDsArray, TS)
}

fetchPromise.then( (answer) => {

const fileStream = streamSaver.createWriteStream('Dicom_' + Date.now() + '.zip')

console.log("ici reponse recue")

if (!answer.ok) throw answer

const readableStream = answer.body

// more optimized
if (window.WritableStream && readableStream.pipeTo) {
return readableStream.pipeTo(fileStream)
.then(() => console.log('done writing'))
}

let writer = fileStream.getWriter()

const reader = answer.body.getReader()
const pump = () => reader.read()
.then(res => res.done
? writer.close()
: writer.write(res.value).then(pump))

pump()

}).catch((error) => {
throw error
})

},

downloadZip(jobID) {
Expand Down

0 comments on commit 3281096

Please sign in to comment.