@socialtip/asset-proxy-url-generator
v0.5.1
Published
Generate asset-proxy-compatible URL paths with optional encryption and signing
Downloads
323
Readme
@socialtip/asset-proxy-url-generator
Generate asset-proxy-compatible URL paths programmatically, with optional source URL encryption and HMAC signing.
Installation
npm install @socialtip/asset-proxy-url-generatorUsage
import { generateUrl } from "@socialtip/asset-proxy-url-generator";
const url = generateUrl({
sourceUrl: "https://example.com/photo.jpg",
outputFormat: "webp",
resize: { type: "fill", width: 480, height: 360 },
quality: 80,
});
// => /_/rs:fill:480:360/q:80/plain/https://example.com/photo.jpg@webpEncrypted source URLs
const url = generateUrl(
{ sourceUrl: "https://example.com/photo.jpg", outputFormat: "webp" },
{ encryptionKey: "0123456789abcdef..." }, // hex-encoded 32-byte key
);
// => /_/enc/dGhpcyBpcy...@webpSigned URLs
const url = generateUrl(
{ sourceUrl: "https://example.com/photo.jpg" },
{
signingKey: "...", // hex-encoded HMAC key
signingSalt: "...", // hex-encoded salt
},
);
// => /oKfUtW34Dvo.../plain/https://example.com/photo.jpgAll options
The generateUrl function accepts all processing options from the asset-proxy URL schema. See the full options reference for details.
