Skip to content

Commit

Permalink
Issue412 (#413)
Browse files Browse the repository at this point in the history
* support for glob paths

* support for globs in trigger patterns

* Added changeLog entry

* reverted gitignore

* update package-lock.json

* package-lock update

* reverted gitignore

* reverted gitignore

* Apply suggestions from code review

Co-authored-by: danecreekphotography <[email protected]>

* Removed build wornings.

* renamed sample dog folder

Co-authored-by: lukaszsalamon <[email protected]>
Co-authored-by: danecreekphotography <[email protected]>
  • Loading branch information
3 people authored Jan 18, 2021
1 parent b8761a0 commit 765b1d5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/triggers.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
{
"name": "Dog detector",
"watchPattern": "/aiinput/Dog*.jpg",
"watchPattern": "/aiinput/**/Dog*.jpg",
"enabled": true,
"threshold": {
"minimum": 50,
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Add support for `customEndpoint` on a trigger to support custom Deepstack models. Resolves [issue 416](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/416).
- Support for glob patterns in trigger watchPatterns. Resolves [issue 412](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/412).

## 5.6.1

Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"devDependencies": {
"@types/ajv-keywords": "^3.4.0",
"@types/express": "^4.17.6",
"@types/glob": "^7.1.3",
"@types/http-terminator": "^2.0.1",
"@types/jest": "^25.2.3",
"@types/mkdirp": "^1.0.1",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion sampleConfiguration/triggers.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
{
"name": "Dog detector",
"watchPattern": "/aiinput/Dog*.jpg",
"watchPattern": "/aiinput/**/Dog*.jpg",
"enabled": true,
"threshold": {
"minimum": 50,
Expand Down
13 changes: 5 additions & 8 deletions src/TriggerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import * as log from "./Log";
import * as MQTTManager from "./handlers/mqttManager/MqttManager";

import ITriggerConfigJson from "./types/ITriggerConfigJson";
import * as fs from "fs";
import glob from "glob"
import MqttHandlerConfig from "./handlers/mqttManager/MqttHandlerConfig";
import path from "path";
import PushbulletConfig from "./handlers/pushbulletManager/PushbulletConfig";
import PushoverConfig from "./handlers/pushoverManager/PushoverConfig";
import Rect from "./Rect";
Expand Down Expand Up @@ -69,7 +68,7 @@ export function loadConfiguration(configurations: IConfiguration[]): IConfigurat
if (!triggerConfigJson) {
throw Error(
"Unable to find a trigger configuration file. Verify the trigger secret points to a file " +
"called triggers.json or that the /config mount point contains a file called triggers.json.",
"called triggers.json or that the /config mount point contains a file called triggers.json.",
);
}

Expand Down Expand Up @@ -272,21 +271,19 @@ export function resetOverallStatistics(): ITriggerStatistics {
*/
export function verifyTriggerWatchLocations(): boolean {
const invalidWatchLocations = triggers?.filter(trigger => {
const watchFolder = path.dirname(trigger.watchPattern);

let files: string[];

try {
files = fs.readdirSync(watchFolder);
files = glob.sync(trigger.watchPattern);
} catch (e) {
log.warn(
"Trigger manager",
`Unable to read contents of watch folder ${watchFolder} for trigger ${trigger.name}. Check and make sure the image folder is mounted properly. ${e}`,
`Unable to read contents of watch folder ${trigger.watchPattern} for trigger ${trigger.name}. Check and make sure the image folder is mounted properly. ${e}`,
);
return true;
}

log.verbose("Trigger manager", `There are ${files.length} images waiting in ${watchFolder} for ${trigger.name}.`);
log.verbose("Trigger manager", `There are ${files.length} images waiting in ${trigger.watchPattern} for ${trigger.name}.`);
return false;
});

Expand Down

0 comments on commit 765b1d5

Please sign in to comment.