From 95a826379791030f636fb11c25f098832abcbe49 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Sat, 10 Feb 2024 19:41:50 -0600 Subject: [PATCH] new: Show version number --- actix/resources/index.html | 4 +++- actix/resources/static/script.js | 13 +++++++++++++ actix/src/main.rs | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/actix/resources/index.html b/actix/resources/index.html index 770f4b9..090b0f7 100644 --- a/actix/resources/index.html +++ b/actix/resources/index.html @@ -63,7 +63,9 @@
- Source Code + +
diff --git a/actix/resources/static/script.js b/actix/resources/static/script.js index 01e75e7..3272614 100644 --- a/actix/resources/static/script.js +++ b/actix/resources/static/script.js @@ -9,6 +9,12 @@ const getSiteUrl = async () => await fetch("/api/siteurl") } }); +const getVersion = async () => await fetch("/api/version") + .then(res => res.text()) + .then(text => { + return text; + }); + const refreshData = async () => { let reply = await fetch("/api/all").then(res => res.text()); if (reply == "logged_out") { @@ -32,7 +38,14 @@ const refreshData = async () => { }; const displayData = async (data) => { + let version = await getVersion(); + link = document.getElementById("version-number") + link.innerText = "v" + version; + link.href = "https://github.com/SinTan1729/chhoto-url/releases/tag/" + version; + link.hidden = false; + let site = await getSiteUrl(); + table_box = document.querySelector(".pure-table"); loading_text = document.getElementsByName("loading-text")[0]; diff --git a/actix/src/main.rs b/actix/src/main.rs index 00e1b7c..3c2caef 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -19,6 +19,9 @@ struct AppState { db: Connection, } +// Store the version number +const VERSION: &str = env!("CARGO_PKG_VERSION"); + // Define the routes // Add new links @@ -57,6 +60,12 @@ async fn siteurl(session: Session) -> HttpResponse { } } +// Get the version number +#[get("/api/version")] +async fn version() -> HttpResponse { + HttpResponse::Ok().body(VERSION) +} + // 404 error page async fn error404() -> impl Responder { NamedFile::open_async("./resources/static/404.html") @@ -141,6 +150,7 @@ async fn main() -> std::io::Result<()> { .service(link_handler) .service(getall) .service(siteurl) + .service(version) .service(add_link) .service(delete_link) .service(login)