Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre committed Dec 29, 2019
2 parents c854771 + 6264409 commit 6247678
Show file tree
Hide file tree
Showing 31 changed files with 4,032 additions and 1,126 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",
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:6.3
FROM node:10.13.0

ENV API_URL http://localhost:8080
ENV USE_LOCAL_ASSETS true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# audio.quran.com
# Quranic Audio [![SLACK](http://i.imgur.com/Lk5HsBo.png)](https://quranslack.herokuapp.com)

The source code for the upcoming version of [quranicaudio.com](http://quranicaudio.com).

Expand All @@ -24,7 +24,7 @@ npm run start
```

## Database
Assuming you already have user/role `quran_dev`, just run
This project uses a Postgres database. Assuming you have Postgres installed create a user/role `quran_dev` then run the commands below:
```
psql -c 'create database audio_quran;' -U quran_dev
psql audio_quran < audio_quran.psql
Expand Down
10 changes: 0 additions & 10 deletions api/api.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import express from 'express';
import session from 'express-session';
import bodyParser from 'body-parser';
import config from '../src/config';
import morgan from 'morgan';

import routes from './routes';

const app = express();

app.use(
session({
secret: 'react and redux rule!!!!',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
})
);
app.use(bodyParser.json());
app.use(morgan('dev'));

Expand Down
18 changes: 13 additions & 5 deletions api/routes/audio_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@ router.get('/', (req, res) => {
return models.audioFile
.all({ include: [models.qari] })
.then(files => res.send(files))
.catch(error => res.status(500).send({ error: error }));
.catch(error => res.status(500).send({ error }));
});

router.get('/:id', (req, res) => {
return models.audioFile
if (!req.params.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: error }));
.catch(error => res.status(500).send({ error }));
});

router.get('/download/:id', (req, res) => {
return models.audioFile
if (!req.params.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: error }));
.catch(error => res.status(500).send({ error }));
});

export default router;
62 changes: 47 additions & 15 deletions api/routes/qaris.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,72 @@ const routerInit = Router;
const router = routerInit();

router.get('/', (req, res) => {
return models.qari.all().then(qaris => res.send(qaris));
return models.qari
.all()
.then(qaris => res.send(qaris))
.catch(error => res.status(500).send({ error }));
});

router.get('/audio_files', (req, res) => {
return models.qari
.all({ include: [models.audioFile] })
.then(qaris => res.send(qaris));
.then(qaris => res.send(qaris))
.catch(error => res.status(500).send({ error }));
});

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

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

export default router;
5 changes: 4 additions & 1 deletion api/routes/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const routerInit = Router;
const router = routerInit();

router.get('/', (req, res) => {
models.section.all().then(sections => res.send(sections));
models.section
.all()
.then(sections => res.send(sections))
.catch(err => res.status(500).send({ err }));
});

export default router;
40 changes: 32 additions & 8 deletions api/routes/surahs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,47 @@ const routerInit = Router;
const router = routerInit();

router.get('/', (req, res) => {
models.surah.all().then(surahs => res.send(surahs));
models.surah
.all()
.then(surahs => res.send(surahs))
.catch(error => res.status(500).send({ error }));
});

router.get('/:id', (req, res) => {
models.surah.findById(req.params.id).then(surah => res.send(surah));
if (!req.params.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) => {
models.surah.findById(req.params.id).then(surah => {
surah.getAudioFiles().then(files => res.send(files));
});
if (!req.params.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) => {
models.surah.findById(req.params.id).then(surah => {
surah.getQaris().then(qaris => res.send(qaris));
});
if (!req.params.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;
}
Loading

0 comments on commit 6247678

Please sign in to comment.