Skip to content

Commit 28924f3

Browse files
committed
update to mysql
1 parent 3184c3b commit 28924f3

File tree

8 files changed

+163
-206
lines changed

8 files changed

+163
-206
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
node: true,
1919
jest: true,
2020
},
21-
ignorePatterns: ['.eslintrc.js'],
21+
ignorePatterns: ['.eslintrc.js', 'test/test.ts'],
2222
rules: {
2323
'@typescript-eslint/interface-name-prefix': 'off',
2424
'@typescript-eslint/explicit-function-return-type': 'off',

Dockerfile

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
### BASE IMAGE
2-
FROM node:20-bullseye-slim AS base
2+
FROM node:24-bullseye-slim AS base
3+
4+
# Opcional: timezone/locale mínimos, se precisar.
5+
# RUN apt-get update && apt-get install -y tzdata && rm -rf /var/lib/apt/lists/*
36

47
### BUILD IMAGE
58
FROM base AS builder
6-
79
WORKDIR /codechat
810

9-
# Instalar dependências de construção primeiro
11+
# Dependências de SO necessárias no build (git/ffmpeg se usados em build)
1012
RUN apt-get update && apt-get install -y git ffmpeg && rm -rf /var/lib/apt/lists/*
1113

12-
# Copiar arquivos package.json e instalar dependências
14+
# Instalar TODAS as deps (inclui dev) para conseguir rodar tsc
1315
COPY package*.json ./
14-
RUN npm install --force
16+
# Use npm ci para builds reprodutíveis
17+
RUN npm i --force
1518

16-
# Copiar os demais arquivos necessários para o build
19+
# Copiar código
1720
COPY tsconfig.json .
1821
COPY ./src ./src
1922
COPY ./public ./public
@@ -22,37 +25,42 @@ COPY ./prisma ./prisma
2225
COPY ./views ./views
2326
COPY .env.dev .env
2427

25-
# Definir variável de ambiente para a construção
26-
ENV DATABASE_URL=mysql://mysql:pass@localhost/db_test
27-
RUN npx prisma generate
28+
# Variável para gerar Prisma Client (não precisa apontar p/ DB real)
29+
ENV DATABASE_URL="mysql://mysql:pass@localhost/db_test"
2830

31+
# Gerar prisma e compilar TS -> JS
32+
RUN npx prisma generate
2933
RUN npm run build
3034

35+
# Remover devDependencies para preparar node_modules "de produção"
36+
# RUN npm prune --omit=dev
37+
3138
### PRODUCTION IMAGE
3239
FROM base AS production
33-
3440
WORKDIR /codechat
3541

36-
LABEL com.api.version="1.3.3"
37-
LABEL com.api.mantainer="https://github.com/code-chat-br"
38-
LABEL com.api.repository="https://github.com/code-chat-br/whatsapp-api"
39-
LABEL com.api.issues="https://github.com/code-chat-br/whatsapp-api/issues"
42+
# Instale apenas o que o app precisa em runtime (ex.: ffmpeg)
43+
RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/*
4044

41-
# Copiar arquivos construídos do estágio builder
45+
LABEL com.api.version="1.3.3" \
46+
com.api.mantainer="https://github.com/code-chat-br" \
47+
com.api.repository="https://github.com/code-chat-br/whatsapp-api" \
48+
com.api.issues="https://github.com/code-chat-br/whatsapp-api/issues"
49+
50+
# Copiar artefatos já prontos e node_modules podado
4251
COPY --from=builder /codechat/dist ./dist
4352
COPY --from=builder /codechat/docs ./docs
4453
COPY --from=builder /codechat/prisma ./prisma
4554
COPY --from=builder /codechat/views ./views
46-
COPY --from=builder /codechat/node_modules ./node_modules
55+
COPY --from=builder /codechat/public ./public
4756
COPY --from=builder /codechat/package*.json ./
4857
COPY --from=builder /codechat/.env ./
49-
COPY --from=builder /codechat/public ./public
58+
COPY --from=builder /codechat/node_modules ./node_modules
5059
COPY ./deploy_db.sh ./
5160

52-
RUN chmod +x ./deploy_db.sh
53-
54-
RUN mkdir instances
61+
RUN chmod +x ./deploy_db.sh && mkdir -p instances
5562

5663
ENV DOCKER_ENV=true
5764

58-
ENTRYPOINT [ "/bin/bash", "-c", ". ./deploy_db.sh && node ./dist/src/main" ]
65+
# Se seu deploy_db.sh precisa do shell, mantenha o bash -c
66+
ENTRYPOINT ["/bin/bash", "-c", ". ./deploy_db.sh && node ./dist/src/main"]

PROJECT_STRUCTURE.md

Lines changed: 0 additions & 118 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "ts-node --files --transpile-only ./src/main.ts",
99
"start:prod": "bash start.sh",
1010
"start:dev": "tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
11-
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts"
11+
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/test.ts"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -44,7 +44,7 @@
4444
"@adiwajshing/keyed-db": "^0.2.4",
4545
"@hapi/boom": "^10.0.1",
4646
"@prisma/client": "^5.19.1",
47-
"@whiskeysockets/baileys": "^6.7.16",
47+
"@whiskeysockets/baileys": "7.0.0-rc.8",
4848
"axios": "^1.7.7",
4949
"class-validator": "^0.14.0",
5050
"cross-env": "^7.0.3",

prisma.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// import { defineConfig, env } from 'prisma/config';
2+
3+
// export default defineConfig({
4+
// schema: 'prisma/schema.prisma',
5+
// migrations: {
6+
// path: 'prisma/migrations',
7+
// },
8+
// engine: 'classic',
9+
// datasource: {
10+
// url: env('DATABASE_URL'),
11+
// },
12+
// });

prisma/schema.prisma

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,25 @@ enum DeviceMessage {
8888
}
8989

9090
model Message {
91-
id Int @id @default(autoincrement())
92-
keyId String @db.VarChar(100)
93-
keyRemoteJid String @db.VarChar(100)
94-
keyFromMe Boolean @db.TinyInt
95-
keyParticipant String? @db.VarChar(100)
96-
pushName String? @db.VarChar(100)
97-
messageType String @db.VarChar(100)
98-
content Json @db.Json
99-
messageTimestamp Int @db.Int
100-
device DeviceMessage
101-
isGroup Boolean? @db.TinyInt
102-
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
103-
instanceId Int
104-
MessageUpdate MessageUpdate[]
105-
Media Media?
106-
107-
@@index([keyId], name: "keyId")
91+
id Int @id @default(autoincrement())
92+
keyId String? @db.VarChar(100)
93+
keyLid String? @db.VarChar(100)
94+
keyRemoteJid String? @db.VarChar(100)
95+
keyFromMe Boolean @db.TinyInt
96+
keyParticipant String? @db.VarChar(100)
97+
keyParticipantLid String? @db.VarChar(100)
98+
pushName String? @db.VarChar(100)
99+
messageType String @db.VarChar(100)
100+
content Json @db.Json
101+
messageTimestamp Int @db.Int
102+
device DeviceMessage
103+
isGroup Boolean? @db.TinyInt
104+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
105+
instanceId Int
106+
MessageUpdate MessageUpdate[]
107+
Media Media?
108+
109+
@@index([instanceId, keyRemoteJid, id(sort: Desc)], name: "idx_message_instance_jid_id")
108110
}
109111

110112
model Media {

src/utils/wa-version.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { WAVersion } from '@whiskeysockets/baileys';
2+
import axios from 'axios';
3+
4+
export const fetchLatestBaileysVersionV2 = async () => {
5+
try {
6+
const resp = await axios.get<string>('https://web.whatsapp.com/sw.js');
7+
const re = /JSON\.parse\(\s*(?:\/\*[^]*?\*\/\s*)?("(?:(?:\\.|[^"\\])*)")\s*\)/;
8+
const m = re.exec(resp.data);
9+
if (!m) {
10+
return {
11+
version: [2, 3000, 1030436551.257521] as WAVersion,
12+
isLatest: false,
13+
error: new Error('regexp-filed'),
14+
};
15+
}
16+
17+
const escaped = m[1];
18+
const jsonText = JSON.parse(escaped) as string;
19+
const obj = JSON.parse(jsonText) as Record<string, unknown>;
20+
21+
const v = obj?.dynamic_data?.['dynamic_modules']?.SiteData?.client_revision as number;
22+
if (v) {
23+
return {
24+
version: [2, 3000, v] as WAVersion,
25+
isLatest: true,
26+
error: null as unknown,
27+
};
28+
} else {
29+
return {
30+
version: [2, 3000, 1030436551.257521] as WAVersion,
31+
isLatest: false,
32+
error: new Error('version not-found'),
33+
};
34+
}
35+
} catch (error) {
36+
const waVersion = JSON.parse(process.env?.WA_VERSION || '[]') as number[];
37+
return {
38+
version: [2, 3000, waVersion?.[2] ?? 1029707447] as WAVersion,
39+
isLatest: false,
40+
error: error as unknown,
41+
};
42+
}
43+
};

0 commit comments

Comments
 (0)