about summary refs log tree commit diff stats
path: root/src/server/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-27 03:06:24 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-27 03:06:24 +0200
commit14baa050d3ab4e45879582a8f87eeb1e42407909 (patch)
treeba16ced8c763e169ccf1c54f8a85a85e12e61caf /src/server/buffer.nim
parentac3e737867245ac65adfa2352ce6e7fdacc57b18 (diff)
downloadchawan-14baa050d3ab4e45879582a8f87eeb1e42407909.tar.gz
Response.text: encode/decode properly
also, use blob() for images
Diffstat (limited to 'src/server/buffer.nim')
-rw-r--r--src/server/buffer.nim13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index b1c67f78..f7ead4e5 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -40,6 +40,7 @@ import loader/connecterror
 import loader/loader
 import render/renderdocument
 import render/rendertext
+import types/blob
 import types/buffersource
 import types/cell
 import types/color
@@ -644,18 +645,20 @@ proc loadResource(buffer: Buffer, elem: HTMLImageElement): EmptyPromise =
   if url.isSome:
     let url = url.get
     return buffer.loader.fetch(newRequest(url))
-      .then(proc(res: JSResult[Response]): Promise[JSResult[string]] =
+      .then(proc(res: JSResult[Response]): Promise[JSResult[Blob]] =
         if res.isErr:
           return
         let res = res.get
         if res.contentType == "image/png":
-          #TODO using text() for PNG is wrong
-          return res.text()
-      ).then(proc(pngData: JSResult[string]) =
+          return res.blob()
+      ).then(proc(pngData: JSResult[Blob]) =
         if pngData.isErr:
           return
         let pngData = pngData.get
-        elem.bitmap = fromPNG(toOpenArrayByte(pngData, 0, pngData.high)))
+        let buffer = cast[ptr UncheckedArray[uint8]](pngData.buffer)
+        let high = int(pngData.size - 1)
+        elem.bitmap = fromPNG(toOpenArray(buffer, 0, high))
+      )
 
 proc loadResources(buffer: Buffer): EmptyPromise =
   let document = buffer.document