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]) =