UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

230 lines • 9.13 kB
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 { Controller, Delete, Get, Inject, InternalServerErrorException, Param, Post, Put, Req, Res, UseGuards, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiParam, ApiTags, } from '@nestjs/swagger'; import { AdminGuard } from '../../core/auth/guards/admin.guard.js'; import { Logger } from '../../core/logger/logger.service.js'; import { BackupService } from './backup.service.js'; let BackupController = class BackupController { backupService; logger; constructor(backupService, logger) { this.backupService = backupService; this.logger = logger; } async createBackupInDirectory() { return await this.backupService.createBackupInDirectory(); } async downloadBackup(res) { try { return await this.backupService.downloadBackup(res); } catch (e) { console.error(e); this.logger.error(`Backup Failed ${e}`); throw new InternalServerErrorException(e.message); } } async getNextBackupTime() { return this.backupService.getNextBackupTime(); } async listScheduledBackups() { return this.backupService.listScheduledBackups(); } async getScheduledBackup(backupId) { return this.backupService.getScheduledBackup(backupId); } async deleteScheduledBackup(backupId) { await this.backupService.deleteScheduledBackup(backupId); } async restoreScheduledBackup(backupId) { return this.backupService.restoreScheduledBackup(backupId); } async restoreBackup(req) { try { const data = await req.file(); if (data.file.truncated) { throw new InternalServerErrorException(`Restore file exceeds maximum size ${globalThis.backup.maxBackupSizeText}.`); } else { await this.backupService.uploadBackupRestore(data); } } catch (err) { this.logger.error(`Restore backup failed as ${err.message}`); throw new InternalServerErrorException(err.message); } } async restoreBackupTrigger() { return await this.backupService.triggerHeadlessRestore(); } async restoreHbfx(req) { try { const data = await req.file(); await this.backupService.uploadHbfxRestore(data); } catch (err) { this.logger.error(`Restore backup failed as ${err.message}`); throw new InternalServerErrorException(err.message); } } postBackupRestoreRestart() { return this.backupService.postBackupRestoreRestart(); } }; __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Create a backup file and save it in the backup directory.' }), Post('/'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], BackupController.prototype, "createBackupInDirectory", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Download a `.tar.gz` of the Homebridge instance.' }), Get('/download'), __param(0, Res({ passthrough: true })), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], BackupController.prototype, "downloadBackup", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Return the date and time of the next scheduled backup.' }), Get('/scheduled-backups/next'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], BackupController.prototype, "getNextBackupTime", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'List available system generated instance backups.' }), Get('/scheduled-backups'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], BackupController.prototype, "listScheduledBackups", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Download a system generated instance backup.' }), ApiParam({ name: 'backupId', type: 'string' }), Get('/scheduled-backups/:backupId'), __param(0, Param('backupId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], BackupController.prototype, "getScheduledBackup", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Delete a system generated instance backup.' }), ApiParam({ name: 'backupId', type: 'string' }), Delete('/scheduled-backups/:backupId'), __param(0, Param('backupId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], BackupController.prototype, "deleteScheduledBackup", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Extract a system generated instance backup into the restore directory.', description: 'NOTE: This endpoint does not trigger the restore process.', }), ApiParam({ name: 'backupId', type: 'string' }), Post('/scheduled-backups/:backupId/restore'), __param(0, Param('backupId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], BackupController.prototype, "restoreScheduledBackup", null); __decorate([ UseGuards(AdminGuard), Post('/restore'), ApiOperation({ summary: 'Upload a `.tar.gz` of the Homebridge instance.', description: 'NOTE: This endpoint does not trigger the restore process.', }), 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) ], BackupController.prototype, "restoreBackup", null); __decorate([ UseGuards(AdminGuard), Put('/restore/trigger'), ApiOperation({ summary: 'Triggers a headless restore process from the last uploaded backup file.', description: 'Logs to `stdout`/`stderr`.', }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], BackupController.prototype, "restoreBackupTrigger", null); __decorate([ UseGuards(AdminGuard), ApiOperation({ summary: 'Upload a `.hbfx` backup file created by third party apps.', description: 'NOTE: This endpoint does not trigger the restore process.', }), ApiConsumes('multipart/form-data'), ApiBody({ schema: { type: 'object', properties: { file: { type: 'string', format: 'binary', }, }, }, }), Post('/restore/hbfx'), __param(0, Req()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], BackupController.prototype, "restoreHbfx", null); __decorate([ UseGuards(AdminGuard), Put('/restart'), ApiOperation({ summary: 'Trigger a hard restart of Homebridge (use after restoring backup).' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], BackupController.prototype, "postBackupRestoreRestart", null); BackupController = __decorate([ ApiTags('Backup & Restore'), ApiBearerAuth(), UseGuards(AuthGuard()), Controller('backup'), __param(0, Inject(BackupService)), __param(1, Inject(Logger)), __metadata("design:paramtypes", [BackupService, Logger]) ], BackupController); export { BackupController }; //# sourceMappingURL=backup.controller.js.map