Skip to content

Instantly share code, notes, and snippets.

@bhouston
Created December 13, 2023 14:09
Show Gist options
  • Save bhouston/bb731a57037d5e2d30d49307253bf11f to your computer and use it in GitHub Desktop.
Save bhouston/bb731a57037d5e2d30d49307253bf11f to your computer and use it in GitHub Desktop.
old lv api image serving code.
const fileUrl = new URL(`/api/files/${fileId}/content`, API_URL);
const url = new URL('/api/images', API_URL);
url.pathname += `/webp`;
url.pathname += `/${params.width ?? 0}`;
url.pathname += 'x';
url.pathname += `${params.height ?? 0}`;
url.pathname += `/filters:format(${params.extension ?? 'png'})`;
url.pathname += `/${fileUrl}`;
const response = await fetch(url, {
method: 'GET',
headers: {
authorization: `Bearer ${API_TOKEN}`,
'content-type': `image/${formattingParams.extension ?? 'png'}`
}
});
return response.body as NodeJS.ReadableStream;
const imageReadableStream = await getConfigurationSnapshot(recipeId, view, sizeParams, formattingParams);
res.setHeader(`content-type`, `image/${formattingParams.extension ?? 'png'}`);
imageReadableStream.pipe(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment