Skip to content

Commit

Permalink
add timeout for download
Browse files Browse the repository at this point in the history
  • Loading branch information
Last-Order committed Jan 23, 2019
1 parent e4d89b7 commit edbdafe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
13 changes: 9 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minyami",
"version": "2.1.9",
"version": "2.1.10",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -21,6 +21,6 @@
"ws": "^6.1.2"
},
"devDependencies": {
"@types/node": "^10.3.6"
"@types/node": "^10.12.18"
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* openssl
* mkvmerge

! Minyami requires Node 10.5.0+

Make sure you had put these binary files into your system `PATH`.

## Installation
Expand Down
1 change: 1 addition & 0 deletions src/core/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Downloader {
});

rl.on("SIGINT", function () {
// @ts-ignore
process.emit("SIGINT");
});
}
Expand Down
11 changes: 10 additions & 1 deletion src/utils/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function mergeToTS(fileList = [], output = "./output.ts") {
* @param path
*/
export function download(url: string, path: string, proxy: AxiosProxyConfig = undefined, options: AxiosRequestConfig = {}) {
return new Promise(async (resolve, reject) => {
const promise = new Promise(async (resolve, reject) => {
try {
const response = await axios({
url,
Expand All @@ -87,7 +87,16 @@ export function download(url: string, path: string, proxy: AxiosProxyConfig = un
} catch (e) {
reject(e);
}
});
const timeout = new Promise((resolve, reject) => {
setTimeout(() => {
reject('Timeout');
}, 60000);
})
return Promise.race([
promise,
timeout
]);
}

/**
Expand Down

0 comments on commit edbdafe

Please sign in to comment.