From a3bc16f7d254ff46073f4c330d24c85709f9a08c Mon Sep 17 00:00:00 2001 From: ayaka Date: Sun, 3 Nov 2024 10:08:26 +1300 Subject: [PATCH] port update checker to gitea compatible version --- Cargo.lock | 9 --------- src/main.rs | 6 +++--- static/check_update.js | 9 +++------ static/style.css | 7 +++++++ templates/error.html | 6 +++--- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fd7abb..29193e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,15 +1198,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.11.1" diff --git a/src/main.rs b/src/main.rs index 58368af..a66f734 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,7 +247,7 @@ async fn main() { .at("/check_update.js") .get(|_| resource(include_str!("../static/check_update.js"), "text/javascript", false).boxed()); - app.at("/commits.atom").get(|_| async move { proxy_commit_info().await }.boxed()); + app.at("/commits.json").get(|_| async move { proxy_commit_info().await }.boxed()); // FFmpeg app @@ -442,9 +442,9 @@ pub async fn proxy_commit_info() -> Result, String> { #[cached(time = 600)] async fn fetch_commit_info() -> String { - let uri = Uri::from_str("https://github.com/redlib-org/redlib/commits/main.atom").expect("Invalid URI"); + let uri = Uri::from_str("https://git.stardust.wtf/api/v1/repos/iridium/redsunlib/commits?verification=false&stat=false").expect("Invalid URI"); - let resp: Body = CLIENT.get(uri).await.expect("Failed to request GitHub").into_body(); + let resp: Body = CLIENT.get(uri).await.expect("Failed to request git.stardust.wtf").into_body(); hyper::body::to_bytes(resp).await.expect("Failed to read body").iter().copied().map(|x| x as char).collect() } diff --git a/static/check_update.js b/static/check_update.js index 7741edb..0bf42c8 100644 --- a/static/check_update.js +++ b/static/check_update.js @@ -1,18 +1,15 @@ async function checkInstanceUpdateStatus() { try { - const response = await fetch('/commits.atom'); + const response = await fetch('/commits.json'); const text = await response.text(); - const parser = new DOMParser(); - const xmlDoc = parser.parseFromString(text, "application/xml"); - const entries = xmlDoc.getElementsByTagName('entry'); + const entries = JSON.parse(text); const localCommit = document.getElementById('git_commit').dataset.value; let statusMessage = ''; if (entries.length > 0) { const commitHashes = Array.from(entries).map(entry => { - const id = entry.getElementsByTagName('id')[0].textContent; - return id.split('/').pop(); + return entry.sha }); const commitIndex = commitHashes.indexOf(localCommit); diff --git a/static/style.css b/static/style.css index b7c3732..990ddf4 100644 --- a/static/style.css +++ b/static/style.css @@ -1965,6 +1965,13 @@ th { color: var(--accent); } +#issue_warning { + color: var(--popup-toreddit-text); + background: var(--popup-background); + border-radius: 5px; + padding: 10px; +} + /* Messages */ #duplicates_msg h3 { diff --git a/templates/error.html b/templates/error.html index f7a2d5d..f892d14 100644 --- a/templates/error.html +++ b/templates/error.html @@ -11,9 +11,9 @@
-

Expected something to work? Report - an issue

+

Expected something to work? Try a upstream instance.

+
+

!! Do NOT open an issue on the redlib repository with a redsunlib specific issue !!


Head back home?