webarc/src/lib.rs
JMARyA aba031a047
Some checks are pending
ci/woodpecker/push/build Pipeline is pending
better mime + more index
2025-02-25 00:06:48 +01:00

39 lines
932 B
Rust

use based::{
request::{RequestContext, StringResponse},
ui::components::prelude::Shell,
};
use maud::PreEscaped;
pub mod ai;
pub mod archive;
pub mod blacklist;
pub mod conf;
pub mod favicon;
use std::io::Write;
use std::process::{Command, Stdio};
pub fn get_mime_type(content: &[u8]) -> std::io::Result<String> {
let mut child = Command::new("file")
.arg("--mime-type")
.arg("--brief")
.arg("-") // Read from stdin
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
if let Some(mut stdin) = child.stdin.take() {
stdin.write_all(content)?;
}
let output = child.wait_with_output()?;
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}
pub async fn render_page(
content: PreEscaped<String>,
ctx: RequestContext,
shell: &Shell,
) -> StringResponse {
shell.render_page(content, "Website Archive", ctx).await
}