Skip to content

Commit

Permalink
Updates to match latest linter (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Aug 6, 2019
1 parent 4da88e3 commit efa0125
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 44 deletions.
25 changes: 12 additions & 13 deletions lib/convert-to-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ const deleteFile = require('./delete-file')
const saveFile = require('./save-file')
const logger = require('./logger')

module.exports = document => {
return new Promise(async (resolve, reject) => {
logger('info', ['convert-to-pdf', document.title])
if (document.data !== '') {
const docx = Buffer.from(document.data, 'base64')
const fileName = `${config.TEMP_DIRECTORY_PATH}/${uuid()}.docx`
await saveFile({ filePath: fileName, data: docx })

module.exports = async document => {
logger('info', ['convert-to-pdf', document.title])
if (document.data !== '') {
const docx = Buffer.from(document.data, 'base64')
const fileName = `${config.TEMP_DIRECTORY_PATH}/${uuid()}.docx`
await saveFile({ filePath: fileName, data: docx })
return new Promise((resolve, reject) => {
unoconv.convert(fileName, 'pdf', { port: '2002' }, async (error, pdfFile) => {
if (error) {
logger('error', ['convert-to-pdf', error])
Expand All @@ -28,9 +27,9 @@ module.exports = document => {
resolve(document)
}
})
} else {
logger('error', ['convert-to-pdf', `Missing data field`])
reject(new Error('document.data is empty'))
}
})
})
} else {
logger('error', ['convert-to-pdf', `Missing data field`])
throw new Error('document.data is empty')
}
}
33 changes: 16 additions & 17 deletions lib/steps/convert-docx-to-pdf.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
const convertToPdf = require('../convert-to-pdf')

module.exports = data => {
return new Promise(async (resolve, reject) => {
let jobs = data.documents.map(document => !document.file ? document : document.file)
let counter = 0
const next = async () => {
if (jobs.length > 0) {
const document = jobs.shift()
if (data.documents[counter].file) {
data.documents[counter].file = await convertToPdf(document)
} else {
data.documents[counter] = await convertToPdf(document)
}
counter++
await next()
module.exports = async data => {
const jobs = data.documents.map(document => !document.file ? document : document.file)
let counter = 0
const next = async () => {
if (jobs.length > 0) {
const document = jobs.shift()
if (data.documents[counter].file) {
data.documents[counter].file = await convertToPdf(document)
} else {
resolve(data)
data.documents[counter] = await convertToPdf(document)
}
counter++
await next()
} else {
return data
}
}

await next()
})
const result = await next()
return result
}
12 changes: 5 additions & 7 deletions lib/steps/remove-from-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ const config = require('../../config')
const deleteFile = require('../delete-file')
const logger = require('../logger')

module.exports = data => {
return new Promise(async (resolve, reject) => {
logger('info', ['remove-from-queue', data._id])
const fileName = `${config.QUEUE_DIRECTORY_PATH}/${data._id}.json`
await deleteFile(fileName)
resolve(data)
})
module.exports = async data => {
logger('info', ['remove-from-queue', data._id])
const fileName = `${config.QUEUE_DIRECTORY_PATH}/${data._id}.json`
await deleteFile(fileName)
return data
}
12 changes: 5 additions & 7 deletions lib/steps/save-to-done.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ const saveFile = require('../save-file')
const logger = require('../logger')
const config = require('../../config')

module.exports = data => {
return new Promise(async (resolve, reject) => {
logger('info', ['save-to-done', data._id])
const fileName = `${config.DONE_DIRECTORY_PATH}/${data._id}.json`
await saveFile({ filePath: fileName, data: JSON.stringify(data, null, 2) })
module.exports = async data => {
logger('info', ['save-to-done', data._id])
const fileName = `${config.DONE_DIRECTORY_PATH}/${data._id}.json`
await saveFile({ filePath: fileName, data: JSON.stringify(data, null, 2) })

resolve(data)
})
return data
}

0 comments on commit efa0125

Please sign in to comment.