Comparing version 0.5.1 to 0.5.2
@@ -5,2 +5,14 @@ # Changelog | ||
### [0.5.2](https://github.com/nuxt-contrib/ipx/compare/v0.5.1...v0.5.2) (2021-02-03) | ||
### Features | ||
* support meta, content-type and svg handling ([37592e7](https://github.com/nuxt-contrib/ipx/commit/37592e711d166df41c29f1b1117adb186d42ce5d)) | ||
### Bug Fixes | ||
* only giveup svg if no format modifier set ([f5ce8b7](https://github.com/nuxt-contrib/ipx/commit/f5ce8b7aecd18629b7a116dc6aecd5096d4573aa)) | ||
### [0.5.1](https://github.com/nuxt-contrib/ipx/compare/v0.5.0...v0.5.1) (2021-02-03) | ||
@@ -7,0 +19,0 @@ |
@@ -9,2 +9,3 @@ #!/usr/bin/env node | ||
const defu2 = require('defu'); | ||
const imageMeta = require('image-meta'); | ||
const path = require('path'); | ||
@@ -26,2 +27,3 @@ const isValidPath = require('is-valid-path'); | ||
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2); | ||
const imageMeta__default = /*#__PURE__*/_interopDefaultLegacy(imageMeta); | ||
const isValidPath__default = /*#__PURE__*/_interopDefaultLegacy(isValidPath); | ||
@@ -78,3 +80,3 @@ const destr2__default = /*#__PURE__*/_interopDefaultLegacy(destr2); | ||
maxAge: options.maxAge || 300, | ||
getData: () => fsExtra.readFile(fsPath) | ||
getData: cachedPromise(() => fsExtra.readFile(fsPath)) | ||
}; | ||
@@ -115,3 +117,3 @@ }; | ||
maxAge, | ||
getData: () => response.buffer() | ||
getData: cachedPromise(() => response.buffer()) | ||
}; | ||
@@ -251,3 +253,3 @@ }; | ||
} | ||
const meta = cachedPromise(() => { | ||
const getSrc = cachedPromise(() => { | ||
const source2 = inputOpts.source || id.startsWith("http") ? "http" : "filesystem"; | ||
@@ -259,9 +261,19 @@ if (!ctx.sources[source2]) { | ||
}); | ||
const data = async () => { | ||
const src = await meta(); | ||
const data2 = await src.getData(); | ||
const getMeta = cachedPromise(async () => { | ||
const src = await getSrc(); | ||
const data = await src.getData(); | ||
const meta = imageMeta__default['default'](data); | ||
return meta; | ||
}); | ||
const getData = cachedPromise(async () => { | ||
const src = await getSrc(); | ||
const data = await src.getData(); | ||
if (!inputOpts.modifiers || Object.values(inputOpts.modifiers).length === 0) { | ||
return data2; | ||
return data; | ||
} | ||
let sharp2 = Sharp__default['default'](data2); | ||
const meta = await getMeta(); | ||
if (meta.type === "svg" && (!inputOpts.modifiers.f || !inputOpts.modifiers.format)) { | ||
return data; | ||
} | ||
let sharp2 = Sharp__default['default'](data); | ||
Object.assign(sharp2.options, options.sharp); | ||
@@ -273,6 +285,7 @@ const modifierCtx = {}; | ||
return sharp2.toBuffer(); | ||
}; | ||
}); | ||
return { | ||
meta, | ||
data | ||
src: getSrc, | ||
data: getData, | ||
meta: getMeta | ||
}; | ||
@@ -297,6 +310,6 @@ }; | ||
}); | ||
const meta = await img.meta(); | ||
if (meta.mtime) { | ||
const src = await img.src(); | ||
if (src.mtime) { | ||
if (req.headers["if-modified-since"]) { | ||
if (new Date(req.headers["if-modified-since"]) >= meta.mtime) { | ||
if (new Date(req.headers["if-modified-since"]) >= src.mtime) { | ||
res.statusCode = 304; | ||
@@ -306,6 +319,6 @@ return res.end(); | ||
} | ||
res.setHeader("Last-Modified", +meta.mtime); | ||
res.setHeader("Last-Modified", +src.mtime); | ||
} | ||
if (meta.maxAge !== void 0) { | ||
res.setHeader("Cache-Control", "maxAge=" + +meta.maxAge); | ||
if (src.maxAge !== void 0) { | ||
res.setHeader("Cache-Control", "maxAge=" + +src.maxAge); | ||
} | ||
@@ -319,2 +332,6 @@ const data = await img.data(); | ||
} | ||
const meta = await img.meta(); | ||
if (meta.mimeType) { | ||
res.setHeader("Content-Type", meta.mimeType); | ||
} | ||
res.end(data); | ||
@@ -321,0 +338,0 @@ } |
@@ -11,2 +11,8 @@ import { IncomingMessage, ServerResponse } from 'http'; | ||
interface ImageMeta { | ||
width: number; | ||
height: number; | ||
type: string; | ||
mimeType: string; | ||
} | ||
interface IPXInputOptions { | ||
@@ -20,4 +26,5 @@ source?: string; | ||
declare type IPX = (id: string, opts?: IPXInputOptions) => { | ||
meta: () => Promise<SourceData>; | ||
src: () => Promise<SourceData>; | ||
data: () => Promise<Buffer>; | ||
meta: () => Promise<ImageMeta>; | ||
}; | ||
@@ -35,2 +42,2 @@ interface IPXOptions { | ||
export { IPX, IPXCTX, IPXInputOptions, IPXOptions, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware }; | ||
export { IPX, IPXCTX, IPXInputOptions, IPXOptions, ImageMeta, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware }; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const defu2 = require('defu'); | ||
const imageMeta = require('image-meta'); | ||
const path = require('path'); | ||
@@ -23,2 +24,3 @@ const isValidPath = require('is-valid-path'); | ||
const defu2__default = /*#__PURE__*/_interopDefaultLegacy(defu2); | ||
const imageMeta__default = /*#__PURE__*/_interopDefaultLegacy(imageMeta); | ||
const isValidPath__default = /*#__PURE__*/_interopDefaultLegacy(isValidPath); | ||
@@ -75,3 +77,3 @@ const destr2__default = /*#__PURE__*/_interopDefaultLegacy(destr2); | ||
maxAge: options.maxAge || 300, | ||
getData: () => fsExtra.readFile(fsPath) | ||
getData: cachedPromise(() => fsExtra.readFile(fsPath)) | ||
}; | ||
@@ -112,3 +114,3 @@ }; | ||
maxAge, | ||
getData: () => response.buffer() | ||
getData: cachedPromise(() => response.buffer()) | ||
}; | ||
@@ -248,3 +250,3 @@ }; | ||
} | ||
const meta = cachedPromise(() => { | ||
const getSrc = cachedPromise(() => { | ||
const source2 = inputOpts.source || id.startsWith("http") ? "http" : "filesystem"; | ||
@@ -256,9 +258,19 @@ if (!ctx.sources[source2]) { | ||
}); | ||
const data = async () => { | ||
const src = await meta(); | ||
const data2 = await src.getData(); | ||
const getMeta = cachedPromise(async () => { | ||
const src = await getSrc(); | ||
const data = await src.getData(); | ||
const meta = imageMeta__default['default'](data); | ||
return meta; | ||
}); | ||
const getData = cachedPromise(async () => { | ||
const src = await getSrc(); | ||
const data = await src.getData(); | ||
if (!inputOpts.modifiers || Object.values(inputOpts.modifiers).length === 0) { | ||
return data2; | ||
return data; | ||
} | ||
let sharp2 = Sharp__default['default'](data2); | ||
const meta = await getMeta(); | ||
if (meta.type === "svg" && (!inputOpts.modifiers.f || !inputOpts.modifiers.format)) { | ||
return data; | ||
} | ||
let sharp2 = Sharp__default['default'](data); | ||
Object.assign(sharp2.options, options.sharp); | ||
@@ -270,6 +282,7 @@ const modifierCtx = {}; | ||
return sharp2.toBuffer(); | ||
}; | ||
}); | ||
return { | ||
meta, | ||
data | ||
src: getSrc, | ||
data: getData, | ||
meta: getMeta | ||
}; | ||
@@ -294,6 +307,6 @@ }; | ||
}); | ||
const meta = await img.meta(); | ||
if (meta.mtime) { | ||
const src = await img.src(); | ||
if (src.mtime) { | ||
if (req.headers["if-modified-since"]) { | ||
if (new Date(req.headers["if-modified-since"]) >= meta.mtime) { | ||
if (new Date(req.headers["if-modified-since"]) >= src.mtime) { | ||
res.statusCode = 304; | ||
@@ -303,6 +316,6 @@ return res.end(); | ||
} | ||
res.setHeader("Last-Modified", +meta.mtime); | ||
res.setHeader("Last-Modified", +src.mtime); | ||
} | ||
if (meta.maxAge !== void 0) { | ||
res.setHeader("Cache-Control", "maxAge=" + +meta.maxAge); | ||
if (src.maxAge !== void 0) { | ||
res.setHeader("Cache-Control", "maxAge=" + +src.maxAge); | ||
} | ||
@@ -316,2 +329,6 @@ const data = await img.data(); | ||
} | ||
const meta = await img.meta(); | ||
if (meta.mimeType) { | ||
res.setHeader("Content-Type", meta.mimeType); | ||
} | ||
res.end(data); | ||
@@ -318,0 +335,0 @@ } |
{ | ||
"name": "ipx", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"repository": "nuxt-contrib/ipx", | ||
@@ -28,2 +28,3 @@ "license": "MIT", | ||
"fs-extra": "^9.0.1", | ||
"image-meta": "^0.0.1", | ||
"is-valid-path": "^0.1.1", | ||
@@ -30,0 +31,0 @@ "listhen": "^0.1.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38607
1027
9
12
+ Addedimage-meta@^0.0.1
+ Addedimage-meta@0.0.1(transitive)