mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-10 18:39:38 -06:00
Refactor imports and clean up code structure
This commit is contained in:
parent
2408384b0f
commit
bbf60e30b0
@ -76,21 +76,19 @@ import {
|
|||||||
S3,
|
S3,
|
||||||
} from '@config/env.config';
|
} from '@config/env.config';
|
||||||
import { BadRequestException, InternalServerErrorException, NotFoundException } from '@exceptions';
|
import { BadRequestException, InternalServerErrorException, NotFoundException } from '@exceptions';
|
||||||
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files';
|
||||||
import { Boom } from '@hapi/boom';
|
|
||||||
import { createId as cuid } from '@paralleldrive/cuid2';
|
|
||||||
import { Instance, Message } from '@prisma/client';
|
|
||||||
import { createJid } from '@utils/createJid';
|
import { createJid } from '@utils/createJid';
|
||||||
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
|
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
|
||||||
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
|
|
||||||
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
|
||||||
|
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
|
||||||
import { status } from '@utils/renderStatus';
|
import { status } from '@utils/renderStatus';
|
||||||
import { sendTelemetry } from '@utils/sendTelemetry';
|
import { sendTelemetry } from '@utils/sendTelemetry';
|
||||||
import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma';
|
import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma';
|
||||||
import { AuthStateProvider } from '@utils/use-multi-file-auth-state-provider-files';
|
|
||||||
import { useMultiFileAuthStateRedisDb } from '@utils/use-multi-file-auth-state-redis-db';
|
import { useMultiFileAuthStateRedisDb } from '@utils/use-multi-file-auth-state-redis-db';
|
||||||
import axios from 'axios';
|
|
||||||
import { createHash } from 'crypto';
|
import { BaileysMessageProcessor } from './baileysMessage.processor';
|
||||||
|
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
|
||||||
|
|
||||||
import makeWASocket, {
|
import makeWASocket, {
|
||||||
AnyMessageContent,
|
AnyMessageContent,
|
||||||
BufferedEventData,
|
BufferedEventData,
|
||||||
@ -105,7 +103,6 @@ import makeWASocket, {
|
|||||||
DisconnectReason,
|
DisconnectReason,
|
||||||
downloadContentFromMessage,
|
downloadContentFromMessage,
|
||||||
downloadMediaMessage,
|
downloadMediaMessage,
|
||||||
jidNormalizedUser,
|
|
||||||
generateWAMessageFromContent,
|
generateWAMessageFromContent,
|
||||||
getAggregateVotesInPollMessage,
|
getAggregateVotesInPollMessage,
|
||||||
GetCatalogOptions,
|
GetCatalogOptions,
|
||||||
@ -116,6 +113,7 @@ import makeWASocket, {
|
|||||||
isJidGroup,
|
isJidGroup,
|
||||||
isJidNewsletter,
|
isJidNewsletter,
|
||||||
isPnUser,
|
isPnUser,
|
||||||
|
jidNormalizedUser,
|
||||||
makeCacheableSignalKeyStore,
|
makeCacheableSignalKeyStore,
|
||||||
MessageUpsertType,
|
MessageUpsertType,
|
||||||
MessageUserReceiptUpdate,
|
MessageUserReceiptUpdate,
|
||||||
@ -134,15 +132,20 @@ import makeWASocket, {
|
|||||||
} from 'baileys';
|
} from 'baileys';
|
||||||
import { Label } from 'baileys/lib/Types/Label';
|
import { Label } from 'baileys/lib/Types/Label';
|
||||||
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
|
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
|
||||||
import { spawn } from 'child_process';
|
import { createId as cuid } from '@paralleldrive/cuid2';
|
||||||
|
import { Instance, Message } from '@prisma/client';
|
||||||
|
import axios from 'axios';
|
||||||
import { isArray, isBase64, isURL } from 'class-validator';
|
import { isArray, isBase64, isURL } from 'class-validator';
|
||||||
|
import { createHash } from 'crypto';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
|
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
|
import { Boom } from '@hapi/boom';
|
||||||
import Long from 'long';
|
import Long from 'long';
|
||||||
import mimeTypes from 'mime-types';
|
import mimeTypes from 'mime-types';
|
||||||
import NodeCache from 'node-cache';
|
|
||||||
import cron from 'node-cron';
|
import cron from 'node-cron';
|
||||||
|
import NodeCache from 'node-cache';
|
||||||
import { release } from 'os';
|
import { release } from 'os';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import P from 'pino';
|
import P from 'pino';
|
||||||
@ -150,11 +153,9 @@ import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
|
|||||||
import qrcodeTerminal from 'qrcode-terminal';
|
import qrcodeTerminal from 'qrcode-terminal';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { PassThrough, Readable } from 'stream';
|
import { PassThrough, Readable } from 'stream';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { BaileysMessageProcessor } from './baileysMessage.processor';
|
|
||||||
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';
|
|
||||||
|
|
||||||
export interface ExtendedIMessageKey extends proto.IMessageKey {
|
export interface ExtendedIMessageKey extends proto.IMessageKey {
|
||||||
remoteJidAlt?: string;
|
remoteJidAlt?: string;
|
||||||
participantAlt?: string;
|
participantAlt?: string;
|
||||||
@ -1250,7 +1251,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
...new Set(creatorCandidates.filter(Boolean).map((id) => jidNormalizedUser(id))),
|
...new Set(creatorCandidates.filter(Boolean).map((id) => jidNormalizedUser(id))),
|
||||||
];
|
];
|
||||||
const uniqueVoters = [
|
const uniqueVoters = [
|
||||||
...new Set(voterCandidates.filter(Boolean).map((id) => jidNormalizedUser(id))),
|
...new Set(voterCandidates.filter(Boolean).map((id) => jidNormalizedUser(id)))
|
||||||
];
|
];
|
||||||
|
|
||||||
let decryptedVote;
|
let decryptedVote;
|
||||||
@ -1268,7 +1269,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
successfulVoterJid = voter;
|
successfulVoterJid = voter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (_err) {
|
||||||
// Continue trying
|
// Continue trying
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1349,7 +1350,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
|
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
|
||||||
const { pollUpdates, ...messageData } = messageRaw;
|
const { _pollUpdates, ...messageData } = messageRaw;
|
||||||
const msg = await this.prismaRepository.message.create({ data: messageData });
|
const msg = await this.prismaRepository.message.create({ data: messageData });
|
||||||
|
|
||||||
const { remoteJid } = received.key;
|
const { remoteJid } = received.key;
|
||||||
@ -1559,10 +1560,12 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
const cached = await this.baileysCache.get(updateKey);
|
const cached = await this.baileysCache.get(updateKey);
|
||||||
|
|
||||||
const secondsSinceEpoch = Math.floor(Date.now() / 1000)
|
const secondsSinceEpoch = Math.floor(Date.now() / 1000);
|
||||||
console.log('CACHE:', {cached, updateKey, messageTimestamp: update.messageTimestamp, secondsSinceEpoch});
|
|
||||||
|
|
||||||
if ((update.messageTimestamp && update.messageTimestamp === cached) || (!update.messageTimestamp && secondsSinceEpoch === cached)) {
|
if (
|
||||||
|
(update.messageTimestamp && update.messageTimestamp === cached) ||
|
||||||
|
(!update.messageTimestamp && secondsSinceEpoch === cached)
|
||||||
|
) {
|
||||||
this.logger.info(`Update Message duplicated ignored [avoid deadlock]: ${updateKey}`);
|
this.logger.info(`Update Message duplicated ignored [avoid deadlock]: ${updateKey}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1689,7 +1692,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
|
this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
|
||||||
|
|
||||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
|
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
|
||||||
const { message: _msg, ...messageData } = message;
|
const { message: __msg, ...messageData } = message;
|
||||||
await this.prismaRepository.messageUpdate.create({ data: messageData });
|
await this.prismaRepository.messageUpdate.create({ data: messageData });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user