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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user