Merge pull request #937 from oismaelash/v2.0.0

update: docker with expose port and localcache hGet and hSet return null
This commit is contained in:
Davidson Gomes 2024-10-03 08:35:17 -03:00 committed by GitHub
commit 10174069e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 55 additions and 14 deletions

View File

@ -53,4 +53,6 @@ COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts
ENV DOCKER_ENV=true
EXPOSE 8080
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]

View File

@ -3,16 +3,17 @@ const { execSync } = require('child_process');
dotenv.config();
const { DATABASE_PROVIDER } = process.env;
const databaseProviderDefault = DATABASE_PROVIDER ?? "postgresql"
if (!DATABASE_PROVIDER) {
console.error('DATABASE_PROVIDER is not set in the .env file');
process.exit(1);
console.error(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
// process.exit(1);
}
const command = process.argv
.slice(2)
.join(' ')
.replace(/\DATABASE_PROVIDER/g, DATABASE_PROVIDER);
.replace(/\DATABASE_PROVIDER/g, databaseProviderDefault);
try {
execSync(command, { stdio: 'inherit' });

View File

@ -1,8 +1,11 @@
import { ICache } from '@api/abstract/abstract.cache';
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
import NodeCache from 'node-cache';
import { BufferJSON } from 'baileys';
import { Logger } from '@config/logger.config';
export class LocalCache implements ICache {
private readonly logger = new Logger('LocalCache');
private conf: CacheConfLocal;
static localCache = new NodeCache();
@ -45,16 +48,51 @@ export class LocalCache implements ICache {
return `${this.module}:${key}`;
}
async hGet() {
console.log('hGet not implemented');
async hGet(key: string, field: string) {
try {
const data = LocalCache.localCache.get(this.buildKey(key)) as Object;
if (data && field in data) {
return JSON.parse(data[field], BufferJSON.reviver);
}
return null;
} catch (error) {
this.logger.error(error);
}
}
async hSet() {
console.log('hSet not implemented');
async hSet(key: string, field: string, value: any) {
try {
const json = JSON.stringify(value, BufferJSON.replacer);
let hash = LocalCache.localCache.get(this.buildKey(key));
if (!hash) {
hash = {};
}
hash[field] = json;
LocalCache.localCache.set(key, hash);
} catch (error) {
this.logger.error(error);
}
}
async hDelete() {
console.log('hDelete not implemented');
return 0;
async hDelete(key: string, field: string) {
try {
const data = LocalCache.localCache.get(this.buildKey(key)) as Object;
if (data && field in data) {
delete data[field];
LocalCache.localCache.set(key, data);
return 1;
}
return 0;
} catch (error) {
this.logger.error(error);
}
}
}

View File

@ -269,8 +269,8 @@ export class ConfigService {
DISABLE_MANAGER: process.env?.SERVER_DISABLE_MANAGER === 'true',
},
CORS: {
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
METHODS: (process.env.CORS_METHODS.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'],
ORIGIN: process.env.CORS_ORIGIN?.split(',') || ['*'],
METHODS: (process.env.CORS_METHODS?.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'] as HttpMethods[],
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
},
SSL_CONF: {
@ -354,7 +354,7 @@ export class ConfigService {
LANGUAGE: process.env.WA_BUSINESS_LANGUAGE || 'en',
},
LOG: {
LEVEL: (process.env?.LOG_LEVEL.split(',') as LogLevel[]) || [
LEVEL: (process.env?.LOG_LEVEL?.split(',') as LogLevel[]) || [
'ERROR',
'WARN',
'DEBUG',
@ -364,7 +364,7 @@ export class ConfigService {
'DARK',
'WEBHOOKS',
'WEBSOCKET',
],
] as LogLevel[],
COLOR: process.env?.LOG_COLOR === 'true',
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
},