Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thabti committed Nov 17, 2016
1 parent 10b6141 commit 6fab011
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/routes/audio_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ router.get('/:id', (req, res) => {
});

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

export default router;
18 changes: 13 additions & 5 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ proxy.on('error', (error, req, res) => {
});

app.get('/download/:id', (req, res) => {
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
res.end(fullUrl);

// fetch()

const fullUrl = req.protocol + '://' + req.get('host') + '/api/audio_files/download/' + req.params.id;
fetch(fullUrl)
.then((response) => {
if (response.status >= 400) {
throw new Error('Bad response from server');
}
return response.json();
})
.then((data) => {
console.log(data);
const url = `http://download.quranicaudio.com/quran/abdullaah_basfar/${data.file_name}`;
res.end(url);
});
});

app.use((req, res) => {
Expand Down

0 comments on commit 6fab011

Please # to comment.