create LRT module frame

This commit is contained in:
Jurgis Sakalauskas
2022-12-06 19:36:10 +02:00
parent d20295326f
commit 8c9190675b
12 changed files with 243 additions and 4 deletions
+34
View File
@@ -0,0 +1,34 @@
import ResponseItem from './response-item.dto';
export default class ApiResponse {
items: Array<ResponseItem> = [];
content = 'videos';
updateList = true;
category: string;
play: string;
msgBoxOK: string;
setTitle(title) {
this.category = title;
return this;
}
setToPlayable(path) {
this.updateList = false;
this.play = path;
return this;
}
createItem() {
const item = new ResponseItem();
this.items.push(item);
return item;
}
addMessage(message) {
this.msgBoxOK = message;
}
}
+12
View File
@@ -0,0 +1,12 @@
export default class ContextMenu {
name: string;
urlParams: { action: string; path: string };
constructor(name, path) {
this.name = name;
this.urlParams = {
action: 'query',
path: path,
};
}
}
+9
View File
@@ -0,0 +1,9 @@
export default class NotificationResponse {
notification: string;
refreshContainer: boolean;
constructor(message: string, refreshContainer = true) {
this.notification = message;
this.refreshContainer = refreshContainer;
}
}
+95
View File
@@ -0,0 +1,95 @@
import ContextMenu from './context-menu.dto';
export default class ResponseItem {
isFolder = false;
isPlayable = true;
mediatype: string;
action: 'query' | 'search';
label: string;
path: string;
size: number;
plot: string;
duration: number;
thumb: string;
contextMenus: Array<ContextMenu>;
constructor() {
this.setToPlayable();
}
setToFolder() {
this.isFolder = true;
delete this.isPlayable;
delete this.mediatype;
delete this.action;
return this;
}
setToPlayable(withQueryAction = false) {
this.isFolder = false;
this.isPlayable = true;
this.mediatype = 'video';
// if path provided is not to a video, but additional api request is needed
// for video url
if (withQueryAction) {
this.action = 'query';
}
return this;
}
setActionSearch() {
this.action = 'search';
delete this.isPlayable;
this.isFolder = false;
return this;
}
setLabel(label) {
this.label = label;
return this;
}
setPath(path) {
this.path = path;
return this;
}
setSize(size) {
this.size = size;
return this;
}
setPlot(plot) {
this.plot = plot;
return this;
}
setDuration(duration: number) {
this.duration = duration;
return this;
}
setThumb(thumb) {
this.thumb = thumb;
return this;
}
addContextMenu(name, path) {
if (!this.contextMenus) {
this.contextMenus = [];
}
const cm = new ContextMenu(name, path);
this.contextMenus.push(cm);
return this;
}
}
+50
View File
@@ -0,0 +1,50 @@
import { Controller, Get, Param, Query, Req } from '@nestjs/common';
import { Request } from 'express';
@Controller('api/lrt')
export class LrtController {
@Get()
getLrtMenu(@Req() request: Request) {
return {
mod: 'lrt - menu',
path: request.url,
};
}
@Get('search')
getSearch(@Req() request: Request, @Query('search') search: string) {
return {
mod: 'lrt',
path: request.url,
search: search ?? 'no',
};
}
@Get('cat/:id')
getCategory(@Req() request: Request, @Param('id') id: number) {
return {
mod: 'lrt - category',
path: request.url,
category: id,
};
}
@Get('tema/:tema')
getTema(@Req() request: Request, @Param('tema') tema: string) {
return {
mod: 'lrt - category',
path: request.url,
tema: tema,
};
}
@Get('play/*')
getPlay(@Req() request: Request, @Param() params: string[]) {
const playPath = params[0];
return {
mod: 'lrt - play',
path: request.url,
playPath: playPath,
};
}
}
+8
View File
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { LrtController } from './lrt.controller';
@Module({
controllers: [LrtController],
providers: [],
})
export class LrtModule {}
+8
View File
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class LrtService {
getMainMenu(): string {
return 'Hello World!';
}
}
@@ -5,11 +5,12 @@ import { join } from 'path';
export class KodiApiUrlRewriteMiddleware implements NestMiddleware {
async use(req: Request, res: Response, next: NextFunction) {
let path: string;
let path = '';
if (req.query && req.query.path) {
path = req.query.path as string;
}
req.url = join('/api/', path);
const query = req.url.split('?').pop();
req.url = join('/api/', path) + (query ? '?' + query : '');
next();
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { Request } from 'express';
@Controller('api')
export class KodiApiController {
@Get('*')
@Get()
getMainMenu(
@RequestRange() requestedRange: RequestRangeBytes,
@Req() request: Request,
+2
View File
@@ -6,8 +6,10 @@ import {
} from '@nestjs/common';
import { KodiApiController } from './kodi-api.controller';
import { KodiApiUrlRewriteMiddleware } from './UrlRewrite/url-rewrite.middleware';
import { LrtModule } from './LRT/lrt.module';
@Module({
imports: [LrtModule],
controllers: [KodiApiController],
providers: [],
})
+21
View File
@@ -0,0 +1,21 @@
import { Injectable } from '@nestjs/common';
import ApiResponse from './Dto/api-response.dto';
import NotificationResponse from './Dto/notification-response';
@Injectable()
export class KodiApiService {
getMainMenu(): string {
return 'Hello World!';
}
createApiResponse(): ApiResponse {
return new ApiResponse();
}
createNotificationResponse(
message: string,
refreshContainer = true,
): NotificationResponse {
return new NotificationResponse(message, refreshContainer);
}
}