refactor some code

This commit is contained in:
zapashcanon 2022-04-05 23:08:57 +02:00
parent 0632a713c7
commit 3796a96997
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1
7 changed files with 330 additions and 403 deletions

View file

@ -267,11 +267,13 @@ let upload_post ~image post =
(fun cited_id -> Db.exec Q.upload_post_reply (cited_id, id))
citations
in
match thread_data with
| None -> Ok id
| Some { subject; lng; lat } ->
let^ () = Db.exec Q.upload_thread_info (id, subject, lat, lng) in
Ok id
let^ () =
match thread_data with
| None -> Ok ()
| Some { subject; lng; lat } ->
Db.exec Q.upload_thread_info (id, subject, lat, lng)
in
Ok id
let build_reply ~comment ~image_info ~tag_list ?parent_id user_id =
let comment = Dream.html_escape comment in
@ -323,14 +325,8 @@ let build_op ~comment ~image_info ~tag_list ~categories ~subject ~lat ~lng
if not is_valid_latlng then Error "Invalid coordinate"
else if String.length subject > 600 then Error "Invalid subject"
else
let thread_data = { subject; lng; lat } in
let* reply = build_reply ~comment ~image_info ~tag_list user_id in
let op = (thread_data, reply) in
Ok op
let build_image image_input =
let* image = Image.make_image image_input in
Ok image
Ok ({ subject; lng; lat }, reply)
let make_post ~comment ?image_input ~tags ~op_or_reply_data user_id =
let tag_list = String.split_on_char ',' tags in
@ -338,7 +334,7 @@ let make_post ~comment ?image_input ~tags ~op_or_reply_data user_id =
match image_input with
| None -> Ok (None, None)
| Some image_input ->
let* image = build_image image_input in
let* image = Image.make_image image_input in
Ok (Some image, Some (image.name, image.alt))
in
let* post =
@ -391,8 +387,7 @@ let get_post id =
let get_thread_data id =
if thread_exist id then
let^? subject, lat, lng = Db.find_opt Q.get_thread_info id in
let thread_data = { subject; lat; lng } in
Ok thread_data
Ok { subject; lat; lng }
else Error "not an op"
let get_op id =