Skip to content

Conversation

@abdulbasitkay
Copy link

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

@thabti
Copy link

thabti commented Mar 31, 2018

I will look at this over the weekend iA - holiday time.

@ahmedre
Copy link
Contributor

ahmedre commented Mar 31, 2018

Deployed to: http://dev.quranicaudio.com:33020

Copy link

@mmahalwy mmahalwy left a 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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool!

const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
const header = {
Copy link

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?

Copy link
Author

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?

archive
.on('warning', err => {
if (err.code === 'ENOENT') {
console.log(err);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Author

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());
Copy link

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?

Copy link
Author

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?

Copy link

@thabti thabti Apr 5, 2018

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');

Copy link

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());


archive.pipe(res);

const qariId = req.params.id;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top of the callback?

archive.append(`Name: ${qari.name}\n Arabic Name: ${qari.arabic_name}`, {
name: 'qari_name.txt'
});
console.log(`Complete download of qari ${qari.name}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need this?

@abdulbasitkay
Copy link
Author

@mmahalwy

Pragma: 'public',
Expires: '0',
'Cache-Control': 'private, must-revalidate, post-check=0, pre-check=0',
'Content-disposition': `attachment; filename=\"complete_quran.zip\"`,
Copy link

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 "

@abdulbasitkay
Copy link
Author

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.
Any other ideas on how else to achieve issue #100?

@abdulbasitkay abdulbasitkay changed the title Api implementation to download all surahs of a Reciter WIP: Api implementation to download all surahs of a Reciter Apr 8, 2018
@khansaahil223
Copy link

Does this issue still need work? I can help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants