1 Commits

Author SHA1 Message Date
Первов Артем
203bdf193e BUR-58 Добавлена поддержка работы с камерой 2026-07-05 06:57:54 +03:00
13 changed files with 126 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
PORT=3101 PORT=3101
branch=
DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud
# Optional. When set, POST /api/ingest requires x-api-key: <value>. # Optional. When set, POST /api/ingest requires x-api-key: <value>.

19
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,19 @@
services:
drill-cloud-v3-dev:
container_name: container-drill-cloud-v3${branch:+-${branch}}
build: .
restart: unless-stopped
environment:
NODE_ENV: production
PORT: ${PORT}
DATABASE_URL: ${DATABASE_URL}
INGEST_API_KEY: ${INGEST_API_KEY}
CURRENT_EVENTS_POLL_MS: ${CURRENT_EVENTS_POLL_MS}
expose:
- "3101"
networks:
- proxy
networks:
proxy:
external: true

View File

@@ -1,5 +1,6 @@
services: services:
drill-cloud-v3: drill-cloud-v3:
container_name: container-drill-cloud-v3${branch:+-${branch}}
build: . build: .
restart: unless-stopped restart: unless-stopped
environment: environment:

View File

@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS camera (
edge varchar NOT NULL,
protocol varchar NOT NULL,
source varchar NOT NULL,
PRIMARY KEY (edge, protocol, source)
);
CREATE INDEX IF NOT EXISTS camera_edge_idx ON camera (edge);

View File

@@ -1,4 +1,5 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { CameraModule } from './camera/camera.module';
import { CurrentModule } from './current/current.module'; import { CurrentModule } from './current/current.module';
import { DbModule } from './db/db.module'; import { DbModule } from './db/db.module';
import { EdgeModule } from './edge/edge.module'; import { EdgeModule } from './edge/edge.module';
@@ -10,6 +11,7 @@ import { TagModule } from './tag/tag.module';
@Module({ @Module({
imports: [ imports: [
DbModule, DbModule,
CameraModule,
IngestModule, IngestModule,
EdgeModule, EdgeModule,
CurrentModule, CurrentModule,

View File

@@ -0,0 +1,16 @@
import { Controller, Get, Header, Query } from '@nestjs/common';
import { CameraService } from './camera.service';
import { GetCamerasDto } from './dto/get-cameras.dto';
@Controller('camera')
export class CameraController {
constructor(private readonly camera: CameraService) {}
@Get()
@Header('Cache-Control', 'no-store')
@Header('Pragma', 'no-cache')
@Header('Expires', '0')
findByEdge(@Query() query: GetCamerasDto) {
return this.camera.findByEdge(query);
}
}

View File

@@ -0,0 +1,12 @@
import { CameraResponseDto } from './dto/camera-response.dto';
import { CameraRow } from './camera.types';
export function createCameraResponse(edge: string, rows: CameraRow[]): CameraResponseDto {
return {
edge,
items: rows.map((row) => ({
protocol: row.protocol,
source: row.source,
})),
};
}

View File

@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { CameraController } from './camera.controller';
import { CameraRepository } from './camera.repository';
import { CameraService } from './camera.service';
@Module({
controllers: [CameraController],
providers: [CameraService, CameraRepository],
})
export class CameraModule {}

View File

@@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { DbService } from '../db/db.service';
import { CameraRow } from './camera.types';
@Injectable()
export class CameraRepository {
constructor(private readonly db: DbService) {}
async findByEdge(edge: string): Promise<CameraRow[]> {
const result = await this.db.query<CameraRow>(
`
SELECT protocol, source
FROM camera
WHERE edge = $1
ORDER BY source ASC
`,
[edge],
);
return result.rows;
}
}

View File

@@ -0,0 +1,15 @@
import { Injectable } from '@nestjs/common';
import { CameraResponseDto } from './dto/camera-response.dto';
import { GetCamerasDto } from './dto/get-cameras.dto';
import { createCameraResponse } from './camera.mapper';
import { CameraRepository } from './camera.repository';
@Injectable()
export class CameraService {
constructor(private readonly repository: CameraRepository) {}
async findByEdge(query: GetCamerasDto): Promise<CameraResponseDto> {
const rows = await this.repository.findByEdge(query.edge);
return createCameraResponse(query.edge, rows);
}
}

View File

@@ -0,0 +1,4 @@
export type CameraRow = {
protocol: string;
source: string;
};

View File

@@ -0,0 +1,9 @@
export type CameraItemDto = {
protocol: string;
source: string;
};
export type CameraResponseDto = {
edge: string;
items: CameraItemDto[];
};

View File

@@ -0,0 +1,7 @@
import { IsNotEmpty, IsString } from 'class-validator';
export class GetCamerasDto {
@IsNotEmpty()
@IsString()
edge!: string;
}