fix: adopt sharp 0.35.2+ by centralizing the FormatEnum key type (#362)

Centralizes the sharp format key type into a single `SharpFormat` alias derived from `toFormat()`'s signature (exported from @snapotter/image-engine, imported by the API consumers), replacing the duplicated `keyof FormatEnum` definitions. Adds convert/compress format round-trip tests covering webp/avif/png/jpeg. Part of #325.
This commit is contained in:
Matt Van Horn
2026-07-01 21:50:29 +08:00
committed by GitHub
parent 852f6cecba
commit 9052da27f3
4 changed files with 56 additions and 9 deletions
+2 -3
View File
@@ -1,6 +1,5 @@
import sharp, { type FormatEnum } from "sharp";
export type SharpFormat = Extract<keyof FormatEnum, string> | "avif";
import type { SharpFormat } from "@snapotter/image-engine";
import sharp from "sharp";
export interface OutputFormat {
format: SharpFormat;
+2 -3
View File
@@ -1,8 +1,9 @@
import { randomUUID } from "node:crypto";
import { extname } from "node:path";
import type { SharpFormat } from "@snapotter/image-engine";
import archiver from "archiver";
import type { FastifyInstance } from "fastify";
import sharp, { type FormatEnum } from "sharp";
import sharp from "sharp";
import { z } from "zod";
import { autoOrient } from "../../lib/auto-orient.js";
import { getSecurityHeaders } from "../../lib/csp.js";
@@ -24,8 +25,6 @@ const settingsSchema = z.object({
quality: z.number().min(1).max(100).default(90),
});
type SharpFormat = Extract<keyof FormatEnum, string> | "avif";
function resolveOutputFormat(
outputFormat: string,
originalExt: string,