mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: support AVIF compress and fix hardcoded content type
This commit is contained in:
@@ -17,6 +17,7 @@ const FORMAT_MAP: Record<
|
||||
gif: { format: "gif", extension: "gif", contentType: "image/gif" },
|
||||
tiff: { format: "tiff", extension: "tiff", contentType: "image/tiff" },
|
||||
avif: { format: "avif", extension: "avif", contentType: "image/avif" },
|
||||
heif: { format: "avif", extension: "avif", contentType: "image/avif" },
|
||||
};
|
||||
|
||||
const DEFAULT_QUALITY = 95;
|
||||
|
||||
@@ -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 };
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ const FORMAT_MAP: Record<string, string> = {
|
||||
png: "png",
|
||||
webp: "webp",
|
||||
avif: "avif",
|
||||
heif: "avif",
|
||||
tiff: "tiff",
|
||||
gif: "gif",
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ const FORMAT_MAP: Record<string, string> = {
|
||||
png: "png",
|
||||
webp: "webp",
|
||||
avif: "avif",
|
||||
heif: "avif",
|
||||
tiff: "tiff",
|
||||
gif: "gif",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user