UNPKG

homebridge-config-ui-x

Version:

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

129 lines • 5.5 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 { Body, Controller, Get, Header, Inject, Post, Request, UseGuards, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { ApiBearerAuth, ApiExcludeEndpoint, ApiOperation, ApiTags } from '@nestjs/swagger'; import { PluginsService } from '../../modules/plugins/plugins.service.js'; import { ConfigService } from '../config/config.service.js'; import { Logger } from '../logger/logger.service.js'; import { AuthDto } from './auth.dto.js'; import { AuthService } from './auth.service.js'; import { CustomGuard } from './guards/custom.guard.js'; let AuthController = class AuthController { authService; configService; pluginsService; logger; constructor(authService, configService, pluginsService, logger) { this.authService = authService; this.configService = configService; this.pluginsService = pluginsService; this.logger = logger; } signIn(body) { return this.authService.signIn(body.username, body.password, body.otp); } getSettings(req) { const settings = this.configService.uiSettings(req.user); if (req.user && !this.pluginsService.isPluginManagementInProgress) { const cachedPlugins = this.pluginsService.getCachedInstalledPlugins(); if (cachedPlugins) { settings.env.hasInstalledPlugins = cachedPlugins.some(p => p.name !== this.configService.name); } else { void this.pluginsService.getInstalledPlugins().catch((e) => { this.logger.error(`Failed to warm installed-plugins cache for /auth/settings: ${e.message}.`); }); } } return settings; } getCustomWallpaper() { return this.configService.streamCustomWallpaper(); } getToken() { return this.authService.generateNoAuthToken(); } checkAuth() { return { status: 'OK' }; } refreshToken(req) { return this.authService.refreshToken(req.user); } }; __decorate([ ApiOperation({ summary: 'Exchange a username and password for an authentication token.' }), Post('login'), __param(0, Body()), __metadata("design:type", Function), __metadata("design:paramtypes", [AuthDto]), __metadata("design:returntype", void 0) ], AuthController.prototype, "signIn", null); __decorate([ Get('/settings'), ApiOperation({ summary: 'Return settings required to load the UI before authentication.' }), UseGuards(CustomGuard), __param(0, Request()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], AuthController.prototype, "getSettings", null); __decorate([ ApiExcludeEndpoint(), Get('/wallpaper/:hash'), Header('Content-Type', 'image/jpeg'), Header('Cache-Control', 'public,max-age=31536000,immutable'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], AuthController.prototype, "getCustomWallpaper", null); __decorate([ ApiOperation({ summary: 'This method can be used to obtain an access token ONLY when authentication has been disabled.' }), Post('/noauth'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], AuthController.prototype, "getToken", null); __decorate([ ApiBearerAuth(), ApiOperation({ summary: 'Check to see if an authentication token is still valid.' }), UseGuards(AuthGuard()), Get('/check'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], AuthController.prototype, "checkAuth", null); __decorate([ ApiBearerAuth(), ApiOperation({ summary: 'Refresh the authentication token to extend the session.' }), UseGuards(AuthGuard()), Post('/refresh'), __param(0, Request()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], AuthController.prototype, "refreshToken", null); AuthController = __decorate([ ApiTags('Authentication'), Controller('auth'), __param(0, Inject(AuthService)), __param(1, Inject(ConfigService)), __param(2, Inject(PluginsService)), __param(3, Inject(Logger)), __metadata("design:paramtypes", [AuthService, ConfigService, PluginsService, Logger]) ], AuthController); export { AuthController }; //# sourceMappingURL=auth.controller.js.map