mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-09 04:47:41 +00:00
add initial frame, kodi api module, static serve module, settings, etc.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { NestMiddleware } from '@nestjs/common';
|
||||
import { NextFunction } from 'express';
|
||||
import { Request, Response } from 'express';
|
||||
import { join } from 'path';
|
||||
|
||||
export class KodiApiUrlRewriteMiddleware implements NestMiddleware {
|
||||
async use(req: Request, res: Response, next: NextFunction) {
|
||||
let path: string;
|
||||
if (req.query && req.query.path) {
|
||||
path = req.query.path as string;
|
||||
}
|
||||
req.url = join('/api/', path);
|
||||
|
||||
next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Controller, Get, Req } from '@nestjs/common';
|
||||
import RequestRangeBytes from 'src/RequestRange/request-range-bytes.class';
|
||||
import { RequestRange } from 'src/RequestRange/request-range.decorator';
|
||||
import { Request } from 'express';
|
||||
|
||||
@Controller('api')
|
||||
export class KodiApiController {
|
||||
@Get('*')
|
||||
getMainMenu(
|
||||
@RequestRange() requestedRange: RequestRangeBytes,
|
||||
@Req() request: Request,
|
||||
) {
|
||||
return {
|
||||
range: requestedRange,
|
||||
path: request.url,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
MiddlewareConsumer,
|
||||
Module,
|
||||
NestModule,
|
||||
RequestMethod,
|
||||
} from '@nestjs/common';
|
||||
import { KodiApiController } from './kodi-api.controller';
|
||||
import { KodiApiUrlRewriteMiddleware } from './UrlRewrite/url-rewrite.middleware';
|
||||
|
||||
@Module({
|
||||
controllers: [KodiApiController],
|
||||
providers: [],
|
||||
})
|
||||
export class KodiApiModule implements NestModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
consumer
|
||||
.apply(KodiApiUrlRewriteMiddleware)
|
||||
.forRoutes({ path: '/api*', method: RequestMethod.ALL });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user