fastify-ximagepipeline
getVariantPresets / getSourceTypes / getVariants
Inspect the active variant and source type configuration at runtime.
getVariantPresets / getSourceTypes / getVariants
Three synchronous accessors that expose the active configuration built at registration time. Useful for building admin UIs, validation logic, or dynamic upload forms.
Signatures
fastify.xImagePipeline.getVariantPresets(): Record<string, string[]>
fastify.xImagePipeline.getSourceTypes(): Record<string, SourceTypeConfig>
fastify.xImagePipeline.getVariants(): Record<string, VariantSpec>
interface SourceTypeConfig {
variants: string[] // variant names to generate
formats: string[] // output formats (always ["webp"])
quality: number // WebP quality 0–100
storeOriginal: boolean // whether to keep the original file
}
interface VariantSpec {
width: number
height: number | null // null = auto (maintain aspect ratio)
fit: "cover" | "inside"
}
Methods
| Method | Returns | Description |
|---|---|---|
getVariantPresets() | Record<string, string[]> | Maps each source type to the variant names it produces |
getSourceTypes() | Record<string, SourceTypeConfig> | Full configuration per source type including quality and storeOriginal |
getVariants() | Record<string, VariantSpec> | Dimension specs for every variant name |
All three methods are synchronous and return the resolved configuration (merged defaults + any overrides passed at registration).
Examples
Expose config for a frontend upload form
fastify.get("/api/image-config", async (request, reply) => {
return {
sourceTypes: Object.keys(fastify.xImagePipeline.getSourceTypes()),
variantPresets: fastify.xImagePipeline.getVariantPresets(),
};
});
// Response:
// {
// sourceTypes: ["avatar", "member_photo", "gallery", "hero", "content"],
// variantPresets: {
// avatar: ["xs", "sm"],
// gallery: ["md", "lg", "xl"],
// ...
// }
// }
Validate a sourceType before proxying an upload
fastify.post("/upload", async (request, reply) => {
const { sourceType } = request.body;
const validTypes = Object.keys(fastify.xImagePipeline.getSourceTypes());
if (!validTypes.includes(sourceType)) {
return reply.code(400).send({
error: `Invalid sourceType. Must be one of: ${validTypes.join(", ")}`,
});
}
// forward to image pipeline...
});
See Also
- POST /image-pipeline/upload — Uses sourceTypes and variants at upload time
- listMedia(sourceType, sourceId) — Query processed media by source type
AI Context
package: "@xenterprises/fastify-ximagepipeline"
methods: fastify.xImagePipeline.getVariantPresets() | fastify.xImagePipeline.getSourceTypes() | fastify.xImagePipeline.getVariants(sourceType)
use-when: Inspect the active variant specs and source type configuration at runtime
fastify-ximagepipeline
Async image upload pipeline for Fastify — EXIF stripping, content moderation, WebP variant generation, blurhash placeholders, and R2/S3 storage with a background job queue.
deleteMedia
Delete a Media record from the database and all associated R2 objects (variants and originals).
