better mime + more index
Some checks are pending
ci/woodpecker/push/build Pipeline is pending

This commit is contained in:
JMARyA 2025-02-25 00:06:48 +01:00
parent 2e5b4fc3d2
commit aba031a047
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
7 changed files with 64 additions and 52 deletions

View file

@ -7,11 +7,15 @@ use crate::{
blacklist::{check_blacklist, check_blacklist_path},
conf::get_config,
favicon::download_fav_for,
get_mime_type,
};
mod document;
mod domain;
use based::get_pg;
use based::{
get_pg,
ui::{components::prelude::Shell, prelude::Nothing},
};
use chrono::NaiveDate;
pub use document::Document;
pub use domain::*;
@ -288,20 +292,38 @@ pub async fn index_path(dom: &Domain, path: &str) {
pub async fn index_document(doc: &Document) {
for version_str in &doc.versions() {
if let Ok(version) = chrono::NaiveDate::parse_from_str(version_str, "%Y-%m-%d") {
sqlx::query(
r#"
INSERT INTO document_index (domain, path, version)
VALUES ($1, $2, $3)
if let Ok(content) = doc
.render_local(
Some(version_str.to_string()),
&Shell::new(Nothing(), Nothing(), Nothing()),
)
.await
{
let size = content.len();
let mime = get_mime_type(&content).unwrap_or_default();
if mime.as_str() == "text/html" {
// TODO : domain links index
// TODO : data fragments
}
if let Ok(version) = chrono::NaiveDate::parse_from_str(version_str, "%Y-%m-%d") {
sqlx::query(
r#"
INSERT INTO document_index (domain, path, version, size, mime)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (domain, path, version) DO NOTHING
"#,
)
.bind(&doc.domain)
.bind(&doc.path)
.bind(version)
.execute(get_pg!())
.await
.unwrap();
)
.bind(&doc.domain)
.bind(&doc.path)
.bind(version)
.bind(size as i64)
.bind(mime)
.execute(get_pg!())
.await
.unwrap();
}
}
}
}