File size: 1,022 Bytes
0bfe2e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// looks at Env.ALIASED_CONFIGURATIONS and then redirects to /stremio/{uuid}/{encryptedPassword} after parsing the alias value

import { APIError, constants, createLogger, Env } from '@aiostreams/core';
import { Router, Request } from 'express';
import { createResponse } from '../../utils/responses';

const logger = createLogger('server');
const router = Router();

interface AliasParams {
  alias: string;
  [key: string]: string;
}

router.get('/:alias/*', (req: Request<AliasParams>, res) => {
  const { alias } = req.params;
  const wildcardPath = req.params[0] || '';

  const configuration = Env.ALIASED_CONFIGURATIONS[alias];
  if (!configuration || !configuration.uuid || !configuration.password) {
    throw new APIError(constants.ErrorCode.USER_NOT_FOUND);
  }

  const redirectPath = `/stremio/${configuration.uuid}/${configuration.password}${wildcardPath ? `/${wildcardPath}` : ''}`;
  logger.debug(`Redirecting alias ${alias} to ${redirectPath}`);

  res.redirect(redirectPath);
});

export default router;