split tags
This commit is contained in:
parent
4b85655be2
commit
e9aaa4dbed
1 changed files with 40 additions and 29 deletions
25
src/user.ml
25
src/user.ml
|
|
@ -329,8 +329,15 @@ let add_plant tags files nick =
|
||||||
match files with
|
match files with
|
||||||
| files -> (
|
| files -> (
|
||||||
(* TODO parse tags*)
|
(* 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*)
|
(* 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
|
let valid_files = List.for_all (fun valid -> valid) ok_list in
|
||||||
if not valid_files then
|
if not valid_files then
|
||||||
Error "Invalid image"
|
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))
|
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
||||||
| Ok _ -> (
|
| Ok _ -> (
|
||||||
(* add to plant_id <-> tag table*)
|
(* add to plant_id <-> tag table*)
|
||||||
(* TODO iter on tags*)
|
(* TODO iter on tag_list*)
|
||||||
let res_tags = Db.exec Q.upload_plant_tag (plant_id, tags) in
|
let res_tags =
|
||||||
match res_tags with
|
List.map
|
||||||
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
(fun tag -> Db.exec Q.upload_plant_tag (plant_id, tag))
|
||||||
| Ok _ -> (
|
tag_list
|
||||||
|
in
|
||||||
|
if List.exists Result.is_error res_tags then
|
||||||
|
Error (Format.sprintf "db error")
|
||||||
|
else
|
||||||
(* add to plant_id <-> image*)
|
(* add to plant_id <-> image*)
|
||||||
let res_images =
|
let res_images =
|
||||||
List.find_opt Result.is_error
|
List.find_opt Result.is_error
|
||||||
|
|
@ -362,4 +373,4 @@ let add_plant tags files nick =
|
||||||
| Some (Error e) ->
|
| Some (Error e) ->
|
||||||
Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
||||||
| Some (Ok _) -> assert false
|
| Some (Ok _) -> assert false
|
||||||
| None -> Ok () ) ) )
|
| None -> Ok () ) )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue