Skip to content

Commit

Permalink
push latest changes before big release
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Dec 12, 2021
1 parent c61634a commit 5f38073
Show file tree
Hide file tree
Showing 35 changed files with 850 additions and 504 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ test.js
diverses
stream
writeStream.js
mp4
mp4
interface2
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ yarn.lock
.envtest/stream
writeStream.js
mp4
interface2
2 changes: 1 addition & 1 deletion bin/camera.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if (cluster.isPrimary) {

shuttingDown = true;

log.warn(`Got ${signal}, shutting down camera.ui...`);
log.warn(`Got ${signal}, shutting down camera.ui...`, 'System', 'system');

setTimeout(() => {
// eslint-disable-next-line unicorn/no-process-exit
Expand Down
26 changes: 16 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.0.0-beta.0",
"version": "1.0.0-beta.1",
"description": "User Interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand Down
16 changes: 5 additions & 11 deletions src/api/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable quotes */
/* eslint-disable unicorn/prevent-abbreviations */
'use-strict';

Expand Down Expand Up @@ -39,12 +40,10 @@ exports.App = (options) => {
app.use(
helmet.contentSecurityPolicy({
directives: {
// eslint-disable-next-line quotes
defaultSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'"],
// eslint-disable-next-line quotes
scriptSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'https://*.googleapis.com', 'blob:'],
// eslint-disable-next-line quotes
scriptSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'https://*.googleapis.com', 'blob:', 'data:'],
childSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'blob:', 'https:'],
fontSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'data:'],
connectSrc: [
'ws:',
'wss:',
Expand All @@ -56,17 +55,12 @@ exports.App = (options) => {
'mediastream:',
'https://registry.npmjs.org',
'https://unpkg.com',
// eslint-disable-next-line quotes
"'unsafe-eval'",
// eslint-disable-next-line quotes
"'unsafe-inline'",
// eslint-disable-next-line quotes
"'self'",
],
// eslint-disable-next-line quotes
'img-src': ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'data:', 'blob:'],
// eslint-disable-next-line quotes
'media-src': ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'data:', 'blob:'],
imgSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'data:', 'blob:'],
mediaSrc: ["'unsafe-eval'", "'unsafe-inline'", "'self'", 'data:', 'blob:'],
},
})
);
Expand Down
6 changes: 3 additions & 3 deletions src/api/components/backup/backup.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.createBackup = async (localStorage) => {
cwd: backupDirectory,
filter: (filePath, stat) => {
if (stat.size > 5e7) {
log.warn(`Backup is skipping "${filePath}" because it is larger than 50MB.`);
log.warn(`Backup is skipping "${filePath}" because it is larger than 50MB.`, 'Interface', 'interface');
return false;
}
return true;
Expand All @@ -76,7 +76,7 @@ exports.restoreBackup = async (file) => {
const backupFileName = file.filename; // eslint-disable-line no-unused-vars
const backupPath = file.path;

log.warn('Starting backup restore...');
log.info('Starting backup restore...');

// extract the tar
await tar.x({
Expand All @@ -91,7 +91,7 @@ exports.restoreBackup = async (file) => {
await fs.move(backupDirectory + '/recordings', recordingsPath, { overwrite: true });

// remove tmp
log.warn('Removing unnecessary files...');
log.debug('Removing unnecessary files...');
await fs.remove(backupDirectory);

// refresh db
Expand Down
156 changes: 128 additions & 28 deletions src/api/components/system/system.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ const { ConfigService } = require('../../../services/config/config.service');
const { Database } = require('../../database');
const { Socket } = require('../../socket');

const { MotionController } = require('../../../controller/motion/motion.controller');

const { log } = LoggerService;

let updating = false;

const setTimeoutAsync = (ms) => new Promise((res) => setTimeout(res, ms));

const updatePlugin = (version) => {
return new Promise((resolve, reject) => {
updating = true;
Expand Down Expand Up @@ -56,19 +60,20 @@ const updatePlugin = (version) => {
});
};

exports.getLog = async (req, res) => {
exports.clearLog = async (req, res) => {
try {
const logPath = ConfigService.logFile;
const truncateSize = 200000;
const logStats = await fs.stat(logPath);
const logStartPosition = logStats.size - truncateSize;
const logBuffer = Buffer.alloc(truncateSize);

const fd = await fs.open(logPath, 'r');
// eslint-disable-next-line no-unused-vars
const { bytesRead, buffer } = await fs.read(fd, logBuffer, 0, truncateSize, logStartPosition);
fs.truncate(logPath, (err) => {
if (err) {
return res.status(500).send({
statusCode: 500,
message: err.message,
});
}

res.status(200).send(buffer.toString());
Socket.io.emit('clearLog');
res.status(204).send({});
});
} catch (error) {
res.status(500).send({
statusCode: 500,
Expand Down Expand Up @@ -102,20 +107,17 @@ exports.downloadLog = async (req, res) => {
}
};

exports.clearLog = async (req, res) => {
exports.fetchNpm = async (req, res) => {
try {
const logPath = ConfigService.logFile;
fs.truncate(logPath, (err) => {
if (err) {
return res.status(500).send({
statusCode: 500,
message: err.message,
});
}
const moduleName = ConfigService.env.moduleName;

Socket.io.emit('clearLog');
res.status(204).send({});
const response = await axios(`https://registry.npmjs.org/${moduleName}`, {
headers: {
accept: 'application/vnd.npm.install-v1+json',
},
});

res.status(200).send(response.data);
} catch (error) {
res.status(500).send({
statusCode: 500,
Expand All @@ -140,17 +142,115 @@ exports.getChangelog = async (req, res) => {
}
};

exports.fetchNpm = async (req, res) => {
exports.getHttpServerStatus = async (req, res) => {
try {
const moduleName = ConfigService.env.moduleName;
const status = MotionController.httpServer.listening;

const response = await axios(`https://registry.npmjs.org/${moduleName}`, {
headers: {
accept: 'application/vnd.npm.install-v1+json',
},
res.status(200).send({
status: status ? 'running' : 'not running',
});
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

res.status(200).send(response.data);
exports.getLog = async (req, res) => {
try {
const logPath = ConfigService.logFile;
const truncateSize = 200000;
const logStats = await fs.stat(logPath);
const logStartPosition = logStats.size - truncateSize;
const logBuffer = Buffer.alloc(truncateSize);

const fd = await fs.open(logPath, 'r');
// eslint-disable-next-line no-unused-vars
const { bytesRead, buffer } = await fs.read(fd, logBuffer, 0, truncateSize, logStartPosition);

res.status(200).send(buffer.toString());
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

exports.getMqttClientStatus = async (req, res) => {
try {
const status = MotionController.mqttClient.connected;

res.status(200).send({
status: status ? 'running' : 'not running',
});
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

exports.getSmtpServerStatus = async (req, res) => {
try {
const status = MotionController.smtpServer.server.listening;

res.status(200).send({
status: status ? 'running' : 'not running',
});
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

exports.restarHttpServer = async (req, res) => {
try {
MotionController.closeHttpServer();
await setTimeoutAsync(1000);

MotionController.startHttpServer();
await setTimeoutAsync(1000);

res.status(204).send({});
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

exports.restartMqttClient = async (req, res) => {
try {
MotionController.closeMqttClient();
await setTimeoutAsync(1000);

MotionController.startMqttClient();
await setTimeoutAsync(1000);

res.status(204).send({});
} catch (error) {
res.status(500).send({
statusCode: 500,
message: error.message,
});
}
};

exports.restartSmtpServer = async (req, res) => {
try {
MotionController.closeSmtpServer();
await setTimeoutAsync(1000);

MotionController.startSmtpServer();
await setTimeoutAsync(1000);

res.status(204).send({});
} catch (error) {
res.status(500).send({
statusCode: 500,
Expand Down
Loading

0 comments on commit 5f38073

Please sign in to comment.