Skip to content

Commit

Permalink
Merge pull request #58 from sabeurthabti/feature/56
Browse files Browse the repository at this point in the history
support for legacy /download path.
  • Loading branch information
thabti committed Nov 18, 2016
2 parents e81a6f0 + 22fe13d commit d72b85f
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/models/audio_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = function(sequelize, DataTypes) {
var AudioFile = sequelize.define('audioFile', {
qari_id: DataTypes.INTEGER,
surah_id: DataTypes.INTEGER,
main_id:{ type: DataTypes.INTEGER, field: "id" },
recitation_id: DataTypes.INTEGER,
filenum: DataTypes.INTEGER,
file_name: DataTypes.STRING,
Expand Down
8 changes: 6 additions & 2 deletions api/routes/audio_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import models from '../models';
const router = Router();

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

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

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

export default router;
12 changes: 12 additions & 0 deletions src/actions/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const LOAD = '@@quran/download/LOAD';
export const LOAD_SUCCESS = '@@quran/download/LOAD_SUCCESS';
export const LOAD_FAIL = '@@quran/download/LOAD_FAIL';

export function load(id) {
console.log('download ', id);
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
promise: (client) => client.get(`/audio_files/download/${id}`),
id
};
}
3 changes: 0 additions & 3 deletions src/containers/Main/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default () => {
QuranicAudio.com is the largest collection of cd quality Quran recitations on the internet. Mp3s on this site may be downloaded and used for personal use free of charge. However, you may not use these files for commercial purposes as many of these files have rules and regulations that prevent their sale except by the publishing companies.
</p>
<p>
QuranicAudio.com is the largest collection of cd quality Quran recitations on the internet. Mp3s on this site may be downloaded and used for personal use free of charge. However, you may not use these files for commercial purposes as many of these files have rules and regulations that prevent their sale except by the publishing companies.
</p>
<p>
Files on QuranicAudio.com come from many different sources. Many of them are hand ripped from cds. Others have been downloaded from various other high quality sites on the internet, including HidayahOnline, DawahAcademy, <a href="http://kalamullah.com">Kalamullah.com</a>, <a href="http://sabbir.com">Sabbir.com</a>, <a href="http://dhikrullah.com">dhikrullah.com</a>, <a href="http://zanjabil.net">zanjabil.net</a>, <a href="http://shuraym.com">shuraym.com</a>, and others. Many of the files have also been sent to us by some of our users, may Allah reward them greatly.
</p>
</Row>
Expand Down
56 changes: 56 additions & 0 deletions src/containers/Main/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { PropTypes, Component } from 'react';
import Grid from 'react-bootstrap/lib/Grid';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import Header from '../../components/Header';
import { connect } from 'react-redux';
import { asyncConnect } from 'redux-connect';
import { load } from 'actions/download';
import zeroPad from 'utils/zeroPad';

const styles = require('./style.scss');

class Download extends Component {

static propTypes = {
qaris: PropTypes.object.isRequired,
surahs: PropTypes.object.isRequired,
data: PropTypes.object.isRequired
}

render() {
const { surahs, data, qaris} = this.props;
const { surahId, qariId } = data;
return (
<div>
<Header />
<Grid>
<Row className={styles.aboutContainer}>
<Col md={8} mdOffset={2}>
{data.loaded ? <Row>
<h1>Surat {surahs[surahId].name.simple} by {qaris[qariId].name}</h1>
<a className={styles.downloadLink} href={`http://download.quranicaudio.com/quran/${qaris[qariId].relativePath}${zeroPad(surahId, 3)}.mp3`}>Download</a>
</Row> : <h1>Not Found</h1>}
</Col>
</Row>
</Grid>
</div>
);
}
}

const connectedDownload = connect(
state => ({
qaris: state.qaris.entities,
surahs: state.surahs.entities,
sections: state.sections.entities,
data: state.download
})
)(Download);


export default asyncConnect([{
promise({ params, store: { dispatch } }) {
return dispatch(load(params.id));
}
}])(connectedDownload);
21 changes: 20 additions & 1 deletion src/containers/Main/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@
}
}

.downloadLink {
font-weight: 600;
font-size: 20px;
text-align: center;
display: flex;
justify-content: center;
padding: 20px;
border: 2px solid $brand-primary;
position: relative;
top: 50px;
text-decoration: none;

&:hover {
background: $brand-primary;
color: white;
}
}


.aboutContainer {
position: relative;
background: white;
Expand Down Expand Up @@ -85,7 +104,7 @@

.pillsItem {
font-size: 16px;
&:hover {
&:hover {
background-color: $hover-grey;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export NotFound from './NotFound';
export Qari from './Qari';
export Sura from './Qari/Sura';
export About from './Main/about';
export Download from './Main/download';
41 changes: 41 additions & 0 deletions src/reducers/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
LOAD,
LOAD_SUCCESS,
LOAD_FAIL
} from 'actions/download';

const initialState = {
errored: false,
loaded: false,
entities: {}
};

export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case LOAD:
return {
...state,
loaded: false,
loading: true
};
case LOAD_FAIL:
return {
...state,
loaded: false,
errored: true,
};
case LOAD_SUCCESS:

return {
...state,
loaded: true,
errored: false,
entities: {
...state.entities,
},
...action.result
};
default:
return state;
}
}
4 changes: 3 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qaris from 'reducers/qaris';
import sections from 'reducers/sections';
import surahs from 'reducers/surahs';
import files from 'reducers/files';
import download from 'reducers/download';

export default combineReducers({
routing: routerReducer,
Expand All @@ -15,5 +16,6 @@ export default combineReducers({
files,
qaris,
sections,
surahs
surahs,
download
});
5 changes: 3 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Qaris,
Qari,
About,
Sura
Sura,
Download
} from 'containers';

function isValid(nextState, replaceState) {
Expand All @@ -28,9 +29,9 @@ export default () => {
<Route path="/reciters" component={Qaris} />

<Route path="quran/:id" component={Qari} />
<Route path="download/:id" component={Download} />
<Route path="/sura" component={Home} onEnter={isValid}/>
<Route path="/sura/:id" component={Sura} onEnter={isValid}/>
<Route path="/download/:id" component={Home} />
{ /* Catch all route */ }
<Route path="*" component={NotFound} status={404} />
</Route>
Expand Down
1 change: 1 addition & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ proxy.on('error', (error, req, res) => {
res.end(JSON.stringify(json));
});


app.use((req, res) => {
if (__DEVELOPMENT__) {
// Do not cache webpack stats: the script file would change since
Expand Down

0 comments on commit d72b85f

Please sign in to comment.