This commit is contained in:
parent
2e5b4fc3d2
commit
aba031a047
7 changed files with 64 additions and 52 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue