fix: storage structure
This commit is contained in:
parent
0a42a32817
commit
7e04fcbbb0
|
|
@ -40,11 +40,11 @@ uploadRouter.post(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract org/project slugs from validated API key
|
// Extract org/project slugs from validated API key
|
||||||
const orgId = req.apiKey?.organizationSlug || 'default';
|
const orgSlug = req.apiKey?.organizationSlug || process.env.DEFAULT_ORG_SLUG || 'default';
|
||||||
const projectId = req.apiKey?.projectSlug!; // Guaranteed by requireProjectKey middleware
|
const projectSlug = req.apiKey?.projectSlug || process.env.DEFAULT_PROJECT_SLUG || 'main'; // Guaranteed by requireProjectKey middleware
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`[${timestamp}] [${requestId}] Starting file upload for org:${orgId}, project:${projectId}`,
|
`[${timestamp}] [${requestId}] Starting file upload for org:${orgSlug}, project:${projectSlug}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const file = req.file;
|
const file = req.file;
|
||||||
|
|
@ -59,8 +59,8 @@ uploadRouter.post(
|
||||||
);
|
);
|
||||||
|
|
||||||
const uploadResult = await storageService.uploadFile(
|
const uploadResult = await storageService.uploadFile(
|
||||||
orgId,
|
orgSlug,
|
||||||
projectId,
|
projectSlug,
|
||||||
'uploads',
|
'uploads',
|
||||||
file.originalname,
|
file.originalname,
|
||||||
file.buffer,
|
file.buffer,
|
||||||
|
|
|
||||||
|
|
@ -114,10 +114,14 @@ generationsRouter.post(
|
||||||
|
|
||||||
const projectId = req.apiKey.projectId;
|
const projectId = req.apiKey.projectId;
|
||||||
const apiKeyId = req.apiKey.id;
|
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({
|
const generation = await service.create({
|
||||||
projectId,
|
projectId,
|
||||||
apiKeyId,
|
apiKeyId,
|
||||||
|
organizationSlug,
|
||||||
|
projectSlug,
|
||||||
prompt,
|
prompt,
|
||||||
referenceImages,
|
referenceImages,
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { eq, desc, count, and, isNull, inArray } from 'drizzle-orm';
|
import { eq, desc, count, and, isNull, inArray } from 'drizzle-orm';
|
||||||
import { db } from '@/db';
|
import { db } from '@/db';
|
||||||
import { generations, flows, images } from '@banatie/database';
|
import { generations, flows, images, projects, organizations } from '@banatie/database';
|
||||||
import type {
|
import type {
|
||||||
Generation,
|
Generation,
|
||||||
NewGeneration,
|
NewGeneration,
|
||||||
|
|
@ -20,6 +20,8 @@ import type { ReferenceImage } from '@/types/api';
|
||||||
export interface CreateGenerationParams {
|
export interface CreateGenerationParams {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
apiKeyId: string;
|
apiKeyId: string;
|
||||||
|
organizationSlug: string; // For storage paths (orgSlug/projectSlug/category/file)
|
||||||
|
projectSlug: string; // For storage paths
|
||||||
prompt: string;
|
prompt: string;
|
||||||
referenceImages?: string[] | undefined; // Aliases to resolve
|
referenceImages?: string[] | undefined; // Aliases to resolve
|
||||||
aspectRatio?: string | undefined;
|
aspectRatio?: string | undefined;
|
||||||
|
|
@ -151,8 +153,8 @@ export class GenerationService {
|
||||||
filename: `gen_${generation.id}`,
|
filename: `gen_${generation.id}`,
|
||||||
referenceImages: referenceImageBuffers,
|
referenceImages: referenceImageBuffers,
|
||||||
aspectRatio: params.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
aspectRatio: params.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||||
orgId: 'default',
|
orgId: params.organizationSlug, // Use slug for storage path
|
||||||
projectId: params.projectId,
|
projectId: params.projectSlug, // Use slug for storage path
|
||||||
meta: params.meta || {},
|
meta: params.meta || {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -377,6 +379,27 @@ 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(
|
private async updateStatus(
|
||||||
id: string,
|
id: string,
|
||||||
status: 'pending' | 'processing' | 'success' | 'failed',
|
status: 'pending' | 'processing' | 'success' | 'failed',
|
||||||
|
|
@ -491,14 +514,17 @@ export class GenerationService {
|
||||||
// Update status to processing
|
// Update status to processing
|
||||||
await this.updateStatus(id, '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)
|
// Use EXACT same parameters as original (no overrides)
|
||||||
const genResult = await this.imageGenService.generateImage({
|
const genResult = await this.imageGenService.generateImage({
|
||||||
prompt: generation.prompt,
|
prompt: generation.prompt,
|
||||||
filename: `gen_${id}`,
|
filename: `gen_${id}`,
|
||||||
referenceImages: [], // TODO: Re-resolve referenced images if needed
|
referenceImages: [], // TODO: Re-resolve referenced images if needed
|
||||||
aspectRatio: generation.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
aspectRatio: generation.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO,
|
||||||
orgId: 'default',
|
orgId: orgSlug,
|
||||||
projectId: generation.projectId,
|
projectId: projectSlug,
|
||||||
meta: generation.meta as Record<string, unknown> || {},
|
meta: generation.meta as Record<string, unknown> || {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -605,14 +631,17 @@ export class GenerationService {
|
||||||
const promptToUse = updates.prompt || generation.prompt;
|
const promptToUse = updates.prompt || generation.prompt;
|
||||||
const aspectRatioToUse = updates.aspectRatio || generation.aspectRatio || GENERATION_LIMITS.DEFAULT_ASPECT_RATIO;
|
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
|
// Regenerate image
|
||||||
const genResult = await this.imageGenService.generateImage({
|
const genResult = await this.imageGenService.generateImage({
|
||||||
prompt: promptToUse,
|
prompt: promptToUse,
|
||||||
filename: `gen_${id}`,
|
filename: `gen_${id}`,
|
||||||
referenceImages: [],
|
referenceImages: [],
|
||||||
aspectRatio: aspectRatioToUse,
|
aspectRatio: aspectRatioToUse,
|
||||||
orgId: 'default',
|
orgId: orgSlug,
|
||||||
projectId: generation.projectId,
|
projectId: projectSlug,
|
||||||
meta: updates.meta || generation.meta || {},
|
meta: updates.meta || generation.meta || {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue