mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-25 22:57:44 -06:00
Merge branch 'v2.0.0' of github.com:EvolutionAPI/evolution-api into v2.0.0
This commit is contained in:
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',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user