Compare commits

..

No commits in common. "196b91ae6a41dd7a397d3247d8167235a61b6b7b" and "ed9c54da1ddd1993c8f092fa9c74df41ee0705fe" have entirely different histories.

7 changed files with 45 additions and 40 deletions

View File

@ -63,14 +63,14 @@ uploadRouter.post(
`[${timestamp}] [${requestId}] Uploading file: ${file.originalname} as ${imageId} (${file.size} bytes)`, `[${timestamp}] [${requestId}] Uploading file: ${file.originalname} as ${imageId} (${file.size} bytes)`,
); );
const uploadResult = await storageService.uploadFile({ const uploadResult = await storageService.uploadFile(
orgSlug, orgSlug,
projectSlug, projectSlug,
imageId, imageId,
buffer: file.buffer, file.buffer,
contentType: file.mimetype, file.mimetype,
originalFilename: file.originalname, file.originalname,
}); );
if (!uploadResult.success) { if (!uploadResult.success) {
const errorResponse: UploadFileResponse = { const errorResponse: UploadFileResponse = {

View File

@ -197,16 +197,15 @@ imagesRouter.post(
try { try {
const storageService = await StorageFactory.getInstance(); const storageService = await StorageFactory.getInstance();
const imageId = randomUUID();
const uploadResult = await storageService.uploadFile({ const uploadResult = await storageService.uploadFile(
orgSlug: orgId, orgId,
projectSlug, projectSlug,
imageId, 'uploads',
buffer: file.buffer, file.originalname,
contentType: file.mimetype, file.buffer,
originalFilename: file.originalname, file.mimetype,
}); );
if (!uploadResult.success) { if (!uploadResult.success) {
res.status(500).json({ res.status(500).json({

View File

@ -70,14 +70,14 @@ export class ImageGenService {
// Original filename for metadata (e.g., "my-image.png") // Original filename for metadata (e.g., "my-image.png")
const originalFilename = `generated-image.${generatedData.fileExtension}`; const originalFilename = `generated-image.${generatedData.fileExtension}`;
const uploadResult = await storageService.uploadFile({ const uploadResult = await storageService.uploadFile(
orgSlug: finalOrgSlug, finalOrgSlug,
projectSlug: finalProjectSlug, finalProjectSlug,
imageId, imageId,
buffer: generatedData.buffer, generatedData.buffer,
contentType: generatedData.mimeType, generatedData.mimeType,
originalFilename, originalFilename,
}); );
if (uploadResult.success) { if (uploadResult.success) {
return { return {

View File

@ -1,5 +1,5 @@
import { Client as MinioClient } from 'minio'; import { Client as MinioClient } from 'minio';
import { StorageService, FileMetadata, UploadResult, UploadFileParams } from './StorageService'; import { StorageService, FileMetadata, UploadResult } from './StorageService';
export class MinioStorageService implements StorageService { export class MinioStorageService implements StorageService {
private client: MinioClient; private client: MinioClient;
@ -102,9 +102,14 @@ export class MinioStorageService implements StorageService {
return await this.client.bucketExists(this.bucketName); return await this.client.bucketExists(this.bucketName);
} }
async uploadFile(params: UploadFileParams): Promise<UploadResult> { async uploadFile(
const { orgSlug, projectSlug, imageId, buffer, contentType, originalFilename } = params; orgSlug: string,
projectSlug: string,
imageId: string,
buffer: Buffer,
contentType: string,
originalFilename?: string,
): Promise<UploadResult> {
// Validate inputs first // Validate inputs first
this.validatePath(orgSlug, projectSlug, imageId); this.validatePath(orgSlug, projectSlug, imageId);

View File

@ -21,15 +21,6 @@ export interface UploadResult {
error?: string; error?: string;
} }
export interface UploadFileParams {
orgSlug: string;
projectSlug: string;
imageId: string;
buffer: Buffer;
contentType: string;
originalFilename?: string;
}
export interface StorageService { export interface StorageService {
/** /**
* Create the main bucket if it doesn't exist * Create the main bucket if it doesn't exist
@ -44,8 +35,22 @@ export interface StorageService {
/** /**
* Upload a file to storage * Upload a file to storage
* Path format: {orgSlug}/{projectSlug}/img/{imageId} * Path format: {orgSlug}/{projectSlug}/img/{imageId}
*
* @param orgSlug Organization slug
* @param projectSlug Project slug
* @param imageId UUID for the file (same as image.id in DB)
* @param buffer File buffer
* @param contentType MIME type
* @param originalFilename Original filename from user (for metadata)
*/ */
uploadFile(params: UploadFileParams): Promise<UploadResult>; uploadFile(
orgSlug: string,
projectSlug: string,
imageId: string,
buffer: Buffer,
contentType: string,
originalFilename?: string,
): Promise<UploadResult>;
/** /**
* Download a file from storage * Download a file from storage

View File

@ -1,6 +1,5 @@
# @base = http://localhost:3000 @base = http://localhost:3000
@base = https://api.banatie.app @apiKey = bnt_727d2f4f72bd03ed96da5278bb971a00cb0a2454d4d70f9748b5c39f3f69d88d
@apiKey = bnt_415a15747796a9676cb47c663fcede36af3583cedaec19893b831ec7a2ae0311
############################################################################### ###############################################################################
# BASIC GENERATION TESTS # BASIC GENERATION TESTS

View File

@ -1,8 +1,5 @@
@base = http://localhost:3000 @base = http://localhost:3000
# @base = https://api.banatie.app @apiKey = bnt_727d2f4f72bd03ed96da5278bb971a00cb0a2454d4d70f9748b5c39f3f69d88d
# @apiKey = bnt_e6eb544c505922b9bfe5b088e067fc3940efff16b1b88585c5518946630d4a66
@apiKey = bnt_415a15747796a9676cb47c663fcede36af3583cedaec19893b831ec7a2ae0311
############################################################################### ###############################################################################
# IMAGE UPLOAD & CRUD TESTS # IMAGE UPLOAD & CRUD TESTS