Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.ts text eol=crlf
*.json text eol=crlf
2 changes: 1 addition & 1 deletion src/apps/dto/app.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export class ApplicationDto {

@ApiProperty({ description: 'The name of the application. For a full set of properties see https://docs.interop.io/desktop/developers/configuration/application/index.html ', example: 'client-list', type: String })
name: string;
}
}
2 changes: 1 addition & 1 deletion src/apps/dto/get-apps-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export class GetAppsResponseDto {
type: [ApplicationDto]
})
applications: ApplicationDto[];
}
}
50 changes: 25 additions & 25 deletions src/configs/config.controller.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Controller, Headers, Get, Query, Post, Body } from '@nestjs/common';
import { FileBasedConfigService } from './config.service';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { GetConfigsRequestDto } from './dto/get-configs-request.dto';
import { GetConfigsResponsetDto } from './dto/get-configs-response.dto';
@ApiTags('Configurations')
@Controller("configs")
export class ConfigController {
constructor(private readonly service: FileBasedConfigService) { }
@Post()
@ApiOperation({
summary: "Retrieve configuration objects"
})
@ApiOkResponse({
description: 'Successfully retrieved configurations.',
type: GetConfigsResponsetDto
})
async get(@Body() config : GetConfigsRequestDto): Promise<Record<string, string>> {
let configsParam: string = config.configs ?? "*";
console.log("Getting configs");
return this.service.get(configsParam);
}
}
import { Controller, Headers, Get, Query, Post, Body } from '@nestjs/common';
import { FileBasedConfigService } from './config.service';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { GetConfigsRequestDto } from './dto/get-configs-request.dto';
import { GetConfigsResponseDto } from './dto/get-configs-response.dto';

@ApiTags('Configurations')
@Controller("configs")
export class ConfigController {
constructor(private readonly service: FileBasedConfigService) { }

@Post()
@ApiOperation({
summary: "Retrieve configuration objects"
})
@ApiOkResponse({
description: 'Successfully retrieved configurations.',
type: GetConfigsResponseDto
})
async get(@Body() config : GetConfigsRequestDto): Promise<Record<string, string>> {
let configsParam: string = config.configs ?? "*";
console.log("Getting configs");
return this.service.get(configsParam);
}
}
164 changes: 82 additions & 82 deletions src/configs/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
import { Injectable } from '@nestjs/common';
import { promisify } from "util";
import { readdir, readFile, mkdir, existsSync } from "fs";
import * as json5 from "json5";
import { join } from "path";
const readDirPromisfied = promisify(readdir);
const readFilePromisified = promisify(readFile);
const mkDirPromisified = promisify(mkdir);
@Injectable()
export class FileBasedConfigService {
private folder = process.env.CONFIGS_FOLDER || "./configuration/configs";
// some of the confis are actually arrays (not objects)
private arrayConfigs = ["themes.json", "channels.json"];
constructor() {
mkDirPromisified(this.folder, { recursive: true });
}
public async get(configsR: string): Promise<Record<string, any>> {
let configs: string[] = [];
if (configsR === "*") {
configs = await this.getAvailableConfigFiles();
} else {
configs = configsR.split(",");
}
const result: Record<string, any> = {};
if (configs) {
for (const config of configs) {
let contents;
try {
contents = await this.fetchConfiguration(config);
} catch (e) {
// TODO log
console.error("Error reading config file", e);
}
result[config] = { contents };
}
}
return result;
}
private async fetchConfiguration(configName: string) {
const isArrayResult = this.arrayConfigs.includes(configName);
const result = await this.readConfigFile(configName, isArrayResult);
return result;
}
private async readConfigFile(configName: string, arrayResult = false) {
let defaultResult: any = {};
if (arrayResult) {
defaultResult = [];
}
try {
const filePath = join(this.folder, configName);
if (!existsSync(filePath)) {
return defaultResult;
}
return readFilePromisified(join(filePath), "utf8");
} catch {
return defaultResult;
}
}
private async getAvailableConfigFiles() {
let names: string[] = [];
try {
names = await readDirPromisfied(this.folder);
names = names
.filter(n => n.endsWith(".json") && !n.includes("-"))
} catch (e) {
// TODO log
}
if (names === undefined) {
names = [];
}
return names;
}
}
import { Injectable } from '@nestjs/common';
import { promisify } from "util";
import { readdir, readFile, mkdir, existsSync } from "fs";
import * as json5 from "json5";
import { join } from "path";

const readDirPromisfied = promisify(readdir);
const readFilePromisified = promisify(readFile);
const mkDirPromisified = promisify(mkdir);

@Injectable()
export class FileBasedConfigService {
private folder = process.env.CONFIGS_FOLDER || "./configuration/configs";
// some of the confis are actually arrays (not objects)
private arrayConfigs = ["themes.json", "channels.json"];

constructor() {
mkDirPromisified(this.folder, { recursive: true });
}

public async get(configsR: string): Promise<Record<string, any>> {
let configs: string[] = [];
if (configsR === "*") {
configs = await this.getAvailableConfigFiles();
} else {
configs = configsR.split(",");
}

const result: Record<string, any> = {};
if (configs) {
for (const config of configs) {
let contents;
try {
contents = await this.fetchConfiguration(config);
} catch (e) {
// TODO log
console.error("Error reading config file", e);
}
result[config] = { contents };
}
}
return result;
}

private async fetchConfiguration(configName: string) {
const isArrayResult = this.arrayConfigs.includes(configName);
const result = await this.readConfigFile(configName, isArrayResult);
return result;
}

private async readConfigFile(configName: string, arrayResult = false) {
let defaultResult: any = {};
if (arrayResult) {
defaultResult = [];
}
try {
const filePath = join(this.folder, configName);
if (!existsSync(filePath)) {
return defaultResult;
}
return readFilePromisified(filePath, "utf8");
} catch {
return defaultResult;
}
}

private async getAvailableConfigFiles() {
let names: string[] = [];
try {
names = await readDirPromisfied(this.folder);
names = names
.filter(n => n.endsWith(".json") && !n.includes("-"))
} catch (e) {
// TODO log
}

if (names === undefined) {
names = [];
}
return names;
}
}
17 changes: 9 additions & 8 deletions src/configs/dto/get-configs-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ApiProperty } from "@nestjs/swagger";

