return uuid of latest build when header contains an accept json

This commit is contained in:
PizieDust 2024-12-19 12:22:07 +01:00
parent 9bd42944a9
commit 55d4091256

View file

@ -330,9 +330,18 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs =
Dream.sql req (Model.latest_successful_build_uuid job_id platform)) Dream.sql req (Model.latest_successful_build_uuid job_id platform))
>>= Model.not_found >>= Model.not_found
|> if_error "Error getting job" >>= fun build -> |> if_error "Error getting job" >>= fun build ->
Dream.redirect req match Dream.header req "Accept" with
(Link.Job_build_artifact.make_from_string ~job_name ~build ~artifact ()) | Some accept when String.starts_with ~prefix:"application/json" accept ->
|> Lwt_result.ok let json_response =
`Assoc [
"uuid", `String (Uuidm.to_string build);
] |> Yojson.Basic.to_string
in
Dream.json ~status:`OK json_response |> Lwt_result.ok
| _ ->
Dream.redirect req
(Link.Job_build_artifact.make_from_string ~job_name ~build ~artifact ())
|> Lwt_result.ok
in in
let redirect_latest req = let redirect_latest req =