fix: Add Sharp fallback for photo uploads on old CPUs
The server CPU doesn't support Sharp's prebuilt binaries (requires v2 microarchitecture). Added graceful fallback to upload images without optimization when Sharp is unavailable. Changes: - StorageService.uploadImage() falls back to direct upload without optimization - StorageService.generateThumbnail() uses original image if Sharp fails - Logs warnings when Sharp is unavailable instead of crashing - Photo uploads now work on all CPU architectures Images upload without optimization until Sharp is built from source or server is upgraded. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -135,7 +135,23 @@ export class StorageService {
|
||||
},
|
||||
): Promise<UploadResult & { metadata: ImageMetadata }> {
|
||||
try {
|
||||
const sharp = await this.getSharp();
|
||||
let sharp;
|
||||
try {
|
||||
sharp = await this.getSharp();
|
||||
} catch (error) {
|
||||
this.logger.warn('Sharp not available - uploading without optimization');
|
||||
// Upload without optimization if Sharp is not available
|
||||
const uploadResult = await this.uploadFile(buffer, key, 'image/jpeg');
|
||||
return {
|
||||
...uploadResult,
|
||||
metadata: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
format: 'unknown',
|
||||
size: buffer.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Get original image metadata
|
||||
const imageInfo = await sharp(buffer).metadata();
|
||||
@@ -193,14 +209,23 @@ export class StorageService {
|
||||
height: number = 200,
|
||||
): Promise<UploadResult> {
|
||||
try {
|
||||
const sharp = await this.getSharp();
|
||||
const thumbnailBuffer = await sharp(buffer)
|
||||
.resize(width, height, {
|
||||
fit: 'cover',
|
||||
position: 'center',
|
||||
})
|
||||
.jpeg({ quality: 80 })
|
||||
.toBuffer();
|
||||
let sharp;
|
||||
let thumbnailBuffer;
|
||||
|
||||
try {
|
||||
sharp = await this.getSharp();
|
||||
thumbnailBuffer = await sharp(buffer)
|
||||
.resize(width, height, {
|
||||
fit: 'cover',
|
||||
position: 'center',
|
||||
})
|
||||
.jpeg({ quality: 80 })
|
||||
.toBuffer();
|
||||
} catch (error) {
|
||||
this.logger.warn('Sharp not available - using original image as thumbnail');
|
||||
// Use original image if Sharp is not available
|
||||
thumbnailBuffer = buffer;
|
||||
}
|
||||
|
||||
return this.uploadFile(thumbnailBuffer, key, 'image/jpeg');
|
||||
} catch (error) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user