export class GetConfigsRequestDto {
@ApiProperty({
description: 'Comma seperated list of JSON configurations files to retrieve. If',
})
configs: string;
}
import { ApiProperty } from "@nestjs/swagger";

export class GetConfigsRequestDto {
@ApiProperty({
description: 'Comma separated list of JSON configuration files to retrieve. Use "*" to retrieve all configurations.',
})
configs: string;
}

37 changes: 19 additions & 18 deletions src/configs/dto/get-configs-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ApiProperty } from "@nestjs/swagger";

export class GetConfigsResponsetDto {
@ApiProperty({
description: 'Overriding JSON configuration for the `system.json` file of io.Connect Desktop.',
})
"system.json": string;

@ApiProperty({
description: 'Overriding JSON configuration for the `channels.json` file of io.Connect Desktop',
})
"channels.json": string;

@ApiProperty({
description: 'Overriding JSON configuration for the `logger.json` file of io.Connect Desktop',
})
"logger.json": string;
}
import { ApiProperty } from "@nestjs/swagger";

export class GetConfigsResponseDto {
@ApiProperty({
description: 'Overriding JSON configuration for the `system.json` file of io.Connect Desktop.',
})
"system.json": string;

@ApiProperty({
description: 'Overriding JSON configuration for the `channels.json` file of io.Connect Desktop',
})
"channels.json": string;

@ApiProperty({
description: 'Overriding JSON configuration for the `logger.json` file of io.Connect Desktop',
})
"logger.json": string;
}

2 changes: 1 addition & 1 deletion src/layouts/dto/delete-layout-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export class DeleteLayoutRequestDto {

@ApiProperty({ description: 'The ids of the layouts to be removed. Use this if you want to remove multiple layouts at once.'})
ids?: string[];
}
}
2 changes: 1 addition & 1 deletion src/layouts/dto/get-layouts-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { LayoutDto } from "./layout.dto";
export class GetLayoutsResponseDto {
@ApiProperty({ description: 'The list of layouts', type: [LayoutDto] })
layouts: LayoutDto[];
}
}
2 changes: 1 addition & 1 deletion src/layouts/dto/layout.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export class LayoutDto {

@ApiProperty({ description: 'The type of the layout'})
type: string;
}
}
2 changes: 1 addition & 1 deletion src/layouts/dto/rename-layout-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export class RenameLayoutRequestDto{

@ApiProperty({ description: 'The new name for the layout'})
newName: string;
}
}
2 changes: 1 addition & 1 deletion src/layouts/dto/save-layout-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { LayoutDto } from "./layout.dto";
export class SaveLayoutRequestDto {
@ApiProperty({ description: 'The layout to be saved'})
layout: LayoutDto;
}
}
8 changes: 4 additions & 4 deletions src/layouts/layouts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const unlinkFilePromisified = promisify(unlink);
export class FileBasedLayoutsService {


private layoutsFolder = process.env.APPS_FOLDER || "./configuration/layouts";
private layoutsFolder = process.env.LAYOUTS_FOLDER || "./configuration/layouts";
private defaultLayoutType = "default";

async getAll(): Promise<LayoutDto[]> {
Expand Down Expand Up @@ -83,9 +83,9 @@ export class FileBasedLayoutsService {
console.error("Error deleting old layout file:", error);
}

layout.name = newName;
this.saveLayout(layout);
}
layout.name = newName;
await this.saveLayout(layout);
}

getLayoutPath(layout: LayoutDto): string {
return join(this.layoutsFolder, this.getLayoutName(layout));
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

await app.listen(process.env.PORT ?? 8004);
}
bootstrap();
await app.listen(process.env.SERVER_PORT ?? 8004);
}
bootstrap();
2 changes: 1 addition & 1 deletion src/prefs/dto/add-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export class AddPrefsRequestDto {

@ApiProperty({ description: 'The actual data to be stored', type: Object})
data?: Record<string, any>;
}
}
2 changes: 1 addition & 1 deletion src/prefs/dto/get-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export class GetAppPrefsRequestDto {

@ApiProperty({ description: 'If specified will return the preferences only if they were updated after this date.', type: Date })
lastKnownUpdate?: Date;
}
}
2 changes: 1 addition & 1 deletion src/prefs/dto/prefs.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export class AppPreferencesDto {

@ApiProperty({ description: 'The last update time for the preferences of this applicaiton', type: Date })
lastKnownUpdate: Date;
}
}
2 changes: 1 addition & 1 deletion src/prefs/dto/remove-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { ApiProperty } from "@nestjs/swagger";
export class RemoveAppPrefsRequestDto {
@ApiProperty({ description: 'The name of the application' })
app?: string;
}
}
Loading