diff --git a/src/KodiApi/Dto/api-response.dto.ts b/src/KodiApi/Dto/api-response.dto.ts new file mode 100644 index 0000000..632a941 --- /dev/null +++ b/src/KodiApi/Dto/api-response.dto.ts @@ -0,0 +1,34 @@ +import ResponseItem from './response-item.dto'; + +export default class ApiResponse { + items: Array = []; + 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; + } +} diff --git a/src/KodiApi/Dto/context-menu.dto.ts b/src/KodiApi/Dto/context-menu.dto.ts new file mode 100644 index 0000000..dde1af6 --- /dev/null +++ b/src/KodiApi/Dto/context-menu.dto.ts @@ -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, + }; + } +} diff --git a/src/KodiApi/Dto/notification-response.ts b/src/KodiApi/Dto/notification-response.ts new file mode 100644 index 0000000..48f0cae --- /dev/null +++ b/src/KodiApi/Dto/notification-response.ts @@ -0,0 +1,9 @@ +export default class NotificationResponse { + notification: string; + refreshContainer: boolean; + + constructor(message: string, refreshContainer = true) { + this.notification = message; + this.refreshContainer = refreshContainer; + } +} diff --git a/src/KodiApi/Dto/response-item.dto.ts b/src/KodiApi/Dto/response-item.dto.ts new file mode 100644 index 0000000..b13dfb6 --- /dev/null +++ b/src/KodiApi/Dto/response-item.dto.ts @@ -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; + + 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; + } +} diff --git a/src/KodiApi/LRT/lrt.controller.ts b/src/KodiApi/LRT/lrt.controller.ts new file mode 100644 index 0000000..298ab20 --- /dev/null +++ b/src/KodiApi/LRT/lrt.controller.ts @@ -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, + }; + } +} diff --git a/src/KodiApi/LRT/lrt.module.ts b/src/KodiApi/LRT/lrt.module.ts new file mode 100644 index 0000000..f29f79c --- /dev/null +++ b/src/KodiApi/LRT/lrt.module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common'; +import { LrtController } from './lrt.controller'; + +@Module({ + controllers: [LrtController], + providers: [], +}) +export class LrtModule {} diff --git a/src/KodiApi/LRT/lrt.service.ts b/src/KodiApi/LRT/lrt.service.ts new file mode 100644 index 0000000..a9b2b94 --- /dev/null +++ b/src/KodiApi/LRT/lrt.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class LrtService { + getMainMenu(): string { + return 'Hello World!'; + } +} diff --git a/src/KodiApi/UrlRewrite/url-rewrite.middleware.ts b/src/KodiApi/UrlRewrite/url-rewrite.middleware.ts index 6d38c27..fa21977 100644 --- a/src/KodiApi/UrlRewrite/url-rewrite.middleware.ts +++ b/src/KodiApi/UrlRewrite/url-rewrite.middleware.ts @@ -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(); } diff --git a/src/KodiApi/kodi-api.controller.ts b/src/KodiApi/kodi-api.controller.ts index 8aa3fd1..a7afba1 100644 --- a/src/KodiApi/kodi-api.controller.ts +++ b/src/KodiApi/kodi-api.controller.ts @@ -5,7 +5,7 @@ import { Request } from 'express'; @Controller('api') export class KodiApiController { - @Get('*') + @Get() getMainMenu( @RequestRange() requestedRange: RequestRangeBytes, @Req() request: Request, diff --git a/src/KodiApi/kodi-api.module.ts b/src/KodiApi/kodi-api.module.ts index 26eccbf..9f5696d 100644 --- a/src/KodiApi/kodi-api.module.ts +++ b/src/KodiApi/kodi-api.module.ts @@ -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: [], }) diff --git a/src/KodiApi/kodi-api.service.ts b/src/KodiApi/kodi-api.service.ts new file mode 100644 index 0000000..e3e49c1 --- /dev/null +++ b/src/KodiApi/kodi-api.service.ts @@ -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); + } +} diff --git a/src/Static/UrlRewrite/url-rewrite.middleware.ts b/src/Static/UrlRewrite/url-rewrite.middleware.ts index 3a5009e..752ee67 100644 --- a/src/Static/UrlRewrite/url-rewrite.middleware.ts +++ b/src/Static/UrlRewrite/url-rewrite.middleware.ts @@ -2,7 +2,6 @@ import { NestMiddleware } from '@nestjs/common'; import { NextFunction } from 'express'; import { Request, Response } from 'express'; -//we dont care about query params for static response export class RemoveQueryUrlRewriteMiddleware implements NestMiddleware { async use(req: Request, res: Response, next: NextFunction) { const urlArray = req.url.split('?');