Skip to content

Commit

Permalink
Fix SonarQube Code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishubert committed Feb 4, 2024
1 parent 2f034a8 commit d3baebd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/controllers/clientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ const sendMessage = async (req, res) => {
let messageOut
switch (contentType) {
case 'string':
if (options && options.media) {
if (options?.media) {
const media = options.media
options.media = new MessageMedia(media.mimetype, media.data, media.filename = null, media.filesize = null)
media.filename = null
media.filesize = null
options.media = new MessageMedia(media.mimetype, media.data, media.filename, media.filesize)
}
messageOut = await client.sendMessage(chatId, content, options)
break
Expand Down
9 changes: 4 additions & 5 deletions src/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const initializeEvents = (client, sessionId) => {
waitForNestedObject(client, 'pupPage').then(() => {
const restartSession = async (sessionId) => {
sessions.delete(sessionId)
await client.destroy().catch(e => {})
await client.destroy().catch(e => { })
setupSession(sessionId)
}
client.pupPage.once('close', function () {
Expand All @@ -154,7 +154,7 @@ const initializeEvents = (client, sessionId) => {
console.log(`Error occurred on browser page for ${sessionId}. Restoring`)
restartSession(sessionId)
})
}).catch(e => {})
}).catch(e => { })
}

checkIfEventisEnabled('auth_failure')
Expand Down Expand Up @@ -308,7 +308,6 @@ const initializeEvents = (client, sessionId) => {
})
}

// Function to check if folder is writeable
const deleteSessionFolder = async (sessionId) => {
try {
const targetDirPath = path.join(sessionFolderPath, `session-${sessionId}`)
Expand All @@ -322,7 +321,7 @@ const deleteSessionFolder = async (sessionId) => {
if (!resolvedTargetDirPath.startsWith(safeSessionPath)) {
throw new Error('Invalid path: Directory traversal detected')
}
await fs.promises.rm(targetDirPath, { recursive: true, force: true })
await fs.promises.rm(resolvedTargetDirPath, { recursive: true, force: true })
} catch (error) {
console.log('Folder deletion error', error)
throw error
Expand Down Expand Up @@ -369,7 +368,7 @@ const flushSessions = async (deleteOnlyInactive) => {
for (const file of files) {
// Use regular expression to extract the string from the folder name
const match = file.match(/^session-(.+)$/)
if (match && match[1]) {
if (match) {
const sessionId = match[1]
const validation = await validateSession(sessionId)
if (!deleteOnlyInactive || !validation.success) {
Expand Down

0 comments on commit d3baebd

Please sign in to comment.