From 8cc1ddcbc3d61c1f9bbfb99aabb53f2466fddca0 Mon Sep 17 00:00:00 2001 From: Swrup Date: Thu, 26 Sep 2024 10:16:40 +0200 Subject: [PATCH] add .jpg .svg image type --- src/main.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.ml b/src/main.ml index 2a1c355..eb19464 100644 --- a/src/main.ml +++ b/src/main.ml @@ -6,9 +6,12 @@ let get_img = Array.iter (fun c -> Hashtbl.add tbl c ()) [| '.'; '/'; '\\' |]; tbl in + (* TODO put basic extensions to allow in Drame *) let allowed_extensions = let tbl = Hashtbl.create 16 in - Array.iter (fun e -> Hashtbl.add tbl e ()) [| ".jpeg"; ".png"; ".gif" |]; + Array.iter + (fun e -> Hashtbl.add tbl e ()) + [| ".jpg"; ".jpeg"; ".png"; ".gif"; ".svg" |]; tbl in fun ~filename request -> @@ -34,10 +37,11 @@ let get_img = let content = Bytes.unsafe_to_string s in let mimetype = match extension with - | ".jpeg" -> Mimetype.Image_jpeg + | ".jpg" | ".jpeg" -> Mimetype.Image_jpeg | ".png" -> Mimetype.Image_png | ".gif" -> Mimetype.Image_gif - | _ -> assert false + | ".svg" -> Mimetype.Image_svg + | s -> failwith (Format.sprintf "get_img, invalid extension: %s" s) in Ok (Content.Unsafe { content; mimetype }) @@ -52,7 +56,7 @@ let get_asset ~filename request = match extension with | ".css" -> Ok (Content.Unsafe { mimetype = Mimetype.Text_css; content }) | ".ttf" -> Ok (Content.Unsafe { mimetype = Mimetype.Font_ttf; content }) - | _ -> assert false ) + | s -> failwith (Format.sprintf "get_asset, invalid extension: %s" s) ) let get_favicon request = let title = "The favicon is not where you think it is!" in