homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
635 lines • 25 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 { Body, Controller, Delete, Get, HttpCode, HttpException, Inject, InternalServerErrorException, Param, Post, Put, Query, Req, UseGuards, } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { AdminGuard } from '../../core/auth/guards/admin.guard.js';
import { Logger } from '../../core/logger/logger.service.js';
import { ChildBridgesService } from '../child-bridges/child-bridges.service.js';
import { HomebridgeMdnsSettingDto, HomebridgeNetworkInterfacesDto } from './server.dto.js';
import { ServerService } from './server.service.js';
let ServerController = class ServerController {
serverService;
childBridgesService;
logger;
constructor(serverService, childBridgesService, logger) {
this.serverService = serverService;
this.childBridgesService = childBridgesService;
this.logger = logger;
}
restartServer() {
return this.serverService.restartServer();
}
restartChildBridge(deviceId) {
return this.childBridgesService.restartChildBridge(deviceId);
}
stopChildBridge(deviceId) {
return this.childBridgesService.stopChildBridge(deviceId);
}
startChildBridge(deviceId) {
return this.childBridgesService.startChildBridge(deviceId);
}
getBridgePairingInformation() {
return this.serverService.getBridgePairingInformation();
}
resetHomebridgeAccessory() {
return this.serverService.resetHomebridgeAccessory();
}
deleteAllCachedAccessories() {
return this.serverService.deleteAllCachedAccessories();
}
getCachedAccessories() {
return this.serverService.getCachedAccessories();
}
deleteCachedAccessory(uuid, cacheFile) {
return this.serverService.deleteCachedAccessory(uuid, cacheFile);
}
deleteCachedAccessories(accessories) {
return this.serverService.deleteCachedAccessories(accessories);
}
getMatterAccessories() {
return this.serverService.getMatterAccessories();
}
deleteMatterAccessory(deviceId, uuid) {
return this.serverService.deleteMatterAccessory(deviceId, uuid);
}
deleteMatterAccessories(accessories) {
return this.serverService.deleteMatterAccessories(accessories);
}
getDevicePairings() {
return this.serverService.getDevicePairings();
}
getDevicePairingById(deviceId) {
return this.serverService.getDevicePairingById(deviceId);
}
deleteDevicePairing(deviceId, resetPairingInfo) {
const resetPairingInfoBool = resetPairingInfo === 'true';
return this.serverService.deleteDevicePairing(deviceId, resetPairingInfoBool);
}
deleteDeviceMatterConfig(deviceId) {
return this.serverService.deleteDeviceMatterConfig(deviceId);
}
deleteDevicesPairings(bridges) {
return this.serverService.deleteDevicesPairing(bridges);
}
deleteDeviceAccessories(deviceId) {
return this.serverService.deleteDeviceAccessories(deviceId);
}
deleteDevicesAccessories(bridges) {
return this.serverService.deleteDevicesAccessories(bridges);
}
getNetworkOverview() {
return this.serverService.getNetworkOverview();
}
lookupUnusedPort() {
return this.serverService.lookupUnusedPort();
}
lookupUnusedMatterPort() {
return this.serverService.lookupUnusedMatterPort();
}
getSystemNetworkInterfaces() {
return this.serverService.getSystemNetworkInterfaces();
}
getHomebridgeNetworkInterfaces() {
return this.serverService.getHomebridgeNetworkInterfaces();
}
setHomebridgeNetworkInterfaces(body) {
return this.serverService.setHomebridgeNetworkInterfaces(body.adapters);
}
getHomebridgeMdnsSetting() {
return this.serverService.getHomebridgeMdnsSetting();
}
setHomebridgeMdnsSetting(body) {
return this.serverService.setHomebridgeMdnsSetting(body);
}
setHomebridgeName(body) {
return this.serverService.setHomebridgeName(body.name);
}
getHomebridgePort() {
return this.serverService.getHomebridgePort();
}
setHomebridgePort(body) {
return this.serverService.setHomebridgePort(body.port);
}
getUsablePort() {
return this.serverService.getUsablePorts();
}
setUsablePorts(body) {
return this.serverService.setUsablePorts(body);
}
async uploadWallpaper(req) {
try {
const data = await req.file();
if (data.file.truncated) {
throw new InternalServerErrorException(`Wallpaper exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`);
}
await this.serverService.uploadWallpaper(data);
}
catch (err) {
this.logger.error(`Wallpaper upload failed as ${err.message}`);
throw new InternalServerErrorException(err.message);
}
}
async uploadSslKeyCert(req) {
try {
return await this.serverService.uploadSslKeyCert(req);
}
catch (err) {
if (err instanceof HttpException) {
throw err;
}
this.logger.error(`SSL key/cert upload failed as ${err?.message}`);
throw new InternalServerErrorException(err?.message);
}
}
async uploadSslPfx(req) {
try {
return await this.serverService.uploadSslPfx(req);
}
catch (err) {
if (err instanceof HttpException) {
throw err;
}
this.logger.error(`SSL pfx upload failed as ${err?.message}`);
throw new InternalServerErrorException(err?.message);
}
}
async validateSsl() {
try {
return await this.serverService.validateCurrentSslConfig();
}
catch (err) {
if (err instanceof HttpException) {
throw err;
}
this.logger.error(`SSL validate failed as ${err?.message}`);
throw new InternalServerErrorException(err?.message);
}
}
async generateSelfSigned(body) {
try {
return await this.serverService.generateSelfSignedCertificate(body);
}
catch (err) {
if (err instanceof HttpException) {
throw err;
}
this.logger.error(`Generate self-signed certificate failed as ${err?.message}`);
throw new InternalServerErrorException(err?.message);
}
}
async deleteWallpaper() {
await this.serverService.deleteWallpaper();
}
};
__decorate([
Put('/restart'),
ApiOperation({ summary: 'Restart the Homebridge instance.' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "restartServer", null);
__decorate([
UseGuards(AdminGuard),
Put('/restart/:deviceId'),
ApiOperation({
summary: 'Restart a child bridge instance.',
}),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "restartChildBridge", null);
__decorate([
UseGuards(AdminGuard),
Put('/stop/:deviceId'),
ApiOperation({
summary: 'Stop a child bridge instance.',
}),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "stopChildBridge", null);
__decorate([
UseGuards(AdminGuard),
Put('/start/:deviceId'),
ApiOperation({
summary: 'Start a child bridge instance.',
}),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "startChildBridge", null);
__decorate([
Get('/pairing'),
ApiOperation({ summary: 'Get the Homebridge <> HomeKit pairing information and status.' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getBridgePairingInformation", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Reset the main Homebridge bridge, and change its username and pin. Also remove cached bridges and accessories.' }),
Put('/reset-homebridge-accessory'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "resetHomebridgeAccessory", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove Homebridge cached accessories.',
}),
Put('/reset-cached-accessories'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteAllCachedAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'List cached Homebridge accessories.' }),
Get('/cached-accessories'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getCachedAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove a single Homebridge cached accessory.',
}),
ApiParam({ name: 'uuid' }),
ApiQuery({ name: 'cacheFile' }),
Delete('/cached-accessories/:uuid'),
HttpCode(204),
__param(0, Param('uuid')),
__param(1, Query('cacheFile')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteCachedAccessory", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove multiple Homebridge cached accessories.',
}),
ApiBody({ description: 'Array of accessories (uuid and cacheFile) to remove from the cache', type: 'json', isArray: true }),
Delete('/cached-accessories'),
HttpCode(204),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteCachedAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'List cached Matter accessories.' }),
Get('/matter-accessories'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getMatterAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove a single Matter cached accessory.',
}),
ApiParam({ name: 'deviceId' }),
ApiParam({ name: 'uuid' }),
Delete('/matter-accessories/:deviceId/:uuid'),
HttpCode(204),
__param(0, Param('deviceId')),
__param(1, Param('uuid')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteMatterAccessory", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove multiple Matter cached accessories.',
}),
ApiBody({ description: 'Array of Matter accessories (deviceId and uuid) to remove from the cache', type: 'json', isArray: true }),
Delete('/matter-accessories'),
HttpCode(204),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteMatterAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'List all paired accessories (main bridge, external cameras, TVs etc).' }),
Get('/pairings'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getDevicePairings", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get a single device pairing.' }),
Get('/pairings/:deviceId'),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getDevicePairingById", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove a single paired bridge.',
}),
ApiParam({ name: 'deviceId' }),
ApiQuery({ name: 'resetPairingInfo', type: Boolean }),
Delete('/pairings/:deviceId'),
HttpCode(204),
__param(0, Param('deviceId')),
__param(1, Query('resetPairingInfo')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteDevicePairing", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove Matter configuration from a child bridge.',
}),
ApiParam({ name: 'deviceId' }),
Delete('/pairings/:deviceId/matter'),
HttpCode(204),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteDeviceMatterConfig", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove multiple paired bridges.',
}),
ApiBody({ description: 'Array of paired bridges (id and resetPairingInfo) to remove from the cache', type: 'json', isArray: true }),
Delete('/pairings'),
HttpCode(204),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteDevicesPairings", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove a paired bridge\'s cached accessories.',
}),
ApiParam({ name: 'deviceId' }),
Delete('/pairings/:deviceId/accessories'),
HttpCode(204),
__param(0, Param('deviceId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteDeviceAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({
summary: 'Remove multiple paired bridges\'s cached accessories.',
}),
ApiBody({ description: 'Array of bridges (id and optional protocol) for which to remove accessories.', type: 'json', isArray: true }),
Delete('/pairings/accessories'),
HttpCode(204),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "deleteDevicesAccessories", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get a unified network overview of all port assignments, Matter diagnostics, and conflict detection.' }),
Get('/network/overview'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getNetworkOverview", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return a random, unused port.' }),
Get('/port/new'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "lookupUnusedPort", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return a random, unused port from the Matter port range (5530-5541).' }),
Get('/port/new/matter'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "lookupUnusedMatterPort", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return a list of available network interfaces on the server.' }),
Get('/network-interfaces/system'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getSystemNetworkInterfaces", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return a list of the network interface names assigned to Homebridge.' }),
Get('/network-interfaces/bridge'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getHomebridgeNetworkInterfaces", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Set a list of the network interface names assigned to Homebridge.' }),
Put('/network-interfaces/bridge'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [HomebridgeNetworkInterfacesDto]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "setHomebridgeNetworkInterfaces", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Return the current mDNS advertiser settings.' }),
Get('/mdns-advertiser'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ServerController.prototype, "getHomebridgeMdnsSetting", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Set the mDNS advertiser settings.' }),
Put('/mdns-advertiser'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [HomebridgeMdnsSettingDto]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "setHomebridgeMdnsSetting", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Set the Homebridge name.' }),
Put('/name'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "setHomebridgeName", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get the Homebridge port.' }),
Get('/port'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getHomebridgePort", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Set the Homebridge port.' }),
Put('/port'),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "setHomebridgePort", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Get the usable ports as set in the config file.' }),
Get('/ports'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ServerController.prototype, "getUsablePort", null);
__decorate([
UseGuards(AdminGuard),
Put('/ports'),
ApiOperation({ summary: 'Update the usable ports for Homebridge.' }),
ApiBody({ description: 'Object with start and end properties.', type: 'json', isArray: false }),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ServerController.prototype, "setUsablePorts", null);
__decorate([
UseGuards(AdminGuard),
Post('/wallpaper'),
ApiOperation({ summary: 'Upload an image file to the Homebridge storage directory and reference this as a wallpaper in the config file.' }),
ApiConsumes('multipart/form-data'),
ApiBody({
schema: {
type: 'object',
properties: {
file: {
type: 'string',
format: 'binary',
},
},
},
}),
__param(0, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ServerController.prototype, "uploadWallpaper", null);
__decorate([
UseGuards(AdminGuard),
Post('/ssl/keycert'),
ApiOperation({ summary: 'Upload a PEM private key and certificate, validate, and save to storage, updating config.' }),
ApiConsumes('multipart/form-data'),
ApiBody({
schema: {
type: 'object',
properties: {
key: { type: 'string', format: 'binary' },
cert: { type: 'string', format: 'binary' },
files: { type: 'string', format: 'binary', description: 'Alternatively, submit both files as multiple parts with field name "files"' },
},
},
}),
__param(0, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ServerController.prototype, "uploadSslKeyCert", null);
__decorate([
UseGuards(AdminGuard),
Post('/ssl/pfx'),
ApiOperation({ summary: 'Upload a PKCS#12 (PFX/P12) file with passphrase, validate, and save to storage, updating config.' }),
ApiConsumes('multipart/form-data'),
ApiBody({
schema: {
type: 'object',
properties: {
pfx: { type: 'string', format: 'binary' },
passphrase: { type: 'string' },
},
required: ['pfx'],
},
}),
__param(0, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ServerController.prototype, "uploadSslPfx", null);
__decorate([
UseGuards(AdminGuard),
Post('/ssl/validate'),
ApiOperation({ summary: 'Validate the currently configured SSL settings (key+cert or pfx+passphrase).' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ServerController.prototype, "validateSsl", null);
__decorate([
UseGuards(AdminGuard),
Post('/ssl/selfsigned/generate'),
ApiOperation({ summary: 'Generate a self-signed certificate and optionally set it as active key/cert in config.' }),
ApiBody({
schema: {
type: 'object',
properties: {
hostnames: { type: 'array', items: { type: 'string' } },
mode: { type: 'string', enum: ['selfsigned', 'keycert'], default: 'keycert' },
},
},
}),
__param(0, Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ServerController.prototype, "generateSelfSigned", null);
__decorate([
UseGuards(AdminGuard),
ApiOperation({ summary: 'Delete the current wallpaper file and remove the reference from the config file.' }),
Delete('/wallpaper'),
HttpCode(204),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ServerController.prototype, "deleteWallpaper", null);
ServerController = __decorate([
ApiTags('Homebridge'),
ApiBearerAuth(),
UseGuards(AuthGuard()),
Controller('server'),
__param(0, Inject(ServerService)),
__param(1, Inject(ChildBridgesService)),
__param(2, Inject(Logger)),
__metadata("design:paramtypes", [ServerService,
ChildBridgesService,
Logger])
], ServerController);
export { ServerController };
//# sourceMappingURL=server.controller.js.map