Spaces:
Sleeping
Sleeping
Download src/modules/settings/settings.controller.ts from jinksQspider/openWa: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/settings/settings.controller.ts
- Command line
-
hf download hf://spaces/jinksQspider/openWa/src/modules/settings/settings.controller.ts
-
curl -L -o settings.controller.ts https://huggingface.co/spaces/jinksQspider/openWa/resolve/main/src/modules/settings/settings.controller.ts
2.57 kB
| import { Controller, Get, Put, Body } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; | |
| import { ConfigService } from '@nestjs/config'; | |
| import { RequireRole } from '../auth/decorators/auth.decorators'; | |
| import { ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| interface Settings { | |
| general: { | |
| apiBaseUrl: string; | |
| sessionTimeout: number; | |
| autoReconnect: boolean; | |
| debugMode: boolean; | |
| }; | |
| api: { | |
| rateLimit: number; | |
| rateLimitWindow: number; | |
| enableDocs: boolean; | |
| }; | |
| notifications: { | |
| emailEnabled: boolean; | |
| notificationEmail: string; | |
| webhookAlerts: boolean; | |
| }; | |
| } | |
| ('settings') | |
| ('settings') | |
| export class SettingsController { | |
| private settings: Settings; | |
| constructor(private readonly configService: ConfigService) { | |
| // Initialize with values from configuration (reads from .env) | |
| const port = this.configService.get<number>('port', 2785); | |
| this.settings = { | |
| general: { | |
| apiBaseUrl: `http://localhost:${port}`, | |
| sessionTimeout: Math.floor(this.configService.get<number>('webhook.timeout', 300000) / 60000), | |
| autoReconnect: this.configService.get<boolean>('engine.autoReconnect', false), | |
| debugMode: this.configService.get<boolean>('database.logging', false), | |
| }, | |
| api: { | |
| rateLimit: this.configService.get<number>('api.rateLimit.mediumLimit', 100), | |
| rateLimitWindow: this.configService.get<number>('api.rateLimit.mediumTtl', 60000), | |
| enableDocs: true, // Swagger docs always enabled | |
| }, | |
| notifications: { | |
| emailEnabled: false, | |
| notificationEmail: '', | |
| webhookAlerts: true, | |
| }, | |
| }; | |
| } | |
| () | |
| ({ summary: 'Get application settings' }) | |
| ({ status: 200, description: 'Current settings' }) | |
| get(): Settings { | |
| return this.settings; | |
| } | |
| () | |
| (ApiKeyRole.ADMIN) | |
| ({ summary: 'Update application settings' }) | |
| ({ status: 200, description: 'Settings updated' }) | |
| update(() newSettings: Partial<Settings>): Settings { | |
| if (newSettings.general) { | |
| this.settings.general = { | |
| ...this.settings.general, | |
| ...newSettings.general, | |
| }; | |
| } | |
| if (newSettings.api) { | |
| this.settings.api = { ...this.settings.api, ...newSettings.api }; | |
| } | |
| if (newSettings.notifications) { | |
| this.settings.notifications = { | |
| ...this.settings.notifications, | |
| ...newSettings.notifications, | |
| }; | |
| } | |
| return this.settings; | |
| } | |
| } | |