mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 04:22:02 -06:00
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:
commit
10174069e0
@ -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" ]
|
@ -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' });
|
||||
|
52
src/cache/localcache.ts
vendored
52
src/cache/localcache.ts
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user