fix: support AVIF compress and fix hardcoded content type

This commit is contained in:
ashim-hq
2026-04-20 22:13:53 +08:00
parent 491e6fb554
commit c738f16107
4 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -2,6 +2,7 @@ import { compress } from "@ashim/image-engine";
import type { FastifyInstance } from "fastify";
import sharp from "sharp";
import { z } from "zod";
import { resolveOutputFormat } from "../../lib/output-format.js";
import { createToolRoute } from "../tool-factory.js";
const settingsSchema = z.object({
@@ -16,6 +17,7 @@ export function registerCompress(app: FastifyInstance) {
settingsSchema,
process: async (inputBuffer, settings, filename) => {
const image = sharp(inputBuffer);
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
const compressOptions: {
quality?: number;
@@ -31,7 +33,7 @@ export function registerCompress(app: FastifyInstance) {
const result = await compress(image, compressOptions);
const buffer = await result.toBuffer();
return { buffer, filename, contentType: "image/jpeg" };
return { buffer, filename, contentType: outputFormat.contentType };
},
});
}