feat: qr code filename

This commit is contained in:
Leifer Mendez
2023-01-09 19:43:22 +01:00
parent 4d721f99e2
commit d794f604ac
7 changed files with 21 additions and 13 deletions

View File

@@ -19,13 +19,15 @@ const serve = require('serve-static')(dir)
* Iniciamos Portal WEB para escanear QR * Iniciamos Portal WEB para escanear QR
* @param {port:3000, publicSite:'http://mistio.com', qrFile:'qr.png', dir:__dirname} * @param {port:3000, publicSite:'http://mistio.com', qrFile:'qr.png', dir:__dirname}
*/ */
const start = ( const start = (args) => {
{ port, publicSite, qrFile } = { const injectArgs = {
port: HTTP_PORT, port: HTTP_PORT,
publicSite: PUBLIC_URL, publicSite: PUBLIC_URL,
qrFile: QR_FILE, qrFile: QR_FILE,
...args,
} }
) => { const { port, publicSite, qrFile } = injectArgs
polka() polka()
.use(serve) .use(serve)
.get(qrFile, (_, res) => { .get(qrFile, (_, res) => {

View File

@@ -33,10 +33,12 @@ const PATH_BASE = join(process.cwd(), NAME_DIR_SESSION)
* https://github.com/adiwajshing/Baileys * https://github.com/adiwajshing/Baileys
*/ */
class BaileysProvider extends ProviderClass { class BaileysProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
vendor vendor
saveCredsGlobal = null saveCredsGlobal = null
constructor() { constructor(args) {
super() super()
this.globalVendorArgs = { ...this.globalVendorArgs, ...args }
this.initBailey().then() this.initBailey().then()
} }
@@ -93,7 +95,7 @@ class BaileysProvider extends ProviderClass {
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`, `Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
], ],
}) })
await baileyGenerateImage(qr) await baileyGenerateImage(qr, this.globalVendorArgs.qrFile)
} }
}) })

View File

@@ -15,8 +15,8 @@ const baileyCleanNumber = (number, full = false) => {
* Hace promesa el write * Hace promesa el write
* @param {*} base64 * @param {*} base64
*/ */
const baileyGenerateImage = async (base64) => { const baileyGenerateImage = async (base64, name = 'qr.png') => {
const PATH_QR = `${process.cwd()}/qr.png` const PATH_QR = `${process.cwd()}/${name}`
let qr_svg = qr.image(base64, { type: 'png', margin: 4 }) let qr_svg = qr.image(base64, { type: 'png', margin: 4 })
const writeFilePromise = () => const writeFilePromise = () =>

View File

@@ -20,9 +20,11 @@ const logger = new Console({
* https://github.com/orkestral/venom * https://github.com/orkestral/venom
*/ */
class VenomProvider extends ProviderClass { class VenomProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
vendor vendor
constructor() { constructor(args) {
super() super()
this.globalVendorArgs = { ...this.globalVendorArgs, ...args }
this.init().then(() => this.initBusEvents()) this.init().then(() => this.initBusEvents())
} }

View File

@@ -10,8 +10,8 @@ const venomCleanNumber = (number, full = false) => {
return number return number
} }
const venomGenerateImage = async (base) => { const venomGenerateImage = async (base, name = 'qr.png') => {
const PATH_QR = `${process.cwd()}/qr.png` const PATH_QR = `${process.cwd()}/${name}`
const matches = base.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/) const matches = base.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/)
if (matches.length !== 3) { if (matches.length !== 3) {
return new Error('Invalid input string') return new Error('Invalid input string')

View File

@@ -19,9 +19,11 @@ const logger = new Console({
* https://github.com/pedroslopez/whatsapp-web.js * https://github.com/pedroslopez/whatsapp-web.js
*/ */
class WebWhatsappProvider extends ProviderClass { class WebWhatsappProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
vendor vendor
constructor() { constructor(args) {
super() super()
this.globalVendorArgs = { ...this.globalVendorArgs, ...args }
this.vendor = new Client({ this.vendor = new Client({
authStrategy: new LocalAuth(), authStrategy: new LocalAuth(),
puppeteer: { puppeteer: {

View File

@@ -11,8 +11,8 @@ const wwebCleanNumber = (number, full = false) => {
return number return number
} }
const wwebGenerateImage = async (base64) => { const wwebGenerateImage = async (base64, name = 'qr.png') => {
const PATH_QR = `${process.cwd()}/qr.png` const PATH_QR = `${process.cwd()}/${name}`
let qr_svg = qr.image(base64, { type: 'png', margin: 4 }) let qr_svg = qr.image(base64, { type: 'png', margin: 4 })
const writeFilePromise = () => const writeFilePromise = () =>