mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
feat: only use strings for addon options
This commit is contained in:
@@ -316,16 +316,22 @@ export class AIOStreams {
|
||||
);
|
||||
}
|
||||
case 'gdrive': {
|
||||
let addonUrl = addon.options.addonUrl as string;
|
||||
addonUrl = addonUrl.replace('/manifest.json', '/')
|
||||
const wrapper = new BaseWrapper(addon.options.overrideName ? addon.options.overrideName as string: 'GDrive', addonUrl, addon.options.indexerTimeout ? addon.options.indexerTimeout as number : undefined);
|
||||
const addonUrl = addon.options.addonUrl?.replace('/manifest.json', '/') + '/';
|
||||
const wrapper = new BaseWrapper(
|
||||
addon.options.overrideName || 'GDrive',
|
||||
addonUrl,
|
||||
addon.options.indexerTimeout ? parseInt(addon.options.indexerTimeout) : undefined
|
||||
);
|
||||
return await wrapper.getParsedStreams(streamRequest);
|
||||
}
|
||||
default: {
|
||||
if (!addon.options.url) {
|
||||
throw new Error('Addon URL not found');
|
||||
}
|
||||
console.log(
|
||||
`Using base wrapper for addon ${addon.options.name} with url ${addon.options.url}`
|
||||
);
|
||||
const wrapper = new BaseWrapper(addon.options.name as string, addon.options.url as string, addon.options.indexerTimeout ? addon.options.indexerTimeout as number : undefined);
|
||||
const wrapper = new BaseWrapper(addon.options.name || 'Custom', addon.options.url.trim(), addon.options.indexerTimeout ? parseInt(addon.options.indexerTimeout) : undefined);
|
||||
return await wrapper.getParsedStreams(streamRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,33 +332,21 @@ export function validateConfig(config: Config): {
|
||||
}
|
||||
|
||||
if (option.type === 'number' && addon.options[option.id]) {
|
||||
if (typeof addon.options[option.id] !== 'number') {
|
||||
const input = addon.options[option.id];
|
||||
if (input !== undefined && !parseInt(input)) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidNumber',
|
||||
`${option.label} must be a number`
|
||||
);
|
||||
}
|
||||
|
||||
if (option.constraints) {
|
||||
if (
|
||||
option.constraints.min !== undefined &&
|
||||
addon.options[option.id] as number < option.constraints.min
|
||||
) {
|
||||
} else if (input !== undefined) {
|
||||
const value = parseInt(input);
|
||||
const { min, max } = option.constraints || {};
|
||||
if ((min !== undefined && value < min) || (max !== undefined && value > max)) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidNumber',
|
||||
`${option.label} must be greater than or equal to ${option.constraints.min}`
|
||||
);
|
||||
}
|
||||
if (
|
||||
option.constraints.max !== undefined &&
|
||||
addon.options[option.id] as number > option.constraints.max
|
||||
) {
|
||||
return createResponse(
|
||||
false,
|
||||
'invalidNumber',
|
||||
`${option.label} must be less than or equal to ${option.constraints.max}`
|
||||
`${option.label} must be between ${min} and ${max}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ const AddonsList: React.FC<AddonsListProps> = ({
|
||||
const updateOption = (
|
||||
addonIndex: number,
|
||||
optionKey: string,
|
||||
value?: string | boolean | number
|
||||
value?: string
|
||||
) => {
|
||||
const newAddons = [...addons];
|
||||
newAddons[addonIndex].options[optionKey] = typeof value === 'string' ? value.trim() : value;
|
||||
newAddons[addonIndex].options[optionKey] = value;
|
||||
setAddons(newAddons);
|
||||
};
|
||||
|
||||
@@ -92,12 +92,12 @@ const AddonsList: React.FC<AddonsListProps> = ({
|
||||
{option.type === 'checkbox' && (
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={addon.options[option.id] === true}
|
||||
checked={addon.options[option.id] === 'true'}
|
||||
onChange={(e) =>
|
||||
updateOption(
|
||||
index,
|
||||
option.id,
|
||||
e.target.checked
|
||||
e.target.checked ? 'true' : 'false'
|
||||
)
|
||||
}
|
||||
className={styles.checkbox}
|
||||
@@ -118,9 +118,9 @@ const AddonsList: React.FC<AddonsListProps> = ({
|
||||
{option.type === 'number' && (
|
||||
<input
|
||||
type="number"
|
||||
value={addon.options[option.id] as number}
|
||||
value={addon.options[option.id]}
|
||||
onChange={(e) =>
|
||||
updateOption(index, option.id, e.target.value ? parseInt(e.target.value) : undefined)
|
||||
updateOption(index, option.id, e.target.value ? e.target.value : undefined)
|
||||
}
|
||||
className={styles.textInput}
|
||||
/>
|
||||
|
||||
@@ -108,7 +108,7 @@ export interface Config {
|
||||
minSize: number | null;
|
||||
addons: {
|
||||
id: string;
|
||||
options: { [key: string]: string | boolean | number | undefined };
|
||||
options: { [key: string]: string | undefined};
|
||||
}[];
|
||||
services: {
|
||||
name: string;
|
||||
|
||||
@@ -101,7 +101,7 @@ export class Torbox extends BaseWrapper {
|
||||
export async function getTorboxStreams(
|
||||
config: Config,
|
||||
torboxOptions: {
|
||||
indexerTimeout?: number;
|
||||
indexerTimeout?: string;
|
||||
overrideName?: string;
|
||||
},
|
||||
streamRequest: StreamRequest
|
||||
@@ -118,6 +118,6 @@ export async function getTorboxStreams(
|
||||
throw new Error('Torbox API key not found');
|
||||
}
|
||||
|
||||
const torbox = new Torbox(torboxApiKey, torboxOptions.indexerTimeout, torboxOptions.overrideName);
|
||||
const torbox = new Torbox(torboxApiKey, torboxOptions.indexerTimeout ? parseInt(torboxOptions.indexerTimeout) : undefined, torboxOptions.overrideName);
|
||||
return await torbox.getParsedStreams(streamRequest);
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ export class Torrentio extends BaseWrapper {
|
||||
export async function getTorrentioStreams(
|
||||
config: Config,
|
||||
torrentioOptions: {
|
||||
useMultipleInstances?: boolean;
|
||||
useMultipleInstances?: string;
|
||||
overrideUrl?: string;
|
||||
indexerTimeout?: number;
|
||||
indexerTimeout?: string;
|
||||
overrideName?: string;
|
||||
},
|
||||
streamRequest: StreamRequest
|
||||
@@ -86,10 +86,11 @@ export async function getTorrentioStreams(
|
||||
'debridlink',
|
||||
];
|
||||
const parsedStreams: ParsedStream[] = [];
|
||||
const indexerTimeout = torrentioOptions.indexerTimeout ? parseInt(torrentioOptions.indexerTimeout) : undefined;
|
||||
|
||||
// If overrideUrl is provided, use it to get streams and skip all other steps
|
||||
if (torrentioOptions.overrideUrl) {
|
||||
const torrentio = new Torrentio(null, torrentioOptions.overrideUrl as string, torrentioOptions.indexerTimeout);
|
||||
const torrentio = new Torrentio(null, torrentioOptions.overrideUrl as string, indexerTimeout);
|
||||
return torrentio.getParsedStreams(streamRequest);
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ export async function getTorrentioStreams(
|
||||
|
||||
// if no usable services found, use torrentio without any configuration
|
||||
if (usableServices.length < 0) {
|
||||
const torrentio = new Torrentio(null, null, torrentioOptions.indexerTimeout);
|
||||
const torrentio = new Torrentio(null, null, indexerTimeout);
|
||||
return await torrentio.getParsedStreams(streamRequest);
|
||||
}
|
||||
|
||||
@@ -115,14 +116,14 @@ export async function getTorrentioStreams(
|
||||
: `${serviceId}=${credentials.apiKey}`;
|
||||
};
|
||||
|
||||
if (torrentioOptions.useMultipleInstances) {
|
||||
if (torrentioOptions.useMultipleInstances === 'true') {
|
||||
for (const service of usableServices) {
|
||||
if (!service.enabled) {
|
||||
continue;
|
||||
}
|
||||
console.log('Creating Torrentio instance with service:', service.id);
|
||||
let configString = getServicePair(service.id, service.credentials);
|
||||
const torrentio = new Torrentio(configString, null, torrentioOptions.indexerTimeout);
|
||||
const torrentio = new Torrentio(configString, null, indexerTimeout);
|
||||
const streams = await torrentio.getParsedStreams(streamRequest);
|
||||
parsedStreams.push(...streams);
|
||||
}
|
||||
@@ -135,7 +136,7 @@ export async function getTorrentioStreams(
|
||||
}
|
||||
configString += getServicePair(service.id, service.credentials) + '|';
|
||||
}
|
||||
const torrentio = new Torrentio(configString, null, torrentioOptions.indexerTimeout, torrentioOptions.overrideName);
|
||||
const torrentio = new Torrentio(configString, null, indexerTimeout, torrentioOptions.overrideName);
|
||||
return await torrentio.getParsedStreams(streamRequest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user