chore: use add-on URL as default externalUrl
This commit is contained in:
parent
b5855aaab4
commit
552620a7eb
6 changed files with 23 additions and 15 deletions
|
|
@ -28,6 +28,7 @@ export class StreamController {
|
|||
const id: string = req.params['id'] || '';
|
||||
|
||||
const ctx: Context = {
|
||||
hostUrl: new URL(`${req.protocol}://${req.host}`),
|
||||
id: res.getHeader('X-Request-ID') as string,
|
||||
...(req.ip && { ip: req.ip }),
|
||||
config,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { CineHDPlus, Cuevana, Eurostreaming, Frembed, FrenchCloud, Source, KinoG
|
|||
import { createExtractors, ExtractorRegistry } from './extractor';
|
||||
import { ConfigureController, ManifestController, StreamController } from './controller';
|
||||
import { envGet, envIsProd, Fetcher, StreamResolver, tmdbFetch, TmdbId } from './utils';
|
||||
import { Context } from './types';
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
|
|
@ -72,7 +73,11 @@ addon.listen(port, () => {
|
|||
});
|
||||
|
||||
const cacheWarmup = async () => {
|
||||
const ctx = { id: 'warmup', config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' } };
|
||||
const ctx: Context = {
|
||||
hostUrl: new URL('http://localhost'),
|
||||
id: 'warmup',
|
||||
config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' },
|
||||
};
|
||||
logger.info(`starting cache warmup`, ctx);
|
||||
|
||||
interface ResponsePartial { results: { id: number }[] }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { getDefaultConfig } from '../utils';
|
|||
|
||||
export const createTestContext = (config?: Config): Context => {
|
||||
return {
|
||||
hostUrl: new URL('http://localhost'),
|
||||
id: 'test',
|
||||
config: config ?? getDefaultConfig(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Manifest, ManifestConfig } from 'stremio-addon-sdk';
|
||||
|
||||
export interface Context {
|
||||
hostUrl: URL;
|
||||
id: string;
|
||||
ip?: string;
|
||||
config: Config;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export class StreamResolver {
|
|||
{
|
||||
name: 'WebStreamr',
|
||||
title: '⚠️ No sources found. Please re-configure the plugin.',
|
||||
ytId: 'E4WlUXrJgy4',
|
||||
externalUrl: ctx.hostUrl.href,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
@ -73,7 +73,7 @@ export class StreamResolver {
|
|||
streams.push({
|
||||
name: envGetAppName(),
|
||||
title: [`🔗 ${handler.label}`, this.logErrorAndReturnNiceString(ctx, handler.id, error)].join('\n'),
|
||||
ytId: 'E4WlUXrJgy4',
|
||||
externalUrl: ctx.hostUrl.href,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -136,7 +136,7 @@ export class StreamResolver {
|
|||
return Math.min(...urlResults.map(urlResult => urlResult.ttl as number));
|
||||
};
|
||||
|
||||
private buildUrl(ctx: Context, urlResult: UrlResult): { externalUrl: string } | { url: string } | { ytId: string } {
|
||||
private buildUrl(ctx: Context, urlResult: UrlResult): { externalUrl: string } | { url: string } {
|
||||
if (!urlResult.isExternal) {
|
||||
return { url: urlResult.url.href };
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ export class StreamResolver {
|
|||
return { externalUrl: urlResult.url.href };
|
||||
}
|
||||
|
||||
return { ytId: 'E4WlUXrJgy4' };
|
||||
return { externalUrl: ctx.hostUrl.href };
|
||||
};
|
||||
|
||||
private buildName(ctx: Context, urlResult: UrlResult): string {
|
||||
|
|
|
|||
|
|
@ -5,59 +5,59 @@ exports[`resolve adds error info 1`] = `
|
|||
"streams": [
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
⚠️ Request was blocked.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
⚠️ Request was blocked.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
🚦 Request was rate-limited. Please try again later or consider self-hosting.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
🚦 Too many recent timeouts. Please try again later.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
❌ Request failed. Request-id: test.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
🐢 Request timed out.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
⏳ Request queue is full. Please try again later or consider self-hosting.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
{
|
||||
"behaviorHints": {},
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr 🇩🇪",
|
||||
"title": "🔗 hoster.com
|
||||
❌ Request failed with status 500 (Internal Server Error). Request-id: test.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -151,9 +151,9 @@ exports[`resolve returns info as stream if no sources were configured 1`] = `
|
|||
{
|
||||
"streams": [
|
||||
{
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr",
|
||||
"title": "⚠️ No sources found. Please re-configure the plugin.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -331,10 +331,10 @@ exports[`resolve returns source errors as stream 1`] = `
|
|||
{
|
||||
"streams": [
|
||||
{
|
||||
"externalUrl": "http://localhost/",
|
||||
"name": "WebStreamr",
|
||||
"title": "🔗 MeineCloud
|
||||
❌ Request failed. Request-id: test.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue