optimize
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2024-12-29 23:16:57 +01:00
parent 634706beec
commit df0b1b910a
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 21 additions and 13 deletions

View file

@ -2,7 +2,7 @@ use std::{io::Read, path::PathBuf};
use based::{
page::Shell,
request::{assets::DataResponse, respond_html, RequestContext, StringResponse},
request::{assets::DataResponse, RequestContext, StringResponse},
};
use maud::{html, PreEscaped};
use rocket::{get, State};
@ -36,7 +36,7 @@ pub async fn favicon_route(domain: &str) -> Option<DataResponse> {
Some(DataResponse::new(
buf,
"image/x-icon",
"image/x-icon".to_string(),
Some(60 * 60 * 24 * 5),
))
}
@ -178,7 +178,7 @@ pub async fn render_website(
path: PathBuf,
time: Option<&str>,
arc: &State<WebsiteArchive>,
) -> Option<StringResponse> {
) -> Option<DataResponse> {
let document = arc.get_domain(domain).path(path.to_str().unwrap());
let content = document
@ -186,7 +186,11 @@ pub async fn render_website(
.await;
if let Some(content) = content {
return Some(respond_html(&content));
return Some(DataResponse::new(
content.as_bytes().to_vec(),
"text/html".to_string(),
Some(60 * 60 * 24),
));
} else {
if std::env::var("DOWNLOAD_ON_DEMAND")
.unwrap_or("false".to_string())
@ -196,14 +200,18 @@ pub async fn render_website(
arc.archive_url(&format!("https://{domain}/{}", path.to_str().unwrap()))
.await;
return Some(respond_html(
&document
.render_local(if time.is_some() {
Some(time.unwrap().to_string())
} else {
None
})
.await?,
let content = document
.render_local(if time.is_some() {
Some(time.unwrap().to_string())
} else {
None
})
.await?;
return Some(DataResponse::new(
content.as_bytes().to_vec(),
"text/html".to_string(),
Some(60 * 60 * 24),
));
}
}