mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 17:08:44 -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
|
ENV DOCKER_ENV=true
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
|
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
|
@ -3,16 +3,17 @@ const { execSync } = require('child_process');
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const { DATABASE_PROVIDER } = process.env;
|
const { DATABASE_PROVIDER } = process.env;
|
||||||
|
const databaseProviderDefault = DATABASE_PROVIDER ?? "postgresql"
|
||||||
|
|
||||||
if (!DATABASE_PROVIDER) {
|
if (!DATABASE_PROVIDER) {
|
||||||
console.error('DATABASE_PROVIDER is not set in the .env file');
|
console.error(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
|
||||||
process.exit(1);
|
// process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const command = process.argv
|
const command = process.argv
|
||||||
.slice(2)
|
.slice(2)
|
||||||
.join(' ')
|
.join(' ')
|
||||||
.replace(/\DATABASE_PROVIDER/g, DATABASE_PROVIDER);
|
.replace(/\DATABASE_PROVIDER/g, databaseProviderDefault);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(command, { stdio: 'inherit' });
|
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 { ICache } from '@api/abstract/abstract.cache';
|
||||||
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
|
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
|
||||||
import NodeCache from 'node-cache';
|
import NodeCache from 'node-cache';
|
||||||
|
import { BufferJSON } from 'baileys';
|
||||||
|
import { Logger } from '@config/logger.config';
|
||||||
|
|
||||||
export class LocalCache implements ICache {
|
export class LocalCache implements ICache {
|
||||||
|
private readonly logger = new Logger('LocalCache');
|
||||||
private conf: CacheConfLocal;
|
private conf: CacheConfLocal;
|
||||||
static localCache = new NodeCache();
|
static localCache = new NodeCache();
|
||||||
|
|
||||||
@ -45,16 +48,51 @@ export class LocalCache implements ICache {
|
|||||||
return `${this.module}:${key}`;
|
return `${this.module}:${key}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async hGet() {
|
async hGet(key: string, field: string) {
|
||||||
console.log('hGet not implemented');
|
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() {
|
async hSet(key: string, field: string, value: any) {
|
||||||
console.log('hSet not implemented');
|
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() {
|
async hDelete(key: string, field: string) {
|
||||||
console.log('hDelete not implemented');
|
try {
|
||||||
return 0;
|
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',
|
DISABLE_MANAGER: process.env?.SERVER_DISABLE_MANAGER === 'true',
|
||||||
},
|
},
|
||||||
CORS: {
|
CORS: {
|
||||||
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
|
ORIGIN: process.env.CORS_ORIGIN?.split(',') || ['*'],
|
||||||
METHODS: (process.env.CORS_METHODS.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'],
|
METHODS: (process.env.CORS_METHODS?.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'] as HttpMethods[],
|
||||||
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
|
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
|
||||||
},
|
},
|
||||||
SSL_CONF: {
|
SSL_CONF: {
|
||||||
@ -354,7 +354,7 @@ export class ConfigService {
|
|||||||
LANGUAGE: process.env.WA_BUSINESS_LANGUAGE || 'en',
|
LANGUAGE: process.env.WA_BUSINESS_LANGUAGE || 'en',
|
||||||
},
|
},
|
||||||
LOG: {
|
LOG: {
|
||||||
LEVEL: (process.env?.LOG_LEVEL.split(',') as LogLevel[]) || [
|
LEVEL: (process.env?.LOG_LEVEL?.split(',') as LogLevel[]) || [
|
||||||
'ERROR',
|
'ERROR',
|
||||||
'WARN',
|
'WARN',
|
||||||
'DEBUG',
|
'DEBUG',
|
||||||
@ -364,7 +364,7 @@ export class ConfigService {
|
|||||||
'DARK',
|
'DARK',
|
||||||
'WEBHOOKS',
|
'WEBHOOKS',
|
||||||
'WEBSOCKET',
|
'WEBSOCKET',
|
||||||
],
|
] as LogLevel[],
|
||||||
COLOR: process.env?.LOG_COLOR === 'true',
|
COLOR: process.env?.LOG_COLOR === 'true',
|
||||||
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
|
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user