fix: Add Sharp fallback for photo uploads on old CPUs
Some checks failed
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled

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:
2025-10-04 08:35:25 +00:00
parent d22b0d56a5
commit 9c4bc1b90f
2 changed files with 35 additions and 10 deletions

View File

@@ -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)
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