Compare commits
1 Commits
main
...
docker-imp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e98348cac |
@@ -1,5 +1,4 @@
|
||||
PORT=3101
|
||||
branch=
|
||||
DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud
|
||||
|
||||
# Optional. When set, POST /api/ingest requires x-api-key: <value>.
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
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
|
||||
@@ -1,6 +1,5 @@
|
||||
services:
|
||||
drill-cloud-v3:
|
||||
container_name: container-drill-cloud-v3${branch:+-${branch}}
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
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);
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE current
|
||||
ALTER COLUMN value DROP NOT NULL;
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CameraModule } from './camera/camera.module';
|
||||
import { CurrentModule } from './current/current.module';
|
||||
import { DbModule } from './db/db.module';
|
||||
import { EdgeModule } from './edge/edge.module';
|
||||
@@ -11,7 +10,6 @@ import { TagModule } from './tag/tag.module';
|
||||
@Module({
|
||||
imports: [
|
||||
DbModule,
|
||||
CameraModule,
|
||||
IngestModule,
|
||||
EdgeModule,
|
||||
CurrentModule,
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
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,
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
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 {}
|
||||
@@ -1,22 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export type CameraRow = {
|
||||
protocol: string;
|
||||
source: string;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
export type CameraItemDto = {
|
||||
protocol: string;
|
||||
source: string;
|
||||
};
|
||||
|
||||
export type CameraResponseDto = {
|
||||
edge: string;
|
||||
items: CameraItemDto[];
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class GetCamerasDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
edge!: string;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { applyDecorators } from '@nestjs/common';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsNumber, ValidateIf, ValidationOptions } from 'class-validator';
|
||||
|
||||
export function IsNullableNumber(options?: ValidationOptions): PropertyDecorator {
|
||||
return applyDecorators(
|
||||
Transform(({ value }) => (value === null ? null : Number(value))),
|
||||
ValidateIf((_, value) => value !== null),
|
||||
IsNumber({}, options),
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export type CurrentRow = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
value: number | null;
|
||||
value: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
name: string | null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type CurrentItemDto = {
|
||||
edge: string;
|
||||
tag: string;
|
||||
value: number | null;
|
||||
value: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
time: Date;
|
||||
|
||||
@@ -5,5 +5,5 @@ export class IngestEdgeValuesDto {
|
||||
timestamp!: string;
|
||||
|
||||
@IsObject()
|
||||
values!: Record<string, number | null>;
|
||||
values!: Record<string, number>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IsDateString, IsNotEmpty, IsString } from 'class-validator';
|
||||
import { IsNullableNumber } from '../../common/is-nullable-number.decorator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDateString, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class IngestPointDto {
|
||||
@IsNotEmpty()
|
||||
@@ -13,6 +13,7 @@ export class IngestPointDto {
|
||||
@IsDateString()
|
||||
timestamp!: string;
|
||||
|
||||
@IsNullableNumber()
|
||||
value!: number | null;
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
value!: number;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export class IngestController {
|
||||
const points = Object.entries(body.values).map(([tag, value]) => ({
|
||||
edge,
|
||||
tag,
|
||||
value,
|
||||
value: Number(value),
|
||||
timestamp: body.timestamp,
|
||||
}));
|
||||
|
||||
|
||||
@@ -10,17 +10,15 @@ type IngestResult = {
|
||||
export class IngestService {
|
||||
constructor(private readonly db: DbService) {}
|
||||
|
||||
/** Пишет числовую точку в history и всегда обновляет текущий снимок current для UI/SSE. */
|
||||
/** Пишет одну входящую точку в history и обновляет текущий снимок current для UI/SSE. */
|
||||
async ingestPoint(point: IngestPointDto): Promise<IngestResult> {
|
||||
if (point.value !== null) {
|
||||
await this.db.query(
|
||||
`
|
||||
INSERT INTO history (timestamp, edge, tag, value)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`,
|
||||
[point.timestamp, point.edge, point.tag, point.value],
|
||||
);
|
||||
}
|
||||
await this.db.query(
|
||||
`
|
||||
INSERT INTO history (timestamp, edge, tag, value)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`,
|
||||
[point.timestamp, point.edge, point.tag, point.value],
|
||||
);
|
||||
|
||||
await this.db.query(
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user