Resolve merge conflicts in events system
All checks were successful
Build And Push Image / docker (push) Successful in 3m13s
All checks were successful
Build And Push Image / docker (push) Successful in 3m13s
- Fixed conflicts in server/api/events/index.get.ts with improved logging and session management - Fixed conflicts in server/api/events/index.post.ts with better validation and error handling - Fixed conflicts in server/utils/nocodb-events.ts incorporating admin config integration and token validation - Events system now uses proper session management and NocoDB v2 API patterns - Maintains compatibility with existing admin configuration system
This commit is contained in:
@@ -278,7 +278,11 @@ export function getEffectiveNocoDBConfig(): EffectiveNocoDB {
|
||||
url: runtimeConfig.nocodb?.url || 'https://database.monacousa.org',
|
||||
token: runtimeConfig.nocodb?.token || '',
|
||||
baseId: runtimeConfig.nocodb?.baseId || '',
|
||||
tables: { members: 'members-table-id' } // Default table mapping
|
||||
tables: {
|
||||
members: 'members-table-id',
|
||||
events: (runtimeConfig.nocodb as any)?.eventsTableId || '',
|
||||
rsvps: (runtimeConfig.nocodb as any)?.rsvpTableId || ''
|
||||
} // Default table mapping
|
||||
};
|
||||
|
||||
// Override with file configuration if available
|
||||
@@ -306,7 +310,11 @@ export async function getCurrentConfig(): Promise<NocoDBSettings> {
|
||||
url: config.nocodb.url || runtimeConfig.nocodb?.url || 'https://database.monacousa.org',
|
||||
apiKey: config.nocodb.apiKey ? '••••••••••••••••' : '',
|
||||
baseId: config.nocodb.baseId || runtimeConfig.nocodb?.baseId || '',
|
||||
tables: config.nocodb.tables || { members: 'members-table-id' }
|
||||
tables: config.nocodb.tables || {
|
||||
members: 'members-table-id',
|
||||
events: '',
|
||||
rsvps: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -315,7 +323,11 @@ export async function getCurrentConfig(): Promise<NocoDBSettings> {
|
||||
url: runtimeConfig.nocodb?.url || 'https://database.monacousa.org',
|
||||
apiKey: runtimeConfig.nocodb?.token ? '••••••••••••••••' : '',
|
||||
baseId: runtimeConfig.nocodb?.baseId || '',
|
||||
tables: { members: 'members-table-id' }
|
||||
tables: {
|
||||
members: 'members-table-id',
|
||||
events: '',
|
||||
rsvps: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -328,7 +340,7 @@ export async function saveRecaptchaConfig(config: { siteKey: string; secretKey:
|
||||
await createBackup();
|
||||
|
||||
const currentConfig = configCache || await loadAdminConfig() || {
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: {} },
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: { members: '', events: '', rsvps: '' } },
|
||||
lastUpdated: new Date().toISOString(),
|
||||
updatedBy: 'system'
|
||||
};
|
||||
@@ -374,7 +386,7 @@ export async function saveRegistrationConfig(config: { membershipFee: number; ib
|
||||
await createBackup();
|
||||
|
||||
const currentConfig = configCache || await loadAdminConfig() || {
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: {} },
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: { members: '', events: '', rsvps: '' } },
|
||||
lastUpdated: new Date().toISOString(),
|
||||
updatedBy: 'system'
|
||||
};
|
||||
@@ -430,7 +442,7 @@ export async function saveSMTPConfig(config: SMTPConfig, updatedBy: string): Pro
|
||||
await createBackup();
|
||||
|
||||
const currentConfig = configCache || await loadAdminConfig() || {
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: {} },
|
||||
nocodb: { url: '', apiKey: '', baseId: '', tables: { members: '', events: '', rsvps: '' } },
|
||||
lastUpdated: new Date().toISOString(),
|
||||
updatedBy: 'system'
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// server/utils/nocodb-events.ts
|
||||
import type { Event, EventRSVP, EventsResponse, EventFilters } from '~/utils/types';
|
||||
import { createSessionManager } from '~/server/utils/session';
|
||||
import { getEffectiveNocoDBConfig } from './admin-config';
|
||||
|
||||
// Import shared NocoDB utilities from the working members system
|
||||
import { getNocoDbConfiguration, setGlobalNocoDBConfig, handleNocoDbError } from '~/server/utils/nocodb';
|
||||
@@ -25,7 +26,22 @@ export enum EventTable {
|
||||
|
||||
// Dynamic table ID getter - will use configured table ID from admin panel
|
||||
export const getEventTableId = (tableName: 'Events' | 'EventRSVPs'): string => {
|
||||
// Try to get table ID from global configuration first
|
||||
try {
|
||||
// Try to get effective configuration from admin config system first
|
||||
const effectiveConfig = getEffectiveNocoDBConfig();
|
||||
if (effectiveConfig?.tables) {
|
||||
const tableKey = tableName === 'Events' ? 'events' : 'event_rsvps';
|
||||
const tableId = effectiveConfig.tables[tableKey] || effectiveConfig.tables[tableName];
|
||||
if (tableId) {
|
||||
console.log(`[nocodb-events] Using admin config table ID for ${tableName}:`, tableId);
|
||||
return tableId;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`[nocodb-events] Admin config not available, trying fallback for ${tableName}`);
|
||||
}
|
||||
|
||||
// Try to get table ID from global configuration
|
||||
const globalConfig = (global as any).globalNocoDBConfig;
|
||||
if (globalConfig?.tables) {
|
||||
const tableKey = tableName === 'Events' ? 'events' : 'event_rsvps';
|
||||
@@ -124,6 +140,32 @@ export const normalizeEventFieldsFromNocoDB = (data: any): Event => {
|
||||
* Following the same pattern as the working members client
|
||||
*/
|
||||
export function createNocoDBEventsClient() {
|
||||
// Validate API token before using it (from incoming version)
|
||||
const config = getNocoDbConfiguration();
|
||||
const token = config.token;
|
||||
|
||||
if (token) {
|
||||
const cleanToken = token.trim();
|
||||
|
||||
// Check for non-ASCII characters that would cause ByteString errors
|
||||
if (!/^[\x00-\xFF]*$/.test(cleanToken)) {
|
||||
console.error('[nocodb-events] ❌ CRITICAL ERROR: API token contains invalid Unicode characters!');
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Events system: NocoDB API token contains invalid characters. Please reconfigure the database connection.'
|
||||
});
|
||||
}
|
||||
|
||||
// Additional validation for common token issues
|
||||
if (cleanToken.includes('•') || cleanToken.includes('…') || cleanToken.includes('"') || cleanToken.includes('"')) {
|
||||
console.error('[nocodb-events] ❌ CRITICAL ERROR: API token contains formatting characters!');
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Events system: NocoDB API token contains formatting characters. Please reconfigure with the raw token from NocoDB.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const eventsClient = {
|
||||
/**
|
||||
* Find all events with optional filtering
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user