Skip to content

Commit

Permalink
fix: ⚡ fix inject port args
Browse files Browse the repository at this point in the history
  • Loading branch information
leifermendez committed Jan 9, 2023
1 parent dfc7847 commit 20f752e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
12 changes: 6 additions & 6 deletions packages/portal/portal.http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { bgYellow, cyan } = require('kleur')
const polka = require('polka')

const HTTP_PORT = process.env.PORT || 3000
const QR_FILE = process.env.QR_FILE ?? 'qr.png'
const QR_FILE = process.env.QR_FILE ?? 'bot'
const PUBLIC_URL =
process.env.PUBLIC_URL ??
process.env.RAILWAY_STATIC_URL ??
Expand All @@ -23,18 +23,18 @@ const start = (args) => {
const injectArgs = {
port: HTTP_PORT,
publicSite: PUBLIC_URL,
qrFile: QR_FILE,
name: QR_FILE,
...args,
}
const { port, publicSite, qrFile } = injectArgs
const { port, publicSite, name } = injectArgs

polka()
.use(serve)
.get('qr.png', (_, res) => {
const qrSource = [
join(process.cwd(), qrFile),
join(__dirname, '..', qrFile),
join(__dirname, qrFile),
join(process.cwd(), `${name}.png`),
join(__dirname, '..', `${name}.png`),
join(__dirname, `${name}.png`),
].find((i) => existsSync(i))

const qrMark = [
Expand Down
12 changes: 7 additions & 5 deletions packages/provider/src/baileys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ const logger = new Console({
stdout: createWriteStream(`${process.cwd()}/baileys.log`),
})

const NAME_DIR_SESSION = `sessions`
const PATH_BASE = join(process.cwd(), NAME_DIR_SESSION)

/**
* ⚙️ BaileysProvider: Es una clase tipo adaptor
* que extiende clases de ProviderClass (la cual es como interfaz para sber que funciones rqueridas)
* https://github.com/adiwajshing/Baileys
*/
class BaileysProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
globalVendorArgs = { name: `bot` }
vendor
saveCredsGlobal = null
constructor(args) {
Expand All @@ -46,6 +43,7 @@ class BaileysProvider extends ProviderClass {
* Iniciar todo Bailey
*/
initBailey = async () => {
const NAME_DIR_SESSION = `${this.globalVendorArgs.name}_sessions`
const { state, saveCreds } = await useMultiFileAuthState(
NAME_DIR_SESSION
)
Expand All @@ -72,6 +70,7 @@ class BaileysProvider extends ProviderClass {
}

if (statusCode === DisconnectReason.loggedOut) {
const PATH_BASE = join(process.cwd(), NAME_DIR_SESSION)
rimraf(PATH_BASE, (err) => {
if (err) return
})
Expand All @@ -95,7 +94,10 @@ class BaileysProvider extends ProviderClass {
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
],
})
await baileyGenerateImage(qr, this.globalVendorArgs.qrFile)
await baileyGenerateImage(
qr,
`${this.globalVendorArgs.name}.png`
)
}
})

Expand Down
7 changes: 4 additions & 3 deletions packages/provider/src/venom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const logger = new Console({
* https://github.com/orkestral/venom
*/
class VenomProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
globalVendorArgs = { name: `bot` }
vendor
constructor(args) {
super()
Expand All @@ -32,10 +32,11 @@ class VenomProvider extends ProviderClass {
* Iniciamos el Proveedor Venom
*/
init = async () => {
const NAME_DIR_SESSION = `${this.globalVendorArgs.name}_sessions`
try {
const client = await venom.create(
{
session: 'session-base',
session: NAME_DIR_SESSION,
multidevice: true,
},
(base) => this.generateQr(base),
Expand Down Expand Up @@ -68,7 +69,7 @@ class VenomProvider extends ProviderClass {
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
],
})
await venomGenerateImage(qr)
await venomGenerateImage(qr, `${this.globalVendorArgs.name}.png`)
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/provider/src/web-whatsapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ const logger = new Console({
* https://github.com/pedroslopez/whatsapp-web.js
*/
class WebWhatsappProvider extends ProviderClass {
globalVendorArgs = { qrFile: 'qr.png' }
globalVendorArgs = { name: `bot` }
vendor
constructor(args) {
super()
this.globalVendorArgs = { ...this.globalVendorArgs, ...args }
this.vendor = new Client({
authStrategy: new LocalAuth(),
authStrategy: new LocalAuth({
clientId: `${this.globalVendorArgs.name}_sessions`,
}),
puppeteer: {
headless: true,
args: [
Expand Down Expand Up @@ -75,7 +77,7 @@ class WebWhatsappProvider extends ProviderClass {
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
],
})
await wwebGenerateImage(qr)
await wwebGenerateImage(qr, `${this.globalVendorArgs.name}.png`)
},
},
{
Expand Down

0 comments on commit 20f752e

Please sign in to comment.