aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs62
1 files changed, 21 insertions, 41 deletions
diff --git a/src/main.rs b/src/main.rs
index 833a7ae..ab65f8e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,41 +1,18 @@
-use rocket::fairing::{self, AdHoc};
-use rocket::fs::{relative, FileServer};
-use rocket::http::Status;
-use rocket::State;
-use rocket::{Build, Request, Rocket};
-use rocket_db_pools::sqlx;
-use rocket_db_pools::Database;
-use rocket_dyn_templates::{context, Template};
-use std::borrow::Cow;
-
+mod error;
mod posts;
mod scrobbles;
mod skweets;
-#[derive(Database)]
-#[database("blossom")]
-struct Blossom(sqlx::SqlitePool);
+use std::borrow::Cow;
-async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
- match Blossom::fetch(&rocket) {
- Some(db) => match sqlx::migrate!().run(&**db).await {
- Ok(_) => Ok(rocket),
- Err(e) => {
- error!("failed to init blossom database: {}", e);
- Err(rocket)
- }
- },
- None => Err(rocket),
- }
-}
+use rocket::fs::{relative, FileServer};
+use rocket::http::Status;
+use rocket::{Request, State};
+use rocket_dyn_templates::{context, Template};
-fn stage() -> AdHoc {
- AdHoc::on_ignite("blossom database stage", |rocket| async {
- rocket
- .attach(Blossom::init())
- .attach(AdHoc::try_on_ignite("database migrations", run_migrations))
- })
-}
+use error::BlossomError;
+
+type Result<T> = std::result::Result<T, BlossomError>;
struct Clients {
listenbrainz: listenbrainz::raw::Client,
@@ -46,13 +23,20 @@ struct Clients {
extern crate rocket;
#[get("/")]
-async fn home(clients: &State<Clients>) -> Result<Template, BlossomError> {
+async fn home(clients: &State<Clients>) -> Result<Template> {
+ let (listenbrainz, skweets) = tokio::join!(
+ scrobbles::get_now_playing(&clients.listenbrainz),
+ skweets::get_recents(&clients.skinnyverse)
+ );
+ let listenbrainz = listenbrainz.unwrap_or_default();
+ let skweets = skweets.unwrap_or_default();
Ok(Template::render(
"home",
context! {
is_live: false,
- listenbrainz: scrobbles::get_now_playing(&clients.listenbrainz).await.unwrap_or_default(),
- skweets: skweets::get_recents(&clients.skinnyverse).await.unwrap_or_default() },
+ listenbrainz,
+ skweets,
+ },
))
}
@@ -62,7 +46,7 @@ async fn contact() -> Template {
}
#[get("/plants")]
-async fn plants() -> Result<Template, BlossomError> {
+async fn plants() -> Result<Template> {
Err(BlossomError::Unimplemented(Status::NotImplemented))
}
@@ -86,12 +70,11 @@ fn catcher(status: Status, req: &Request) -> Template {
}
#[tokio::main]
-async fn main() -> Result<(), rocket::Error> {
+async fn main() -> std::result::Result<(), rocket::Error> {
let mut skinny_data = mastodon_async::Data::default();
skinny_data.base = Cow::from("https://skinnyver.se");
let _rocket = rocket::build()
- .attach(stage())
.manage(Clients {
listenbrainz: listenbrainz::raw::Client::new(),
skinnyverse: mastodon_async::Mastodon::from(skinny_data),
@@ -107,6 +90,3 @@ async fn main() -> Result<(), rocket::Error> {
Ok(())
}
-
-mod error;
-use error::BlossomError;