Skip to content

Commit

Permalink
Refactoring, linting and remove deleteTorrent function
Browse files Browse the repository at this point in the history
  • Loading branch information
johackim committed May 22, 2016
1 parent c57a181 commit 996b81b
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 200 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"rules": {
"indent": [2, 4],
"no-console": [0],
"max-len": [0],
"func-names": [0]
},
"globals": {
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
npm-debug.log*
node_modules
config/test.json
config/development.json
config/dev.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Download links, magnets and torrent files.
# TODO

- [ ] Handle Ctrl+u and backspace in prompt password
- [x] Add [ora](https://www.npmjs.com/package/ora) spinner
- [ ] Update text errors
- [ ] Handle multi-link

Expand Down
1 change: 1 addition & 0 deletions build/http.js

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

3 changes: 2 additions & 1 deletion build/rdcli.js

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

2 changes: 1 addition & 1 deletion build/real-debrid.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"apiBaseUrl": "https://api.real-debrid.com/",
"apiBaseUrl": "https://api.real-debrid.com",
"apiEndpoint": "https://api.real-debrid.com/rest/1.0",
"clientId": "MPCF6OE5DLDM2",
"requestDelay": 1000
"requestDelay": 2000
}
6 changes: 0 additions & 6 deletions config/dev.json

This file was deleted.

2 changes: 1 addition & 1 deletion config/dev.json.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiBaseUrl": "https://api.real-debrid.com/",
"apiBaseUrl": "https://api.real-debrid.com",
"apiEndpoint": "https://api.real-debrid.com/rest/1.0",
"clientId": "MPCF6OE5DLDM2",
"requestDelay": 1000
Expand Down
46 changes: 46 additions & 0 deletions src/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import request from 'request';
import chalk from 'chalk';
import fs from 'fs';

const callback = (resolve, reject) => (error, response, body) => {
if (error) {
reject('Resource temporarily unavailable');
}

if (body) {
const bodyParse = JSON.parse(body);
if (!bodyParse || bodyParse.error) {
reject(bodyParse.error);
}
resolve(bodyParse);
}

resolve(true);
};

const http = {
post: (url, data = []) => new Promise((resolve, reject) => {
request.post(url, data, callback(resolve, reject));
}).catch((error) => {
console.error(chalk.red(error));
process.exit();
}),

get: (url, delay = 0) => new Promise((resolve, reject) => {
setTimeout(() => {
request(url, callback(resolve, reject));
}, delay);
}).catch((error) => {
console.error(chalk.red(error));
process.exit();
}),

put: (url, file) => new Promise((resolve, reject) => {
fs.createReadStream(file).pipe(request.put(url, {}, callback(resolve, reject)));
}).catch((error) => {
console.error(chalk.red(error));
process.exit();
}),
};

export default http;
2 changes: 1 addition & 1 deletion src/rdcli.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ program
const spinner = ora('Download: 0.0% Speed: 0Mbps').start();
yield api.download(unrestrictLink, (res) => {
if (res.percent) {
spinner.text = `Download: ${res.percent}% Speed: ${res.mbps}Mbps ${res.bytesWriting}/${res.totalSize} Remaining: ${res.remaining}sec`;
spinner.text = `Download: ${res.percent}% Speed: ${res.mbps}Mbps ${res.bytesWriting}/${res.totalSize} Remaining: ${res.remaining}sec`; // eslint-disable-line max-len
} else if (res === 'end') {
spinner.stop();
console.log('File downloaded.');
Expand Down
Loading

0 comments on commit 996b81b

Please sign in to comment.