Skip to content

Commit

Permalink
new: Show version number
Browse files Browse the repository at this point in the history
  • Loading branch information
SinTan1729 committed Feb 11, 2024
1 parent 0227c5f commit 95a8263
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actix/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
13 changes: 13 additions & 0 deletions actix/resources/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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];

Expand Down
10 changes: 10 additions & 0 deletions actix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 95a8263

Please sign in to comment.