Skip to content

Commit

Permalink
client: file upload checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhyfritz committed Sep 12, 2018
1 parent 883251c commit 67412fb
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions client/src/static/js/alfred.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function run() {
summaryTab.innerHTML = ''

mergeInputs(fileObjects).then(() => {
handleSuccess(data)
if (data) {
handleSuccess(data)
}
})
}

Expand Down Expand Up @@ -100,14 +102,22 @@ function readFile(file) {
fileReader.readAsText(file)
}

return new Promise(resolve => {
return new Promise((resolve, reject) => {
fileReader.onload = event => {
let content = event.target.result
if (isGzip) {
content = pako.ungzip(content, { to: 'string' })
}
data = JSON.parse(content)
resolve(data)
try {
data = JSON.parse(content)
// TODO better check
if (!data.samples) {
reject(`Error(${file.name}): wrong format, missing 'samples' key.`)
}
resolve(data)
} catch (error) {
reject(`Error(${file.name}): not a JSON file.`)
}
}
})
}
Expand All @@ -117,14 +127,19 @@ function mergeInputs(fileObjects) {
for (const fileObject of fileObjects) {
fileReads.push(readFile(fileObject.file))
}
return Promise.all(fileReads).then(fileData => {
data = {
samples: fileData
.map(d => d.samples)
.reduce((acc, cur) => acc.concat(cur))
}
consolidateSummaries(data)
})
return Promise.all(fileReads)
.then(fileData => {
data = {
samples: fileData
.map(d => d.samples)
.reduce((acc, cur) => acc.concat(cur))
}
consolidateSummaries(data)
})
.catch(error => {
data = undefined
showError(error)
})
}

function consolidateSummaries(data) {
Expand Down

0 comments on commit 67412fb

Please sign in to comment.