new: Show version number

This commit is contained in:
SinTan1729 2024-02-10 19:41:50 -06:00
parent 0227c5f783
commit 95a8263797
No known key found for this signature in database
GPG Key ID: EB3E68BFBA25C85F
3 changed files with 26 additions and 1 deletions

View File

@ -63,7 +63,9 @@
</div> </div>
<div name="github-link"> <div name="github-link">
<a href="https://github.com/SinTan1729/chhoto-url" target="_blank" rel="noopener noreferrer">Source Code</a> <a id="version-number" href="https://github.com/SinTan1729/chhoto-url" target="_blank" rel="noopener noreferrer"
hidden>Source Code</a>
<!-- The version number would be inserted here -->
</div> </div>
<dialog id="login-dialog"> <dialog id="login-dialog">

View File

@ -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 () => { const refreshData = async () => {
let reply = await fetch("/api/all").then(res => res.text()); let reply = await fetch("/api/all").then(res => res.text());
if (reply == "logged_out") { if (reply == "logged_out") {
@ -32,7 +38,14 @@ const refreshData = async () => {
}; };
const displayData = async (data) => { 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(); let site = await getSiteUrl();
table_box = document.querySelector(".pure-table"); table_box = document.querySelector(".pure-table");
loading_text = document.getElementsByName("loading-text")[0]; loading_text = document.getElementsByName("loading-text")[0];

View File

@ -19,6 +19,9 @@ struct AppState {
db: Connection, db: Connection,
} }
// Store the version number
const VERSION: &str = env!("CARGO_PKG_VERSION");
// Define the routes // Define the routes
// Add new links // 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 // 404 error page
async fn error404() -> impl Responder { async fn error404() -> impl Responder {
NamedFile::open_async("./resources/static/404.html") NamedFile::open_async("./resources/static/404.html")
@ -141,6 +150,7 @@ async fn main() -> std::io::Result<()> {
.service(link_handler) .service(link_handler)
.service(getall) .service(getall)
.service(siteurl) .service(siteurl)
.service(version)
.service(add_link) .service(add_link)
.service(delete_link) .service(delete_link)
.service(login) .service(login)