mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-08 20:37:41 +00:00
create LRT module frame
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export default class NotificationResponse {
|
||||
notification: string;
|
||||
refreshContainer: boolean;
|
||||
|
||||
constructor(message: string, refreshContainer = true) {
|
||||
this.notification = message;
|
||||
this.refreshContainer = refreshContainer;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { LrtController } from './lrt.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [LrtController],
|
||||
providers: [],
|
||||
})
|
||||
export class LrtModule {}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Request } from 'express';
|
||||
|
||||
@Controller('api')
|
||||
export class KodiApiController {
|
||||
@Get('*')
|
||||
@Get()
|
||||
getMainMenu(
|
||||
@RequestRange() requestedRange: RequestRangeBytes,
|
||||
@Req() request: Request,
|
||||
|
||||
@@ -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: [],
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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('?');
|
||||
|
||||
Reference in New Issue
Block a user