diff options
author | bptato <nincsnevem662@gmail.com> | 2024-06-27 21:50:31 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-28 21:26:33 +0200 |
commit | 8268ba2cf049be1865875e3e01305a500fa533e2 (patch) | |
tree | 7ce60624f9212e65dad0c1a2d168eb6ab7c03ec9 /src/loader/response.nim | |
parent | f9734e2b3900781901bb5f268137bd9adbfc33ef (diff) | |
download | chawan-8268ba2cf049be1865875e3e01305a500fa533e2.tar.gz |
img, loader: add image resizing, misc fixes
* resize images with stb_image_resize * use tee for output handle redirection (redirectToFile blocks) * cache original image files * accept lseek in sandbox * misc stbi fixes For now, I just pulled in stb_image_resize v1. v2 is an extra 150K in size, not sure if it's worth the cost. (Either way, we can always switch later if needed, since the API is almost the same.) Next step: move sixel/kitty encoders to CGI, and cache their output in memory instead of the intermediate RGBA representation.
Diffstat (limited to 'src/loader/response.nim')
-rw-r--r-- | src/loader/response.nim | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/loader/response.nim b/src/loader/response.nim index ab74571e..b8d95e36 100644 --- a/src/loader/response.nim +++ b/src/loader/response.nim @@ -129,6 +129,10 @@ proc onReadText(response: Response) = opaque.buf.setLen(olen) break +proc resume*(response: Response) = + response.resumeFun(response.outputId) + response.resumeFun = nil + proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} = if response.body == nil: let p = newPromise[JSResult[string]]() @@ -144,8 +148,7 @@ proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} = response.opaque = opaque response.onRead = onReadText response.bodyUsed = true - response.resumeFun(response.outputId) - response.resumeFun = nil + response.resume() return response.bodyRead.then(proc(): JSResult[string] = let charset = response.getCharset(CHARSET_UTF_8) ok(opaque.buf.decodeAll(charset)) @@ -183,8 +186,7 @@ proc blob*(response: Response): Promise[JSResult[Blob]] {.jsfunc.} = response.opaque = opaque response.onRead = onReadBlob response.bodyUsed = true - response.resumeFun(response.outputId) - response.resumeFun = nil + response.resume() let contentType = response.getContentType() return response.bodyRead.then(proc(): JSResult[Blob] = let p = realloc(opaque.p, opaque.len) @@ -220,8 +222,7 @@ proc saveToBitmap*(response: Response; bmp: Bitmap): EmptyPromise = response.opaque = opaque response.onRead = onReadBitmap response.bodyUsed = true - response.resumeFun(response.outputId) - response.resumeFun = nil + response.resume() return response.bodyRead proc json(ctx: JSContext; this: Response): Promise[JSResult[JSValue]] |