From 351fffcc782159384e2b5048b9e062808f38a6af Mon Sep 17 00:00:00 2001 From: web Date: Thu, 4 Sep 2025 22:51:59 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Update=20getAppSubLink=20?= =?UTF-8?q?function=20to=20improve=20URL=20handling=20and=20encoding=20log?= =?UTF-8?q?ic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user/config/use-global.tsx | 88 +++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/apps/user/config/use-global.tsx b/apps/user/config/use-global.tsx index 158890b..1e17321 100644 --- a/apps/user/config/use-global.tsx +++ b/apps/user/config/use-global.tsx @@ -110,45 +110,71 @@ export const useGlobalStore = create((set, get) => ({ getAppSubLink: (url: string, schema?: string) => { const name = get().common?.site?.site_name || ''; - if (!schema) return url; + if (!schema) return 'url'; try { - let result = schema; + let result = schema.replace(/\${url}/g, url).replace(/\${name}/g, name); - result = result.replace(/\${url}/g, url); - result = result.replace(/\${name}/g, name); + const maxLoop = 10; + let prev; + let loop = 0; + do { + prev = result; + result = result.replace( + /\${encodeURIComponent\(JSON\.stringify\(([^)]+)\)\)}/g, + (match, expr) => { + try { + const processedExpr = expr.replace(/url/g, `"${url}"`).replace(/name/g, `"${name}"`); + if (processedExpr.includes('server_remote')) { + const serverRemoteValue = `${url}, tag=${name}`; + return encodeURIComponent(JSON.stringify({ server_remote: [serverRemoteValue] })); + } + const obj = eval(`(${processedExpr})`); + return encodeURIComponent(JSON.stringify(obj)); + } catch { + return match; + } + }, + ); - result = result.replace(/\${encodeURIComponent\(([^)]+)\)}/g, (match, expr) => { - if (expr === 'url') return encodeURIComponent(url); - if (expr === 'name') return encodeURIComponent(name); - return match; - }); - - result = result.replace(/\${window\.btoa\(([^)]+)\)}/g, (match, expr) => { - const btoa = typeof window !== 'undefined' ? window.btoa : (str: string) => str; - if (expr === 'url') return btoa(url); - if (expr === 'name') return btoa(name); - return match; - }); - - result = result.replace(/\${JSON\.stringify\(([^}]+)\)}/g, (match, expr) => { - try { - const processedExpr = expr.replace(/url/g, `"${url}"`).replace(/name/g, `"${name}"`); - - if (processedExpr.includes('server_remote')) { - const serverRemoteValue = `${url}, tag=${name}`; - return JSON.stringify({ server_remote: [serverRemoteValue] }); + result = result.replace(/\${encodeURIComponent\(([^)]+)\)}/g, (match, expr) => { + if (expr === 'url') return encodeURIComponent(url); + if (expr === 'name') return encodeURIComponent(name); + try { + return encodeURIComponent(expr); + } catch { + return match; } + }); - const result = eval(`(${processedExpr})`); - return JSON.stringify(result); - } catch { - return match; - } - }); + result = result.replace(/\${window\.btoa\(([^)]+)\)}/g, (match, expr) => { + const btoa = typeof window !== 'undefined' ? window.btoa : (str: string) => str; + if (expr === 'url') return btoa(url); + if (expr === 'name') return btoa(name); + try { + return btoa(expr); + } catch { + return match; + } + }); + result = result.replace(/\${JSON\.stringify\(([^}]+)\)}/g, (match, expr) => { + try { + const processedExpr = expr.replace(/url/g, `"${url}"`).replace(/name/g, `"${name}"`); + if (processedExpr.includes('server_remote')) { + const serverRemoteValue = `${url}, tag=${name}`; + return JSON.stringify({ server_remote: [serverRemoteValue] }); + } + const result = eval(`(${processedExpr})`); + return JSON.stringify(result); + } catch { + return match; + } + }); + loop++; + } while (result !== prev && loop < maxLoop); return result; } catch (error) { - return url; + return ''; } }, }));