redirect after successful posting

This commit is contained in:
Swrup 2022-01-10 18:39:29 +01:00
parent ad5b0f2034
commit 94cdecd7a4

View file

@ -250,15 +250,15 @@ let newthread_post request =
match file with match file with
| [] -> render_unsafe "No image" request | [] -> render_unsafe "No image" request
| _ :: _ :: _ -> render_unsafe "More than one image" request | _ :: _ :: _ -> render_unsafe "More than one image" request
| [ file ] -> | [ file ] -> (
let res =
match match
Babillard.make_thread comment file (lat, lng) subject tags nick Babillard.make_thread comment file (lat, lng) subject tags nick
with with
| Ok _post_id -> "Your thread was posted on the babillard!" | Ok thread_id ->
| Error e -> e let adress = Format.sprintf "/babillard/%s" thread_id in
in Dream.respond ~status:`See_Other ~headers:[ ("Location", adress) ]
render_unsafe res request ) ) "Your thread was posted on the babillard!"
| Error e -> render_unsafe e request ) ) )
| `Ok _ -> Dream.empty `Bad_Request | `Ok _ -> Dream.empty `Bad_Request
| `Expired _ | `Expired _
| `Many_tokens _ | `Many_tokens _
@ -282,10 +282,7 @@ let thread_view request =
let thread_view = Babillard.view_thread thread_id in let thread_view = Babillard.view_thread thread_id in
match thread_view with match thread_view with
| Error e -> render_unsafe e request | Error e -> render_unsafe e request
| Ok thread_view -> | Ok thread_view -> Dream.html (Thread_page.f thread_view thread_id request)
Dream.respond
~headers:[ ("Content-Type", "html") ]
(Thread_page.f thread_view thread_id request)
(*form to reply to a thread *) (*form to reply to a thread *)
let thread_post request = let thread_post request =
@ -301,7 +298,7 @@ let thread_post request =
| `Ok | `Ok
(("file", file) (("file", file)
:: ("tags", [ (_, tags) ]) :: ("tags", [ (_, tags) ])
:: ("replyComment", [ (_, comment) ]) :: _ :: _ ) -> :: ("replyComment", [ (_, comment) ]) :: _ :: _ ) -> (
let parent_id = Dream.param "thread_id" request in let parent_id = Dream.param "thread_id" request in
let res = let res =
match file with match file with
@ -309,12 +306,12 @@ let thread_post request =
| [ file ] -> Babillard.make_post ~comment ~file ~tags ~parent_id nick | [ file ] -> Babillard.make_post ~comment ~file ~tags ~parent_id nick
| _ :: _ :: _ -> Error "More than one image" | _ :: _ :: _ -> Error "More than one image"
in in
let msg =
match res with match res with
| Ok _post_id -> "Your reply was posted" | Ok post_id ->
| Error e -> e let adress = Format.sprintf "/babillard/%s#%s" parent_id post_id in
in Dream.respond ~status:`See_Other ~headers:[ ("Location", adress) ]
render_unsafe msg request "Your thread was posted on the babillard!"
| Error e -> render_unsafe e request )
| `Ok _ -> Dream.empty `Bad_Request | `Ok _ -> Dream.empty `Bad_Request
| `Expired _ | `Expired _
| `Many_tokens _ | `Many_tokens _