Skip to content

Commit 0e09649

Browse files
committed
fix(code): format
1 parent b779d99 commit 0e09649

13 files changed

+109
-67
lines changed

cli/src/index.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ export class Commander {
206206
'--config [PATH]',
207207
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
208208
)
209-
.option(
210-
'--file-read <PATH>',
211-
'read the message body from the file',
212-
parseFileRead
213-
)
209+
.option('--file-read <PATH>', 'read the message body from the file', parseFileRead)
214210
.option(
215211
'-Pp, --protobuf-path <PATH>',
216212
'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)',
@@ -311,8 +307,16 @@ export class Commander {
311307
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
312308
)
313309
// https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js
314-
.addOption(new Option('--file-write <PATH>', 'append received messages to a specified file').argParser(parseFileWrite).conflicts('fileSave'))
315-
.addOption(new Option('--file-save <PATH>', 'save each received message to a new file').argParser(parseFileSave).conflicts('fileWrite'))
310+
.addOption(
311+
new Option('--file-write <PATH>', 'append received messages to a specified file')
312+
.argParser(parseFileWrite)
313+
.conflicts('fileSave'),
314+
)
315+
.addOption(
316+
new Option('--file-save <PATH>', 'save each received message to a new file')
317+
.argParser(parseFileSave)
318+
.conflicts('fileWrite'),
319+
)
316320
.option(
317321
'-Pp, --protobuf-path <PATH>',
318322
'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)',
@@ -496,11 +500,7 @@ export class Commander {
496500
'--config [PATH]',
497501
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
498502
)
499-
.option(
500-
'--file-read <PATH>',
501-
'read the message body from the file',
502-
parseFileRead
503-
)
503+
.option('--file-read <PATH>', 'read the message body from the file', parseFileRead)
504504
.allowUnknownOption(false)
505505
.action(benchPub)
506506

cli/src/lib/conn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const benchConn = async (options: BenchConnectOptions) => {
7878
const start = Date.now()
7979

8080
for (let i = 1; i <= count; i++) {
81-
; ((i: number, connOpts: mqtt.IClientOptions) => {
81+
;((i: number, connOpts: mqtt.IClientOptions) => {
8282
const opts = { ...connOpts }
8383

8484
opts.clientId = clientId.includes('%i') ? clientId.replaceAll('%i', i.toString()) : `${clientId}_${i}`

cli/src/lib/pub.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const pub = (options: PublishOptions) => {
183183
concat((data) => {
184184
pubOpts.message = data
185185
send(config, connOpts, pubOpts)
186-
})
186+
}),
187187
)
188188
}
189189
}
@@ -231,7 +231,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |
231231
} = options
232232

233233
let fileData: Buffer | string
234-
if(fileRead) {
234+
if (fileRead) {
235235
fileData = handleFileRead(processPath(fileRead))
236236
}
237237

@@ -321,7 +321,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |
321321
}
322322
publishMessage = simulationResult.message
323323
}
324-
if(fileRead) {
324+
if (fileRead) {
325325
publishMessage = fileData
326326
}
327327
client.publish(publishTopic, publishMessage, pubOpts.opts, (err) => {

cli/src/lib/sub.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const processReceivedMessage = (
3939
}
4040

4141
const handleDefaultBinaryFile = (format: FormatType | undefined, filePath?: string) => {
42-
if(filePath) {
42+
if (filePath) {
4343
if ((!format || format !== 'binary') && isSupportedBinaryFormatForMQTT(getPathExtname(filePath))) {
4444
signale.warn('Please use the --format binary option for handling binary files')
45-
if(!format) {
45+
if (!format) {
4646
return 'binary'
4747
}
4848
}
@@ -115,7 +115,7 @@ const sub = (options: SubscribeOptions) => {
115115
const receivedMessage = processReceivedMessage(payload, protobufPath, protobufMessageName, format)
116116

117117
const savePath = fileSave ? createNextNumberedFileName(fileSave) : fileWrite
118-
if(savePath) {
118+
if (savePath) {
119119
fileSave && writeFile(savePath, receivedMessage)
120120
fileWrite && appendFile(savePath, receivedMessage)
121121
}
@@ -127,7 +127,7 @@ const sub = (options: SubscribeOptions) => {
127127

128128
packet.retain && msgData.push({ label: 'retain', value: packet.retain })
129129

130-
if(savePath) {
130+
if (savePath) {
131131
const successMessage = fileSave ? 'Saved to file' : 'Appended to file'
132132
msgData.push({ label: 'payload', value: `${successMessage}: ${savePath}` })
133133
} else {

cli/src/types/global.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ declare global {
160160
}
161161

162162
interface IDisconnectPacket {
163-
cmd: 'disconnect',
163+
cmd: 'disconnect'
164164
qos: QoS
165165
dup: boolean
166166
retain: boolean
167-
reasonCode: number,
167+
reasonCode: number
168168
length: number
169169
}
170170
}

cli/src/utils/binaryFormats.ts

+41-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
const supportedBinaryFormatsForMQTT = [
2-
'.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.tif', '.tiff', // Image file formats
3-
'.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.mpeg', '.3gp', // Video file formats
4-
'.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma', '.m4a', '.m4p', // Audio file formats
5-
'.zip', '.gz', '.rar', '.tar', '.7z', '.bz2', '.xz', '.jar', // Compressed file formats
6-
'.bin', '.exe', '.dll', '.so', '.dmg', '.iso', '.img', // Binary file formats
7-
'.pdf', '.epub', // Binary document file formats
2+
'.png',
3+
'.jpg',
4+
'.jpeg',
5+
'.gif',
6+
'.bmp',
7+
'.ico',
8+
'.tif',
9+
'.tiff', // Image file formats
10+
'.mp4',
11+
'.avi',
12+
'.mov',
13+
'.mkv',
14+
'.flv',
15+
'.wmv',
16+
'.mpeg',
17+
'.3gp', // Video file formats
18+
'.mp3',
19+
'.wav',
20+
'.flac',
21+
'.aac',
22+
'.ogg',
23+
'.wma',
24+
'.m4a',
25+
'.m4p', // Audio file formats
26+
'.zip',
27+
'.gz',
28+
'.rar',
29+
'.tar',
30+
'.7z',
31+
'.bz2',
32+
'.xz',
33+
'.jar', // Compressed file formats
34+
'.bin',
35+
'.exe',
36+
'.dll',
37+
'.so',
38+
'.dmg',
39+
'.iso',
40+
'.img', // Binary file formats
41+
'.pdf',
42+
'.epub', // Binary document file formats
843
]
944

1045
const isSupportedBinaryFormatForMQTT = (fileExtname: string) => {

cli/src/utils/config.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import signale from 'signale'
2-
import { fileExists, writeFile, readFile, processPath, stringifyToYamlOrJson, parseYamlOrJson, isYaml } from '../utils/fileUtils'
2+
import {
3+
fileExists,
4+
writeFile,
5+
readFile,
6+
processPath,
7+
stringifyToYamlOrJson,
8+
parseYamlOrJson,
9+
isYaml,
10+
} from '../utils/fileUtils'
311

412
const defaultPath = `${process.cwd()}/mqttx-cli-config.json`
513

614
const mergeConfig = (oldConfig: Config, newConfig: Config) => Object.assign({}, oldConfig, newConfig)
715

8-
916
const removeUselessOptions = (
1017
opts:
1118
| ConnectOptions

cli/src/utils/fileUtils.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ const appendFile = (filePath: string, data: string | Buffer): void => {
6262

6363
const createNextNumberedFileName = (filePath: string): string => {
6464
const escapeRegExp = (string: string) => {
65-
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
65+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
6666
}
6767
try {
68-
if(!fileExists(filePath))
69-
return filePath
68+
if (!fileExists(filePath)) return filePath
7069

7170
const dir = path.dirname(filePath)
7271
const baseNameWithoutExt = path.basename(filePath, path.extname(filePath))
@@ -86,7 +85,7 @@ const createNextNumberedFileName = (filePath: string): string => {
8685
const newNumber = maxNumber + 1
8786
const newFileName = `${baseNameWithoutExt}(${newNumber})${ext}`
8887
return path.join(dir, newFileName)
89-
} catch(err) {
88+
} catch (err) {
9089
signale.error(`Error: Unable to create a new numbered file name for path '${filePath}'.`)
9190
process.exit(1)
9291
}
@@ -102,5 +101,5 @@ export {
102101
readFile,
103102
writeFile,
104103
appendFile,
105-
createNextNumberedFileName
106-
}
104+
createNextNumberedFileName,
105+
}

cli/src/utils/parse.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ const parsePubTopic = (value: string) => {
102102

103103
const parseFileRead = (value: string) => {
104104
const filePath = processPath(value)
105-
if(!filePath) {
105+
if (!filePath) {
106106
signale.error('A valid file path is required when reading from file.')
107107
process.exit(1)
108108
}
109109

110110
const fileContent = readFile(filePath)
111-
if(fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) {
111+
if (fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) {
112112
signale.error('File size over 256MB not supported by MQTT.')
113113
process.exit(1)
114114
}
@@ -117,7 +117,7 @@ const parseFileRead = (value: string) => {
117117

118118
const parseFileSave = (value: string) => {
119119
const filePath = processPath(value)
120-
if(!filePath) {
120+
if (!filePath) {
121121
signale.error('A valid file path is required when saving to file.')
122122
process.exit(1)
123123
}
@@ -126,7 +126,7 @@ const parseFileSave = (value: string) => {
126126

127127
const parseFileWrite = (value: string) => {
128128
const filePath = processPath(value)
129-
if(!filePath) {
129+
if (!filePath) {
130130
signale.error('A valid file path is required when writing to file.')
131131
process.exit(1)
132132
}

cli/src/utils/signale.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const basicLog = {
3131
signale.await('Connecting...')
3232
} else {
3333
signale.await(
34-
`Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${message ? `, message: ${message}` : ''
34+
`Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${
35+
message ? `, message: ${message}` : ''
3536
}`,
3637
)
3738
}
@@ -51,7 +52,11 @@ const basicLog = {
5152
disconnect: (packet: IDisconnectPacket, clientId?: string) => {
5253
const { reasonCode } = packet
5354
const reason = reasonCode === 0 ? 'Normal disconnection' : getErrorReason(reasonCode)
54-
signale.warn(`${clientId ? `Client ID: ${clientId}, ` : ''}The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`)
55+
signale.warn(
56+
`${
57+
clientId ? `Client ID: ${clientId}, ` : ''
58+
}The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`,
59+
)
5560
},
5661
fileReading: () => signale.await('Reading file...'),
5762
fileReadSuccess: () => signale.success('Read file successfully'),

src/background.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function handleIpcMessages() {
104104
type: 'error',
105105
title: 'Rebuild Database Error',
106106
message: 'An error occurred while rebuilding the database.',
107-
detail: error.message
107+
detail: error.message,
108108
})
109109
}
110110
})

src/components/DatabaseError.vue

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
22
<div class="connect-database-error-page">
33
<div class="page-content">
4-
<p class="info">A corruption has been detected in the database file, preventing the software from launching properly. To fix this, please click 'Rebuild Database'.</p>
4+
<p class="info">
5+
A corruption has been detected in the database file, preventing the software from launching properly. To fix
6+
this, please click 'Rebuild Database'.
7+
</p>
58
<p class="error">Error - {{ connectDatabaseFailMessage }}</p>
69
</div>
7-
<el-button class="rebuild-database-btn" type="primary" @click="confirmRebuild">
8-
Rebuild Database
9-
</el-button>
10+
<el-button class="rebuild-database-btn" type="primary" @click="confirmRebuild"> Rebuild Database </el-button>
1011
</div>
1112
</template>
1213

13-
1414
<script lang="ts">
1515
import { Component, Vue } from 'vue-property-decorator'
1616
import { Getter } from 'vuex-class'
@@ -25,25 +25,21 @@ export default class DatabaseError extends Vue {
2525
}
2626
2727
private confirmRebuild() {
28-
this.$confirm(
29-
'Proceed with database rebuild now? All data will be lost and cannot be undone',
30-
{
31-
title:'Database Rebuild Confirmation',
32-
showClose: false,
33-
closeOnClickModal:false,
34-
confirmButtonText: 'Confirm',
35-
cancelButtonText: 'Cancel',
36-
type: 'warning',
37-
beforeClose: (action, instance, done) => {
38-
if (action === 'confirm') {
39-
instance.confirmButtonLoading = true
40-
instance.confirmButtonText = 'Loading...'
41-
}
42-
done()
28+
this.$confirm('Proceed with database rebuild now? All data will be lost and cannot be undone', {
29+
title: 'Database Rebuild Confirmation',
30+
showClose: false,
31+
closeOnClickModal: false,
32+
confirmButtonText: 'Confirm',
33+
cancelButtonText: 'Cancel',
34+
type: 'warning',
35+
beforeClose: (action, instance, done) => {
36+
if (action === 'confirm') {
37+
instance.confirmButtonLoading = true
38+
instance.confirmButtonText = 'Loading...'
4339
}
44-
}
45-
)
46-
.then(() => {
40+
done()
41+
},
42+
}).then(() => {
4743
try {
4844
this.rebuildDatabase()
4945
this.$log.info('Database rebuild completed. The application will restart')

src/lang/common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default {
123123
en: 'Save Success',
124124
tr: 'Kaydetme Başarılı',
125125
ja: '保存に成功しました',
126-
hu: 'Sikeres mentés'
126+
hu: 'Sikeres mentés',
127127
},
128128
warning: {
129129
zh: '提示',

0 commit comments

Comments
 (0)