Skip to content

Commit 1017406

Browse files
Merge pull request #937 from oismaelash/v2.0.0
update: docker with expose port and localcache hGet and hSet return null
2 parents e146921 + 0ad330b commit 1017406

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts
5353

5454
ENV DOCKER_ENV=true
5555

56+
EXPOSE 8080
57+
5658
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]

runWithProvider.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ const { execSync } = require('child_process');
33
dotenv.config();
44

55
const { DATABASE_PROVIDER } = process.env;
6+
const databaseProviderDefault = DATABASE_PROVIDER ?? "postgresql"
67

78
if (!DATABASE_PROVIDER) {
8-
console.error('DATABASE_PROVIDER is not set in the .env file');
9-
process.exit(1);
9+
console.error(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
10+
// process.exit(1);
1011
}
1112

1213
const command = process.argv
1314
.slice(2)
1415
.join(' ')
15-
.replace(/\DATABASE_PROVIDER/g, DATABASE_PROVIDER);
16+
.replace(/\DATABASE_PROVIDER/g, databaseProviderDefault);
1617

1718
try {
1819
execSync(command, { stdio: 'inherit' });

src/cache/localcache.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ICache } from '@api/abstract/abstract.cache';
22
import { CacheConf, CacheConfLocal, ConfigService } from '@config/env.config';
33
import NodeCache from 'node-cache';
4+
import { BufferJSON } from 'baileys';
5+
import { Logger } from '@config/logger.config';
46

57
export class LocalCache implements ICache {
8+
private readonly logger = new Logger('LocalCache');
69
private conf: CacheConfLocal;
710
static localCache = new NodeCache();
811

@@ -45,16 +48,51 @@ export class LocalCache implements ICache {
4548
return `${this.module}:${key}`;
4649
}
4750

48-
async hGet() {
49-
console.log('hGet not implemented');
51+
async hGet(key: string, field: string) {
52+
try {
53+
const data = LocalCache.localCache.get(this.buildKey(key)) as Object;
54+
55+
if (data && field in data) {
56+
return JSON.parse(data[field], BufferJSON.reviver);
57+
}
58+
59+
return null;
60+
} catch (error) {
61+
this.logger.error(error);
62+
}
5063
}
5164

52-
async hSet() {
53-
console.log('hSet not implemented');
65+
async hSet(key: string, field: string, value: any) {
66+
try {
67+
const json = JSON.stringify(value, BufferJSON.replacer);
68+
69+
let hash = LocalCache.localCache.get(this.buildKey(key));
70+
71+
if (!hash) {
72+
hash = {};
73+
}
74+
75+
hash[field] = json;
76+
LocalCache.localCache.set(key, hash);
77+
78+
} catch (error) {
79+
this.logger.error(error);
80+
}
5481
}
5582

56-
async hDelete() {
57-
console.log('hDelete not implemented');
58-
return 0;
83+
async hDelete(key: string, field: string) {
84+
try {
85+
const data = LocalCache.localCache.get(this.buildKey(key)) as Object;
86+
87+
if (data && field in data) {
88+
delete data[field];
89+
LocalCache.localCache.set(key, data);
90+
return 1;
91+
}
92+
93+
return 0;
94+
} catch (error) {
95+
this.logger.error(error);
96+
}
5997
}
6098
}

src/config/env.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ export class ConfigService {
269269
DISABLE_MANAGER: process.env?.SERVER_DISABLE_MANAGER === 'true',
270270
},
271271
CORS: {
272-
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
273-
METHODS: (process.env.CORS_METHODS.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'],
272+
ORIGIN: process.env.CORS_ORIGIN?.split(',') || ['*'],
273+
METHODS: (process.env.CORS_METHODS?.split(',') as HttpMethods[]) || ['POST', 'GET', 'PUT', 'DELETE'] as HttpMethods[],
274274
CREDENTIALS: process.env?.CORS_CREDENTIALS === 'true',
275275
},
276276
SSL_CONF: {
@@ -354,7 +354,7 @@ export class ConfigService {
354354
LANGUAGE: process.env.WA_BUSINESS_LANGUAGE || 'en',
355355
},
356356
LOG: {
357-
LEVEL: (process.env?.LOG_LEVEL.split(',') as LogLevel[]) || [
357+
LEVEL: (process.env?.LOG_LEVEL?.split(',') as LogLevel[]) || [
358358
'ERROR',
359359
'WARN',
360360
'DEBUG',
@@ -364,7 +364,7 @@ export class ConfigService {
364364
'DARK',
365365
'WEBHOOKS',
366366
'WEBSOCKET',
367-
],
367+
] as LogLevel[],
368368
COLOR: process.env?.LOG_COLOR === 'true',
369369
BAILEYS: (process.env?.LOG_BAILEYS as LogBaileys) || 'error',
370370
},

0 commit comments

Comments
 (0)