Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 6d911be

Browse files
author
danecreekphotography
authored
Retrieve image for MQTT when annotations are disabled (#352)
Fixes #350
1 parent b2c7de2 commit 6d911be

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
- The original image that caused a trigger to fire is now stored temporarily and available for
6+
use via the built-in web server. The images are available in the `/originals` folder
7+
with the original filename. Resolves [issue 350](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/350).
8+
39
## Version 5.1.2
410

511
- Address a low-severity security vulnerability in a 3rd party library. Resolves [issue 347](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/347).

src/LocalStorageManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { promises as fsPromise } from "fs";
1313
export enum Locations {
1414
Annotations = "annotations",
1515
Snapshots = "snapshots",
16+
Originals = "originals",
1617
}
1718

1819
/**
@@ -38,6 +39,7 @@ export async function initializeStorage(): Promise<void> {
3839

3940
await mkdirp(path.join(localStoragePath, Locations.Annotations));
4041
await mkdirp(path.join(localStoragePath, Locations.Snapshots));
42+
await mkdirp(path.join(localStoragePath, Locations.Originals));
4143
}
4244

4345
/**
@@ -101,6 +103,12 @@ async function purgeOldFiles(): Promise<void> {
101103
(await fsPromise.readdir(purgeDir)).map(async fileName => await purgeFile(path.join(purgeDir, fileName))),
102104
);
103105

106+
// Now do originals.
107+
purgeDir = path.join(localStoragePath, Locations.Originals);
108+
await Promise.all(
109+
(await fsPromise.readdir(purgeDir)).map(async fileName => await purgeFile(path.join(purgeDir, fileName))),
110+
);
111+
104112
log.verbose("Local storage", "Purge complete");
105113
_backgroundTimer = setTimeout(purgeOldFiles, Settings.purgeInterval * _millisecondsInAMinute);
106114
}

src/Trigger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export default class Trigger {
133133
// nothing if annotations are disabled.
134134
await AnnotationManager.processTrigger(fileName, this, triggeredPredictions);
135135

136+
// Copy the image to the originals folder
137+
await LocalStorage.copyToLocalStorage(LocalStorage.Locations.Originals, fileName);
138+
136139
// Call all the handlers for the trigger. There is no need to wait for these to finish before proceeding.
137140
MqttManager.processTrigger(fileName, this, triggeredPredictions);
138141
PushbulletManager.processTrigger(fileName, this, triggeredPredictions);

src/WebServer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ let httpTerminator: HttpTerminator;
1919

2020
export function startApp(): void {
2121
const annotatedImagePath = path.join(LocalStorageManager.localStoragePath, LocalStorageManager.Locations.Annotations);
22+
const originalsImagePath = path.join(LocalStorageManager.localStoragePath, LocalStorageManager.Locations.Originals);
2223
app.use("/", express.static(annotatedImagePath));
2324
app.use("/annotations", express.static(annotatedImagePath));
25+
app.use("/originals", express.static(originalsImagePath));
2426
app.use("/motion", motionRouter);
2527
app.use("/statistics", statisticsRouter);
2628

0 commit comments

Comments
 (0)