fix: image paths
This commit is contained in:
parent
960183c9c4
commit
91ba71cc23
|
|
@ -61,8 +61,8 @@ export const createApp = (): Application => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// API info endpoint
|
// API info endpoint
|
||||||
app.get('/api/info', (_req, res) => {
|
app.get('/api/info', async (req: any, res) => {
|
||||||
const info = {
|
const info: any = {
|
||||||
name: 'Banatie - Nano Banana Image Generation API',
|
name: 'Banatie - Nano Banana Image Generation API',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
description: 'REST API service for AI-powered image generation using Gemini Flash Image model',
|
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`);
|
console.log(`[${new Date().toISOString()}] API info requested`);
|
||||||
res.json(info);
|
res.json(info);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,8 @@ export class MinioStorageService implements StorageService {
|
||||||
category: 'uploads' | 'generated' | 'references',
|
category: 'uploads' | 'generated' | 'references',
|
||||||
filename: string
|
filename: string
|
||||||
): string {
|
): string {
|
||||||
const now = new Date();
|
// Simplified path without date folder for now
|
||||||
const year = now.getFullYear();
|
return `${orgId}/${projectId}/${category}/${filename}`;
|
||||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
||||||
|
|
||||||
return `${orgId}/${projectId}/${category}/${year}-${month}/${filename}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateUniqueFilename(originalFilename: string): string {
|
private generateUniqueFilename(originalFilename: string): string {
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,20 @@ export default function DemoTTIPage() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
setApiKeyValidated(true);
|
setApiKeyValidated(true);
|
||||||
// Try to extract org/project info if available
|
// Extract org/project info from API response
|
||||||
// For now, we'll set placeholder - this would come from API response
|
if (data.keyInfo) {
|
||||||
setApiKeyInfo({
|
setApiKeyInfo({
|
||||||
organizationName: 'Your Organization',
|
organizationName: data.keyInfo.organizationName || data.keyInfo.organizationId,
|
||||||
projectName: 'Your Project',
|
projectName: data.keyInfo.projectName || data.keyInfo.projectId,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
setApiKeyInfo({
|
||||||
|
organizationName: 'Unknown',
|
||||||
|
projectName: 'Unknown',
|
||||||
|
});
|
||||||
|
}
|
||||||
} else{
|
} else{
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
setApiKeyError(error.message || 'Invalid API key');
|
setApiKeyError(error.message || 'Invalid API key');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue