pass ip to all debrid requests

This commit is contained in:
TheBeastLT 2024-04-26 09:45:05 +03:00
parent c916a4ce34
commit 87648bbe50
4 changed files with 13 additions and 13 deletions

View file

@ -8,8 +8,8 @@ import { BadTokenError, AccessDeniedError, sameFilename } from './mochHelper.js'
const KEY = 'alldebrid';
const AGENT = 'torrentio';
export async function getCachedStreams(streams, apiKey) {
const options = await getDefaultOptions();
export async function getCachedStreams(streams, apiKey, ip) {
const options = await getDefaultOptions(ip);
const AD = new AllDebridClient(apiKey, options);
const hashes = streams.map(stream => stream.infoHash);
const available = await AD.magnet.instant(hashes)
@ -35,11 +35,11 @@ export async function getCachedStreams(streams, apiKey) {
}, {})
}
export async function getCatalog(apiKey, offset = 0) {
export async function getCatalog(apiKey, offset = 0, ip) {
if (offset > 0) {
return [];
}
const options = await getDefaultOptions();
const options = await getDefaultOptions(ip);
const AD = new AllDebridClient(apiKey, options);
return AD.magnet.status()
.then(response => response.data.magnets)
@ -52,8 +52,8 @@ export async function getCatalog(apiKey, offset = 0) {
})));
}
export async function getItemMeta(itemId, apiKey) {
const options = await getDefaultOptions();
export async function getItemMeta(itemId, apiKey, ip) {
const options = await getDefaultOptions(ip);
const AD = new AllDebridClient(apiKey, options);
return AD.magnet.status(itemId)
.then(response => response.data.magnets)
@ -160,7 +160,7 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
}
async function getDefaultOptions(ip) {
return { base_agent: AGENT, timeout: 10000 };
return { ip, base_agent: AGENT, timeout: 10000 };
}
export function toCommonError(error) {

View file

@ -80,7 +80,7 @@ export async function applyMochs(streams, config) {
if (isInvalidToken(config[moch.key], moch.key)) {
return { moch, error: BadTokenError };
}
return moch.instance.getCachedStreams(streams, config[moch.key])
return moch.instance.getCachedStreams(streams, config[moch.key], config.ip)
.then(mochStreams => ({ moch, mochStreams }))
.catch(rawError => {
const error = moch.instance.toCommonError(rawError) || rawError;

View file

@ -10,7 +10,7 @@
"license": "MIT",
"dependencies": {
"@putdotio/api-client": "^8.42.0",
"all-debrid-api": "^1.1.0",
"all-debrid-api": "^1.2.0",
"axios": "^1.6.1",
"bottleneck": "^2.19.5",
"cache-manager": "^3.4.4",
@ -111,9 +111,9 @@
}
},
"node_modules/all-debrid-api": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/all-debrid-api/-/all-debrid-api-1.1.0.tgz",
"integrity": "sha512-p6Z8M9UBGkEZK2/qJ2YHBPDyDGW1CEZQ+GCp8IQb4UlC/9GIUgeRPjh2ohoAIBPn3gs6hPvZ8wIVS04lJ3SuHA==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/all-debrid-api/-/all-debrid-api-1.2.0.tgz",
"integrity": "sha512-aT6w166Hy2/HadNgBiOQxAjBn20z82CYZxYd7f70wAzzzScoJYjt4j93+TvKyRvCilKTrZIljVqbT4/9gi8U2Q==",
"dependencies": {
"request": "^2.83.0"
}

View file

@ -10,7 +10,7 @@
"license": "MIT",
"dependencies": {
"@putdotio/api-client": "^8.42.0",
"all-debrid-api": "^1.1.0",
"all-debrid-api": "^1.2.0",
"axios": "^1.6.1",
"bottleneck": "^2.19.5",
"cache-manager": "^3.4.4",