Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added limit api and improvements #13

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions Backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.2.10",
"@nestjs/platform-ws": "^10.2.10",
"@nestjs/swagger": "^7.1.16",
"@nestjs/websockets": "^10.2.10",
"bcrypt": "^5.1.1",
Expand All @@ -46,33 +45,23 @@
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^10.0.28-alpha",
"@types/eslint": "^8.44.7",
"@types/eslint-config-prettier": "^6.11.3",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.10",
"@types/node": "^20.3.1",
"@types/node-telegram-bot-api": "^0.63.3",
"@types/simple-peer": "^9.11.8",
"@types/source-map-support": "^0.5.10",
"@types/supertest": "^2.0.12",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
}
}
2 changes: 2 additions & 0 deletions Backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CameraStreamGateway } from './cameraStream/cameraStream.gateway';
import { LoginService } from './login/login.service';
import { MediaServerController } from './app/mediaServer/mediaServer.controller';
import { CSSOpenVidu } from './cameraStream/open-vidu.service';
import { SharedController } from './app/shared/shared.controller';

@Module({
imports: [
Expand All @@ -30,6 +31,7 @@ import { CSSOpenVidu } from './cameraStream/open-vidu.service';
FrontendController,
LoginController,
MediaServerController,
SharedController,
],
providers: [
DatabaseService,
Expand Down
46 changes: 41 additions & 5 deletions Backend/src/app/frontend/frontend.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Get,
Header,
Param,
Post,
StreamableFile,
UseGuards,
} from '@nestjs/common';
Expand All @@ -20,10 +21,7 @@ import {
FiltersAvailable,
FiltersValidator,
} from '../../validators/filters/filters.pipe';
import {
CameraIds,
CameraValidator,
} from '../../validators/camera-id/camera.pipe';
import { PositiveNumberValidator } from '../../validators/camera-id/camera.pipe';
import { AuthGuard } from '../../auth/auth.guard';

const filterParams = {
Expand Down Expand Up @@ -73,6 +71,20 @@ export class FrontendController {
return this.databaseService.getData(filter);
}

@ApiParam(filterParams)
@ApiParam({
name: 'limit',
type: 'number',
example: 10,
})
@Get(`:filter(${filters.join('|')})/:limit(\\d+)`)
getValuesLimit(
@Param('filter', FiltersValidator) filter: FiltersAvailable,
@Param('limit', PositiveNumberValidator) limit: number,
) {
return this.databaseService.getData(filter, limit);
}

@ApiParam({
name: 'id',
type: 'number',
Expand All @@ -87,7 +99,7 @@ export class FrontendController {
@Header('Content-Type', 'image/jpeg')
@Get('/:id(\\d+)/:timestamp')
async getImage(
@Param('id', CameraValidator) cameraId: CameraIds,
@Param('id', PositiveNumberValidator) cameraId: number,
@Param('timestamp') timestamp: string,
) {
const array = await this.databaseService.getRawDataArray('cameras', {
Expand All @@ -97,4 +109,28 @@ export class FrontendController {

return new StreamableFile(array[0].intrusionDetection.buffer);
}

@Post('/:id(\\d+)/:name')
@ApiParam({
name: 'id',
type: 'number',
example: 1,
})
@ApiParam({
name: 'name',
type: 'string',
example: 'Kitchen',
})
async setChannelName(
@Param('id', PositiveNumberValidator) id: number,
@Param('name') name: string,
) {
try {
await this.databaseService.setChannelName(id, name);
return 'OK';
} catch (e) {
console.error(e);
return 'ERROR' + e;
}
}
}
9 changes: 3 additions & 6 deletions Backend/src/app/machineLearning/machineLearning.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import {
ApiProperty,
ApiTags,
} from '@nestjs/swagger';
import {
CameraIds,
CameraValidator,
} from '../../validators/camera-id/camera.pipe';
import { PositiveNumberValidator } from '../../validators/camera-id/camera.pipe';
import { AuthGuard } from '../../auth/auth.guard';
import { TelegramService } from '../../telegram/telegram.service';

Expand Down Expand Up @@ -80,7 +77,7 @@ export class MachineLearningController {
@UseGuards(AuthGuard)
@Post(`:status(online|offline)`)
saveStatus(
@Param('id', CameraValidator) cameraId: CameraIds,
@Param('id', PositiveNumberValidator) cameraId: number,
@Param('status') status: string,
) {
// Following condition could be removed as the path can only be online or offline
Expand Down Expand Up @@ -112,7 +109,7 @@ export class MachineLearningController {
@UseInterceptors(FileInterceptor('file'))
@Post()
async uploadImage(
@Param('id', CameraValidator) cameraId: CameraIds,
@Param('id', PositiveNumberValidator) cameraId: number,
@UploadedFile(
new ParseFilePipeBuilder()
.addFileTypeValidator({ fileType: 'image/jpeg' })
Expand Down
21 changes: 2 additions & 19 deletions Backend/src/app/mediaServer/mediaServer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import { Body, Controller, Get, Header, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Header, Post } from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiCreatedResponse,
ApiNotFoundResponse,
ApiOkResponse,
ApiParam,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { AuthGuard } from '../../auth/auth.guard';
import { CameraStreamGateway } from 'src/cameraStream/cameraStream.gateway';

type ParticipantLeft = {
event: 'participantLeft';
timestamp: number;
sessionId: string;
startTime: number;
duration: number;
reason: string;
connectionId: string;
location: string;
ip: string;
platform: string;
clientData: string;
serverData: string;
};

@ApiTags('Media Server')
@ApiBearerAuth('CSS-Auth')
@ApiOkResponse()
Expand All @@ -45,7 +28,7 @@ export class MediaServerController {
@ApiCreatedResponse()
@ApiNotFoundResponse()
@Header('Content-Type', 'application/json')
@Post('media-server')
@Post('/media-server')
async getMediaServerEvents(@Body() event: any) {
console.log(event);
this.cameraStreamGateway.broadcastEvent(event);
Expand Down
20 changes: 20 additions & 0 deletions Backend/src/app/shared/shared.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SharedController } from './shared.controller';
import { DatabaseService } from '../../database/database.service';

describe('SharedController', () => {
let controller: SharedController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SharedController],
providers: [DatabaseService],
}).compile();

controller = module.get<SharedController>(SharedController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
40 changes: 40 additions & 0 deletions Backend/src/app/shared/shared.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Controller, Get, Param } from '@nestjs/common';
import { DatabaseService } from '../../database/database.service';
import { PositiveNumberValidator } from '../../validators/camera-id/camera.pipe';
import { ApiParam, ApiTags } from '@nestjs/swagger';

// This defines a shared controller between Frontend and Machine Learning
@ApiTags('Shared')
@Controller('shared')
export class SharedController {
constructor(private readonly databaseService: DatabaseService) {}

@Get('/nvr')
async getNVR() {
return await this.databaseService.getNVRData();
}

// @Get('/channel')
// async getChannel() {
// return await this.databaseService.getChannelName();
// }

@ApiParam({
name: 'id',
type: 'string',
required: false,
examples: {
undefined: {
description: 'sends an undefined value',
value: undefined,
},
camera: {
value: '1',
},
},
})
@Get('/channel/:id(\\d+|,)?')
async getChannelId(@Param('id', PositiveNumberValidator) id?: number) {
return await this.databaseService.getChannelName(id);
}
}
Loading
Loading