From 122d6fdd2648518e19f048f0beb5bf9e3662d2c7 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 12 Aug 2025 13:07:43 +0200 Subject: [PATCH] fixes --- server/utils/nocodb.ts | 50 +++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/server/utils/nocodb.ts b/server/utils/nocodb.ts index b55aeea..3fa38e9 100644 --- a/server/utils/nocodb.ts +++ b/server/utils/nocodb.ts @@ -210,25 +210,55 @@ export const setGlobalNocoDBConfig = (config: any) => { }; export const getNocoDbConfiguration = () => { + let configToUse: any = null; + // Try to use the global configuration first if (globalNocoDBConfig) { console.log('[nocodb] Using global configuration - URL:', globalNocoDBConfig.url); - return { + configToUse = { url: globalNocoDBConfig.url, token: globalNocoDBConfig.token, baseId: globalNocoDBConfig.baseId }; + } else { + // Fallback to runtime config + console.log('[nocodb] Global config not available, using runtime config'); + const config = useRuntimeConfig().nocodb; + configToUse = { + ...config, + url: config.url || 'https://database.monacousa.org' + }; + console.log('[nocodb] Fallback configuration URL:', configToUse.url); } - // Fallback to runtime config - console.log('[nocodb] Global config not available, using runtime config'); - const config = useRuntimeConfig().nocodb; - const fallbackConfig = { - ...config, - url: config.url || 'https://database.monacousa.org' - }; - console.log('[nocodb] Fallback configuration URL:', fallbackConfig.url); - return fallbackConfig; + // Validate API token before using it + if (configToUse.token) { + const token = configToUse.token.trim(); + + // Check for non-ASCII characters that would cause ByteString errors + if (!/^[\x00-\xFF]*$/.test(token)) { + console.error('[nocodb] ❌ CRITICAL ERROR: API token contains invalid Unicode characters!'); + console.error('[nocodb] This will cause ByteString conversion errors in HTTP headers.'); + console.error('[nocodb] Please update the API token in the admin configuration.'); + throw createError({ + statusCode: 500, + statusMessage: 'NocoDB API token contains invalid characters. Please reconfigure the database connection in the admin panel with a valid API token.' + }); + } + + // Additional validation for common token issues + if (token.includes('•') || token.includes('…') || token.includes('"') || token.includes('"')) { + console.error('[nocodb] ❌ CRITICAL ERROR: API token contains formatting characters!'); + console.error('[nocodb] Found characters like bullets (•), quotes, etc. that break HTTP headers.'); + console.error('[nocodb] Please copy the raw API token from NocoDB without any formatting.'); + throw createError({ + statusCode: 500, + statusMessage: 'NocoDB API token contains formatting characters (bullets, quotes, etc.). Please reconfigure with the raw token from NocoDB.' + }); + } + } + + return configToUse; }; export const createTableUrl = (table: Table | string) => {