diff --git a/.eslintrc b/.eslintrc index c274c27..da29fad 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,8 @@ "env": { "browser": true, "node": true, - "mocha": true + "mocha": true, + "es6": true }, "rules": { "react/no-multi-comp": 0, @@ -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" @@ -34,5 +38,9 @@ "__DEVTOOLS__": true, "socket": true, "webpackIsomorphicTools": true + }, + "parserOptions" : { + "ecmaVersion": 6, + "sourceType": "module", } } diff --git a/api/routes/audio_files.js b/api/routes/audio_files.js index 0bd4ba2..d09f2b8 100644 --- a/api/routes/audio_files.js +++ b/api/routes/audio_files.js @@ -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; diff --git a/api/routes/qaris.js b/api/routes/qaris.js index 614dd61..b5f6676 100644 --- a/api/routes/qaris.js +++ b/api/routes/qaris.js @@ -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; diff --git a/api/routes/surahs.js b/api/routes/surahs.js index d997844..2c91581 100644 --- a/api/routes/surahs.js +++ b/api/routes/surahs.js @@ -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; diff --git a/api/tasks/addAudioData.js b/api/tasks/addAudioData.js index f0d3c38..e4563eb 100644 --- a/api/tasks/addAudioData.js +++ b/api/tasks/addAudioData.js @@ -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; @@ -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); + }); diff --git a/api/utils/url.js b/api/utils/url.js index cd913bf..939a9b1 100644 --- a/api/utils/url.js +++ b/api/utils/url.js @@ -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) { @@ -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; } diff --git a/package.json b/package.json index c8f99ff..c62aa09 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "env": { "NODE_PATH": "./src", "NODE_ENV": "production", - "PORT": 8080, + "PORT": 8000, "APIPORT": 8080 } }, @@ -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", @@ -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", @@ -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", @@ -212,4 +217,4 @@ "engines": { "node": "^10.13.0" } -} \ No newline at end of file +} diff --git a/src/actions/qaris.js b/src/actions/qaris.js index 1efe68a..89d2897 100644 --- a/src/actions/qaris.js +++ b/src/actions/qaris.js @@ -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') }; } diff --git a/src/actions/sections.js b/src/actions/sections.js index 83cb518..1d74601 100644 --- a/src/actions/sections.js +++ b/src/actions/sections.js @@ -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') }; } diff --git a/src/actions/surahs.js b/src/actions/surahs.js index e4e3e85..30a55c5 100644 --- a/src/actions/surahs.js +++ b/src/actions/surahs.js @@ -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') }; } diff --git a/src/components/Audioplayer/MobilePlayer.js b/src/components/Audioplayer/MobilePlayer.js index b68abf6..72e9d31 100644 --- a/src/components/Audioplayer/MobilePlayer.js +++ b/src/components/Audioplayer/MobilePlayer.js @@ -92,7 +92,9 @@ class MobilePlayer extends Component { if (file.readyState < 4) { return ( ); } @@ -147,7 +149,7 @@ class MobilePlayer extends Component { return (
-
@@ -159,7 +161,7 @@ class MobilePlayer extends Component { return (
-
diff --git a/src/components/Audioplayer/index.js b/src/components/Audioplayer/index.js index 1a80abd..9a22866 100644 --- a/src/components/Audioplayer/index.js +++ b/src/components/Audioplayer/index.js @@ -146,7 +146,7 @@ class Audioplayer extends Component { styles.active}`} > -