From 11de0e4509a46990b11c2db33450c46212db2ff8 Mon Sep 17 00:00:00 2001 From: jiro Date: Thu, 26 Nov 2020 00:57:33 +0900 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E3=83=98=E3=83=83=E3=83=80=E3=81=8CGIF89a?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AFgif=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=81=A8=E3=81=97=E3=81=A6=E3=83=95=E3=83=AD=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AB=E8=BF=94=E3=81=99=20#189=20(#190)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- websh_front/src/index.nim | 7 ++++++- websh_server/src/websh_server.nim | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/websh_front/src/index.nim b/websh_front/src/index.nim index adf899e..e08a164 100644 --- a/websh_front/src/index.nim +++ b/websh_front/src/index.nim @@ -18,6 +18,7 @@ type ImageObj = object image: cstring filesize: cint + format: cstring MediaObj = object name, data: cstring @@ -248,7 +249,11 @@ proc createDom(): VNode = for img in outputImages: tdiv: # imgでbase64を表示するときに必要なメタ情報を追加 - img(src = "data:image/png;base64," & img.image) + case $img.format + of "gif": + img(src = "data:image/gif;base64," & img.image) + else: + img(src = "data:image/png;base64," & img.image) tdiv: text &"{img.filesize} byte" diff --git a/websh_server/src/websh_server.nim b/websh_server/src/websh_server.nim index 1487fbb..7b61c8f 100644 --- a/websh_server/src/websh_server.nim +++ b/websh_server/src/websh_server.nim @@ -14,6 +14,7 @@ type ImageObj* = object image*: string filesize*: int + format*: string const scriptName = "exec.sh" @@ -29,7 +30,13 @@ proc getImages(dir: string): seq[ImageObj] = if not path.existsFile: continue let content = readFile(path) - let img = ImageObj(image: base64.encode(content), filesize: content.len) + var format = "png" + if 6 < content.len: + let f = content[0..<6] + case f + of "GIF89a": format = "gif" + else: discard + let img = ImageObj(image: base64.encode(content), filesize: content.len, format: format) result.add(img) proc createMediaFiles(dir: string, medias: seq[string]) =