Redirect on form submission for the execution
This commit is contained in:
parent
72935aef37
commit
c94c8b3aed
|
@ -2,7 +2,7 @@
|
|||
openapi: "3.0.0"
|
||||
info:
|
||||
description: |
|
||||
Janky API defintion
|
||||
Janky API v1 defintion
|
||||
version: "1.0.0"
|
||||
title: Janky APIs
|
||||
contact:
|
||||
|
|
|
@ -40,13 +40,20 @@ pub async fn project(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
|||
pub mod api {
|
||||
use crate::{AppState, JankyYml, Scm};
|
||||
use log::*;
|
||||
use serde::Deserialize;
|
||||
use tide::{Request, Response, StatusCode};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct RedirectedForm {
|
||||
next: Option<String>,
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /projects/{name}
|
||||
*/
|
||||
pub async fn execute_project(req: Request<AppState<'_>>) -> Result<Response, tide::Error> {
|
||||
pub async fn execute_project(mut req: Request<AppState<'_>>) -> tide::Result {
|
||||
let name: String = req.param("name")?.into();
|
||||
let next: RedirectedForm = req.body_form().await?;
|
||||
let state = req.state();
|
||||
|
||||
if !state.config.has_project(&name) {
|
||||
|
@ -96,6 +103,10 @@ pub mod api {
|
|||
.send()
|
||||
.await?;
|
||||
|
||||
if let Some(red) = &next.next {
|
||||
return Ok(tide::Redirect::new(red).into());
|
||||
}
|
||||
|
||||
return Ok(
|
||||
json!({ "msg": format!("Executing on {}", &agent.url) }).into()
|
||||
);
|
||||
|
|
|
@ -52,7 +52,8 @@
|
|||
</td>
|
||||
<td>
|
||||
<form method="POST" action="/api/v1/projects/{{this.name}}">
|
||||
<input type="submit" value="Execute"/>
|
||||
<input type="hidden" name="next" value="/project/{{this.name}}"/>
|
||||
<input type="image" value="Execute" src="/static/icons/actions/view-refresh.svg"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue