Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 23, 2022
1 parent d5c356d commit ac1c9ed
Show file tree
Hide file tree
Showing 31 changed files with 418 additions and 287 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
All notable changes to this project will be documented in this file.

# v1.1.3 - 2022-01-23

## Other Changes
- Refactored recordings/notifications filter
- Refactored config generator

## Bugfixes
- Fixed an issue where camera names were displayed incorrectly in recordings
- Fixed an issue where the recordings/notifications could not be filtered properly
- Fixed an issue where config.json was not created in standalone mode
- Fixed an issue where deleting the camera via the interface caused errors
- Minor bugfixes

# v1.1.2 - 2022-01-22

## Bugfixes
Expand Down
7 changes: 5 additions & 2 deletions bin/camera.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ process.env.CUI_STORAGE_DATABASE_PATH = path.resolve(storagePath, 'database');
process.env.CUI_STORAGE_DATABASE_USER_PATH = path.resolve(storagePath, 'database', 'user');
process.env.CUI_STORAGE_DATABASE_FILE = path.resolve(storagePath, 'database', 'database.json');
process.env.CUI_STORAGE_LOG_PATH = path.resolve(storagePath, 'logs');
process.env.CUI_STORAGE_LOG_FILE = path.resolve(storagePath, 'logs', 'camera.ui.log.txt');
process.env.CUI_STORAGE_LOG_FILE = path.resolve(storagePath, 'logs', 'camera.ui.log');
process.env.CUI_STORAGE_RECORDINGS_PATH = path.resolve(storagePath, 'recordings');
process.env.CUI_STORAGE_REPORTS_PATH = path.resolve(storagePath, 'reports');

process.env.CUI_MODULE_NAME = moduleName;
process.env.CUI_MODULE_VERSION = packageJson.version;
Expand All @@ -68,7 +69,9 @@ process.env.CUI_MODULE_SUDO = sudoEnabled;
process.env.CUI_VERSION = packageJson.version;

const logger = new LoggerService();
const config = new ConfigService();

const configJson = fs.readJSONSync(process.env.CUI_STORAGE_CONFIG_FILE, { throws: false });
const config = new ConfigService(configJson);

