From 138e92afc5c94b9ed60bbd0fc61d5d86d84b068c Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Thu, 19 Jun 2025 11:52:21 +0000 Subject: [PATCH] chore: make ip in Context optional --- src/controller/StreamController.ts | 2 +- src/index.ts | 2 +- src/test/index.ts | 1 - src/types.ts | 2 +- src/utils/Fetcher.test.ts | 2 +- src/utils/Fetcher.ts | 12 +++++++----- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/controller/StreamController.ts b/src/controller/StreamController.ts index 5f45109..72bc6e8 100644 --- a/src/controller/StreamController.ts +++ b/src/controller/StreamController.ts @@ -29,7 +29,7 @@ export class StreamController { const ctx: Context = { id: res.getHeader('X-Request-ID') as string, - ip: req.ip as string, + ...(req.ip && { ip: req.ip }), config, }; diff --git a/src/index.ts b/src/index.ts index 23b32f4..0f446f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,7 +72,7 @@ addon.listen(port, () => { }); const cacheWarmup = async () => { - const ctx = { id: 'warmup', ip: '127.0.0.1', config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' } }; + const ctx = { 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 }[] } diff --git a/src/test/index.ts b/src/test/index.ts index a4ac9b8..29cdece 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -4,7 +4,6 @@ import { getDefaultConfig } from '../utils'; export const createTestContext = (config?: Config): Context => { return { id: 'test', - ip: '0.0.0.0', config: config ?? getDefaultConfig(), }; }; diff --git a/src/types.ts b/src/types.ts index 625128f..ff91158 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,7 +2,7 @@ import { Manifest, ManifestConfig } from 'stremio-addon-sdk'; export interface Context { id: string; - ip: string; + ip?: string; config: Config; } diff --git a/src/utils/Fetcher.test.ts b/src/utils/Fetcher.test.ts index 636f363..e02e22b 100644 --- a/src/utils/Fetcher.test.ts +++ b/src/utils/Fetcher.test.ts @@ -8,7 +8,7 @@ fetchMock.mockGlobal(); const fetcher = new Fetcher(winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] })); describe('fetch', () => { - const ctx = createTestContext(); + const ctx = { ...createTestContext(), ip: '0.0.0.0' }; afterEach(() => { fetchMock.clearHistory(); diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 141a3c1..a3b5741 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -91,13 +91,15 @@ export class Fetcher { headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en', - ...(cookieString && { Cookie: cookieString }), - 'Forwarded': `for=${ctx.ip}`, 'Priority': 'u=0', 'User-Agent': this.hostUserAgentMap.get(url.host) ?? 'node', - 'X-Forwarded-For': ctx.ip, - 'X-Forwarded-Proto': url.protocol.slice(0, -1), - 'X-Real-IP': ctx.ip, + ...(cookieString && { Cookie: cookieString }), + ...(ctx.ip && { + 'Forwarded': `for=${ctx.ip}`, + 'X-Forwarded-For': ctx.ip, + 'X-Forwarded-Proto': url.protocol.slice(0, -1), + 'X-Real-IP': ctx.ip, + }), ...init?.headers, }, };