Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react'
import bowser from 'bowser'
import Issues from '../components/Issues'
import BrowserWarning from './BrowserWarning'
import Validate from '../components/Validate'
import validate from 'bids-validator'
import validatorPackageJson from 'bids-validator/package.json'
const version = validatorPackageJson.version
// component setup -----------------------------------------------------------
const initState = () => ({
dirName: '',
list: {},
nameError: null,
projectId: '',
refs: {},
errors: [],
warnings: [],
summary: null,
status: '',
uploadStatus: '',
options: {
ignoreWarnings: false,
_validate(selectedFiles) {
const dirName = selectedFiles.list[0].webkitRelativePath.split('/')[0]
const defaultConfig = `${dirName}/.bids-validator-config.json`
this.setState({
status: 'validating',
showIssues: true,
activeKey: 3,
dirName,
})
return validate.BIDS(
selectedFiles.list,
{
verbose: true,
...this.state.options,
config: defaultConfig,
},
(issues, summary) => {
if (issues === 'Invalid') {
return this.setState({
errors: 'Invalid',
summary,
status: 'validated',
})
} else {
return this.setState({
errors: issues.errors ? issues.errors : [],
return new Promise((resolve, reject) => {
validate.BIDS(dir, options, ({ errors, warnings }, summary) => {
if (errors.length + warnings.length === 0) {
resolve({ summary })
} else {
reject({ errors, warnings })
}
})
})
}
new Promise(resolve => {
validate.BIDS(files, options, (issues, summary) =>
resolve({ issues, summary }),
)
})
componentWillMount() {
const options = {}
validate.BIDS(this.props.files, options, this.done)
}
scitran.downloadSymlinkDataset(datasetId, (err, hash) => {
if (err) {
return res.status(500).send({ error: generic_failure })
}
try {
validate.BIDS(
config.location + '/persistent/datasets/' + hash,
{},
(validation, summary) => {
scitran.updateProject(
datasetId,
{
metadata: { validation, summary },
},
() => {
scitran.removeTag('projects', datasetId, 'validating', () => {
if (validation.errors && validation.errors.length > 0) {
scitran.addTag('projects', datasetId, 'invalid', () => {
res.send({ validation, summary })
})
} else {
scitran.removeTag('projects', datasetId, 'invalid', () => {
scitran.getProject(snapshotId, (res) => {
for (let app of this.props.apps) {
let longDescription = typeof(app.longDescription) == 'string' ? JSON.parse(app.longDescription) : app.longDescription;
let appConfig = longDescription.hasOwnProperty('appConfig') ? longDescription.appConfig : {error: []};
let issues = validate.reformat(res.body.metadata.validation, res.body.metadata.summary, appConfig);
if (issues.errors.length > 0) {
disabledApps[app.id] = {issues};
}
}
this.setState({selectedSnapshot: snapshotId, disabledApps});
},{snapshot:true});
}