Spaces:
Running
Running
| import { | |
| Controller, | |
| Post, | |
| Body, | |
| Get, | |
| HttpCode, | |
| HttpStatus, | |
| Logger, | |
| } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger'; | |
| import { DirectService } from './direct.service'; | |
| import { | |
| DirectDecodeHashDto, | |
| DirectDecodeHashResponseDto, | |
| DirectHealthStatsDto, | |
| } from './direct.dto'; | |
| ('direct') | |
| ('direct') | |
| export class DirectController { | |
| private readonly logger = new Logger(DirectController.name); | |
| constructor(private readonly directService: DirectService) {} | |
| ('decode') | |
| (HttpStatus.OK) | |
| ({ | |
| summary: 'Decode a hash using direct connection', | |
| description: | |
| 'Decode a hash string using direct connection to the API without proxies', | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Hash decoded successfully', | |
| type: DirectDecodeHashResponseDto, | |
| }) | |
| ({ | |
| status: 400, | |
| description: 'Invalid hash format or empty hash', | |
| }) | |
| ({ | |
| status: 404, | |
| description: 'Hash not found', | |
| }) | |
| ({ | |
| status: 429, | |
| description: 'Rate limit exceeded', | |
| }) | |
| ({ | |
| status: 500, | |
| description: 'Internal server error', | |
| }) | |
| ({ type: DirectDecodeHashDto }) | |
| async decodeHash( | |
| () directDecodeHashDto: DirectDecodeHashDto, | |
| ): Promise<DirectDecodeHashResponseDto> { | |
| this.logger.log( | |
| `π Direct decode request received for hash: ${directDecodeHashDto.hash.substring(0, 8)}...`, | |
| ); | |
| try { | |
| const result = await this.directService.decodeHash(directDecodeHashDto); | |
| this.logger.log( | |
| `β Direct decode successful for hash: ${directDecodeHashDto.hash.substring(0, 8)}... (${result.responseTime}ms)`, | |
| ); | |
| return result; | |
| } catch (error) { | |
| this.logger.error( | |
| `β Direct decode failed for hash: ${directDecodeHashDto.hash.substring(0, 8)}... - ${error.message}`, | |
| ); | |
| throw error; | |
| } | |
| } | |
| ('health') | |
| ({ | |
| summary: 'Get direct service health statistics', | |
| description: | |
| 'Retrieve comprehensive health and performance statistics for the direct decoder service', | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Health statistics retrieved successfully', | |
| type: DirectHealthStatsDto, | |
| }) | |
| getHealthStats(): DirectHealthStatsDto { | |
| this.logger.log('π Direct service health stats requested'); | |
| return this.directService.getHealthStats(); | |
| } | |
| ('reset-stats') | |
| (HttpStatus.OK) | |
| ({ | |
| summary: 'Reset service statistics', | |
| description: 'Reset all performance statistics for the direct service', | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Statistics reset successfully', | |
| }) | |
| resetStats(): { message: string; previousStats: any } { | |
| this.logger.log('π Resetting direct service statistics'); | |
| return this.directService.resetStats(); | |
| } | |
| ('status') | |
| ({ | |
| summary: 'Get service status', | |
| description: | |
| 'Get current status and basic information about the direct service', | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Service status retrieved successfully', | |
| }) | |
| getStatus(): { | |
| service: string; | |
| status: string; | |
| connectionMethod: string; | |
| features: string[]; | |
| timestamp: string; | |
| } { | |
| this.logger.log('π Direct service status requested'); | |
| return { | |
| service: 'DirectService', | |
| status: 'operational', | |
| connectionMethod: 'direct', | |
| features: [ | |
| 'Direct API connection', | |
| 'No proxy dependencies', | |
| 'Built-in rate limiting', | |
| 'Response time tracking', | |
| 'Automatic retries', | |
| 'SSL/TLS support', | |
| ], | |
| timestamp: new Date().toISOString(), | |
| }; | |
| } | |
| } | |