split tags

This commit is contained in:
Swrup 2021-12-09 02:10:11 +01:00
parent 4b85655be2
commit e9aaa4dbed

View file

@ -329,8 +329,15 @@ let add_plant tags files nick =
match files with
| files -> (
(* TODO parse tags*)
let tags_len = String.length tags in
if tags_len > 1000 then
Error "tags too long"
else
let tag_list = Str.split (Str.regexp " +") tags in
(* id for plant*)
let ok_list = List.map (fun (_, content) -> is_valid_image content) files in
let ok_list =
List.map (fun (_, content) -> is_valid_image content) files
in
let valid_files = List.for_all (fun valid -> valid) ok_list in
if not valid_files then
Error "Invalid image"
@ -345,11 +352,15 @@ let add_plant tags files nick =
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
| Ok _ -> (
(* add to plant_id <-> tag table*)
(* TODO iter on tags*)
let res_tags = Db.exec Q.upload_plant_tag (plant_id, tags) in
match res_tags with
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
| Ok _ -> (
(* TODO iter on tag_list*)
let res_tags =
List.map
(fun tag -> Db.exec Q.upload_plant_tag (plant_id, tag))
tag_list
in
if List.exists Result.is_error res_tags then
Error (Format.sprintf "db error")
else
(* add to plant_id <-> image*)
let res_images =
List.find_opt Result.is_error
@ -362,4 +373,4 @@ let add_plant tags files nick =
| Some (Error e) ->
Error (Format.sprintf "db error: %s" (Caqti_error.show e))
| Some (Ok _) -> assert false
| None -> Ok () ) ) )
| None -> Ok () ) )