port update checker to gitea compatible version

This commit is contained in:
ayaka 2024-11-03 10:08:26 +13:00
parent bd4cb96c0f
commit a3bc16f7d2
5 changed files with 16 additions and 21 deletions

9
Cargo.lock generated
View File

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

View File

@ -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<Response<Body>, 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()
}

View File

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

View File

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

View File

@ -11,9 +11,9 @@
<div id="git_commit" data-value="{{ crate::instance_info::INSTANCE_INFO.git_commit }}"></div>
<script src="/check_update.js"></script>
<h3>Expected something to work? <a
href="https://github.com/redlib-org/redlib/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=%F0%9F%90%9B+Bug+Report%3A+{{ msg }}">Report
an issue</a></h3>
<h3>Expected something to work? Try a <a href="https://github.com/redlib-org/redlib/">upstream</a> instance.</h3>
<br />
<h3 id="issue_warning" >!! Do <b>NOT</b> open an issue on the redlib repository with a redsunlib specific issue !!</h3>
<br />
<h3>Head back <a href="/">home</a>?</h3>
</div>