moved images to uuid (#259)

This commit is contained in:
arkml 2025-09-15 21:50:03 +05:30 committed by GitHub
parent 14fd7214c5
commit a7abdc43a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 11 deletions

View file

@ -659,11 +659,11 @@ export function createGenerateImageTool(
const images = await Promise.all(result.images.map(async (img) => {
const buf = Buffer.from(img.dataBase64, 'base64');
const ext = img.mimeType === 'image/jpeg' ? '.jpg' : img.mimeType === 'image/webp' ? '.webp' : '.png';
const base = `${projectId}-${Math.floor(Math.random() * 1e12).toString(36)}`;
const last2 = base.slice(-2).padStart(2, '0');
const imageId = crypto.randomUUID();
const last2 = imageId.slice(-2).padStart(2, '0');
const dirA = last2.charAt(0);
const dirB = last2.charAt(1);
const filename = `${base}${ext}`;
const filename = `${imageId}${ext}`;
const key = `generated_images/${dirA}/${dirB}/${filename}`;
await s3.send(new PutObjectCommand({
Bucket: s3Bucket,
@ -671,7 +671,7 @@ export function createGenerateImageTool(
Body: buf,
ContentType: img.mimeType,
}));
const url = `/api/generated-images/${dirA}/${dirB}/${filename}`;
const url = `/api/generated-images/${imageId}`;
return { mimeType: img.mimeType, bytes: buf.length, url };
}));
const payload = {