webstreamr-github/src/controller/ConfigureController.ts
2025-06-12 21:05:24 +00:00

29 lines
908 B
TypeScript

import { Request, Response, Router } from 'express';
import { landingTemplate } from '../landingTemplate';
import { buildManifest, getDefaultConfig } from '../utils';
import { Source } from '../source';
import { Config } from '../types';
export class ConfigureController {
public readonly router: Router;
private readonly sources: Source[];
constructor(sources: Source[]) {
this.router = Router();
this.sources = sources;
this.router.get('/configure', this.getConfigure.bind(this));
this.router.get('/:config/configure', this.getConfigure.bind(this));
}
private readonly getConfigure = (req: Request, res: Response) => {
const config: Config = JSON.parse(req.params['config'] || JSON.stringify(getDefaultConfig()));
const manifest = buildManifest(this.sources, config);
res.setHeader('content-type', 'text/html');
res.send(landingTemplate(manifest));
};
}