-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
503 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#app | ||
DEFAULT_CNPJ_INPUT=63543580000183 | ||
|
||
#twilio | ||
TWILIO_ENABLE_SEND=false | ||
TWILIO_ACCOUNT_SID= | ||
TWILIO_AUTH_TOKEN= | ||
TWILIO_CELL_FROM= | ||
TWILIO_CELL_TO= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
node_modules/ | ||
|
||
# files | ||
.local.env | ||
bin/*.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import winston from 'winston'; | ||
|
||
export const logger = winston.createLogger({ | ||
level: "info", | ||
format: winston.format.simple(), | ||
transports: [new winston.transports.Console()], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,57 @@ | ||
import { PDFBarcodeJs } from 'pdf-barcode'; | ||
import winston from 'winston'; | ||
import { addDac } from './addDAC.js'; | ||
|
||
const logger = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.simple(), | ||
transports: [ | ||
new winston.transports.Console() | ||
] | ||
}); | ||
import { PDFBarcodeJs } from "pdf-barcode"; | ||
import { logger } from './loggers.js'; | ||
import { addDac } from "./addDAC.js"; | ||
import { sendSMS } from "./sendSMS.js"; | ||
|
||
// path to save the DAS tab | ||
const downloadPath = process.cwd() + '/bin'; | ||
const downloadPath = process.cwd() + "/bin"; | ||
|
||
const configs = { | ||
scale: { | ||
once: true, | ||
value: 3, | ||
start: 3, | ||
step: 0.6, | ||
stop: 4.8 | ||
once: true, | ||
value: 3, | ||
start: 3, | ||
step: 0.6, | ||
stop: 4.8, | ||
}, | ||
resultOpts: { | ||
singleCodeInPage: true, | ||
multiCodesInPage: false, | ||
maxCodesInPage: 1 | ||
singleCodeInPage: true, | ||
multiCodesInPage: false, | ||
maxCodesInPage: 1, | ||
}, | ||
patches: [ | ||
"x-small", | ||
"small", | ||
"medium" | ||
], | ||
patches: ["x-small", "small", "medium"], | ||
improve: true, | ||
noisify: true, | ||
quagga: { | ||
inputStream: {}, | ||
locator: { | ||
halfSample: false | ||
}, | ||
decoder: { | ||
readers: [ | ||
"i2of5_reader", | ||
], | ||
multiple: false | ||
}, | ||
locate: true | ||
} | ||
inputStream: {}, | ||
locator: { | ||
halfSample: false, | ||
}, | ||
decoder: { | ||
readers: ["i2of5_reader"], | ||
multiple: false, | ||
}, | ||
locate: true, | ||
}, | ||
}; | ||
|
||
//Reads the barcode from a PDF file | ||
function readBarcodePDF(header) { | ||
if (typeof header['content-disposition'] === "string") { | ||
if(header['content-disposition'].includes('filename')) { | ||
const filename = header['content-disposition'].replace("attachment; filename=", ""); | ||
if (typeof header["content-disposition"] === "string") { | ||
if (header["content-disposition"].includes("filename")) { | ||
const filename = header["content-disposition"].replace( | ||
"attachment; filename=", | ||
"" | ||
); | ||
const filePath = new URL(`file:///${downloadPath + "/" + filename}`).href; | ||
PDFBarcodeJs.decodeSinglePage(filePath, 1, configs, (response) => { | ||
const barcode = response.codes[0]; | ||
const barcodeWithDAC = addDac(barcode); | ||
logger.info(`Barcode: ${barcodeWithDAC}`); | ||
const barcode = response.codes[0]; | ||
const barcodeWithDAC = addDac(barcode); | ||
sendSMS(barcodeWithDAC); | ||
logger.info(`Barcode: ${barcodeWithDAC}`); | ||
}); | ||
}; | ||
} | ||
} | ||
} | ||
|
||
export { readBarcodePDF }; | ||
export { readBarcodePDF }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createRequire } from 'module'; | ||
import dotenv from 'dotenv'; | ||
import { logger } from './loggers.js'; | ||
|
||
// Load environment variables from .env file | ||
dotenv.config(); | ||
|
||
function sendSMS(msg) { | ||
//Send sms if TWILIO ENABLE SEND environment variable is set to true | ||
if(process.env.TWILIO_ENABLE_SEND.toLowerCase() === 'true') { | ||
const accountSid = process.env.TWILIO_ACCOUNT_SID; | ||
const authToken = process.env.TWILIO_AUTH_TOKEN; | ||
const require = createRequire(import.meta.url); | ||
const client = require('twilio')(accountSid, authToken); | ||
client.messages | ||
.create({ | ||
body: `Código de barra da guia do DAS: ${msg}`, | ||
from: process.env.TWILIO_CELL_FROM, | ||
to: process.env.TWILIO_CELL_TO | ||
}) | ||
.then(message => logger.info(message.body)); | ||
} | ||
}; | ||
|
||
export { sendSMS }; |
Oops, something went wrong.