if (cluster.isPrimary) {
const { log } = LoggerService;
Expand Down
48 changes: 24 additions & 24 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.1.2",
"version": "1.1.3",
"description": "NVR like user interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"fs-extra": "10.0.0",
"ftp-srv": "^4.5.0",
"got": "^12.0.1",
"helmet": "^5.0.1",
"helmet": "^5.0.2",
"ip": "^1.1.5",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
Expand All @@ -58,7 +58,7 @@
"web-push": "^3.4.5"
},
"devDependencies": {
"@babel/core": "^7.16.10",
"@babel/core": "^7.16.12",
"@babel/eslint-parser": "^7.16.5",
"@babel/eslint-plugin": "^7.16.5",
"concurrently": "6.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/cameras/cameras.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const getByName = async (req, res) => {

export const patchByName = async (req, res) => {
try {
if (Object.keys(req.body).length === 0) {
if (req.body === undefined) {
return res.status(400).send({
statusCode: 400,
message: 'Bad request',
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/config/config.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const show = async (req, res) => {

export const patchConfig = async (req, res) => {
try {
if (Object.keys(req.body).length === 0) {
if (req.body === undefined) {
return res.status(400).send({
statusCode: 400,
message: 'Bad request',
Expand Down
15 changes: 7 additions & 8 deletions src/api/components/notifications/notifications.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ export const list = async (query) => {

if (moment(query.from, 'YYYY-MM-DD').isValid()) {
notifications = notifications.filter((notification) => {
let date = notification.time.split(',')[0].split('.');
const date = moment.unix(notification.timestamp).format('YYYY-MM-DD');
const dateMoment = moment(date).set({ hour: 0, minute: 0, second: 1 });

let year = date[2];
let month = date[1];
let day = date[0];
const fromDate = query.from;
const toDate = moment(query.to, 'YYYY-MM-DD').isValid() ? query.to : moment();

date = year + '-' + month + '-' + day;
const fromDateMoment = moment(fromDate).set({ hour: 0, minute: 0, second: 0 });
const toDateMoment = moment(toDate).set({ hour: 23, minute: 59, second: 59 });

let to = moment(query.to, 'YYYY-MM-DD').isValid() ? query.to : moment();

let isBetween = moment(date).isBetween(query.from, to);
const isBetween = dateMoment.isBetween(fromDateMoment, toDateMoment);

return isBetween;
});
Expand Down
15 changes: 7 additions & 8 deletions src/api/components/recordings/recordings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ export const list = (query) => {

if (moment(query.from, 'YYYY-MM-DD').isValid()) {
recordings = recordings.filter((recording) => {
let date = recording.time.split(',')[0].split('.');
const date = moment.unix(recording.timestamp).format('YYYY-MM-DD');
const dateMoment = moment(date).set({ hour: 0, minute: 0, second: 1 });

let year = date[2];
let month = date[1];
let day = date[0];
const fromDate = query.from;
const toDate = moment(query.to, 'YYYY-MM-DD').isValid() ? query.to : moment();

date = year + '-' + month + '-' + day;
const fromDateMoment = moment(fromDate).set({ hour: 0, minute: 0, second: 0 });
const toDateMoment = moment(toDate).set({ hour: 23, minute: 59, second: 59 });

let to = moment(query.to, 'YYYY-MM-DD').isValid() ? query.to : moment();

let isBetween = moment(date).isBetween(query.from, to);
const isBetween = dateMoment.isBetween(fromDateMoment, toDateMoment);

return isBetween;
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/settings/settings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getTarget = async (req, res) => {

export const patchTarget = async (req, res) => {
try {
if (Object.keys(req.body).length === 0) {
if (req.body === undefined) {
return res.status(400).send({
statusCode: 400,
message: 'Bad request',
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/users/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const patchByName = async (req, res) => {
req.body.photo = req.file.filename;
}

if (Object.keys(req.body).length === 0) {
if (req.body === undefined) {
return res.status(400).send({
statusCode: 400,
message: 'Bad request',
Expand Down
4 changes: 3 additions & 1 deletion src/api/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default class Database {
static databasePath = ConfigService.databasePath;
static databaseUserPath = ConfigService.databaseUserPath;
static recordingsPath = ConfigService.recordingsPath;
static reportsPath = ConfigService.reportsPath;
static databaseFilePath = ConfigService.databaseFilePath;

static controller;
Expand All @@ -175,6 +176,7 @@ export default class Database {
async prepareDatabase() {
await fs.ensureDir(Database.recordingsPath);
await fs.ensureDir(Database.databaseUserPath);
await fs.ensureDir(Database.reportsPath);

Database.interfaceDB = new Low(new JSONFile(Database.databaseFilePath));
Database.tokensDB = new Low(new MemorySync());
Expand Down Expand Up @@ -324,7 +326,7 @@ export default class Database {

return {
id: id,
camera: cameraName,
camera: cameraName.replace(/_/g, ' '),
fileName: `${fileName}.${extension}`,
name: fileName,
extension: extension,
Expand Down
22 changes: 13 additions & 9 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
import http from 'http';
import https from 'https';

import ConfigService from '../services/config/config.service.js';
import LoggerService from '../services/logger/logger.service.js';

const { log } = LoggerService;

import App from './app.js';

export default class Server {
constructor(controller) {
const log = controller.log;
const config = controller.config;

const app = new App({
debug: process.env.CUI_LOG_DEBUG === '1',
version: config.version,
version: ConfigService.ui.version,
});

const server = config.ssl
const server = ConfigService.ui.ssl
? https.createServer(
{
key: config.ssl.key,
cert: config.ssl.cert,
key: ConfigService.ui.ssl.key,
cert: ConfigService.ui.ssl.cert,
},
app
)
Expand All @@ -30,7 +32,9 @@ export default class Server {
let addr = server.address();
let bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;

log.info(`camera.ui v${config.version} is listening on ${bind} (${config.ssl ? 'https' : 'http'})`);
log.info(
`camera.ui v${ConfigService.ui.version} is listening on ${bind} (${ConfigService.ui.ssl ? 'https' : 'http'})`
);

controller.emit('finishLaunching');
});
Expand All @@ -42,7 +46,7 @@ export default class Server {
log.error(error, 'Interface', 'server');
}

let bind = typeof port === 'string' ? 'Pipe ' + config.port : 'Port ' + config.port;
let bind = typeof port === 'string' ? 'Pipe ' + ConfigService.ui.port : 'Port ' + ConfigService.ui.port;

switch (error.code) {
case 'EACCES':
Expand Down
4 changes: 2 additions & 2 deletions src/common/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { URL } from 'url';

import LoggerService from '../services/logger/logger.service.js';

const { log } = LoggerService;

export default class Ping {
static async status(camera, timeout = 1) {
const { log } = LoggerService;

let cameraSource = camera.videoConfig.source.split('-i ')[1];

if (!cameraSource) {
Expand Down
Loading

0 comments on commit ac1c9ed

Please sign in to comment.