-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patrick José Pereira <[email protected]>
- Loading branch information
1 parent
7c15a13
commit 2172381
Showing
4 changed files
with
13,820 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use axum::{ | ||
extract::Path, | ||
response::{Html, IntoResponse}, | ||
Json, | ||
}; | ||
use include_dir::{include_dir, Dir}; | ||
use serde::Serialize; | ||
|
||
static HTML_DIST: Dir = include_dir!("src/web/html"); | ||
|
||
#[derive(Serialize, Debug, Default)] | ||
pub struct InfoContent { | ||
/// Name of the program | ||
name: String, | ||
/// Version/tag | ||
version: String, | ||
/// Git SHA | ||
sha: String, | ||
build_date: String, | ||
/// Authors name | ||
authors: String, | ||
} | ||
|
||
#[derive(Serialize, Debug, Default)] | ||
pub struct Info { | ||
/// Version of the REST API | ||
version: u32, | ||
/// Service information | ||
service: InfoContent, | ||
} | ||
|
||
pub async fn root(filename: Option<Path<String>>) -> impl IntoResponse { | ||
let filename = if filename.is_none() { | ||
"index.html".to_string() | ||
} else { | ||
filename.unwrap().0 | ||
}; | ||
|
||
HTML_DIST.get_file(filename).map_or( | ||
Html("File not found".to_string()).into_response(), | ||
|file| { | ||
let content = file.contents_utf8().unwrap_or(""); | ||
Html(content.to_string()).into_response() | ||
}, | ||
) | ||
} | ||
|
||
pub async fn info() -> Json<Info> { | ||
let info = Info { | ||
version: 0, | ||
service: InfoContent { | ||
name: env!("CARGO_PKG_NAME").into(), | ||
version: "0.0.0".into(), //env!("VERGEN_GIT_SEMVER").into(), | ||
sha: env!("VERGEN_GIT_SHA").into(), | ||
build_date: env!("VERGEN_BUILD_TIMESTAMP").into(), | ||
authors: env!("CARGO_PKG_AUTHORS").into(), | ||
}, | ||
}; | ||
|
||
Json(info) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<html> | ||
<head> | ||
<title>mavlink-server</title> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<div id="app" style="display: flex; column-gap: 1em"> | ||
<div style="display: flex; column-gap: 1em"> | ||
<div> | ||
<div v-if="info"> | ||
<div v-once> | ||
{{info.service.name}} - {{info.service.version}} - | ||
{{info.service.sha.substring(0, 7)}} - {{info.service.build_date.substring(0, 10)}}<br/> | ||
By: {{formatAuthors(info.service.authors)}}<br /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="vue.global.js"></script> | ||
<script> | ||
const app = Vue.createApp({ | ||
mounted () { | ||
fetch('info').then( | ||
function (response) { | ||
response.json().then((info) => this.info = info) | ||
}.bind(this), | ||
) | ||
}, | ||
methods: { | ||
formatAuthors (authors) { | ||
const formatted = authors.split(':').map((author) => { | ||
console.log(`author: ${author}`) | ||
const { | ||
groups: { name }, | ||
} = /(?<name>.*) <.*>/gm.exec(author) | ||
return name | ||
}) | ||
return formatted.join(', ') | ||
}, | ||
}, | ||
data () { | ||
return { | ||
info: undefined, | ||
} | ||
}, | ||
}) | ||
|
||
app.mount('#app') | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.