diff --git a/apps/api-service/src/app.ts b/apps/api-service/src/app.ts index c98c550..0a9ed62 100644 --- a/apps/api-service/src/app.ts +++ b/apps/api-service/src/app.ts @@ -61,8 +61,8 @@ export const createApp = (): Application => { }); // API info endpoint - app.get('/api/info', (_req, res) => { - const info = { + app.get('/api/info', async (req: any, res) => { + const info: any = { name: 'Banatie - Nano Banana Image Generation API', version: '1.0.0', description: 'REST API service for AI-powered image generation using Gemini Flash Image model', @@ -80,6 +80,52 @@ export const createApp = (): Application => { } }; + // If API key is provided, validate and return key info + const providedKey = req.headers['x-api-key'] as string; + if (providedKey) { + try { + const { ApiKeyService } = await import('./services/ApiKeyService'); + const apiKeyService = new ApiKeyService(); + const apiKey = await apiKeyService.validateKey(providedKey); + + if (apiKey) { + // Query org and project names + let organizationName = apiKey.organizationId; + let projectName = apiKey.projectId; + + try { + const { db } = await import('./db'); + const { organizations, projects } = await import('@banatie/database'); + const { eq } = await import('drizzle-orm'); + + if (apiKey.organizationId) { + const org = await db.select().from(organizations).where(eq(organizations.id, apiKey.organizationId)).limit(1); + if (org.length > 0) organizationName = org[0].name; + } + + if (apiKey.projectId) { + const proj = await db.select().from(projects).where(eq(projects.id, apiKey.projectId)).limit(1); + if (proj.length > 0) projectName = proj[0].name; + } + } catch (dbError) { + // Fallback to IDs if DB query fails + } + + info.authenticated = true; + info.keyInfo = { + type: apiKey.keyType, + organizationId: apiKey.organizationId, + organizationName, + projectId: apiKey.projectId, + projectName, + expiresAt: apiKey.expiresAt + }; + } + } catch (error) { + // Ignore errors, just don't add key info + } + } + console.log(`[${new Date().toISOString()}] API info requested`); res.json(info); }); diff --git a/apps/api-service/src/services/MinioStorageService.ts b/apps/api-service/src/services/MinioStorageService.ts index dea9434..ade4692 100644 --- a/apps/api-service/src/services/MinioStorageService.ts +++ b/apps/api-service/src/services/MinioStorageService.ts @@ -40,11 +40,8 @@ export class MinioStorageService implements StorageService { category: 'uploads' | 'generated' | 'references', filename: string ): string { - const now = new Date(); - const year = now.getFullYear(); - const month = String(now.getMonth() + 1).padStart(2, '0'); - - return `${orgId}/${projectId}/${category}/${year}-${month}/${filename}`; + // Simplified path without date folder for now + return `${orgId}/${projectId}/${category}/${filename}`; } private generateUniqueFilename(originalFilename: string): string { diff --git a/apps/landing/src/app/demo/tti/page.tsx b/apps/landing/src/app/demo/tti/page.tsx index cd42929..33f3357 100644 --- a/apps/landing/src/app/demo/tti/page.tsx +++ b/apps/landing/src/app/demo/tti/page.tsx @@ -69,14 +69,21 @@ export default function DemoTTIPage() { }); if (response.ok) { + const data = await response.json(); setApiKeyValidated(true); - // Try to extract org/project info if available - // For now, we'll set placeholder - this would come from API response - setApiKeyInfo({ - organizationName: 'Your Organization', - projectName: 'Your Project', - }); - } else { + // Extract org/project info from API response + if (data.keyInfo) { + setApiKeyInfo({ + organizationName: data.keyInfo.organizationName || data.keyInfo.organizationId, + projectName: data.keyInfo.projectName || data.keyInfo.projectId, + }); + } else { + setApiKeyInfo({ + organizationName: 'Unknown', + projectName: 'Unknown', + }); + } + } else{ const error = await response.json(); setApiKeyError(error.message || 'Invalid API key'); setApiKeyValidated(false);