Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locales/en/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "Email",
"errorMessage": "Your file could not be completed, please try again",
"reportGenAt": "Report generated at",
"copyright": "Copyright © 2013-2024 iFinex Inc. All rights reserved.",
"copyright": "Copyright © 2013-{{currYear}} iFinex Inc. All rights reserved.",
"page": "Page",
"from": "from"
}
Expand Down
2 changes: 1 addition & 1 deletion locales/es-EM/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "Correo",
"errorMessage": "Tu archivo no pudo ser completado, por favor inténtalo de nuevo",
"reportGenAt": "Reporte generado al",
"copyright": "Copyright © 2013-2024 iFinex Inc. Todos los derechos reservados.",
"copyright": "Copyright © 2013-{{currYear}} iFinex Inc. Todos los derechos reservados.",
"page": "Página",
"from": "de"
}
Expand Down
2 changes: 1 addition & 1 deletion locales/pt-BR/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "e-mail",
"errorMessage": "Seu arquivo não pode ser completado, por favor tente novamente",
"reportGenAt": "Informe gerado em ",
"copyright": "Copyright © 2013-2024 iFinex Inc. Todos os direitos reservados.",
"copyright": "Copyright © 2013-{{currYear}} iFinex Inc. Todos os direitos reservados.",
"page": "Página",
"from": "de"
}
Expand Down
2 changes: 1 addition & 1 deletion locales/ru/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "Эл. почта",
"errorMessage": "Ваш файл не может быть завершен, пожалуйста, попробуйте еще раз",
"reportGenAt": "Отчет сгенерирован в",
"copyright": "Авторское право © 2013-2024 iFinex Inc. Все права защищены.",
"copyright": "Авторское право © 2013-{{currYear}} iFinex Inc. Все права защищены.",
"page": "Стр.",
"from": "из"
}
Expand Down
16 changes: 0 additions & 16 deletions locales/tr/pdf.json

This file was deleted.

2 changes: 1 addition & 1 deletion locales/zh-CN/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "电子邮箱",
"errorMessage": "无法建立档案,请重试",
"reportGenAt": "报告创建时间",
"copyright": "Copyright © 2013-2024 iFinex Inc. All rights reserved.",
"copyright": "Copyright © 2013-{{currYear}} iFinex Inc. All rights reserved.",
"page": "页数",
"from": "从"
}
Expand Down
2 changes: 1 addition & 1 deletion locales/zh-TW/pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "電子郵箱",
"errorMessage": "無法建立檔案,請重試",
"reportGenAt": "報告建立時間:",
"copyright": "Copyright © 2013-2024 iFinex Inc. All rights reserved.",
"copyright": "Copyright © 2013-{{currYear}} iFinex Inc. All rights reserved.",
"page": "頁數",
"from": "從"
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-report",
"version": "4.13.2",
"version": "4.14.0",
"description": "Reporting tool",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
'use strict'

const { pipeline } = require('stream/promises')
const { stringify } = require('csv')

const {
pipelineStreams
} = require('../../../helpers')

