Skip to content

Commit

Permalink
Fixes for recent github libraries upgrades (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudfelfel authored and thabti committed Sep 8, 2019
1 parent ef1c61b commit e6a62df
Show file tree
Hide file tree
Showing 22 changed files with 1,698 additions and 664 deletions.
12 changes: 10 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"env": {
"browser": true,
"node": true,
"mocha": true
"mocha": true,
"es6": true
},
"rules": {
"react/no-multi-comp": 0,
Expand All @@ -15,7 +16,10 @@
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
"indent": [2, 2, {"SwitchCase": 1}],
"no-console": 0,
"no-alert": 0
"no-alert": 0,
"no-empty-label": 0,
"space-after-keywords": 0,
"space-return-throw-case": 0
},
"plugins": [
"react", "import"
Expand All @@ -34,5 +38,9 @@
"__DEVTOOLS__": true,
"socket": true,
"webpackIsomorphicTools": true
},
"parserOptions" : {
"ecmaVersion": 6,
"sourceType": "module",
}
}
24 changes: 12 additions & 12 deletions api/routes/audio_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ router.get('/', (req, res) => {
});

router.get('/:id', (req, res) => {
if (req.params.id) {
return models.audioFile
.findById(req.params.id)
.then(files => res.send(files))
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}

res.status(500).send({ error: 'missing or invalid id' });
models.audioFile
.findById(req.params.id)
.then(files => res.send(files))
.catch(error => res.status(500).send({ error }));
});

router.get('/download/:id', (req, res) => {
if (req.params.id) {
return models.audioFile
.findOne({ where: { id: req.params.id, extension: 'mp3' } })
.then(files => res.send(files))
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}

res.status(500).send({ error: 'missing or invalid id' });
models.audioFile
.findOne({ where: { id: req.params.id, extension: 'mp3' } })
.then(files => res.send(files))
.catch(error => res.status(500).send({ error }));
});

export default router;
72 changes: 37 additions & 35 deletions api/routes/qaris.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,58 @@ router.get('/audio_files', (req, res) => {
});

router.get('/:id', (req, res) => {
if (req.params.id) {
return models.qari
.findById(req.params.id)
.then(qari => res.send(qari))
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}

res.status(500).send({ error: 'missing or invalid id' });
models.qari
.findById(req.params.id)
.then(qari => res.send(qari))
.catch(error => res.status(500).send({ error }));
});

