fix: uploading endpoint

This commit is contained in:
Oleg Proskurin 2026-02-01 20:04:46 +07:00
parent bf248c3f2f
commit 196b91ae6a
7 changed files with 35 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,15 @@ export interface UploadResult {
error?: string;
}
export interface UploadFileParams {
orgSlug: string;
projectSlug: string;
imageId: string;
buffer: Buffer;
contentType: string;
originalFilename?: string;
}
export interface StorageService {
/**
* Create the main bucket if it doesn't exist
@ -35,22 +44,8 @@ export interface StorageService {
/**
* Upload a file to storage
* 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(
orgSlug: string,
projectSlug: string,
imageId: string,
buffer: Buffer,
contentType: string,
originalFilename?: string,
): Promise<UploadResult>;
uploadFile(params: UploadFileParams): Promise<UploadResult>;
/**
* Download a file from storage

View File

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

View File

@ -2,7 +2,7 @@
# @base = https://api.banatie.app
# @apiKey = bnt_e6eb544c505922b9bfe5b088e067fc3940efff16b1b88585c5518946630d4a66
@apiKey = bnt_f4fcf12c7b62a48dd660dcebccc744d4e668f66ffdf54b873c4ee866c0008763
@apiKey = bnt_415a15747796a9676cb47c663fcede36af3583cedaec19893b831ec7a2ae0311
###############################################################################
# IMAGE UPLOAD & CRUD TESTS