Use heic-convert for HEIC-to-JPEG conversion

Sharp's prebuilt libvips lacks HEIF codec support. Replace with
heic-convert (pure JS decoder) for reliable HEIC conversion on all
platforms. Existing HEIC files on disk will be converted on-the-fly
when served via /api/files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
denshooter
2026-02-22 02:01:04 +01:00
parent 6f826c66ea
commit 31dff10636
6 changed files with 74 additions and 6 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ import { writeFile, mkdir } from 'fs/promises'
import path from 'path'
import { randomUUID } from 'crypto'
import { getDb } from '@/lib/db'
import sharp from 'sharp'
import { convertHeicToJpeg } from '@/lib/heic'
export const runtime = 'nodejs'
export const maxDuration = 60
@@ -77,7 +77,7 @@ export async function POST(req: NextRequest) {
let finalExt = ext
if (mimeType === 'image/heic' || mimeType === 'image/heif') {
try {
finalBuffer = Buffer.from(await sharp(buffer).jpeg({ quality: 90 }).toBuffer())
finalBuffer = await convertHeicToJpeg(buffer)
finalExt = '.jpg'
} catch {
// Conversion failed — keep original