-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
76 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import config from 'config'; | ||
import debug from 'debug'; | ||
import fetch from 'node-fetch'; | ||
import fetch from './fetch'; | ||
|
||
const log = debug('connect'); | ||
|
||
export default async function getToken(username, password) { | ||
const getToken = async (username, password) => { | ||
log('connect to real-debrid.com'); | ||
|
||
const url = `${config.apiBaseUrl}/oauth/v2/token`; | ||
const res = await fetch(url, { | ||
const data = await fetch(`${config.apiBaseUrl}/oauth/v2/token`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
body: { | ||
username, | ||
password, | ||
client_id: config.clientId, | ||
grant_type: 'password', | ||
}), | ||
}, | ||
}); | ||
|
||
return (await res.json()).access_token; | ||
} | ||
return data.access_token; | ||
}; | ||
|
||
export default getToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fetch from 'node-fetch'; | ||
import querystring from 'querystring'; | ||
import handleErrorMessage from './utils'; | ||
|
||
export default async function (url, opts = { method: 'GET' }) { | ||
const res = await fetch(url, { | ||
method: opts.method, | ||
body: querystring.stringify(opts.body), | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
}); | ||
|
||
let data = await res.text(); | ||
|
||
if (!data) return null; | ||
|
||
data = JSON.parse(data); | ||
|
||
if (res.status !== 200) { | ||
return handleErrorMessage(data); | ||
} | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
import config from 'config'; | ||
import debug from 'debug'; | ||
import fetch from 'node-fetch'; | ||
import handleErrorMessage from './utils'; | ||
import fetch from './fetch'; | ||
|
||
const log = debug('unrestrict'); | ||
|
||
export default async (link, token) => { | ||
log(`unrestrict link ${link}`); | ||
|
||
try { | ||
const url = `${config.apiEndpoint}/unrestrict/link?auth_token=${token}`; | ||
const res = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
link, | ||
}), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
return (await res.json()).download; | ||
} catch (e) { | ||
return handleErrorMessage(e); | ||
} | ||
const data = await fetch(`${config.apiEndpoint}/unrestrict/link?auth_token=${token}`, { | ||
method: 'POST', | ||
body: { link }, | ||
}); | ||
|
||
return data.download; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters