homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
113 lines • 4.65 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Inject, UseGuards, UsePipes, ValidationPipe } from '@nestjs/common';
import { SubscribeMessage, WebSocketGateway, WsException } from '@nestjs/websockets';
import { red } from 'bash-color';
import { WsAdminGuard } from '../../core/auth/guards/ws-admin-guard.js';
import { devServerCorsConfig } from '../../core/cors.config.js';
import { Logger } from '../../core/logger/logger.service.js';
import { HomebridgeUpdateActionDto, PluginActionDto } from './plugins.dto.js';
import { PluginsService } from './plugins.service.js';
let PluginsGateway = class PluginsGateway {
pluginsService;
logger;
constructor(pluginsService, logger) {
this.pluginsService = pluginsService;
this.logger = logger;
}
async installPlugin(client, pluginAction) {
try {
return await this.pluginsService.managePlugin('install', pluginAction, client);
}
catch (e) {
this.logger.error(e);
client.emit('stdout', `\n\r${red(e.toString())}\n\r`);
return new WsException(e);
}
}
async uninstallPlugin(client, pluginAction) {
try {
return await this.pluginsService.managePlugin('uninstall', pluginAction, client);
}
catch (e) {
this.logger.error(e);
client.emit('stdout', `\n\r${red(e.toString())}\n\r`);
return new WsException(e);
}
}
async updatePlugin(client, pluginAction) {
try {
return await this.pluginsService.managePlugin('install', pluginAction, client);
}
catch (e) {
this.logger.error(e);
client.emit('stdout', `\n\r${red(e.toString())}\n\r`);
return new WsException(e);
}
}
async homebridgeUpdate(client, homebridgeUpdateAction) {
try {
return await this.pluginsService.updateHomebridgePackage(homebridgeUpdateAction, client);
}
catch (e) {
this.logger.error(e);
client.emit('stdout', `\n\r${red(e.toString())}\n\r`);
return new WsException(e);
}
}
};
__decorate([
SubscribeMessage('install'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function, PluginActionDto]),
__metadata("design:returntype", Promise)
], PluginsGateway.prototype, "installPlugin", null);
__decorate([
SubscribeMessage('uninstall'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function, PluginActionDto]),
__metadata("design:returntype", Promise)
], PluginsGateway.prototype, "uninstallPlugin", null);
__decorate([
SubscribeMessage('update'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function, PluginActionDto]),
__metadata("design:returntype", Promise)
], PluginsGateway.prototype, "updatePlugin", null);
__decorate([
SubscribeMessage('homebridge-update'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Function, HomebridgeUpdateActionDto]),
__metadata("design:returntype", Promise)
], PluginsGateway.prototype, "homebridgeUpdate", null);
PluginsGateway = __decorate([
UseGuards(WsAdminGuard),
WebSocketGateway({
namespace: '/plugins',
allowEIO3: true,
cors: devServerCorsConfig,
}),
UsePipes(new ValidationPipe({
whitelist: true,
exceptionFactory: (err) => {
console.error(err);
return new WsException(err);
},
})),
__param(0, Inject(PluginsService)),
__param(1, Inject(Logger)),
__metadata("design:paramtypes", [PluginsService,
Logger])
], PluginsGateway);
export { PluginsGateway };
//# sourceMappingURL=plugins.gateway.js.map