Skip to content

Commit

Permalink
refactor: upgrade to image-meta 0.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 18, 2023
1 parent ce0cf0e commit 1017deb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"destr": "^2.0.1",
"etag": "^1.8.1",
"h3": "^1.8.2",
"image-meta": "^0.1.1",
"image-meta": "^0.2.0",
"listhen": "^1.5.5",
"ofetch": "^1.3.3",
"pathe": "^1.1.1",
Expand All @@ -67,4 +67,4 @@
"vitest": "^0.34.6"
},
"packageManager": "[email protected]"
}
}
9 changes: 4 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/ipx.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defu } from "defu";
import { imageMeta as getImageMeta } from "image-meta";
import { hasProtocol, joinURL, withLeadingSlash } from "ufo";
import type { SharpOptions } from "sharp";
import { createError } from "h3";
import type { ImageMeta, IPXStorage } from "./types";
import { imageMeta as getImageMeta, type ImageMeta } from "image-meta";
import type { IPXStorage } from "./types";
import { HandlerName, applyHandler, getHandler } from "./handlers";
import { cachedPromise, getEnv } from "./utils";

Expand All @@ -19,8 +19,8 @@ export type IPX = (
getSourceMeta: () => Promise<IPXSourceMeta>;
process: () => Promise<{
data: Buffer;
meta: ImageMeta;
format: string;
meta?: ImageMeta;
format?: string;
}>;
};

Expand Down Expand Up @@ -153,7 +153,7 @@ export function createIPX(userOptions: IPXOptions): IPX {
const format =
mFormat && SUPPORTED_FORMATS.has(mFormat)
? mFormat
: SUPPORTED_FORMATS.has(imageMeta.type) // eslint-disable-line unicorn/no-nested-ternary
: SUPPORTED_FORMATS.has(imageMeta.type || "") // eslint-disable-line unicorn/no-nested-ternary
? imageMeta.type
: "jpeg";

Expand Down Expand Up @@ -201,7 +201,7 @@ export function createIPX(userOptions: IPXOptions): IPX {
}

// Apply format
if (SUPPORTED_FORMATS.has(format)) {
if (SUPPORTED_FORMATS.has(format || "")) {
sharp = sharp.toFormat(format as any, {
quality: handlerContext.quality,
progressive: format === "jpeg",
Expand Down
10 changes: 1 addition & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ImageMeta } from "image-meta";
import type { Sharp, Color, KernelEnum } from "sharp";

// ---- Handlers ----
Expand Down Expand Up @@ -42,12 +43,3 @@ export interface IPXStorage {
opts?: IPXStorageOptions,
) => MaybePromise<ArrayBuffer | undefined>;
}

// ---- External Types ----

export interface ImageMeta {
width: number;
height: number;
type: string;
mimeType: string;
}

0 comments on commit 1017deb

Please sign in to comment.