Spaces:
Build error
Build error
import { Addon, Option, UserData } from '../db'; | |
import { Preset, baseOptions } from './preset'; | |
import { Env, RESOURCES } from '../utils'; | |
export class CustomPreset extends Preset { | |
static override get METADATA() { | |
const options: Option[] = [ | |
{ | |
id: 'name', | |
name: 'Name', | |
description: 'What to call this addon', | |
type: 'string', | |
required: true, | |
default: 'Custom Addon', | |
}, | |
{ | |
id: 'manifestUrl', | |
name: 'Manifest URL', | |
description: 'Provide the Manifest URL for this custom addon.', | |
type: 'url', | |
required: true, | |
}, | |
{ | |
id: 'libraryAddon', | |
name: 'Library Addon', | |
description: | |
'Whether to mark this addon as a library addon. This will result in all streams from this addon being marked as library streams.', | |
type: 'boolean', | |
required: false, | |
default: false, | |
}, | |
{ | |
id: 'streamPassthrough', | |
name: 'Stream Passthrough', | |
description: | |
'Whether to pass through the stream formatting. This means your formatting will not be applied and original stream formatting is retained.', | |
type: 'boolean', | |
}, | |
{ | |
id: 'timeout', | |
name: 'Timeout', | |
description: 'The timeout for this addon', | |
type: 'number', | |
default: Env.DEFAULT_TIMEOUT, | |
constraints: { | |
min: Env.MIN_TIMEOUT, | |
max: Env.MAX_TIMEOUT, | |
}, | |
}, | |
{ | |
id: 'resources', | |
name: 'Resources', | |
description: | |
'Optionally override the resources that are fetched from this addon ', | |
type: 'multi-select', | |
required: false, | |
default: undefined, | |
options: RESOURCES.map((resource) => ({ | |
label: resource, | |
value: resource, | |
})), | |
}, | |
]; | |
return { | |
ID: 'custom', | |
NAME: 'Custom', | |
LOGO: '', | |
URL: '', | |
TIMEOUT: Env.DEFAULT_TIMEOUT, | |
USER_AGENT: Env.DEFAULT_USER_AGENT, | |
SUPPORTED_SERVICES: [], | |
DESCRIPTION: 'Add your own addon by providing its Manifest URL.', | |
OPTIONS: options, | |
SUPPORTED_STREAM_TYPES: [], | |
SUPPORTED_RESOURCES: [], | |
}; | |
} | |
static async generateAddons( | |
userData: UserData, | |
options: Record<string, any> | |
): Promise<Addon[]> { | |
if (!options.manifestUrl.endsWith('/manifest.json')) { | |
throw new Error( | |
`${options.name} has an invalid Manifest URL. It must be a valid link to a manifest.json` | |
); | |
} | |
return [this.generateAddon(userData, options)]; | |
} | |
private static generateAddon( | |
userData: UserData, | |
options: Record<string, any> | |
): Addon { | |
return { | |
name: options.name || this.METADATA.NAME, | |
manifestUrl: options.manifestUrl, | |
enabled: true, | |
library: options.libraryAddon ?? false, | |
resources: options.resources || undefined, | |
timeout: options.timeout || this.METADATA.TIMEOUT, | |
presetType: this.METADATA.ID, | |
presetInstanceId: '', | |
streamPassthrough: options.streamPassthrough ?? false, | |
headers: { | |
'User-Agent': this.METADATA.USER_AGENT, | |
}, | |
}; | |
} | |
} | |