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