router.get('/:id/audio_files', (req, res) => {
if (req.params.id) {
return models.qari
.findById(req.params.id)
.then(qari => {
return qari
.getAudioFiles({ order: 'surah_id' })
.then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}

res.status(500).send({ error: 'missing or invalid id' });
models.qari
.findById(req.params.id)
.then(qari => {
return qari
.getAudioFiles({ order: 'surah_id' })
.then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
});

router.get('/:id/audio_files/:type', (req, res) => {
if (req.params.id) {
return models.qari
.findById(req.params.id)
.then(qari => {
return qari
.getAudioFiles({
order: 'surah_id',
where: { extension: req.params.type }
})
.then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}
res.status(500).send({ error: 'missing or invalid id' });

models.qari
.findById(req.params.id)
.then(qari => {
return qari
.getAudioFiles({
order: 'surah_id',
where: { extension: req.params.type }
})
.then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
});

router.get('/related/:id', (req, res) => {
if (req.params.id) {
return models.related
.findAll({ where: { qari: req.params.id } })
.then(related => res.send(related))
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}
res.status(500).send({ error: 'missing or invalid id' });

models.related
.findAll({ where: { qari: req.params.id } })
.then(related => res.send(related))
.catch(error => res.status(500).send({ error }));
});

export default router;
47 changes: 25 additions & 22 deletions api/routes/surahs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,40 @@ router.get('/', (req, res) => {
});

router.get('/:id', (req, res) => {
if (req.params.id) {
return models.surah
.findById(req.params.id)
.then(surah => res.send(surah))
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}
res.status(500).send({ error: 'missing or invalid id' });

models.surah
.findById(req.params.id)
.then(surah => res.send(surah))
.catch(error => res.status(500).send({ error }));
});

router.get('/:id/audio_files', (req, res) => {
if (req.params.id) {
return models.surah
.findById(req.params.id)
.then(surah => {
return surah.getAudioFiles().then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}
res.status(500).send({ error: 'missing or invalid id' });

models.surah
.findById(req.params.id)
.then(surah => {
return surah.getAudioFiles().then(files => res.send(files));
})
.catch(error => res.status(500).send({ error }));
});

router.get('/:id/qaris', (req, res) => {
if (req.params.id) {
return models.surah
.findById(req.params.id)
.then(surah => {
surah.getQaris().then(qaris => res.send(qaris));
})
.catch(error => res.status(500).send({ error }));
if (!req.params.id) {
res.status(500).send({ error: 'missing or invalid id' });
}
res.status(500).send({ error: 'missing or invalid id' });

return models.surah
.findById(req.params.id)
.then(surah => {
surah.getQaris().then(qaris => res.send(qaris));
})
.catch(error => res.status(500).send({ error }));
});

export default router;
17 changes: 13 additions & 4 deletions api/tasks/addAudioData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const createData = (files, index) => {
const file = files[index];

if (file.qari && (!file.format || !file.metadata)) {
const url = `https://download.quranicaudio.com/quran/${file.qari.relative_path}${file.file_name}`;
const url = `https://download.quranicaudio.com/quran/${
file.qari.relative_path
}${file.file_name}`;
try {
return probe(url, (err, data) => {
file.metadata = data.metadata;
Expand All @@ -18,8 +20,15 @@ const createData = (files, index) => {
console.warn(error);
}
}

return null;
};

models.audioFile.all({ where: {extension: 'mp3', metadata: null, format: null}, include: [models.qari] }).then(files => {
return createData(files, 0);
});
models.audioFile
.all({
where: { extension: 'mp3', metadata: null, format: null },
include: [models.qari]
})
.then(files => {
return createData(files, 0);
});
17 changes: 11 additions & 6 deletions api/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function mapUrl(availableActions = {}, url = []) {
const notFound = {action: null, params: []};
const notFound = { action: null, params: [] };

// test for empty input
if (url.length === 0 || Object.keys(availableActions).length === 0) {
Expand All @@ -8,18 +8,23 @@ export function mapUrl(availableActions = {}, url = []) {
/*eslint-disable */
const reducer = (prev, current) => {
if (prev.action && prev.action[current]) {
return {action: prev.action[current], params: []}; // go deeper
return { action: prev.action[current], params: [] }; // go deeper
} else {
if (typeof prev.action === 'function') {
return {action: prev.action, params: prev.params.concat(current)}; // params are found
return { action: prev.action, params: prev.params.concat(current) }; // params are found
} else {
return notFound;
}
}
};
/*eslint-enable */
/* eslint-enable */

const actionAndParams = url.reduce(reducer, {action: availableActions, params: []});
const actionAndParams = url.reduce(reducer, {
action: availableActions,
params: []
});

return (typeof actionAndParams.action === 'function') ? actionAndParams : notFound;
return typeof actionAndParams.action === 'function'
? actionAndParams
: notFound;
}
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"env": {
"NODE_PATH": "./src",
"NODE_ENV": "production",
"PORT": 8080,
"PORT": 8000,
"APIPORT": 8080
}
},
Expand Down Expand Up @@ -101,6 +101,7 @@
"babel-plugin-transform-runtime": "^6.3.13",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.13.2",
"babel-preset-es2016": "^6.24.1",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.11.6",
Expand Down Expand Up @@ -149,31 +150,34 @@
"redux-logger": "^2.7.0",
"sass-loader": "^3.1.2",
"scroll-behavior": "^0.3.2",
"sequelize": "^5.3.0",
"sequelize": "^3.35.0",
"sequelize-cli": "^2.4.0",
"serialize-javascript": "^1.1.2",
"serve-favicon": "^2.3.0",
"strip-loader": "^0.1.0",
"style-loader": "^0.13.0",
"superagent": "^5.0.2",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^0.5.7",
"warning": "^2.1.0",
"webpack": "2.1.0-beta.20",
"webpack-isomorphic-tools": "^2.5.6"
},
"devDependencies": {
"babel-eslint": "^5.0.0-beta6",
"babel-eslint": "^10.0.3",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-typecheck": "^3.6.0",
"babel-preset-react-hmre": "^1.1.1",
"babili-webpack-plugin": "^0.1.2",
"chai": "^3.3.0",
"concurrently": "^0.1.1",
"prettier": "^1.15.2",
"eslint": "4.18.2",
"eslint": "6.3.0",
"escope": "^3.6.0",
"eslint-config-airbnb": "0.1.0",
"eslint-loader": "^1.0.0",
"eslint-plugin-import": "^0.8.0",
"eslint-plugin-react": "^3.5.0",
"estraverse-fb": "^1.3.2",
"font-awesome": "^4.4.0",
"font-awesome-webpack": "0.0.4",
"husky": "^0.13.3",
Expand All @@ -195,6 +199,7 @@
"mocha": "^2.3.3",
"phantomjs": "^1.9.18",
"phantomjs-polyfill": "0.0.1",
"prettier": "^1.15.2",
"react-a11y": "^0.2.6",
"react-addons-test-utils": "^0.14.0",
"react-transform-catch-errors": "^1.0.0",
Expand All @@ -212,4 +217,4 @@
"engines": {
"node": "^10.13.0"
}
}
}
2 changes: 1 addition & 1 deletion src/actions/qaris.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function loadAll() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(qarisSchema),
promise: client => client.get(`/qaris`)
promise: client => client.get('/qaris')
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/actions/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function loadAll() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(sectionsSchema),
promise: client => client.get(`/sections`)
promise: client => client.get('/sections')
};
}
2 changes: 1 addition & 1 deletion src/actions/surahs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function loadAll() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(surahsSchema),
promise: client => client.get(`/surahs`)
promise: client => client.get('/surahs')
};
}

Expand Down
Loading

0 comments on commit e6a62df

Please sign in to comment.