chore(extractor): log more infos
This commit is contained in:
parent
1454d21e4d
commit
349c26c9b5
10 changed files with 33 additions and 13 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import winston from 'winston';
|
||||
import { EmbedExtractorRegistry } from './EmbedExtractorRegistry';
|
||||
import { Context } from '../types';
|
||||
import { Fetcher } from '../utils';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const embedExtractors = new EmbedExtractorRegistry(fetcher);
|
||||
const embedExtractors = new EmbedExtractorRegistry(logger, fetcher);
|
||||
|
||||
describe('EmbedExtractorRegistry', () => {
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import TTLCache from '@isaacs/ttlcache';
|
||||
import winston from 'winston';
|
||||
import { EmbedExtractor } from './types';
|
||||
import { Context, UrlResult } from '../types';
|
||||
import { Fetcher } from '../utils';
|
||||
|
|
@ -6,11 +7,12 @@ import { Dropload } from './Dropload';
|
|||
import { SuperVideo } from './SuperVideo';
|
||||
|
||||
export class EmbedExtractorRegistry {
|
||||
private readonly logger: winston.Logger;
|
||||
private readonly embedExtractors: EmbedExtractor[];
|
||||
|
||||
private readonly urlResultCache: TTLCache<string, UrlResult>;
|
||||
|
||||
constructor(fetcher: Fetcher) {
|
||||
constructor(logger: winston.Logger, fetcher: Fetcher) {
|
||||
this.logger = logger;
|
||||
this.embedExtractors = [
|
||||
new Dropload(fetcher),
|
||||
new SuperVideo(fetcher),
|
||||
|
|
@ -29,6 +31,8 @@ export class EmbedExtractorRegistry {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
this.logger.info(`Extract stream URL using ${embedExtractor.id} extractor from ${url}`);
|
||||
|
||||
urlResult = await embedExtractor.extract(ctx, url, countryCode);
|
||||
this.urlResultCache.set(url.href, urlResult, { ttl: embedExtractor.ttl });
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { FrenchCloud } from './FrenchCloud';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new FrenchCloud(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const handler = new FrenchCloud(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('FrenchCloud', () => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { KinoKiste } from './KinoKiste';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { Fetcher } from '../utils';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new KinoKiste(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const handler = new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('KinoKiste', () => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { MeineCloud } from './MeineCloud';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new MeineCloud(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const handler = new MeineCloud(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('MeineCloud', () => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { MostraGuarda } from './MostraGuarda';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new MostraGuarda(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const handler = new MostraGuarda(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('MostraGuarda', () => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import winston from 'winston';
|
||||
import { VerHdLink } from './VerHdLink';
|
||||
import { Fetcher } from '../utils';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const handler = new VerHdLink(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const handler = new VerHdLink(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
describe('VerHdLink', () => {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const logger = winston.createLogger({
|
|||
|
||||
const fetcher = new Fetcher(setupCache(axios), logger);
|
||||
|
||||
const embedExtractors = new EmbedExtractorRegistry(fetcher);
|
||||
const embedExtractors = new EmbedExtractorRegistry(logger, fetcher);
|
||||
|
||||
const handlers: Handler[] = [
|
||||
new FrenchCloud(fetcher, embedExtractors),
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import { MeineCloud, MostraGuarda } from '../handler';
|
|||
import { Fetcher } from './Fetcher';
|
||||
import { Context } from '../types';
|
||||
jest.mock('../utils/Fetcher');
|
||||
const streamResolver = new StreamResolver(winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }));
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
const streamResolver = new StreamResolver(logger);
|
||||
const ctx: Context = { ip: '127.0.0.1' };
|
||||
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
const embedExtractorRegistry = new EmbedExtractorRegistry(fetcher);
|
||||
const embedExtractorRegistry = new EmbedExtractorRegistry(logger, fetcher);
|
||||
const meineCloud = new MeineCloud(fetcher, embedExtractorRegistry);
|
||||
const mostraGuarda = new MostraGuarda(fetcher, embedExtractorRegistry);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import winston from 'winston';
|
||||
import { buildManifest } from './manifest';
|
||||
import { KinoKiste } from '../handler';
|
||||
import { Fetcher } from './Fetcher';
|
||||
import { EmbedExtractorRegistry } from '../embed-extractor';
|
||||
|
||||
const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] });
|
||||
// @ts-expect-error No constructor args needed
|
||||
const fetcher = new Fetcher();
|
||||
|
||||
|
|
@ -14,14 +16,14 @@ describe('buildManifest', () => {
|
|||
});
|
||||
|
||||
test('has unchecked handler without a config', () => {
|
||||
const manifest = buildManifest([new KinoKiste(fetcher, new EmbedExtractorRegistry(fetcher))], {});
|
||||
const manifest = buildManifest([new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher))], {});
|
||||
|
||||
expect(manifest.config).toHaveLength(1);
|
||||
expect(manifest.config[0]?.default).toBeUndefined();
|
||||
});
|
||||
|
||||
test('has checked handler with appropriate config', () => {
|
||||
const kinokiste = new KinoKiste(fetcher, new EmbedExtractorRegistry(fetcher));
|
||||
const kinokiste = new KinoKiste(fetcher, new EmbedExtractorRegistry(logger, fetcher));
|
||||
const manifest = buildManifest([kinokiste], { [kinokiste.id]: 'on' });
|
||||
|
||||
expect(manifest.config).toHaveLength(1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue