Compare commits
No commits in common. "b0e6304e07450e298dc5f030b4bb9251223c2390" and "39781de4e8f428e1a02ba148c04b4767bf706118" have entirely different histories.
b0e6304e07
...
39781de4e8
|
|
@ -422,8 +422,6 @@ cdnRouter.get(
|
|||
const generation = await genService.create({
|
||||
projectId: project.id,
|
||||
apiKeyId: null as unknown as string, // System generation for live URLs
|
||||
organizationSlug: orgSlug,
|
||||
projectSlug: projectSlug,
|
||||
prompt,
|
||||
aspectRatio: (aspectRatio as string) || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||
autoEnhance: normalizedAutoEnhance,
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ uploadRouter.post(
|
|||
}
|
||||
|
||||
// Extract org/project slugs from validated API key
|
||||
const orgSlug = req.apiKey?.organizationSlug || process.env['DEFAULT_ORG_SLUG'] || 'default';
|
||||
const projectSlug = req.apiKey?.projectSlug || process.env['DEFAULT_PROJECT_SLUG'] || 'main'; // Guaranteed by requireProjectKey middleware
|
||||
const orgId = req.apiKey?.organizationSlug || 'default';
|
||||
const projectId = req.apiKey?.projectSlug!; // Guaranteed by requireProjectKey middleware
|
||||
|
||||
console.log(
|
||||
`[${timestamp}] [${requestId}] Starting file upload for org:${orgSlug}, project:${projectSlug}`,
|
||||
`[${timestamp}] [${requestId}] Starting file upload for org:${orgId}, project:${projectId}`,
|
||||
);
|
||||
|
||||
const file = req.file;
|
||||
|
|
@ -59,8 +59,8 @@ uploadRouter.post(
|
|||
);
|
||||
|
||||
const uploadResult = await storageService.uploadFile(
|
||||
orgSlug,
|
||||
projectSlug,
|
||||
orgId,
|
||||
projectId,
|
||||
'uploads',
|
||||
file.originalname,
|
||||
file.buffer,
|
||||
|
|
|
|||
|
|
@ -114,14 +114,10 @@ generationsRouter.post(
|
|||
|
||||
const projectId = req.apiKey.projectId;
|
||||
const apiKeyId = req.apiKey.id;
|
||||
const organizationSlug = req.apiKey.organizationSlug || process.env['DEFAULT_ORG_SLUG'] || 'default';
|
||||
const projectSlug = req.apiKey.projectSlug || process.env['DEFAULT_PROJECT_SLUG'] || 'main';
|
||||
|
||||
const generation = await service.create({
|
||||
projectId,
|
||||
apiKeyId,
|
||||
organizationSlug,
|
||||
projectSlug,
|
||||
prompt,
|
||||
referenceImages,
|
||||
aspectRatio,
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ liveRouter.get(
|
|||
|
||||
const projectId = req.apiKey.projectId;
|
||||
const apiKeyId = req.apiKey.id;
|
||||
const organizationSlug = req.apiKey.organizationSlug || process.env['DEFAULT_ORG_SLUG'] || 'default';
|
||||
const projectSlug = req.apiKey.projectSlug || process.env['DEFAULT_PROJECT_SLUG'] || 'main';
|
||||
|
||||
try {
|
||||
// Compute prompt hash for cache lookup
|
||||
|
|
@ -124,8 +122,6 @@ liveRouter.get(
|
|||
const generation = await genService.create({
|
||||
projectId,
|
||||
apiKeyId,
|
||||
organizationSlug,
|
||||
projectSlug,
|
||||
prompt,
|
||||
aspectRatio: (aspectRatio as string) || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||
requestId: req.requestId,
|
||||
|
|
|
|||
|
|
@ -268,13 +268,6 @@ export class MinioStorageService implements StorageService {
|
|||
await this.client.removeObject(this.bucketName, filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public URL for file access
|
||||
* Returns CDN URL if MINIO_PUBLIC_URL is configured (production),
|
||||
* otherwise falls back to API endpoint URL (development)
|
||||
*
|
||||
* @returns {string} URL for accessing the file
|
||||
*/
|
||||
getPublicUrl(
|
||||
orgId: string,
|
||||
projectId: string,
|
||||
|
|
@ -282,21 +275,9 @@ export class MinioStorageService implements StorageService {
|
|||
filename: string,
|
||||
): string {
|
||||
this.validateFilePath(orgId, projectId, category, filename);
|
||||
|
||||
// If MINIO_PUBLIC_URL is configured, use direct CDN access
|
||||
// This provides better performance and reduces API server load
|
||||
if (this.publicUrl && process.env['USE_DIRECT_CDN'] !== 'false') {
|
||||
const filePath = this.getFilePath(orgId, projectId, category, filename);
|
||||
const cdnUrl = `${this.publicUrl}/${this.bucketName}/${filePath}`;
|
||||
console.log(`[MinIO] Using CDN URL: ${cdnUrl}`);
|
||||
return cdnUrl;
|
||||
}
|
||||
|
||||
// Fallback to API URL for local development or when CDN is disabled
|
||||
// Production-ready: Return API URL for presigned URL access
|
||||
const apiBaseUrl = process.env['API_BASE_URL'] || 'http://localhost:3000';
|
||||
const apiUrl = `${apiBaseUrl}/api/images/${orgId}/${projectId}/${category}/${filename}`;
|
||||
console.log(`[MinIO] Using API URL: ${apiUrl}`);
|
||||
return apiUrl;
|
||||
return `${apiBaseUrl}/api/images/${orgId}/${projectId}/${category}/${filename}`;
|
||||
}
|
||||
|
||||
async getPresignedUploadUrl(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { randomUUID } from 'crypto';
|
||||
import { eq, desc, count, and, isNull, inArray } from 'drizzle-orm';
|
||||
import { db } from '@/db';
|
||||
import { generations, flows, images, projects } from '@banatie/database';
|
||||
import { generations, flows, images } from '@banatie/database';
|
||||
import type {
|
||||
Generation,
|
||||
NewGeneration,
|
||||
|
|
@ -20,8 +20,6 @@ import type { ReferenceImage } from '@/types/api';
|
|||
export interface CreateGenerationParams {
|
||||
projectId: string;
|
||||
apiKeyId: string;
|
||||
organizationSlug: string; // For storage paths (orgSlug/projectSlug/category/file)
|
||||
projectSlug: string; // For storage paths
|
||||
prompt: string;
|
||||
referenceImages?: string[] | undefined; // Aliases to resolve
|
||||
aspectRatio?: string | undefined;
|
||||
|
|
@ -153,8 +151,8 @@ export class GenerationService {
|
|||
filename: `gen_${generation.id}`,
|
||||
referenceImages: referenceImageBuffers,
|
||||
aspectRatio: params.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||
orgId: params.organizationSlug, // Use slug for storage path
|
||||
projectId: params.projectSlug, // Use slug for storage path
|
||||
orgId: 'default',
|
||||
projectId: params.projectId,
|
||||
meta: params.meta || {},
|
||||
});
|
||||
|
||||
|
|
@ -379,27 +377,6 @@ export class GenerationService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get organization and project slugs for storage paths
|
||||
*/
|
||||
private async getSlugs(projectId: string): Promise<{ orgSlug: string; projectSlug: string }> {
|
||||
const project = await db.query.projects.findFirst({
|
||||
where: eq(projects.id, projectId),
|
||||
with: {
|
||||
organization: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
throw new Error('Project not found');
|
||||
}
|
||||
|
||||
return {
|
||||
orgSlug: project.organization.slug,
|
||||
projectSlug: project.slug,
|
||||
};
|
||||
}
|
||||
|
||||
private async updateStatus(
|
||||
id: string,
|
||||
status: 'pending' | 'processing' | 'success' | 'failed',
|
||||
|
|
@ -514,17 +491,14 @@ export class GenerationService {
|
|||
// Update status to processing
|
||||
await this.updateStatus(id, 'processing');
|
||||
|
||||
// Get slugs for storage paths
|
||||
const { orgSlug, projectSlug } = await this.getSlugs(generation.projectId);
|
||||
|
||||
// Use EXACT same parameters as original (no overrides)
|
||||
const genResult = await this.imageGenService.generateImage({
|
||||
prompt: generation.prompt,
|
||||
filename: `gen_${id}`,
|
||||
referenceImages: [], // TODO: Re-resolve referenced images if needed
|
||||
aspectRatio: generation.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||
orgId: orgSlug,
|
||||
projectId: projectSlug,
|
||||
orgId: 'default',
|
||||
projectId: generation.projectId,
|
||||
meta: generation.meta as Record<string, unknown> || {},
|
||||
});
|
||||
|
||||
|
|
@ -631,17 +605,14 @@ export class GenerationService {
|
|||
const promptToUse = updates.prompt || generation.prompt;
|
||||
const aspectRatioToUse = updates.aspectRatio || generation.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO;
|
||||
|
||||
// Get slugs for storage paths
|
||||
const { orgSlug, projectSlug } = await this.getSlugs(generation.projectId);
|
||||
|
||||
// Regenerate image
|
||||
const genResult = await this.imageGenService.generateImage({
|
||||
prompt: promptToUse,
|
||||
filename: `gen_${id}`,
|
||||
referenceImages: [],
|
||||
aspectRatio: aspectRatioToUse,
|
||||
orgId: orgSlug,
|
||||
projectId: projectSlug,
|
||||
orgId: 'default',
|
||||
projectId: generation.projectId,
|
||||
meta: updates.meta || generation.meta || {},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -34,11 +34,6 @@ STORAGE_TYPE=minio
|
|||
# Public URL for CDN access (used in API responses)
|
||||
MINIO_PUBLIC_URL=https://cdn.banatie.app
|
||||
|
||||
# Use direct CDN URLs instead of API proxy (recommended for production)
|
||||
# Set to 'false' to force API URLs even when MINIO_PUBLIC_URL is configured
|
||||
# Default: true (CDN enabled when MINIO_PUBLIC_URL is present)
|
||||
USE_DIRECT_CDN=true
|
||||
|
||||
# ----------------------------------------
|
||||
# API Configuration
|
||||
# ----------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue