Skip to content

Commit

Permalink
fix(api): save latest images for misses
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Oct 13, 2021
1 parent a3569f7 commit 62f586c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions api/src/util/recognize.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@ const fs = require('fs');
const { STORAGE } = require('../constants')();

module.exports.save = {
latest: (camera, best = [], unknown = {}) => {
best.forEach(({ name, filename }) => {
fs.copyFileSync(`${STORAGE.PATH}/matches/${filename}`, `${STORAGE.PATH}/latest/${name}.jpg`);
fs.copyFileSync(
`${STORAGE.PATH}/matches/${filename}`,
`${STORAGE.PATH}/latest/${camera}.jpg`
);
latest: (camera, best = [], misses = [], unknown = {}) => {
const names = [];
const cameras = [];

[...best, ...misses].forEach(({ name, filename }) => {
if (!names.includes(name)) {
fs.copyFileSync(
`${STORAGE.PATH}/matches/${filename}`,
`${STORAGE.PATH}/latest/${name}.jpg`
);
names.push(name);
}

if (!cameras.includes(camera)) {
fs.copyFileSync(
`${STORAGE.PATH}/matches/${filename}`,
`${STORAGE.PATH}/latest/${camera}.jpg`
);
cameras.push(camera);
}
});
if (unknown.filename) {
fs.copyFileSync(
`${STORAGE.PATH}/matches/${unknown.filename}`,
`${STORAGE.PATH}/latest/unknown.jpg`
);
if (!best.length)
if (!best.length && !misses.length)
fs.copyFileSync(
`${STORAGE.PATH}/matches/${unknown.filename}`,
`${STORAGE.PATH}/latest/${camera}.jpg`
Expand Down

0 comments on commit 62f586c

Please sign in to comment.