From b0a87b890e2f97842ff738166207341ba5f11e58 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 11 Jul 2022 00:49:15 +0000 Subject: Revert "fix" This reverts commit 7dd708c6613b8e617fe77a6a8ad177485b39c258. --- src/app/mod.rs | 8 ++++++++ src/handlers/mod.rs | 15 +++++++++++++++ src/handlers/notes.rs | 7 +++---- 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/app/mod.rs b/src/app/mod.rs index 4b52a90..24eabc5 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,4 +1,6 @@ use crate::{post::Post, signalboost::Person}; +use bb8::Pool; +use bb8_rusqlite::RusqliteConnectionManager; use chrono::prelude::*; use color_eyre::eyre::Result; use std::{env, fs, path::PathBuf, sync::Arc}; @@ -58,6 +60,7 @@ pub struct State { pub sitemap: Vec, pub patrons: Option, pub mi: mi::Client, + pub pool: Pool, } pub async fn init(cfg: PathBuf) -> Result { @@ -73,6 +76,10 @@ pub async fn init(cfg: PathBuf) -> Result { let gallery = crate::post::load(cfg.clone(), "gallery").await?; let talks = crate::post::load(cfg.clone(), "talks").await?; let mut everything: Vec = vec![]; + let mgr = RusqliteConnectionManager::new( + env::var("DATABASE_URL").unwrap_or("./var/waifud.db".to_string()), + ); + let pool = bb8::Pool::builder().build(mgr).await?; { let blog = blog.clone(); @@ -150,6 +157,7 @@ pub async fn init(cfg: PathBuf) -> Result { jf: jfb.build(), sitemap: sm, patrons: patrons().await?, + pool, }) } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 97939fb..87175ca 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -168,6 +168,21 @@ pub enum Error { #[error("database error: {0}")] SQLite(#[from] rusqlite::Error), + + #[error("database pool error: {0}")] + SQLitePool(#[from] bb8_rusqlite::Error), + + #[error("other error: {0}")] + Catchall(String), +} + +impl From> for Error +where + E: std::error::Error + Send + 'static, +{ + fn from(err: bb8::RunError) -> Self { + Self::Catchall(format!("{}", err)) + } } pub type Result>> = std::result::Result; diff --git a/src/handlers/notes.rs b/src/handlers/notes.rs index 42f89ad..56e0f90 100644 --- a/src/handlers/notes.rs +++ b/src/handlers/notes.rs @@ -20,13 +20,12 @@ impl Note { pub fn to_html(&self) -> Markup { html! { article."h-entry" { - a href={"/notes/" (self.id)} { - "🔗" - } - " " time."dt-published" datetime=(self.created_at) { {(self.detrytemci())} } + a href={"/notes/" (self.id)} { + "🔗" + } @if let Some(reply_to) = &self.reply_to { p { -- cgit v1.2.3