From 0989f8a3ad5ee51c76a4c9dd5e818d5ff8abe034 Mon Sep 17 00:00:00 2001 From: "@milesibastos" Date: Tue, 27 Aug 2024 21:01:48 -0300 Subject: [PATCH 1/2] feat: Define a global proxy to be used if the instance does not have one --- .env.example | 7 +++++++ src/api/services/channel.service.ts | 25 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index c893e888..c7d62c83 100644 --- a/.env.example +++ b/.env.example @@ -212,3 +212,10 @@ AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11 # If you leave this option as true, the instances will be exposed in the fetch instances endpoint. AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true LANGUAGE=en + +# Define a global proxy to be used if the instance does not have one +# PROXY_HOST= +# PROXY_PORT=80 +# PROXY_PROTOCOL=http +# PROXY_USERNAME= +# PROXY_PASSWORD= \ No newline at end of file diff --git a/src/api/services/channel.service.ts b/src/api/services/channel.service.ts index e77b4392..4c55f853 100644 --- a/src/api/services/channel.service.ts +++ b/src/api/services/channel.service.ts @@ -338,18 +338,31 @@ export class ChannelStartupService { } public async loadProxy() { + this.localProxy.enabled = false; + + if (process.env.PROXY_HOST) { + this.localProxy.enabled = true; + this.localProxy.host = process.env.PROXY_HOST; + this.localProxy.port = process.env.PROXY_PORT || '80'; + this.localProxy.protocol = process.env.PROXY_PROTOCOL || 'http'; + this.localProxy.username = process.env.PROXY_USERNAME; + this.localProxy.password = process.env.PROXY_PASSWORD; + } + const data = await this.prismaRepository.proxy.findUnique({ where: { instanceId: this.instanceId, }, }); - this.localProxy.enabled = data?.enabled; - this.localProxy.host = data?.host; - this.localProxy.port = data?.port; - this.localProxy.protocol = data?.protocol; - this.localProxy.username = data?.username; - this.localProxy.password = data?.password; + if (data?.enabled) { + this.localProxy.enabled = true; + this.localProxy.host = data?.host; + this.localProxy.port = data?.port; + this.localProxy.protocol = data?.protocol; + this.localProxy.username = data?.username; + this.localProxy.password = data?.password; + } } public async setProxy(data: ProxyDto) { From a19343d3e1a439aed50405792445399f03038573 Mon Sep 17 00:00:00 2001 From: Judson Cairo Date: Wed, 28 Aug 2024 09:59:40 -0300 Subject: [PATCH 2/2] Validate if cache exists before accessing it --- src/api/services/cache.service.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/services/cache.service.ts b/src/api/services/cache.service.ts index 1004bb9c..af337ac9 100644 --- a/src/api/services/cache.service.ts +++ b/src/api/services/cache.service.ts @@ -21,6 +21,9 @@ export class CacheService { } public async hGet(key: string, field: string) { + if (!this.cache) { + return null; + } try { const data = await this.cache.hGet(key, field); @@ -43,6 +46,9 @@ export class CacheService { } public async hSet(key: string, field: string, value: any) { + if (!this.cache) { + return; + } try { const json = JSON.stringify(value, BufferJSON.replacer); @@ -67,6 +73,9 @@ export class CacheService { } async hDelete(key: string, field: string) { + if (!this.cache) { + return false; + } try { await this.cache.hDelete(key, field); return true;