about summary refs log tree commit diff stats
path: root/src/loader/response.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-27 21:50:31 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-28 21:26:33 +0200
commit8268ba2cf049be1865875e3e01305a500fa533e2 (patch)
tree7ce60624f9212e65dad0c1a2d168eb6ab7c03ec9 /src/loader/response.nim
parentf9734e2b3900781901bb5f268137bd9adbfc33ef (diff)
downloadchawan-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.nim13
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]]