1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2025-12-16 11:08:49 +00:00

Allow got as request backend

This commit is contained in:
Cadence Fish
2020-03-15 19:50:29 +13:00
parent a861df2662
commit 3efc4928a5
10 changed files with 439 additions and 51 deletions

View File

@@ -36,18 +36,25 @@ module.exports = [
Some thumbnails aren't square and would otherwise be stretched on the page without this.
If I cropped the images client side, it would have to be done with CSS background-image, which means no <img srcset>.
*/
return request(verifyResult.url, {}, {log: false}).then(res => {
return request(verifyResult.url, {}, {log: false}).stream().then(body => {
const converter = sharp().resize(width, width, {position: "entropy"})
body.on("error", error => {
console.error("Response stream emitted an error:", error)
})
converter.on("error", error => {
console.error("Sharp instance emitted an error:", error)
})
const piped = body.pipe(converter)
piped.on("error", error => {
console.error("Piped stream emitted na error:", error)
})
return {
statusCode: 200,
contentType: "image/jpeg",
headers: {
"Cache-Control": constants.caching.image_cache_control
},
stream: res.body.pipe(converter)
stream: piped
}
})
} else {