mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-08 20:37:41 +00:00
expand config
This commit is contained in:
+5
-3
@@ -1,3 +1,5 @@
|
|||||||
PORT=80
|
PORT=3000
|
||||||
STATIC_SERVE_FOLDER="../path/to/static/files"
|
DB_PATH=./data/db/db.db
|
||||||
LOG_FILE_REQUESTS="../path/to/log/all/requests.log"
|
LOG_FILE_REQUESTS=./data/static/static.log
|
||||||
|
STATIC_SERVE_FOLDER=./data/static
|
||||||
|
RECENT_SEARCHES_FOLDER=./data/recent
|
||||||
@@ -6,7 +6,7 @@ import { SearchResponseDto } from '../Dto/search-response.dto';
|
|||||||
import { SearchResponseItemDto } from '../Dto/search-response-item.dto';
|
import { SearchResponseItemDto } from '../Dto/search-response-item.dto';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { LrtCategory } from '../Entity/lrt-category.entity';
|
import { LrtCategory } from '../Entity/lrt-category.entity';
|
||||||
import { FindOptionsUtils, Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LrtApiSearchClient {
|
export class LrtApiSearchClient {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class LrtService {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly kodiApiResponseFactory: KodiApiResponseFactory,
|
private readonly kodiApiResponseFactory: KodiApiResponseFactory,
|
||||||
private readonly lrtApiClient: LrtApiClient,
|
private readonly lrtApiClient: LrtApiClient,
|
||||||
private readonly recentSearchesService: RecentSearchesService
|
private readonly recentSearchesService: RecentSearchesService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
getMainMenu(): ApiResponse {
|
getMainMenu(): ApiResponse {
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import { readFile, writeFile } from 'fs/promises';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class RecentSearchesService {
|
export class RecentSearchesService {
|
||||||
private readonly configService: ConfigService;
|
private readonly configService: ConfigService;
|
||||||
constructor(
|
constructor(private readonly kodiApiResponseFactory: KodiApiResponseFactory) {
|
||||||
private readonly kodiApiResponseFactory: KodiApiResponseFactory,
|
|
||||||
) {
|
|
||||||
this.configService = configService;
|
this.configService = configService;
|
||||||
}
|
}
|
||||||
async getRecentSearches(module: string, path: string): Promise<ApiResponse> {
|
async getRecentSearches(module: string, path: string): Promise<ApiResponse> {
|
||||||
@@ -48,6 +46,9 @@ export class RecentSearchesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getFilePath(module: string): string {
|
private getFilePath(module: string): string {
|
||||||
return join(this.configService.getRecentSearchesFolder(), module + '.json');
|
return join(
|
||||||
|
this.configService.getPaths().getRecentSearchesFolder(),
|
||||||
|
module + '.json',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { NestMiddleware } from '@nestjs/common';
|
|||||||
import { NextFunction } from 'express';
|
import { NextFunction } from 'express';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { appendFile } from 'fs';
|
import { appendFile } from 'fs';
|
||||||
import { join } from 'path';
|
|
||||||
import { configService } from '../config/config.service';
|
import { configService } from '../config/config.service';
|
||||||
|
|
||||||
export class RequestLogMiddleware implements NestMiddleware {
|
export class RequestLogMiddleware implements NestMiddleware {
|
||||||
@@ -33,7 +32,7 @@ export class RequestLogMiddleware implements NestMiddleware {
|
|||||||
|
|
||||||
private log(message: string) {
|
private log(message: string) {
|
||||||
const strTime = new Date().toISOString();
|
const strTime = new Date().toISOString();
|
||||||
const logFile = configService.getStaticRequestsLogPath();
|
const logFile = configService.getPaths().getStaticRequestsLogPath();
|
||||||
appendFile(logFile, strTime + ' ' + message + '\n', function (err) {
|
appendFile(logFile, strTime + ' ' + message + '\n', function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('error logging ' + message);
|
console.log('error logging ' + message);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { configService } from '../config/config.service';
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ServeStaticModule.forRoot({
|
ServeStaticModule.forRoot({
|
||||||
rootPath: configService.getStaticFolder(),
|
rootPath: configService.getPaths().getStaticFolder(),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
controllers: [StaticController],
|
controllers: [StaticController],
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class StaticService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = join(configService.getStaticFolder(), relPath);
|
const path = join(configService.getPaths().getStaticFolder(), relPath);
|
||||||
|
|
||||||
const stats: Stats | false = await stat(path).catch(() => false);
|
const stats: Stats | false = await stat(path).catch(() => false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import * as env from 'dotenv';
|
import * as env from 'dotenv';
|
||||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
import { LrtCategory } from '../KodiApi/LRT/LrtApiClient/Entity/lrt-category.entity';
|
import { TypeOrmConfig } from './type-orm.config';
|
||||||
import { join } from 'path';
|
import { PathsConfig } from './paths.config';
|
||||||
import { TitleEntity } from '../KodiApi/AllFiles/Entity/title.entity';
|
|
||||||
import { FileEntity } from '../KodiApi/AllFiles/Entity/file.entity';
|
|
||||||
|
|
||||||
env.config();
|
env.config();
|
||||||
|
|
||||||
export class ConfigService {
|
export class ConfigService {
|
||||||
|
private typeOrmConfig: TypeOrmConfig = new TypeOrmConfig(this);
|
||||||
|
private pathsConfig: PathsConfig = new PathsConfig(this);
|
||||||
|
|
||||||
public getEnv(key: string): any {
|
public getEnv(key: string): any {
|
||||||
return process.env[key];
|
return process.env[key];
|
||||||
}
|
}
|
||||||
@@ -19,27 +20,11 @@ export class ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getTypeOrmConfig(): TypeOrmModuleOptions {
|
public getTypeOrmConfig(): TypeOrmModuleOptions {
|
||||||
return {
|
return this.typeOrmConfig;
|
||||||
type: 'sqlite',
|
|
||||||
database: this.getEnv('DB_PATH'),
|
|
||||||
entities: [LrtCategory, TitleEntity, FileEntity],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStaticRequestsLogPath(): string {
|
public getPaths(): PathsConfig {
|
||||||
return join(this.getRootPath(), this.getEnv('LOG_FILE_REQUESTS'));
|
return this.pathsConfig;
|
||||||
}
|
|
||||||
|
|
||||||
public getStaticFolder(): string {
|
|
||||||
return join(this.getRootPath(), this.getEnv('STATIC_SERVE_FOLDER'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public getRecentSearchesFolder(): string {
|
|
||||||
return join(this.getRootPath(), this.getEnv('RECENT_SEARCHES_FOLDER'));
|
|
||||||
}
|
|
||||||
|
|
||||||
private getRootPath(): string {
|
|
||||||
return join(__dirname, '../..');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { ConfigService } from './config.service';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
export class PathsConfig {
|
||||||
|
constructor(private readonly configService: ConfigService) {
|
||||||
|
this.configService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getStaticRequestsLogPath(): string {
|
||||||
|
return join(
|
||||||
|
this.getRootPath(),
|
||||||
|
this.configService.getEnv('LOG_FILE_REQUESTS'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getStaticFolder(): string {
|
||||||
|
return join(
|
||||||
|
this.getRootPath(),
|
||||||
|
this.configService.getEnv('STATIC_SERVE_FOLDER'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getRecentSearchesFolder(): string {
|
||||||
|
return join(
|
||||||
|
this.getRootPath(),
|
||||||
|
this.configService.getEnv('RECENT_SEARCHES_FOLDER'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getRootPath(): string {
|
||||||
|
return join(__dirname, '../..');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { LrtCategory } from '../KodiApi/LRT/LrtApiClient/Entity/lrt-category.entity';
|
||||||
|
import { TitleEntity } from '../KodiApi/AllFiles/Entity/title.entity';
|
||||||
|
import { FileEntity } from '../KodiApi/AllFiles/Entity/file.entity';
|
||||||
|
import { ConfigService } from './config.service';
|
||||||
|
import { EntityClassOrSchema } from '@nestjs/typeorm/dist/interfaces/entity-class-or-schema.type';
|
||||||
|
|
||||||
|
export class TypeOrmConfig {
|
||||||
|
constructor(configService: ConfigService) {
|
||||||
|
this.type = 'sqlite';
|
||||||
|
this.database = configService.getEnv('DB_PATH');
|
||||||
|
this.entities = [LrtCategory, TitleEntity, FileEntity];
|
||||||
|
}
|
||||||
|
type: 'sqlite';
|
||||||
|
database: string;
|
||||||
|
entities: Array<EntityClassOrSchema>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user