Created
December 13, 2023 14:09
-
-
Save bhouston/bb731a57037d5e2d30d49307253bf11f to your computer and use it in GitHub Desktop.
old lv api image serving code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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