From e39cb17e26d298528e93fce551c19e23c547cd44 Mon Sep 17 00:00:00 2001 From: Viren070 Date: Mon, 10 Feb 2025 02:14:37 +0000 Subject: [PATCH] fix: fixes --- packages/addon/src/server.ts | 9 ++++++--- packages/frontend/src/app/configure/page.tsx | 5 ++++- packages/utils/src/general.ts | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/addon/src/server.ts b/packages/addon/src/server.ts index 32fa1c4d..c922ea47 100644 --- a/packages/addon/src/server.ts +++ b/packages/addon/src/server.ts @@ -13,6 +13,7 @@ import { parseAndDecryptString, Cache, unminifyConfig, + minifyConfig, } from '@aiostreams/utils'; const app = express(); @@ -104,14 +105,16 @@ app.get('/configure', (req, res) => { app.get('/:config/configure', (req, res) => { const config = req.params.config; - if (config.startsWith('eyJ')) { + if (config.startsWith('eyJ') || config.startsWith('eyI')) { return res.sendFile( path.join(__dirname, '../../frontend/out/configure.html') ); } try { - const configJson = encryptInfoInConfig( - unminifyConfig(extractJsonConfig(config)) + // unminify so we can encrypt the sensitive info + // and then minify it again before sending it to the frontend + const configJson = minifyConfig( + encryptInfoInConfig(unminifyConfig(extractJsonConfig(config))) ); const base64Config = Buffer.from(JSON.stringify(configJson)).toString( 'base64' diff --git a/packages/frontend/src/app/configure/page.tsx b/packages/frontend/src/app/configure/page.tsx index 495d14b4..faeca32b 100644 --- a/packages/frontend/src/app/configure/page.tsx +++ b/packages/frontend/src/app/configure/page.tsx @@ -493,7 +493,10 @@ export default function Configure() { if (config.startsWith('E-')) { throw new Error('Encrypted Config Not Supported'); } else { - decodedConfig = unminifyConfig(JSON.parse(atob(config))); + decodedConfig = JSON.parse(atob(decodeURIComponent(config))); + console.log('Decoded config', decodedConfig); + decodedConfig = unminifyConfig(decodedConfig); + console.log('Unminified config', decodedConfig); } return decodedConfig; } diff --git a/packages/utils/src/general.ts b/packages/utils/src/general.ts index 3292e404..38465d96 100644 --- a/packages/utils/src/general.ts +++ b/packages/utils/src/general.ts @@ -26,7 +26,11 @@ export function minifyConfig(obj: any, depth: number = 0): any { throw new Error('Max depth reached'); } if (typeof obj !== 'object' || obj === null) { - if (Object.values(compressedConfigMap).includes(obj)) { + let valueToCheck = obj; + if (typeof obj === 'number') { + valueToCheck = obj.toString(); + } + if (Object.values(compressedConfigMap).includes(valueToCheck)) { return `${obj}${MINIFY_SUFFIX}`; } return compressedConfigMap[obj] ?? obj;