diff --git a/cli/src/index.ts b/cli/src/index.ts index 9f3e85a24..1bb7eae51 100755 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -206,11 +206,7 @@ export class Commander { '--config [PATH]', 'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json', ) - .option( - '--file-read ', - 'read the message body from the file', - parseFileRead - ) + .option('--file-read ', 'read the message body from the file', parseFileRead) .option( '-Pp, --protobuf-path ', 'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)', @@ -311,8 +307,16 @@ export class Commander { 'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json', ) // https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js - .addOption(new Option('--file-write ', 'append received messages to a specified file').argParser(parseFileWrite).conflicts('fileSave')) - .addOption(new Option('--file-save ', 'save each received message to a new file').argParser(parseFileSave).conflicts('fileWrite')) + .addOption( + new Option('--file-write ', 'append received messages to a specified file') + .argParser(parseFileWrite) + .conflicts('fileSave'), + ) + .addOption( + new Option('--file-save ', 'save each received message to a new file') + .argParser(parseFileSave) + .conflicts('fileWrite'), + ) .option( '-Pp, --protobuf-path ', 'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)', @@ -496,11 +500,7 @@ export class Commander { '--config [PATH]', 'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json', ) - .option( - '--file-read ', - 'read the message body from the file', - parseFileRead - ) + .option('--file-read ', 'read the message body from the file', parseFileRead) .allowUnknownOption(false) .action(benchPub) diff --git a/cli/src/lib/conn.ts b/cli/src/lib/conn.ts index 00f0186d7..cda697721 100644 --- a/cli/src/lib/conn.ts +++ b/cli/src/lib/conn.ts @@ -78,7 +78,7 @@ const benchConn = async (options: BenchConnectOptions) => { const start = Date.now() for (let i = 1; i <= count; i++) { - ; ((i: number, connOpts: mqtt.IClientOptions) => { + ;((i: number, connOpts: mqtt.IClientOptions) => { const opts = { ...connOpts } opts.clientId = clientId.includes('%i') ? clientId.replaceAll('%i', i.toString()) : `${clientId}_${i}` diff --git a/cli/src/lib/pub.ts b/cli/src/lib/pub.ts index eebd2d0e6..0265eab48 100644 --- a/cli/src/lib/pub.ts +++ b/cli/src/lib/pub.ts @@ -183,7 +183,7 @@ const pub = (options: PublishOptions) => { concat((data) => { pubOpts.message = data send(config, connOpts, pubOpts) - }) + }), ) } } @@ -231,7 +231,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions | } = options let fileData: Buffer | string - if(fileRead) { + if (fileRead) { fileData = handleFileRead(processPath(fileRead)) } @@ -321,7 +321,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions | } publishMessage = simulationResult.message } - if(fileRead) { + if (fileRead) { publishMessage = fileData } client.publish(publishTopic, publishMessage, pubOpts.opts, (err) => { diff --git a/cli/src/lib/sub.ts b/cli/src/lib/sub.ts index f566be435..7b7c8382d 100644 --- a/cli/src/lib/sub.ts +++ b/cli/src/lib/sub.ts @@ -39,10 +39,10 @@ const processReceivedMessage = ( } const handleDefaultBinaryFile = (format: FormatType | undefined, filePath?: string) => { - if(filePath) { + if (filePath) { if ((!format || format !== 'binary') && isSupportedBinaryFormatForMQTT(getPathExtname(filePath))) { signale.warn('Please use the --format binary option for handling binary files') - if(!format) { + if (!format) { return 'binary' } } @@ -115,7 +115,7 @@ const sub = (options: SubscribeOptions) => { const receivedMessage = processReceivedMessage(payload, protobufPath, protobufMessageName, format) const savePath = fileSave ? createNextNumberedFileName(fileSave) : fileWrite - if(savePath) { + if (savePath) { fileSave && writeFile(savePath, receivedMessage) fileWrite && appendFile(savePath, receivedMessage) } @@ -127,7 +127,7 @@ const sub = (options: SubscribeOptions) => { packet.retain && msgData.push({ label: 'retain', value: packet.retain }) - if(savePath) { + if (savePath) { const successMessage = fileSave ? 'Saved to file' : 'Appended to file' msgData.push({ label: 'payload', value: `${successMessage}: ${savePath}` }) } else { diff --git a/cli/src/types/global.d.ts b/cli/src/types/global.d.ts index 49da0d988..e6d3ef5af 100644 --- a/cli/src/types/global.d.ts +++ b/cli/src/types/global.d.ts @@ -160,11 +160,11 @@ declare global { } interface IDisconnectPacket { - cmd: 'disconnect', + cmd: 'disconnect' qos: QoS dup: boolean retain: boolean - reasonCode: number, + reasonCode: number length: number } } diff --git a/cli/src/utils/binaryFormats.ts b/cli/src/utils/binaryFormats.ts index fcbf8796d..099b94fb5 100644 --- a/cli/src/utils/binaryFormats.ts +++ b/cli/src/utils/binaryFormats.ts @@ -1,10 +1,45 @@ const supportedBinaryFormatsForMQTT = [ - '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.tif', '.tiff', // Image file formats - '.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.mpeg', '.3gp', // Video file formats - '.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma', '.m4a', '.m4p', // Audio file formats - '.zip', '.gz', '.rar', '.tar', '.7z', '.bz2', '.xz', '.jar', // Compressed file formats - '.bin', '.exe', '.dll', '.so', '.dmg', '.iso', '.img', // Binary file formats - '.pdf', '.epub', // Binary document file formats + '.png', + '.jpg', + '.jpeg', + '.gif', + '.bmp', + '.ico', + '.tif', + '.tiff', // Image file formats + '.mp4', + '.avi', + '.mov', + '.mkv', + '.flv', + '.wmv', + '.mpeg', + '.3gp', // Video file formats + '.mp3', + '.wav', + '.flac', + '.aac', + '.ogg', + '.wma', + '.m4a', + '.m4p', // Audio file formats + '.zip', + '.gz', + '.rar', + '.tar', + '.7z', + '.bz2', + '.xz', + '.jar', // Compressed file formats + '.bin', + '.exe', + '.dll', + '.so', + '.dmg', + '.iso', + '.img', // Binary file formats + '.pdf', + '.epub', // Binary document file formats ] const isSupportedBinaryFormatForMQTT = (fileExtname: string) => { diff --git a/cli/src/utils/config.ts b/cli/src/utils/config.ts index 6ed4e19dc..e75e7e87d 100644 --- a/cli/src/utils/config.ts +++ b/cli/src/utils/config.ts @@ -1,11 +1,18 @@ import signale from 'signale' -import { fileExists, writeFile, readFile, processPath, stringifyToYamlOrJson, parseYamlOrJson, isYaml } from '../utils/fileUtils' +import { + fileExists, + writeFile, + readFile, + processPath, + stringifyToYamlOrJson, + parseYamlOrJson, + isYaml, +} from '../utils/fileUtils' const defaultPath = `${process.cwd()}/mqttx-cli-config.json` const mergeConfig = (oldConfig: Config, newConfig: Config) => Object.assign({}, oldConfig, newConfig) - const removeUselessOptions = ( opts: | ConnectOptions diff --git a/cli/src/utils/fileUtils.ts b/cli/src/utils/fileUtils.ts index 92f22abb9..827d36002 100644 --- a/cli/src/utils/fileUtils.ts +++ b/cli/src/utils/fileUtils.ts @@ -62,11 +62,10 @@ const appendFile = (filePath: string, data: string | Buffer): void => { const createNextNumberedFileName = (filePath: string): string => { const escapeRegExp = (string: string) => { - return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') } try { - if(!fileExists(filePath)) - return filePath + if (!fileExists(filePath)) return filePath const dir = path.dirname(filePath) const baseNameWithoutExt = path.basename(filePath, path.extname(filePath)) @@ -86,7 +85,7 @@ const createNextNumberedFileName = (filePath: string): string => { const newNumber = maxNumber + 1 const newFileName = `${baseNameWithoutExt}(${newNumber})${ext}` return path.join(dir, newFileName) - } catch(err) { + } catch (err) { signale.error(`Error: Unable to create a new numbered file name for path '${filePath}'.`) process.exit(1) } @@ -102,5 +101,5 @@ export { readFile, writeFile, appendFile, - createNextNumberedFileName -} \ No newline at end of file + createNextNumberedFileName, +} diff --git a/cli/src/utils/parse.ts b/cli/src/utils/parse.ts index 21d7594a9..8380b0696 100644 --- a/cli/src/utils/parse.ts +++ b/cli/src/utils/parse.ts @@ -102,13 +102,13 @@ const parsePubTopic = (value: string) => { const parseFileRead = (value: string) => { const filePath = processPath(value) - if(!filePath) { + if (!filePath) { signale.error('A valid file path is required when reading from file.') process.exit(1) } const fileContent = readFile(filePath) - if(fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) { + if (fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) { signale.error('File size over 256MB not supported by MQTT.') process.exit(1) } @@ -117,7 +117,7 @@ const parseFileRead = (value: string) => { const parseFileSave = (value: string) => { const filePath = processPath(value) - if(!filePath) { + if (!filePath) { signale.error('A valid file path is required when saving to file.') process.exit(1) } @@ -126,7 +126,7 @@ const parseFileSave = (value: string) => { const parseFileWrite = (value: string) => { const filePath = processPath(value) - if(!filePath) { + if (!filePath) { signale.error('A valid file path is required when writing to file.') process.exit(1) } diff --git a/cli/src/utils/signale.ts b/cli/src/utils/signale.ts index c92aa2eee..bbed41ccc 100644 --- a/cli/src/utils/signale.ts +++ b/cli/src/utils/signale.ts @@ -31,7 +31,8 @@ const basicLog = { signale.await('Connecting...') } else { signale.await( - `Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${message ? `, message: ${message}` : '' + `Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${ + message ? `, message: ${message}` : '' }`, ) } @@ -51,7 +52,11 @@ const basicLog = { disconnect: (packet: IDisconnectPacket, clientId?: string) => { const { reasonCode } = packet const reason = reasonCode === 0 ? 'Normal disconnection' : getErrorReason(reasonCode) - signale.warn(`${clientId ? `Client ID: ${clientId}, ` : ''}The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`) + signale.warn( + `${ + clientId ? `Client ID: ${clientId}, ` : '' + }The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`, + ) }, fileReading: () => signale.await('Reading file...'), fileReadSuccess: () => signale.success('Read file successfully'), diff --git a/src/background.ts b/src/background.ts index 7565d7b18..a6e45d918 100644 --- a/src/background.ts +++ b/src/background.ts @@ -104,7 +104,7 @@ function handleIpcMessages() { type: 'error', title: 'Rebuild Database Error', message: 'An error occurred while rebuilding the database.', - detail: error.message + detail: error.message, }) } }) diff --git a/src/components/DatabaseError.vue b/src/components/DatabaseError.vue index 170cc608f..716925d7c 100644 --- a/src/components/DatabaseError.vue +++ b/src/components/DatabaseError.vue @@ -1,16 +1,16 @@ -