Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const downloadByUrlTest = {
- async handler(ctx: Context) {
- const { photoUrl } = ctx.params;
- let retryCount = 5;
- return new Promise(async (resolve, reject) => {
- const download = () => {
- const stream = this.gotInstanse.stream(photoUrl);
- --retryCount;
- stream.once('error', err => {
- if (retryCount > 0) {
- download();
- } else {
- reject(err.message);
- }
- });
- stream.once('end', resolve);
- };
- download();
- });
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement