add .jpg .svg image type

This commit is contained in:
Swrup 2024-09-26 10:16:40 +02:00
parent 6ee9dc788a
commit 8cc1ddcbc3

View file

@ -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