From bbc007bccdbccf67fc7ac5ae8f94d88bf04ce75a Mon Sep 17 00:00:00 2001 From: Oleg Proskurin Date: Sun, 16 Nov 2025 18:57:23 +0700 Subject: [PATCH] feat: add images references --- .../src/services/core/GenerationService.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/api-service/src/services/core/GenerationService.ts b/apps/api-service/src/services/core/GenerationService.ts index e23964b..3fe5ad2 100644 --- a/apps/api-service/src/services/core/GenerationService.ts +++ b/apps/api-service/src/services/core/GenerationService.ts @@ -10,6 +10,7 @@ import type { import { ImageService } from './ImageService'; import { AliasService } from './AliasService'; import { ImageGenService } from '../ImageGenService'; +import { StorageFactory } from '../StorageFactory'; import { buildWhereClause, buildEqCondition } from '@/utils/helpers'; import { ERROR_MESSAGES, GENERATION_LIMITS } from '@/utils/constants'; import type { ReferenceImage } from '@/types/api'; @@ -170,13 +171,36 @@ export class GenerationService { const buffers: ReferenceImage[] = []; const metadata: Array<{ imageId: string; alias: string }> = []; - // TODO: Implement proper storage key parsing and download - // For now, we'll skip reference image buffers and just store metadata + const storageService = await StorageFactory.getInstance(); + for (const [alias, resolution] of resolutions) { if (!resolution.image) { throw new Error(`${ERROR_MESSAGES.ALIAS_NOT_FOUND}: ${alias}`); } + const parts = resolution.image.storageKey.split('/'); + if (parts.length < 4) { + throw new Error(`Invalid storage key format: ${resolution.image.storageKey}`); + } + + const orgId = parts[0]!; + const projId = parts[1]!; + const category = parts[2]! as 'uploads' | 'generated' | 'references'; + const filename = parts.slice(3).join('/'); + + const buffer = await storageService.downloadFile( + orgId, + projId, + category, + filename + ); + + buffers.push({ + buffer, + mimetype: resolution.image.mimeType, + originalname: filename, + }); + metadata.push({ imageId: resolution.imageId, alias,