use name as alt, display max size
This commit is contained in:
parent
df78d3fa7b
commit
21758dfae2
1 changed files with 17 additions and 9 deletions
22
src/db.ml
22
src/db.ml
|
|
@ -35,14 +35,18 @@ let () =
|
|||
Format.eprintf "db error@\n";
|
||||
exit 1
|
||||
|
||||
let mime_database = Conan.Process.database ~tree:Conan_light.tree
|
||||
|
||||
let mime contents =
|
||||
match Conan_string.run ~database:mime_database contents with
|
||||
let mime =
|
||||
let database = Conan.Process.database ~tree:Conan_light.tree in
|
||||
fun content ->
|
||||
match Conan_string.run ~database content with
|
||||
| Ok m -> Conan.Metadata.mime m
|
||||
| Error _ -> None
|
||||
|
||||
let clean_image image =
|
||||
let max_name = 1000 in
|
||||
let max_alt = 3000 in
|
||||
let max_content = 4200000 in
|
||||
|
||||
let name, alt, content = image in
|
||||
let name =
|
||||
match name with
|
||||
|
|
@ -51,9 +55,13 @@ let clean_image image =
|
|||
(* make up random name if no name was given *)
|
||||
Uuidm.to_string (Uuidm.v4_gen random_state ())
|
||||
in
|
||||
if String.length name > 1000 then Error "Image name too long"
|
||||
else if String.length alt > 1000 then Error "Image description too long"
|
||||
else if String.length content > 4200000 then Error "Image size too big"
|
||||
let alt = if String.trim alt = "" then name else alt in
|
||||
if String.length name > max_name then
|
||||
Error (Format.sprintf "Image name too long: More than %dB" max_name)
|
||||
else if String.length alt > max_alt then
|
||||
Error (Format.sprintf "Image description too long: More than %dB" max_alt)
|
||||
else if String.length content > max_content then
|
||||
Error (Format.sprintf "Image size too big: More than %dB" max_content)
|
||||
else
|
||||
match mime content with
|
||||
| None -> Error "invalid image type"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue