Spaces:
Sleeping
Sleeping
File size: 2,424 Bytes
525d39f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import { Controller, Get, Post, Put, Param, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { PluginsService } from './plugins.service';
import { PluginDto, PluginConfigDto } from './dto/plugin.dto';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
@ApiTags('plugins')
@Controller('plugins')
export class PluginsController {
constructor(private readonly pluginsService: PluginsService) {}
@Get()
@ApiOperation({ summary: 'List all plugins' })
@ApiResponse({ status: 200, description: 'List of all plugins' })
findAll(): PluginDto[] {
return this.pluginsService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get plugin by ID' })
@ApiResponse({ status: 200, description: 'Plugin details' })
@ApiResponse({ status: 404, description: 'Plugin not found' })
findOne(@Param('id') id: string): PluginDto {
return this.pluginsService.findOne(id);
}
@Post(':id/enable')
@RequireRole(ApiKeyRole.ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Enable a plugin' })
@ApiResponse({ status: 200, description: 'Plugin enabled successfully' })
async enable(@Param('id') id: string): Promise<{ success: boolean; message: string }> {
return await this.pluginsService.enable(id);
}
@Post(':id/disable')
@RequireRole(ApiKeyRole.ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Disable a plugin' })
@ApiResponse({ status: 200, description: 'Plugin disabled successfully' })
async disable(@Param('id') id: string): Promise<{ success: boolean; message: string }> {
return await this.pluginsService.disable(id);
}
@Put(':id/config')
@RequireRole(ApiKeyRole.ADMIN)
@ApiOperation({ summary: 'Update plugin configuration' })
@ApiResponse({ status: 200, description: 'Plugin configuration updated' })
updateConfig(@Param('id') id: string, @Body() configDto: PluginConfigDto): { success: boolean; message: string } {
return this.pluginsService.updateConfig(id, configDto.config);
}
@Get(':id/health')
@ApiOperation({ summary: 'Check plugin health' })
@ApiResponse({ status: 200, description: 'Plugin health status' })
async healthCheck(@Param('id') id: string): Promise<{ healthy: boolean; message?: string }> {
return await this.pluginsService.healthCheck(id);
}
}
|