import { Body, Controller, Delete, Param, Post, Req } from '@nestjs/common'; import { Request } from 'express'; import { PlatformControlService } from './platform-control.service'; @Controller('platform-control') export class PlatformControlController { constructor(private readonly platformControlService: PlatformControlService) {} @Post('platforms/statuses') getPlatformStatuses( @Req() request: Request, @Body() body: { platformIds?: string[] }, ) { return this.platformControlService.getPlatformStatuses( this.getBearerToken(request), body.platformIds ?? [], ); } @Post('platforms/:platformId/request') requestControl(@Req() request: Request, @Param('platformId') platformId: string) { return this.platformControlService.requestControl( this.getBearerToken(request), platformId, ); } @Delete('platforms/:platformId/queue') cancelQueue(@Req() request: Request, @Param('platformId') platformId: string) { return this.platformControlService.cancelQueue( this.getBearerToken(request), platformId, ); } @Post('platforms/:platformId/release') releaseControl(@Req() request: Request, @Param('platformId') platformId: string) { return this.platformControlService.releaseControl( this.getBearerToken(request), platformId, ); } @Post('platforms/:platformId/connect') connectPlatform(@Req() request: Request, @Param('platformId') platformId: string) { return this.platformControlService.connectPlatform( this.getBearerToken(request), platformId, ); } @Post('platforms/:platformId/modules/list') listRemoteModules(@Req() request: Request, @Param('platformId') platformId: string) { return this.platformControlService.listRemoteModules( this.getBearerToken(request), platformId, ); } @Post('platforms/:platformId/modules/start') startRemoteModule( @Req() request: Request, @Param('platformId') platformId: string, @Body() body: { folderName?: string; rosDomainId?: string }, ) { return this.platformControlService.startRemoteModule( this.getBearerToken(request), platformId, body, ); } @Post('platforms/:platformId/modules/stop') stopRemoteModule( @Req() request: Request, @Param('platformId') platformId: string, @Body() body: { containerKey?: string }, ) { return this.platformControlService.stopRemoteModule( this.getBearerToken(request), platformId, body, ); } private getBearerToken(request: Request): string | undefined { const [type, token] = request.headers.authorization?.split(' ') ?? []; return type === 'Bearer' ? token : undefined; } }