-
Notifications
You must be signed in to change notification settings - Fork 51
WIP: Api implementation to download all surahs of a Reciter #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
WIP: Api implementation to download all surahs of a Reciter #102
Conversation
|
I will look at this over the weekend iA - holiday time. |
|
Deployed to: http://dev.quranicaudio.com:33020 |
mmahalwy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesome start! Thank you for tackling this again
|
|
||
| import models from '../models'; | ||
| import request from 'request'; | ||
| import archiver from 'archiver'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool!
api/routes/qaris.js
Outdated
| const archive = archiver('zip', { | ||
| zlib: { level: 9 } // Sets the compression level. | ||
| }); | ||
| const header = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unlikely needed inside of this request? It could be at the top of this file or in another constants file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, top of the file maybe? as it's used only with the file?
api/routes/qaris.js
Outdated
| archive | ||
| .on('warning', err => { | ||
| if (err.code === 'ENOENT') { | ||
| console.log(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a js newbie, what's the appropriate way of logging non-fatal errors?
| .on('error', err => { | ||
| throw err; | ||
| }) | ||
| .on('finish', () => res.send()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should send something for the frontend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean in addition to the pipped zip file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he means usually res.send or res.end are passed some text or object/data. But I think in this case because of the at this point (finish) the zip is delivered and the res.send is called back archive.finalize();. Maybe use: res.status(200).end('done');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/archiverjs/node-archiver/blob/master/examples/express.js
based on the example above you don't need .on('finish', () => res.send());
api/routes/qaris.js
Outdated
|
|
||
| archive.pipe(res); | ||
|
|
||
| const qariId = req.params.id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top of the callback?
api/routes/qaris.js
Outdated
| archive.append(`Name: ${qari.name}\n Arabic Name: ${qari.arabic_name}`, { | ||
| name: 'qari_name.txt' | ||
| }); | ||
| console.log(`Complete download of qari ${qari.name}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this?
| Pragma: 'public', | ||
| Expires: '0', | ||
| 'Cache-Control': 'private, must-revalidate, post-check=0, pre-check=0', | ||
| 'Content-disposition': `attachment; filename=\"complete_quran.zip\"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're using templatestrings you won't need to escape "
|
I have been battling with this pr for the last 3 days. The problem is that when I try to download the more than 38 file it just errors out. I can't seem to find a way to download the whole directory instead of downloading file by file. |
|
Does this issue still need work? I can help |
Part implementation of #100. Only the API has been done. The next step is to add a button on the front end that calls this endpoint.
Would need a lot of guidance on the front end