Skip to content

Commit

Permalink
feat(ui:status): frigate last camera in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Oct 5, 2021
1 parent d8c9220 commit ac9c7a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/src/controllers/recognize.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports.start = async (req, res) => {
}

if (event.type === 'frigate') {
process.env.FRIGATE_LAST_EVENT = time.utc();
process.env.FRIGATE_LAST_EVENT = JSON.stringify({ time: time.utc(), camera });
const check = await frigate.checks({
...event,
PROCESSING,
Expand Down
9 changes: 8 additions & 1 deletion api/src/controllers/status.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const axios = require('axios');
const { tryParseJSON } = require('../util/validators.util');
const { connected } = require('../util/mqtt.util');
const { auth, jwt } = require('../util/auth.util');
const { BAD_REQUEST } = require('../constants/http-status');
Expand All @@ -18,10 +19,16 @@ module.exports.auth = (req, res) => {

module.exports.frigate = async (req, res) => {
if (!FRIGATE.URL) return res.status(BAD_REQUEST).error('Frigate URL not configured');

const { time, camera } = tryParseJSON(process.env.FRIGATE_LAST_EVENT) || {
time: null,
camera: null,
};

const { data: version } = await axios({
method: 'get',
url: `${FRIGATE.URL}/api/version`,
});

res.send({ version, last: process.env.FRIGATE_LAST_EVENT || null });
res.send({ version, last: { time, camera } });
};
7 changes: 5 additions & 2 deletions frontend/src/views/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,11 @@ export default {
await Sleep(1000);
const { data } = await ApiService.get('status/frigate');
this.frigate.status = 200;
this.frigate.tooltip = data.version;
if (data.last) this.frigate.tooltip = `${this.frigate.tooltip} | Last Event: ${Time.ago(data.last)}`;
this.frigate.tooltip = `Version: ${data.version}`;
const { last } = data;
if (last.time && last.camera) {
this.frigate.tooltip += `\nLast Event: ${Time.ago(last.time)} (${last.camera})`;
}
} catch (error) {
const status = error.response && error.response.status ? error.response.status : 500;
this.frigate.tooltip = null;
Expand Down

0 comments on commit ac9c7a8

Please sign in to comment.