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" },
|
gif: { format: "gif", extension: "gif", contentType: "image/gif" },
|
||||||
tiff: { format: "tiff", extension: "tiff", contentType: "image/tiff" },
|
tiff: { format: "tiff", extension: "tiff", contentType: "image/tiff" },
|
||||||
avif: { format: "avif", extension: "avif", contentType: "image/avif" },
|
avif: { format: "avif", extension: "avif", contentType: "image/avif" },
|
||||||
|
heif: { format: "avif", extension: "avif", contentType: "image/avif" },
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_QUALITY = 95;
|
const DEFAULT_QUALITY = 95;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { compress } from "@ashim/image-engine";
|
|||||||
import type { FastifyInstance } from "fastify";
|
import type { FastifyInstance } from "fastify";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { resolveOutputFormat } from "../../lib/output-format.js";
|
||||||
import { createToolRoute } from "../tool-factory.js";
|
import { createToolRoute } from "../tool-factory.js";
|
||||||
|
|
||||||
const settingsSchema = z.object({
|
const settingsSchema = z.object({
|
||||||
@@ -16,6 +17,7 @@ export function registerCompress(app: FastifyInstance) {
|
|||||||
settingsSchema,
|
settingsSchema,
|
||||||
process: async (inputBuffer, settings, filename) => {
|
process: async (inputBuffer, settings, filename) => {
|
||||||
const image = sharp(inputBuffer);
|
const image = sharp(inputBuffer);
|
||||||
|
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
|
||||||
|
|
||||||
const compressOptions: {
|
const compressOptions: {
|
||||||
quality?: number;
|
quality?: number;
|
||||||
@@ -31,7 +33,7 @@ export function registerCompress(app: FastifyInstance) {
|
|||||||
|
|
||||||
const result = await compress(image, compressOptions);
|
const result = await compress(image, compressOptions);
|
||||||
const buffer = await result.toBuffer();
|
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",
|
png: "png",
|
||||||
webp: "webp",
|
webp: "webp",
|
||||||
avif: "avif",
|
avif: "avif",
|
||||||
|
heif: "avif",
|
||||||
tiff: "tiff",
|
tiff: "tiff",
|
||||||
gif: "gif",
|
gif: "gif",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const FORMAT_MAP: Record<string, string> = {
|
|||||||
png: "png",
|
png: "png",
|
||||||
webp: "webp",
|
webp: "webp",
|
||||||
avif: "avif",
|
avif: "avif",
|
||||||
|
heif: "avif",
|
||||||
tiff: "tiff",
|
tiff: "tiff",
|
||||||
gif: "gif",
|
gif: "gif",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user