diff options
| author | Xe Iaso <me@christine.website> | 2022-07-11 00:49:15 +0000 |
|---|---|---|
| committer | Xe Iaso <me@christine.website> | 2022-07-11 00:49:15 +0000 |
| commit | b0a87b890e2f97842ff738166207341ba5f11e58 (patch) | |
| tree | ac9a45784c6f3243fcd2a88430483b8d0a35bdfc | |
| parent | 3da2c94f689820815903a826f4682a7b8122d35f (diff) | |
| download | xesite-b0a87b890e2f97842ff738166207341ba5f11e58.tar.xz xesite-b0a87b890e2f97842ff738166207341ba5f11e58.zip | |
Revert "fix"
This reverts commit 7dd708c6613b8e617fe77a6a8ad177485b39c258.
| -rw-r--r-- | Cargo.lock | 59 | ||||
| -rw-r--r-- | Cargo.toml | 6 | ||||
| -rw-r--r-- | src/app/mod.rs | 8 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 15 | ||||
| -rw-r--r-- | src/handlers/notes.rs | 7 |
5 files changed, 85 insertions, 10 deletions
@@ -265,6 +265,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] +name = "bb8" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9f4fa9768efd269499d8fba693260cfc670891cf6de3adc935588447a77cc8" +dependencies = [ + "async-trait", + "futures-channel", + "futures-util", + "parking_lot 0.11.2", + "tokio", +] + +[[package]] +name = "bb8-rusqlite" +version = "0.1.0" +source = "git+https://github.com/pleshevskiy/bb8-rusqlite?branch=bump-rusqlite#fa3da425ce060a20bb09bdd3313ed1b5e8a5f89d" +dependencies = [ + "async-trait", + "bb8", + "rusqlite", + "thiserror", + "tokio", +] + +[[package]] name = "bincode" version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1703,12 +1728,37 @@ checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" [[package]] name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.5", +] + +[[package]] +name = "parking_lot" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.3", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", ] [[package]] @@ -2025,7 +2075,7 @@ dependencies = [ "lazy_static", "libc", "memchr", - "parking_lot", + "parking_lot 0.12.1", "procfs", "thiserror", ] @@ -2719,7 +2769,7 @@ dependencies = [ "mio", "num_cpus", "once_cell", - "parking_lot", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2", @@ -3302,6 +3352,8 @@ dependencies = [ "axum 0.5.11", "axum-extra", "axum-macros", + "bb8", + "bb8-rusqlite", "cfcache", "chrono", "color-eyre", @@ -3347,7 +3399,6 @@ dependencies = [ "tracing", "tracing-futures", "tracing-subscriber", - "ts_localapi", "url", "uuid 0.8.2", "xe_jsonfeed", @@ -12,6 +12,7 @@ repository = "https://github.com/Xe/site" axum = { version = "0.5", features = ["headers"] } axum-macros = "0.2" axum-extra = "0.3" +bb8 = "0.7" color-eyre = "0.6" chrono = "0.4" comrak = "0.13.2" @@ -51,11 +52,12 @@ uuid = { version = "0.8", features = ["serde", "v4"] } # workspace dependencies cfcache = { path = "./lib/cfcache" } +xe_jsonfeed = { path = "./lib/jsonfeed" } mi = { path = "./lib/mi" } patreon = { path = "./lib/patreon" } -ts_localapi = { path = "./lib/ts_localapi" } xesite_types = { path = "./lib/xesite_types" } -xe_jsonfeed = { path = "./lib/jsonfeed" } + +bb8-rusqlite = { git = "https://github.com/pleshevskiy/bb8-rusqlite", branch = "bump-rusqlite" } [dependencies.rusqlite] version = "0.26" 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<u8>, pub patrons: Option<patreon::Users>, pub mi: mi::Client, + pub pool: Pool<RusqliteConnectionManager>, } pub async fn init(cfg: PathBuf) -> Result<State> { @@ -73,6 +76,10 @@ pub async fn init(cfg: PathBuf) -> Result<State> { let gallery = crate::post::load(cfg.clone(), "gallery").await?; let talks = crate::post::load(cfg.clone(), "talks").await?; let mut everything: Vec<Post> = 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<State> { 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<E> From<bb8::RunError<E>> for Error +where + E: std::error::Error + Send + 'static, +{ + fn from(err: bb8::RunError<E>) -> Self { + Self::Catchall(format!("{}", err)) + } } pub type Result<T = Html<Vec<u8>>> = std::result::Result<T, Error>; 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 { |
