image processing lambda

This commit is contained in:
jackiettran
2026-01-14 12:11:50 -05:00
parent f5fdcbfb82
commit da82872297
15 changed files with 8090 additions and 17 deletions

View File

@@ -26,7 +26,8 @@ export const getPublicImageUrl = (
export interface PresignedUrlResponse {
uploadUrl: string;
key: string;
key: string; // Final key for database storage
stagingKey: string | null; // Actual upload location (when image processing enabled)
publicUrl: string;
expiresAt: string;
}
@@ -152,13 +153,15 @@ export async function uploadFile(
// Upload to S3
await uploadToS3(file, presigned.uploadUrl, options);
// Confirm upload
const { confirmed } = await confirmUploads([presigned.key]);
// Confirm upload - use stagingKey if present (image processing enabled), else key
const confirmKey = presigned.stagingKey || presigned.key;
const { confirmed } = await confirmUploads([confirmKey]);
if (confirmed.length === 0) {
throw new Error("Upload verification failed");
}
// Return final key for database storage
return { key: presigned.key, publicUrl: presigned.publicUrl };
}
@@ -253,20 +256,20 @@ export async function uploadImageWithVariants(
)
);
// Confirm all uploads
const keys = presignedUrls.map((p) => p.key);
await confirmUploads(keys);
// Confirm all uploads - use stagingKey if present (image processing enabled), else key
const confirmKeys = presignedUrls.map((p) => p.stagingKey || p.key);
await confirmUploads(confirmKeys);
if (onProgress) onProgress(100);
// Use the baseKey returned by the backend (shared UUID for all variants)
// The stored key format is: items/uuid.jpg (original), and variants are items/uuid_th.jpg, items/uuid_md.jpg
const originalKey = keys.find((k) => !k.includes("_th") && !k.includes("_md")) || keys[0];
// Use the final keys for database storage (not staging keys)
const finalKeys = presignedUrls.map((p) => p.key);
const originalKey = finalKeys.find((k) => !k.includes("_th") && !k.includes("_md")) || finalKeys[0];
return {
baseKey: originalKey,
publicUrl: getPublicImageUrl(originalKey),
variants: keys,
variants: finalKeys,
};
}