Autoformat
This commit is contained in:
parent
e8d1baa652
commit
0ebcc8a280
5 changed files with 33 additions and 26 deletions
|
@ -100,7 +100,8 @@ where
|
|||
index_album_art_pattern,
|
||||
index_sleep_duration_seconds,
|
||||
prefix_url,
|
||||
)).get_result(connection.deref())?;
|
||||
))
|
||||
.get_result(connection.deref())?;
|
||||
config.album_art_pattern = Some(art_pattern);
|
||||
config.reindex_every_n_seconds = Some(sleep_duration);
|
||||
config.prefix_url = if url != "" { Some(url) } else { None };
|
||||
|
@ -124,7 +125,8 @@ where
|
|||
name,
|
||||
password: "".to_owned(),
|
||||
admin: admin != 0,
|
||||
}).collect::<_>(),
|
||||
})
|
||||
.collect::<_>(),
|
||||
);
|
||||
|
||||
let ydns = ddns_config
|
||||
|
@ -194,7 +196,8 @@ where
|
|||
.iter()
|
||||
.find(|old_name| *old_name == &u.name)
|
||||
.is_none()
|
||||
}).collect::<_>();
|
||||
})
|
||||
.collect::<_>();
|
||||
for config_user in &insert_users {
|
||||
let new_user = User::new(&config_user.name, &config_user.password);
|
||||
diesel::insert_into(users::table)
|
||||
|
@ -242,7 +245,8 @@ where
|
|||
host.eq(ydns.host.clone()),
|
||||
username.eq(ydns.username.clone()),
|
||||
password.eq(ydns.password.clone()),
|
||||
)).execute(connection.deref())?;
|
||||
))
|
||||
.execute(connection.deref())?;
|
||||
}
|
||||
|
||||
if let Some(ref prefix_url) = new_config.prefix_url {
|
||||
|
|
|
@ -318,7 +318,8 @@ where
|
|||
.filter(|ref song_path| {
|
||||
let path = Path::new(&song_path);
|
||||
!path.exists() || vfs.real_to_virtual(path).is_err()
|
||||
}).collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
{
|
||||
let connection = db.get_connection();
|
||||
|
@ -343,7 +344,8 @@ where
|
|||
.filter(|ref directory_path| {
|
||||
let path = Path::new(&directory_path);
|
||||
!path.exists() || vfs.real_to_virtual(path).is_err()
|
||||
}).collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
{
|
||||
let connection = db.get_connection();
|
||||
|
@ -623,7 +625,8 @@ where
|
|||
.or(album.like(&like_test))
|
||||
.or(artist.like(&like_test))
|
||||
.or(album_artist.like(&like_test)),
|
||||
).filter(parent.not_like(&like_test))
|
||||
)
|
||||
.filter(parent.not_like(&like_test))
|
||||
.load(connection.deref())?;
|
||||
|
||||
let virtual_songs = real_songs
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -75,7 +75,6 @@ use std::sync::mpsc::channel;
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
mod api;
|
||||
mod rocket_api;
|
||||
mod config;
|
||||
mod db;
|
||||
mod ddns;
|
||||
|
@ -84,6 +83,7 @@ mod index;
|
|||
mod lastfm;
|
||||
mod metadata;
|
||||
mod playlist;
|
||||
mod rocket_api;
|
||||
mod serve;
|
||||
mod thumbnails;
|
||||
mod ui;
|
||||
|
@ -269,10 +269,10 @@ fn run() -> Result<()> {
|
|||
};
|
||||
|
||||
rocket::ignite()
|
||||
.manage(db::DB::new(&db_path)?)
|
||||
.mount(&static_url, StaticFiles::from(web_dir_path))
|
||||
.mount(&api_url, rocket_api::get_routes())
|
||||
.launch();
|
||||
.manage(db::DB::new(&db_path)?)
|
||||
.mount(&static_url, StaticFiles::from(web_dir_path))
|
||||
.mount(&api_url, rocket_api::get_routes())
|
||||
.launch();
|
||||
|
||||
// Start DDNS updates
|
||||
let db_ref = db.clone();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rocket::{Outcome, State};
|
||||
use rocket::http::{Cookies, Status};
|
||||
use rocket::request::{self, Request, FromRequest};
|
||||
use rocket::request::{self, FromRequest, Request};
|
||||
use rocket::{Outcome, State};
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
use config::{self, Config};
|
||||
|
@ -12,11 +12,7 @@ const CURRENT_MAJOR_VERSION: i32 = 2;
|
|||
const CURRENT_MINOR_VERSION: i32 = 2;
|
||||
|
||||
pub fn get_routes() -> Vec<rocket::Route> {
|
||||
routes![
|
||||
version,
|
||||
initial_setup,
|
||||
get_settings,
|
||||
]
|
||||
routes![version, initial_setup, get_settings,]
|
||||
}
|
||||
|
||||
struct Auth {
|
||||
|
@ -29,10 +25,12 @@ impl<'a, 'r> FromRequest<'a, 'r> for Auth {
|
|||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
||||
let mut cookies = request.guard::<Cookies>().unwrap();
|
||||
match cookies.get_private("username") {
|
||||
Some(u) => Outcome::Success(Auth { username: u.to_string() }),
|
||||
_ => Outcome::Failure((Status::Forbidden, ()))
|
||||
Some(u) => Outcome::Success(Auth {
|
||||
username: u.to_string(),
|
||||
}),
|
||||
_ => Outcome::Failure((Status::Forbidden, ())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AdminRights {}
|
||||
|
@ -45,7 +43,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AdminRights {
|
|||
match user::count::<DB>(&db) {
|
||||
Err(_) => return Outcome::Failure((Status::InternalServerError, ())),
|
||||
Ok(0) => return Outcome::Success(AdminRights {}),
|
||||
_ => ()
|
||||
_ => (),
|
||||
};
|
||||
|
||||
let auth = request.guard::<Auth>()?;
|
||||
|
@ -54,7 +52,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AdminRights {
|
|||
Ok(true) => Outcome::Success(AdminRights {}),
|
||||
Ok(false) => Outcome::Failure((Status::Forbidden, ())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
|
@ -58,7 +58,8 @@ fn verify_password(
|
|||
password_salt,
|
||||
attempted_password.as_bytes(),
|
||||
password_hash,
|
||||
).is_ok()
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub fn auth<T>(db: &T, username: &str, password: &str) -> Result<bool>
|
||||
|
@ -111,7 +112,8 @@ where
|
|||
.set((
|
||||
lastfm_username.eq(lastfm_login),
|
||||
lastfm_session_key.eq(session_key),
|
||||
)).execute(connection.deref())?;
|
||||
))
|
||||
.execute(connection.deref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue