allow more stuff for "everything else" section, only link to /info/ if a index.html exists

This commit is contained in:
Mark
2025-05-23 10:59:56 +02:00
parent 92141190aa
commit 80a86e9f8a
3 changed files with 120 additions and 57 deletions

View File

@@ -7,7 +7,7 @@ const REDIRECT: &'static str = "/srv/tomatenmhark-redirect/";
pub struct Status(
pub BTreeMap<String, (bool, bool, String, Option<String>, Option<Duration>)>,
pub BTreeMap<String, String>,
pub BTreeMap<String, (bool, bool, String, Option<String>)>,
pub Duration,
);
impl Status {
@@ -46,7 +46,29 @@ impl Status {
let mut p = f.path();
p.push("desc");
if let Ok(desc) = std::fs::read_to_string(&p) {
rest.insert(id.to_owned(), desc);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& info.try_exists().ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);
let redirect = redirect.starts_with(REDIRECT)
&& redirect.try_exists().ok() == Some(true);
let desc = desc.trim();
if let Some(i) = desc.find('\n') {
rest.insert(
id.to_owned(),
(
info,
redirect,
desc[0..i].trim().to_owned(),
Some(desc[i + 1..].trim().to_owned()),
),
);
} else {
rest.insert(
id.to_owned(),
(info, redirect, desc.to_owned(), None),
);
}
}
}
}
@@ -90,7 +112,26 @@ impl Status {
let mut p = f.path();
p.push("desc");
if let Ok(desc) = tokio::fs::read_to_string(&p).await {
rest.insert(id.to_owned(), desc);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& tokio::fs::try_exists(info).await.ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);
let redirect = redirect.starts_with(REDIRECT)
&& tokio::fs::try_exists(redirect).await.ok() == Some(true);
let desc = desc.trim();
if let Some(i) = desc.find('\n') {
rest.insert(
id.to_owned(),
(
info,
redirect,
desc[0..i].trim().to_owned(),
Some(desc[i + 1..].trim().to_owned()),
),
);
} else {
rest.insert(id.to_owned(), (info, redirect, desc.to_owned(), None));
}
}
}
}
@@ -113,7 +154,7 @@ fn query_status_sync(mut func: impl FnMut(&str, bool, bool, &str, Option<Duratio
.map(|v| v.trim_end())
{
if !status.is_empty() {
let info = Path::new(SLASHINFO).join(id);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& info.try_exists().ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);
@@ -143,7 +184,7 @@ fn query_status_sync(mut func: impl FnMut(&str, bool, bool, &str, Option<Duratio
let out = String::from_utf8_lossy(&output.stdout);
let out = out.trim_end();
if dbg || !out.is_empty() {
let info = Path::new(SLASHINFO).join(id);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& info.try_exists().ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);
@@ -175,7 +216,7 @@ async fn query_status_async(
.map(|v| v.trim_end())
{
if !status.is_empty() {
let info = Path::new(SLASHINFO).join(id);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& tokio::fs::try_exists(info).await.ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);
@@ -204,7 +245,7 @@ async fn query_status_async(
let out = String::from_utf8_lossy(&output.stdout);
let out = out.trim_end();
if dbg || !out.is_empty() {
let info = Path::new(SLASHINFO).join(id);
let info = Path::new(SLASHINFO).join(id).join("index.html");
let info = info.starts_with(SLASHINFO)
&& tokio::fs::try_exists(info).await.ok() == Some(true);
let redirect = Path::new(REDIRECT).join(id);