fixed image previews
This commit is contained in:
@@ -112,9 +112,10 @@ class S3Service {
|
||||
* @param {string} contentType - MIME type of the file
|
||||
* @param {string} fileName - Original filename (used for extension)
|
||||
* @param {number} fileSize - File size in bytes (required for size enforcement)
|
||||
* @param {string} [baseKey] - Optional base key (UUID) for coordinated variant uploads
|
||||
* @returns {Promise<{uploadUrl: string, key: string, publicUrl: string, expiresAt: Date}>}
|
||||
*/
|
||||
async getPresignedUploadUrl(uploadType, contentType, fileName, fileSize) {
|
||||
async getPresignedUploadUrl(uploadType, contentType, fileName, fileSize, baseKey = null) {
|
||||
if (!this.enabled) {
|
||||
throw new Error("S3 storage is not enabled");
|
||||
}
|
||||
@@ -135,8 +136,21 @@ class S3Service {
|
||||
);
|
||||
}
|
||||
|
||||
// Extract known variant suffix from fileName if present (e.g., "photo_th.jpg" -> "_th")
|
||||
const ext = path.extname(fileName) || this.getExtFromMime(contentType);
|
||||
const key = `${config.folder}/${uuidv4()}${ext}`;
|
||||
const baseName = path.basename(fileName, ext);
|
||||
|
||||
// Only recognize known variant suffixes
|
||||
let suffix = "";
|
||||
if (baseName.endsWith("_th")) {
|
||||
suffix = "_th";
|
||||
} else if (baseName.endsWith("_md")) {
|
||||
suffix = "_md";
|
||||
}
|
||||
|
||||
// Use provided baseKey or generate new UUID
|
||||
const uuid = baseKey || uuidv4();
|
||||
const key = `${config.folder}/${uuid}${suffix}${ext}`;
|
||||
|
||||
const cacheDirective = config.public ? "public" : "private";
|
||||
const command = new PutObjectCommand({
|
||||
|
||||
Reference in New Issue
Block a user