const streamWriterToOne = async (
rStream,
wStream,
writeFn,
opts
) => {
const { end = true } = opts ?? {}
const promise = pipeline(rStream, wStream, { end })
const promise = pipelineStreams(rStream, wStream, { end })

writeFn(rStream)
rStream.end()
Expand Down
15 changes: 12 additions & 3 deletions workers/loc.api/generate-report-file/pdf-writer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class PdfWriter {
isError
} = opts ?? {}

const translate = this.getTranslator(language)
const template = this.#getTemplate(
pdfCustomTemplateName,
language
Expand All @@ -176,6 +177,15 @@ class PdfWriter {
jobData.args.params
)
const reportColumns = jobData?.columnsPdf ?? jobData?.columnsCsv
const _date = date instanceof Date
? date
: new Date()
const currYear = _date.getUTCFullYear()
const defaultValue = `Copyright © 2013-${currYear} iFinex Inc. All rights reserved.`
const copyright = translate(defaultValue, {
prop: 'template.copyright',
currYear
})

const html = template({
shouldZoomBeAdjusted: this.shouldZoomBeAdjusted,
Expand All @@ -191,9 +201,8 @@ class PdfWriter {
end: Number.isFinite(jobData?.args?.params?.end)
? new Date(jobData.args.params.end)
: new Date(),
date: date instanceof Date
? date
: new Date()
date: _date,
copyright
})

return html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ html(lang=language)
| : #{date.toLocaleString(language, { timeZone: 'UTC' })}

div.copyright
:translate(prop='template.copyright')
Copyright © 2013-2024 iFinex Inc. All rights reserved.
| #{copyright}

span.footer-page.none-if-no-phantomjs
:translate(prop='template.page')
Expand Down
4 changes: 3 additions & 1 deletion workers/loc.api/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const getDataFromApi = require('./get-data-from-api')
const splitSymbolPairs = require('./split-symbol-pairs')
const FOREX_SYMBS = require('./forex.symbs')
const getTranslator = require('./get-translator')
const pipelineStreams = require('./pipeline-streams')

module.exports = {
getREST,
Expand Down Expand Up @@ -115,5 +116,6 @@ module.exports = {
parsePositionsAuditId,
splitSymbolPairs,
FOREX_SYMBS,
getTranslator
getTranslator,
pipelineStreams
}
24 changes: 24 additions & 0 deletions workers/loc.api/helpers/pipeline-streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const { pipeline } = require('node:stream/promises')

module.exports = async (stringifier, writable, opts) => {
try {
const end = opts?.end ?? true

await pipeline(stringifier, writable, { end })
} catch (err) {
/*
* If an error occurs, eg when receiving data from the BFX API,
* a recording may occur after destruction in the stream
*/
if (
err.code === 'ERR_STREAM_DESTROYED' ||
err.code === 'ERR_STREAM_PREMATURE_CLOSE'
) {
return
}

throw err
}
}
31 changes: 27 additions & 4 deletions workers/loc.api/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TransportIPC extends TransportStream {
}
}

const _getTransports = () => {
const _getTransports = (conf) => {
if (!isProdEnv) {
return {
baseTransports: [
Expand All @@ -151,6 +151,29 @@ const _getTransports = () => {
}
}

if (conf.isHosted) {
return {
baseTransports: [
new transports.Console({
level: 'error',
colorize: false
}),
new TransportSlack({
level: 'error',
colorize: false
})
],
exceptionHandlers: [
new transports.Console({
colorize: false
}),
new TransportSlack({
colorize: false
})
]
}
}

return {
baseTransports: [
new transports.File({
Expand Down Expand Up @@ -239,17 +262,17 @@ const _combineFormat = (colorize = !isProdEnv) => {
)
}

module.exports = ({ isLoggerDisabled }) => {
module.exports = (conf) => {
const {
baseTransports,
exceptionHandlers
} = _getTransports()
} = _getTransports(conf)

return createLogger({
format: _combineFormat(),
transports: baseTransports,
exceptionHandlers,
silent: isLoggerDisabled || isTestEnv,
silent: conf.isLoggerDisabled || isTestEnv,
exitOnError: true
})
}
10 changes: 9 additions & 1 deletion workers/loc.api/queue/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = (
sendMail
) => {
return async (job) => {
const streamSet = new Set()

try {
const {
chunkCommonFolders,
Expand Down Expand Up @@ -50,7 +52,8 @@ module.exports = (
{
...userInfo,
email
}
},
streamSet
)

await sendMail(
Expand Down Expand Up @@ -128,6 +131,11 @@ module.exports = (
}

aggregatorQueue.emit('error:base', err, job)
} finally {
for (const stream of streamSet) {
stream.destroy()
streamSet.delete(stream)
}
}
}
}
2 changes: 0 additions & 2 deletions workers/loc.api/queue/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const getCompleteFileName = require('./get-complete-file-name')
const {
moveFileToLocalStorage,
writableToPromise,
createUniqueFileName
} = require('./utils')
const getLocalReportFolderPaths = require(
Expand All @@ -14,7 +13,6 @@ const getReportContentType = require('./get-report-content-type')

module.exports = {
moveFileToLocalStorage,
writableToPromise,
createUniqueFileName,
getCompleteFileName,
getLocalReportFolderPaths,
Expand Down
12 changes: 0 additions & 12 deletions workers/loc.api/queue/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,7 @@ const createUniqueFileName = async (rootPath, params, count = 0) => {
return path.join(tempReportFolderPath, uniqueFileName)
}

const writableToPromise = stream => {
return new Promise((resolve, reject) => {
stream.once('finish', () => {
resolve('finish')
})
stream.once('error', err => {
reject(err)
})
})
}

module.exports = {
moveFileToLocalStorage,
writableToPromise,
createUniqueFileName
}
Loading