Skip to content

Commit

Permalink
fix: clean queue to avoid retain
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 25, 2023
1 parent f3d8896 commit b93ee97
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
# End of https://www.toptal.com/developers/gitignore/api/node,yarn

src/**/*.png
*.jpeg
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"release": "standard-version",
"test:local": "jest --setupFiles dotenv/config --ci -i",
"test:ci": "jest --ci -i",
"pub": "nodemon --exec \"DEBUG=WQ:* ts-node -r dotenv/config src/pub.ts\""
"pub": "nodemon --exec \"DEBUG=WQ:* ts-node -r dotenv/config scripts/pub.ts\""
},
"author": "AnthonyLzq <sluzquinosa@uni.pe>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/pub.ts → scripts/pub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import debug from 'debug'

import { MAIN_TOPIC } from 'utils'
import { getClient } from './network/mqtt'
import { MAIN_TOPIC } from '../src/utils'
import { getClient } from '../src/network/mqtt'

const pubDebug = debug(`${MAIN_TOPIC}:Mqtt:demo:pub`)
const client = getClient()
Expand Down
21 changes: 13 additions & 8 deletions src/network/mqtt/routes/photo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { z } from 'zod'

import { socketConnection } from 'network/socket'
import { MAIN_TOPIC } from 'utils'
// import { writeFile } from 'fs/promises'

import { writeFile } from 'fs/promises'

const TOPIC = 'receivePhoto'
const SUB_TOPIC = `${MAIN_TOPIC}/${TOPIC}`
Expand Down Expand Up @@ -42,15 +43,19 @@ const sub = (client: MqttClient) => {
}

const { data } = messageValidation
// const base64 = data.base64.split(';base64,').pop()

// if (!base64) return
if (process.env.NODE_ENV === 'local') {
const base64 = data.base64.split(';base64,').pop()

if (!base64) return

const buffer = Buffer.from(base64, 'base64')
// save the base64 as a file
writeFile(`./${data.meta.timestamp}.jpeg`, buffer).then(() => {
subDebug('File saved')
})
}

// const buffer = Buffer.from(base64, 'base64')
// // save the base64 as a file
// writeFile(`./${data.meta.timestamp}.jpeg`, buffer).then(() => {
// subDebug('File saved')
// })
const {
meta: { sensorId }
} = data
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"src",
"test",
"tests",
"__test__"
"__test__",
"scripts"
],
"exclude": [
"node_modules"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test",
"tests",
"__test__",
"dist"
"dist",
"scripts"
],
"include": [
"src"
Expand Down

0 comments on commit b93ee97

Please sign in to comment.