diff --git a/src/manifests/utils/configs.ts b/src/manifests/utils/configs.ts index 25339e8..6c82588 100644 --- a/src/manifests/utils/configs.ts +++ b/src/manifests/utils/configs.ts @@ -33,7 +33,7 @@ export interface CorruptorConfig { * * ex: ...&keyWithEmptyFields=&... */ - fields: { [key: string]: string | number | boolean } | null; + fields?: { [key: string]: string | number | boolean } | null; } export type IndexedCorruptorConfigMap = Map; @@ -106,8 +106,6 @@ export const corruptorConfigUtils = function ( return this; }, getAllManifestConfigs(mseq = 0, isDash = false) { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const that: CorruptorConfigUtils = this; const outputMap = new CorruptorIndexMap(); const configs = ( (this.registered || []) as SegmentCorruptorQueryConfig[] @@ -116,7 +114,7 @@ export const corruptorConfigUtils = function ( for (const config of configs) { // JSONify and remove whitespace - const parsableSearchParam = that.utils.getJSONParsableString( + const parsableSearchParam = this.utils.getJSONParsableString( urlSearchParams.get(config.name) ); let params = JSON.parse(parsableSearchParam); @@ -151,11 +149,9 @@ export const corruptorConfigUtils = function ( const outputMap = new Map(); for (let i = 0; i < this.registered.length; i++) { const SCC = this.registered[i]; - // eslint-disable-next-line @typescript-eslint/no-this-alias - const that: CorruptorConfigUtils = this; if (urlSearchParams.get(SCC.name) !== null) { // To make all object key names double quoted and remove whitespace - const parsedSearchParam = that.utils.getJSONParsableString( + const parsedSearchParam = this.utils.getJSONParsableString( urlSearchParams.get(SCC.name) ); diff --git a/src/manifests/utils/corruptions/delay.ts b/src/manifests/utils/corruptions/delay.ts index 3425e7c..bdacaf6 100644 --- a/src/manifests/utils/corruptions/delay.ts +++ b/src/manifests/utils/corruptions/delay.ts @@ -1,18 +1,18 @@ -/* eslint-disable */ import { unparsableError } from '../../../shared/utils'; import { ServiceError, TargetIndex } from '../../../shared/types'; import { CorruptorConfig, SegmentCorruptorQueryConfig } from '../configs'; interface DelayConfig extends CorruptorConfig { - ms: number; + ms?: number; } // TODO:Flytta till en i en constants fil, och gruppera med and const delayExpectedQueryFormatMsg = 'Incorrect delay query format. Expected format: [{i?:number, sq?:number, br?:number, ms:number}, ...n] where i and sq are mutually exclusive.'; -function getManifestConfigError(value: { [key: string]: any }): string { +function getManifestConfigError(value: { [key: string]: unknown }): string { const o = value as DelayConfig; + if (o.ms && typeof o.ms !== 'number') { return delayExpectedQueryFormatMsg; } @@ -32,19 +32,18 @@ function getManifestConfigError(value: { [key: string]: any }): string { return "Incorrect delay query format. 'i' and 'sq' are mutually exclusive in a single query object."; } - if (o.sq < 0) { + if (Number(o.sq) < 0) { return 'Incorrect delay query format. Field sq must be 0 or positive.'; } - if (o.i < 0) { + if (Number(o.i) < 0) { return 'Incorrect delay query format. Field i must be 0 or positive.'; } return ''; } -function isValidSegmentConfig(value: { [key: string]: any }): boolean { - const o = value as DelayConfig; - if (o.ms && typeof o.ms !== 'number') { +function isValidSegmentConfig(value: { [key: string]: unknown }): boolean { + if (value.ms && typeof value.ms !== 'number') { return false; } return true; @@ -121,7 +120,7 @@ const delayConfig: SegmentCorruptorQueryConfig = { const corruptorConfigs: CorruptorConfig[] = []; - for (var value of configIndexMap.values()) { + for (const value of configIndexMap.values()) { corruptorConfigs.push(value); } @@ -133,7 +132,7 @@ const delayConfig: SegmentCorruptorQueryConfig = { getSegmentConfigs( delayConfigString: string ): [ServiceError | null, CorruptorConfig | null] { - const config: any = JSON.parse(delayConfigString); + const config = JSON.parse(delayConfigString); if (!isValidSegmentConfig(config)) { return [ unparsableError( diff --git a/src/manifests/utils/corruptions/statusCode.ts b/src/manifests/utils/corruptions/statusCode.ts index c3bc32f..25ec93b 100644 --- a/src/manifests/utils/corruptions/statusCode.ts +++ b/src/manifests/utils/corruptions/statusCode.ts @@ -1,4 +1,3 @@ -/* eslint-disable */ import { unparsableError } from '../../../shared/utils'; import { ServiceError, TargetIndex } from '../../../shared/types'; import { CorruptorConfig, SegmentCorruptorQueryConfig } from '../configs'; @@ -35,11 +34,11 @@ function getManifestConfigError(value: { [key: string]: any }): string { return "Incorrect statusCode query format. 'i' and 'sq' are mutually exclusive in a single query object."; } - if (o.sq < 0) { + if (Number(o.sq) < 0) { return 'Incorrect statusCode query format. Field sq must be 0 or positive.'; } - if (o.i < 0) { + if (Number(o.i) < 0) { return 'Incorrect statusCode query format. Field i must be 0 or positive.'; } diff --git a/src/manifests/utils/corruptions/timeout.ts b/src/manifests/utils/corruptions/timeout.ts index 8dc9ff8..37592c2 100644 --- a/src/manifests/utils/corruptions/timeout.ts +++ b/src/manifests/utils/corruptions/timeout.ts @@ -12,8 +12,7 @@ interface TimeoutConfig { ch?: number; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function getManifestConfigError(value: { [key: string]: any }): string { +function getManifestConfigError(value: { [key: string]: unknown }): string { const o = value as TimeoutConfig; if (o.i === undefined && o.sq === undefined) { @@ -31,11 +30,11 @@ function getManifestConfigError(value: { [key: string]: any }): string { return "Incorrect timeout query format. 'i' and 'sq' are mutually exclusive in a single query object."; } - if (o.sq < 0) { + if (Number(o.sq) < 0) { return 'Incorrect timeout query format. Field sq must be 0 or positive.'; } - if (o.i < 0) { + if (Number(o.i) < 0) { return 'Incorrect timeout query format. Field i must be 0 or positive.'; } diff --git a/src/manifests/utils/hlsManifestUtils.ts b/src/manifests/utils/hlsManifestUtils.ts index 7cc0e33..2289635 100644 --- a/src/manifests/utils/hlsManifestUtils.ts +++ b/src/manifests/utils/hlsManifestUtils.ts @@ -14,8 +14,7 @@ export interface HLSManifestTools { createProxyMediaManifest: ( originalM3U: M3U, sourceBaseURL: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mutations: any + mutations: IndexedCorruptorConfigMap ) => Manifest; // look def again createProxyMasterManifest: ( originalM3U: M3U, @@ -122,13 +121,10 @@ export default function (): HLSManifestTools { sourceBaseURL: string, configsMap: IndexedCorruptorConfigMap ) { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const that: HLSManifestTools = this; - const m3u: M3U = clone(originalM3U); // configs for each index - const corruptions = that.utils.mergeMap( + const corruptions = this.utils.mergeMap( m3u.items.PlaylistItem.length, configsMap ); diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4a8d763..6dc04c3 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -18,8 +18,7 @@ import { addSSMUrlParametersToUrl } from './aws.utils'; import dotenv from 'dotenv'; dotenv.config(); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { version } = require('../../package.json'); +const version = process.env.npm_package_version; export const handleOptionsRequest = async (): Promise => { return {