1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-26 07:38:36 -06:00

new: Show version number

This commit is contained in:
Sayantan Santra 2024-02-10 19:41:50 -06:00
parent 0227c5f783
commit 95a8263797
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
3 changed files with 26 additions and 1 deletions

View file

@ -63,7 +63,9 @@
</div>
<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>
<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 () => {
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];

View file

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