From 568b21aa76a452658b6b7f1b01e6ab75a49592cf Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sun, 2 Feb 2020 16:07:29 -0500 Subject: Refresh strava token if it's too old --- src/server.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index 79c3226..abc430b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -14,21 +14,16 @@ use rocket::response::Redirect; use rocket::State; use rocket_contrib::templates::Template; use std::collections::HashMap; -use threadpool::ThreadPool; -use std::sync::Mutex; use std::sync::mpsc::Sender; +use std::sync::Mutex; +use threadpool::ThreadPool; use crate::db; use crate::error::Error; use crate::importer; use crate::models; use crate::strava; - -pub struct Params { - pub base_url: String, - pub strava_client_id: String, - pub strava_client_secret: String, -} +use crate::Params; #[database("db")] pub struct Db(diesel::PgConnection); @@ -62,7 +57,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for LoggedInUser { Ok(user) => { info!("Credentials: {:?}", user); Outcome::Success(user) - }, + } Err(Error::NotFound) => Outcome::Forward(()), Err(e) => Outcome::Failure((Status::InternalServerError, e)), } @@ -139,9 +134,13 @@ fn link_strava_callback( fn import_strava( conn: Db, tx: State>>, - user: LoggedInUser) -> Result<(), Error> { + user: LoggedInUser, +) -> Result<(), Error> { let user = db::get_user(&*conn, &user.username)?; - tx.lock().expect("FIX").send(importer::Command::ImportStravaUser(user)).expect("FIX"); + tx.lock() + .expect("FIX") + .send(importer::Command::ImportStravaUser(user)) + .expect("FIX"); Ok(()) } @@ -154,7 +153,7 @@ fn link_strava(params: State) -> Redirect { "response_type=code&", "redirect_uri={}&", "approval_prompt=force&", - "scope=read", + "scope=read_all,activity:read_all,profile:read_all", ), params.strava_client_id, format!("{}/link_strava_callback", params.base_url) @@ -181,7 +180,7 @@ pub fn start(conn: diesel::PgConnection, db_url: &str, base_url: &str) { .unwrap(); let importer_pool = ThreadPool::with_name("import".to_string(), importer::WORKERS); - let tx = importer::run(importer_pool.clone(), conn); + let tx = importer::run(importer_pool.clone(), conn, ¶ms); rocket::custom(config) .manage(params) -- cgit v1.2.3