fastify-ximagepipeline
listMedia
List all Media records for a given sourceType and sourceId, ordered by most recent first.
listMedia
List all Media records for a given sourceType and sourceId, ordered by createdAt descending (most recent first).
Signature
fastify.xImagePipeline.listMedia(
sourceType: string,
sourceId: string,
): Promise<MediaRecord[]>
interface MediaRecord {
id: string
sourceType: string
sourceId: string
urls: Record<string, string> // variant name → URL
originalUrl: string | null
width: number
height: number
aspectRatio: string
blurhash: string
createdAt: Date
updatedAt: Date
}
Params
| Name | Type | Required | Description |
|---|---|---|---|
sourceType | string | Yes | Source type (e.g. "avatar", "gallery") |
sourceId | string | Yes | Owning resource ID (e.g. user ID, post ID) |
Returns
An array of MediaRecord objects. Empty array if no media exists for that source.
Throws
Throws on database errors only.
Examples
Return a user's gallery images
fastify.get("/users/:id/gallery", async (request, reply) => {
const images = await fastify.xImagePipeline.listMedia(
"gallery",
request.params.id,
);
return {
images: images.map((img) => ({
id: img.id,
thumbnail: img.urls.md,
full: img.urls.xl,
blurhash: img.blurhash,
aspectRatio: img.aspectRatio,
})),
};
});
Find and replace a user's current avatar
fastify.put("/users/:id/avatar", async (request, reply) => {
// Delete existing avatar(s) before processing new upload
const existing = await fastify.xImagePipeline.listMedia("avatar", request.params.id);
await Promise.all(
existing.map((m) => fastify.xImagePipeline.deleteMedia(m.id)),
);
// Proceed with the new upload via POST /image-pipeline/upload
return reply.redirect(`/image-pipeline/upload`);
});
See Also
- deleteMedia(mediaId) — Remove a media record and its R2 files
- getStatus(jobId) — Check a specific job's state
AI Context
package: "@xenterprises/fastify-ximagepipeline"
method: fastify.xImagePipeline.listMedia(sourceType, sourceId)
use-when: List all COMPLETE media records for a given source (e.g. all avatars for a user)
returns: Media[] with variant URLs, blurhash, and metadata
GET /image-pipeline/status/:jobId
Poll the processing status of an upload job — returns variant URLs, blurhash, and dimensions when COMPLETE.
S3 / R2 Utilities
Low-level S3-compatible storage helpers for uploading, downloading, deleting, listing, and signing objects — importable standalone from the pipeline plugin.
