Redirect on form submission for the execution

This commit is contained in:
R Tyler Croy 2023-01-29 22:23:28 -08:00
parent 72935aef37
commit c94c8b3aed
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
3 changed files with 15 additions and 3 deletions

View File

@ -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:

View File

@ -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()
);

View File

@ -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>