Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial commit of Snapshot middleware #219

Merged
merged 23 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42f0016
feat: initial commit of Snapshot middleware
danleyb2 Oct 19, 2024
f78562e
feat: initial commit of Snapshot middleware
danleyb2 Oct 19, 2024
13c9c89
refactor: using object destructuring directly in the parameter list.
danleyb2 Oct 19, 2024
300eed7
refactor: review fixes
danleyb2 Oct 19, 2024
d8bec79
feat: validate Genetec Event
danleyb2 Oct 19, 2024
3eb603b
refactor: review fixes
danleyb2 Oct 19, 2024
a365fda
feat: disable running code review when review_requested
danleyb2 Oct 21, 2024
8100555
feat: code-rabbit review fixes
danleyb2 Oct 21, 2024
718791d
refactor: update worker names
danleyb2 Oct 21, 2024
99cfd19
feat: disable running code review when review_requested
danleyb2 Oct 21, 2024
b3d6e90
feat: validate time values
danleyb2 Oct 21, 2024
65049d0
feat: fix request retry
danleyb2 Oct 21, 2024
941a042
feat: enable mmc
danleyb2 Oct 21, 2024
2327480
feat: allow setting and overriding Snapshot params through URL
danleyb2 Oct 21, 2024
d189770
feat: review fixes
danleyb2 Oct 21, 2024
8098c91
feat: review fixes
danleyb2 Oct 21, 2024
6a72a3d
feat: set MMC on by default
danleyb2 Oct 21, 2024
16fe5ca
feat: log queue message being processed
danleyb2 Oct 21, 2024
ee374bc
feat: typo fix
danleyb2 Oct 22, 2024
0878701
fix: send Gentec events directly to bypass queue limit
danleyb2 Oct 25, 2024
d678f60
fix: send Survision events directly to bypass queue limit
danleyb2 Oct 25, 2024
9b45aeb
fix: date is off by an hour
danleyb2 Oct 28, 2024
fe87f55
refactor: convert tabs to 4 spaces, remove .editorconfig
danleyb2 Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Review GPT

on:
pull_request:
types: [opened, reopened, review_requested]
types: [opened, reopened]
branches: [master]
pull_request_review_comment:
types: [ created ]
Expand Down
172 changes: 172 additions & 0 deletions snapshot-middleware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars
.wrangler/
66 changes: 66 additions & 0 deletions snapshot-middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Snapshot Middleware
Format external requests into expected format by Snapshot then forward

Supported Source:
- Survision Camera
- Genetec Camera

## Deployment steps
> The cloudflare account needs to have a paid plan for workers to be able to create queues

1. Create a [Cloudflare queue](https://developers.cloudflare.com/queues/get-started/#3-create-a-queue) that will hold messages.
Can be done by using below command or manually in the dashboard
```shell
npx wrangler queues create snapshot-middleware
```

2. Deploy the worker by running below command
> this will prompt you to login using your web browser the first time.

A url will be generated to be used as the webhook target on source such as a camera settings page
```shell
npm run deploy
# Deploy with a custom name
npm run deploy -- --name reimaginedparking-middleware
```
To login again `wrangler login`, Logout using `wrangler logout` or delete `.wrangler` folder

3. Update the application env variables with the following values
> This will redeploy the worker and persist any future deployments
> For added security, Click on the Encrypt button on each variable

```shell
# Snapshot Cloud Token - Find it here https://app.platerecognizer.com/service/snapshot-cloud/
SNAPSHOT_TOKEN=
# Snapshot API URL - Optional (You don't need to define it if you use Snapshot Cloud
SNAPSHOT_URL=
```

5. To log errors with Rollbar, Deploy the tail worker
```shell
npm run deploy:rollbar
```
The set this env variable
```shell
# Rollbar Token for Error logging
ROLLBAR_TOKEN=
```

6. Run below command to get realtime logs
```shell
npm run logs
```

## Local development
- Create a `.dev.vars` with the env variables required:
```dotenv
SNAPSHOT_TOKEN=
SNAPSHOT_URL= # Optional
ROLLBAR_TOKEN= # optional
```
- Run `npm run dev` in your terminal to start a development server
- Open a browser tab at http://localhost:8787/ to see your worker in action
- Test with curl
```shell
curl -vX POST http://localhost:8787/ -d @Survision.txt --header "Content-Type: application/json" --header "survision-serial-number: sv1-searial-1"
Pefington marked this conversation as resolved.
Show resolved Hide resolved
```
Loading