ipx
Advanced tools
Comparing version 1.3.0 to 2.0.0-0
@@ -1,17 +0,5 @@ | ||
import { Sharp, Color, KernelEnum, SharpOptions } from 'sharp'; | ||
import { IncomingMessage, ServerResponse } from 'node:http'; | ||
import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp'; | ||
import * as h3 from 'h3'; | ||
import { Storage, Driver } from 'unstorage'; | ||
interface ImageMeta { | ||
width: number; | ||
height: number; | ||
type: string; | ||
mimeType: string; | ||
} | ||
interface SourceData { | ||
mtime?: Date; | ||
maxAge?: number; | ||
getData: () => Promise<Buffer>; | ||
} | ||
type Source = (source: string, requestOptions?: any) => Promise<SourceData>; | ||
type SourceFactory<T = Record<string, any>> = (options: T) => Source; | ||
interface HandlerContext { | ||
@@ -31,2 +19,19 @@ quality?: number; | ||
} | ||
type IPXStorageMeta = { | ||
mtime?: Date | number | string; | ||
maxAge?: number | string; | ||
}; | ||
type IPXStorageOptions = Record<string, unknown>; | ||
type MaybePromise<T> = T | Promise<T>; | ||
interface IPXStorage { | ||
name: string; | ||
getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>; | ||
getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>; | ||
} | ||
interface ImageMeta { | ||
width: number; | ||
height: number; | ||
type: string; | ||
mimeType: string; | ||
} | ||
@@ -106,8 +111,9 @@ declare const quality: Handler; | ||
interface IPXCTX { | ||
sources: Record<string, Source>; | ||
} | ||
type IPXSourceMeta = { | ||
mtime?: Date; | ||
maxAge?: number; | ||
}; | ||
type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => { | ||
src: () => Promise<SourceData>; | ||
data: () => Promise<{ | ||
getSourceMeta: () => Promise<IPXSourceMeta>; | ||
process: () => Promise<{ | ||
data: Buffer; | ||
@@ -118,30 +124,33 @@ meta: ImageMeta; | ||
}; | ||
interface IPXOptions { | ||
dir?: false | string; | ||
type IPXOptions = { | ||
maxAge?: number; | ||
domains?: false | string[]; | ||
alias: Record<string, string>; | ||
fetchOptions: RequestInit; | ||
sharp?: SharpOptions; | ||
} | ||
declare function createIPX(userOptions: Partial<IPXOptions>): IPX; | ||
alias?: Record<string, string>; | ||
sharpOptions?: SharpOptions; | ||
storage: IPXStorage; | ||
httpStorage?: IPXStorage; | ||
}; | ||
declare function createIPX(userOptions: IPXOptions): IPX; | ||
interface IPXHRequest { | ||
url: string; | ||
headers?: Record<string, string>; | ||
options?: any; | ||
} | ||
interface IPXHResponse { | ||
statusCode: number; | ||
statusMessage: string; | ||
headers: Record<string, string>; | ||
body: any; | ||
error?: any; | ||
} | ||
interface MiddlewareOptions { | ||
fallthrough?: boolean; | ||
} | ||
declare function handleRequest(request: IPXHRequest, ipx: IPX): Promise<IPXHResponse>; | ||
declare function createIPXMiddleware(ipx: IPX, options?: Partial<MiddlewareOptions>): (request: IncomingMessage, res: ServerResponse, next?: ((err?: any) => void) | undefined) => Promise<void>; | ||
declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<Buffer | null>>; | ||
declare function createIPXH3App(ipx: IPX): h3.App; | ||
declare function createIPXWebServer(ipx: IPX): h3.WebHandler; | ||
declare function createIPXNodeServer(ipx: IPX): h3.NodeListener; | ||
declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler; | ||
export { type IPX, type IPXCTX, type IPXHRequest, type IPXHResponse, type IPXOptions, type MiddlewareOptions, type Source, type SourceData, type SourceFactory, createIPX, createIPXMiddleware, handleRequest }; | ||
type HTTPStorageOptions = { | ||
fetchOptions?: RequestInit; | ||
maxAge?: number; | ||
domains?: string | string[]; | ||
allowAllDomains?: boolean; | ||
}; | ||
declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage; | ||
type NodeFSSOptions = { | ||
dir?: string; | ||
maxAge?: number; | ||
}; | ||
declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage; | ||
declare function unstorageToIPXStorage(storage: Storage | Driver, prefix: string): IPXStorage; | ||
export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type ImageMeta, type NodeFSSOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage }; |
{ | ||
"name": "ipx", | ||
"version": "1.3.0", | ||
"version": "2.0.0-0", | ||
"repository": "unjs/ipx", | ||
"description": "High performance, secure and easy-to-use image optimizer.", | ||
"license": "MIT", | ||
@@ -26,14 +27,5 @@ "exports": { | ||
], | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "listhen -w playground", | ||
"lint": "eslint --ext .ts . && prettier -c src test", | ||
"lint:fix": "eslint --ext .ts . --fix && prettier -w src test", | ||
"prepack": "pnpm build", | ||
"release": "pnpm test && changelogen --release --push && npm publish", | ||
"start": "node bin/ipx.js", | ||
"test": "pnpm lint && vitest run --coverage" | ||
}, | ||
"dependencies": { | ||
"@fastify/accept-negotiator": "^1.1.0", | ||
"citty": "^0.1.4", | ||
"consola": "^3.2.3", | ||
@@ -43,4 +35,5 @@ "defu": "^6.1.2", | ||
"etag": "^1.8.1", | ||
"h3": "^1.8.1", | ||
"image-meta": "^0.1.1", | ||
"listhen": "^1.4.4", | ||
"listhen": "^1.5.2", | ||
"node-fetch-native": "^1.4.0", | ||
@@ -50,3 +43,3 @@ "pathe": "^1.1.1", | ||
"ufo": "^1.3.0", | ||
"xss": "^1.0.14" | ||
"unstorage": "^1.9.0" | ||
}, | ||
@@ -56,7 +49,7 @@ "devDependencies": { | ||
"@types/is-valid-path": "^0.1.0", | ||
"@vitest/coverage-v8": "^0.34.3", | ||
"@vitest/coverage-v8": "^0.34.4", | ||
"changelogen": "^0.5.5", | ||
"eslint": "^8.48.0", | ||
"eslint": "^8.49.0", | ||
"eslint-config-unjs": "^0.2.1", | ||
"jiti": "^1.19.3", | ||
"jiti": "^1.20.0", | ||
"prettier": "^3.0.3", | ||
@@ -66,5 +59,16 @@ "serve-handler": "^6.1.5", | ||
"unbuild": "^2.0.0", | ||
"vitest": "^0.34.3" | ||
"vitest": "^0.34.4" | ||
}, | ||
"packageManager": "pnpm@8.7.1" | ||
"packageManager": "pnpm@8.7.5", | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "listhen -w playground", | ||
"ipx": "jiti ./src/cli.ts", | ||
"lint": "eslint --ext .ts . && prettier -c src test", | ||
"lint:fix": "eslint --ext .ts . --fix && prettier -w src test", | ||
"release": "pnpm test && changelogen --release --push && npm publish", | ||
"prerelease": "pnpm test && pnpm build && changelogen --release --prerelease --push --publish --publishTag v2", | ||
"start": "node bin/ipx.js", | ||
"test": "pnpm lint && vitest run --coverage" | ||
} | ||
} |
108
README.md
@@ -6,14 +6,27 @@ # 🖼️ IPX | ||
High performance, secure and easy to use image proxy based on [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips). | ||
High performance, secure and easy-to-use image optimizer. | ||
Powered by [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips). | ||
> [!IMPORTANT] | ||
> This is the development branch for IPX v2. Check out [ipx/v1](https://github.com/unjs/ipx/tree/v1) for latest stable docs. | ||
## Using CLI | ||
You can use `ipx` command to start server using: | ||
You can use `ipx` command to start server. | ||
Using `npx`: | ||
```bash | ||
npx ipx@latest | ||
npx ipx@latest serve --dir ./ | ||
``` | ||
The default server directory is the current working directory. | ||
Usin `bun` | ||
```bash | ||
bun x ipx@latest serve --dir ./ | ||
``` | ||
The default serve directory is the current working directory. | ||
## Programatic API | ||
@@ -24,7 +37,14 @@ | ||
```ts | ||
import { createIPX, createIPXMiddleware } from "ipx"; | ||
import { | ||
createIPX, | ||
createIPXMiddleware, | ||
ipxFSStorage, | ||
ipxHttpStorage, | ||
} from "./src"; | ||
const ipx = createIPX({ domains: ["unjs.io"] }); | ||
const ipx = createIPX({ | ||
storage: ipxFSStorage({ dir: "./public" }), | ||
httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }), | ||
}); | ||
// (req, res) => void | ||
const ipxMiddleware = createIPXMiddleware(ipx); | ||
@@ -38,7 +58,3 @@ ``` | ||
import { listen } from "listhen"; | ||
import { createApp, fromNodeMiddleware, toNodeListener } from "h3"; | ||
const ipx = createIPX({}); | ||
const ipxMiddleware = createIPXMiddleware(ipx); | ||
const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware)); | ||
@@ -52,9 +68,5 @@ | ||
```js | ||
import { createIPX, createIPXMiddleware } from "ipx"; | ||
import { listen } from "listhen"; | ||
import express from "express"; | ||
const ipx = createIPX({}); | ||
const ipxMiddleware = createIPXMiddleware(ipx); | ||
const app = express().use("/", ipxMiddleware); | ||
@@ -65,3 +77,3 @@ | ||
## Examples | ||
## URL Examples | ||
@@ -84,2 +96,42 @@ Get original image: | ||
## Config | ||
You can universally customize IPX configuration using `IPX_*` environment variables. | ||
- `IPX_ALIAS` | ||
- Default: `{}` | ||
### Filesystem Source Options | ||
(enabled by default with CLI only) | ||
#### `IPX_FS_DIR` | ||
- Default: `.` (current working directory) | ||
#### `IPX_FS_MAX_AGE` | ||
- Default: `300` | ||
### HTTP(s) Source Options | ||
(enabled by default with CLI only) | ||
#### `IPX_HTTP_DOMAINS` | ||
- Default: `[]` | ||
#### `IPX_HTTP_MAX_AGE` | ||
- Default: `300` | ||
#### `IPX_HTTP_FETCH_OPTIONS` | ||
- Default: `{}` | ||
#### `IPX_HTTP_ALLOW_ALL_DOMAINS` | ||
- Default: `false` | ||
## Modifiers | ||
@@ -116,26 +168,2 @@ | ||
## Config | ||
Config can be customized using `IPX_*` environment variables. | ||
- `IPX_DIR` | ||
- Default: `.` (current working directory) | ||
- `IPX_DOMAINS` | ||
- Default: `[]` | ||
- `IPX_MAX_AGE` | ||
- Default: `300` | ||
- `IPX_ALIAS` | ||
- Default: `{}` | ||
- `IPX_FETCH_OPTIONS` | ||
- Default: `{}` | ||
## License | ||
@@ -142,0 +170,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
75279
17
1726
180
14
2
3
+ Addedcitty@^0.1.4
+ Addedh3@^1.8.1
+ Addedunstorage@^1.9.0
+ Addedanymatch@3.1.3(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedlru-cache@10.2.2(transitive)
+ Addedmri@1.2.0(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedofetch@1.3.4(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedunstorage@1.10.2(transitive)
- Removedxss@^1.0.14
- Removedcommander@2.20.3(transitive)
- Removedcssfilter@0.0.10(transitive)
- Removedxss@1.0.15(transitive)
Updatedlisthen@^1.5.2