webarc/src/main.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

2024-12-30 14:06:32 +01:00
use ai::EmbedStore;
2024-12-29 16:51:34 +01:00
use archive::WebsiteArchive;
2024-12-30 14:06:32 +01:00
use based::get_pg;
2024-12-29 16:51:34 +01:00
use rocket::routes;
2024-12-30 14:06:32 +01:00
mod ai;
2024-12-29 16:51:34 +01:00
mod archive;
2024-12-29 20:13:15 +01:00
mod blacklist;
2024-12-29 18:33:30 +01:00
mod favicon;
2024-12-29 19:35:56 +01:00
mod pages;
2024-12-29 16:51:34 +01:00
#[rocket::launch]
async fn launch() -> _ {
env_logger::init();
let arc = WebsiteArchive::new("./websites");
2024-12-30 14:06:32 +01:00
if std::env::var("DATABASE_URL").is_ok() {
let pg = get_pg!();
sqlx::migrate!("./migrations").run(pg).await.unwrap();
}
2024-12-30 22:06:15 +01:00
let archive = arc.clone();
2024-12-30 14:06:32 +01:00
if std::env::var("OLLAMA_URL").is_ok() {
2024-12-30 22:06:15 +01:00
tokio::spawn(async move {
EmbedStore::generate_embeddings_for(&archive).await;
});
2024-12-30 14:06:32 +01:00
}
2024-12-29 20:13:15 +01:00
let archive = arc.clone();
tokio::spawn(async move {
favicon::download_favicons_for_sites(&archive.domains()).await;
});
2024-12-29 18:33:30 +01:00
2024-12-29 16:51:34 +01:00
rocket::build()
2024-12-29 18:18:01 +01:00
.mount(
"/",
routes![
2024-12-30 21:25:40 +01:00
based::htmx::htmx_script_route,
2024-12-29 18:18:01 +01:00
pages::index,
pages::render_website,
2024-12-29 18:33:30 +01:00
pages::domain_info_route,
2024-12-30 14:06:32 +01:00
pages::favicon_route,
2024-12-31 17:41:52 +01:00
pages::vector_search,
pages::render_txt_website
2024-12-29 18:18:01 +01:00
],
)
2024-12-29 16:51:34 +01:00
.manage(arc)
}