Autoformat
This commit is contained in:
parent
5f28c44506
commit
e7a5fcf01b
3 changed files with 51 additions and 13 deletions
|
@ -15,7 +15,7 @@ use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::*;
|
use std::path::*;
|
||||||
use std::sync::{Arc};
|
use std::sync::Arc;
|
||||||
use typemap;
|
use typemap;
|
||||||
use url::percent_encoding::percent_decode;
|
use url::percent_encoding::percent_decode;
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ use std::time;
|
||||||
use config::MiscSettings;
|
use config::MiscSettings;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use db;
|
use db;
|
||||||
use db::{ConnectionSource, DB};
|
|
||||||
use db::{directories, misc_settings, songs};
|
use db::{directories, misc_settings, songs};
|
||||||
|
use db::{ConnectionSource, DB};
|
||||||
use errors;
|
use errors;
|
||||||
use metadata;
|
use metadata;
|
||||||
use vfs::{VFSSource, VFS};
|
use vfs::{VFSSource, VFS};
|
||||||
|
@ -52,7 +52,9 @@ pub struct CommandSender {
|
||||||
|
|
||||||
impl CommandSender {
|
impl CommandSender {
|
||||||
fn new(sender: Sender<Command>) -> CommandSender {
|
fn new(sender: Sender<Command>) -> CommandSender {
|
||||||
CommandSender{ sender: Mutex::new(sender) }
|
CommandSender {
|
||||||
|
sender: Mutex::new(sender),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trigger_reindex(&self) -> Result<(), errors::Error> {
|
pub fn trigger_reindex(&self) -> Result<(), errors::Error> {
|
||||||
|
|
|
@ -16,7 +16,18 @@ const CURRENT_MINOR_VERSION: i32 = 2;
|
||||||
const SESSION_FIELD_USERNAME: &str = "username";
|
const SESSION_FIELD_USERNAME: &str = "username";
|
||||||
|
|
||||||
pub fn get_routes() -> Vec<rocket::Route> {
|
pub fn get_routes() -> Vec<rocket::Route> {
|
||||||
routes![version, initial_setup, get_settings, put_settings, trigger_index, auth, browse_root, browse, flatten_root, flatten]
|
routes![
|
||||||
|
version,
|
||||||
|
initial_setup,
|
||||||
|
get_settings,
|
||||||
|
put_settings,
|
||||||
|
trigger_index,
|
||||||
|
auth,
|
||||||
|
browse_root,
|
||||||
|
browse,
|
||||||
|
flatten_root,
|
||||||
|
flatten
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Auth {
|
struct Auth {
|
||||||
|
@ -96,13 +107,20 @@ fn get_settings(db: State<DB>, _admin_rights: AdminRights) -> Result<Json<Config
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/settings", data = "<config>")]
|
#[put("/settings", data = "<config>")]
|
||||||
fn put_settings(db: State<DB>, _admin_rights: AdminRights, config: Json<Config>) -> Result<(), errors::Error> {
|
fn put_settings(
|
||||||
|
db: State<DB>,
|
||||||
|
_admin_rights: AdminRights,
|
||||||
|
config: Json<Config>,
|
||||||
|
) -> Result<(), errors::Error> {
|
||||||
config::amend::<DB>(&db, &config)?;
|
config::amend::<DB>(&db, &config)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/trigger_index")]
|
#[post("/trigger_index")]
|
||||||
fn trigger_index(command_sender: State<Arc<index::CommandSender>>, _admin_rights: AdminRights) -> Result<(), errors::Error> {
|
fn trigger_index(
|
||||||
|
command_sender: State<Arc<index::CommandSender>>,
|
||||||
|
_admin_rights: AdminRights,
|
||||||
|
) -> Result<(), errors::Error> {
|
||||||
command_sender.trigger_reindex()?;
|
command_sender.trigger_reindex()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -119,9 +137,16 @@ struct AuthOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/auth", data = "<credentials>")]
|
#[post("/auth", data = "<credentials>")]
|
||||||
fn auth(db: State<DB>, credentials: Json<AuthCredentials>, mut cookies: Cookies) -> Result<(Json<AuthOutput>), errors::Error> {
|
fn auth(
|
||||||
|
db: State<DB>,
|
||||||
|
credentials: Json<AuthCredentials>,
|
||||||
|
mut cookies: Cookies,
|
||||||
|
) -> Result<(Json<AuthOutput>), errors::Error> {
|
||||||
user::auth::<DB>(&db, &credentials.username, &credentials.password)?;
|
user::auth::<DB>(&db, &credentials.username, &credentials.password)?;
|
||||||
cookies.add_private(Cookie::new(SESSION_FIELD_USERNAME, credentials.username.clone()));
|
cookies.add_private(Cookie::new(
|
||||||
|
SESSION_FIELD_USERNAME,
|
||||||
|
credentials.username.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
let auth_output = AuthOutput {
|
let auth_output = AuthOutput {
|
||||||
admin: user::is_admin::<DB>(&db, &credentials.username)?,
|
admin: user::is_admin::<DB>(&db, &credentials.username)?,
|
||||||
|
@ -130,13 +155,20 @@ fn auth(db: State<DB>, credentials: Json<AuthCredentials>, mut cookies: Cookies)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/browse")]
|
#[get("/browse")]
|
||||||
fn browse_root(db: State<DB>, _auth: Auth) -> Result<(Json<Vec<index::CollectionFile>>), errors::Error> {
|
fn browse_root(
|
||||||
|
db: State<DB>,
|
||||||
|
_auth: Auth,
|
||||||
|
) -> Result<(Json<Vec<index::CollectionFile>>), errors::Error> {
|
||||||
let result = index::browse::<DB>(&db, &PathBuf::new())?;
|
let result = index::browse::<DB>(&db, &PathBuf::new())?;
|
||||||
Ok(Json(result))
|
Ok(Json(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/browse/<path..>")]
|
#[get("/browse/<path..>")]
|
||||||
fn browse(db: State<DB>, _auth: Auth, path: PathBuf) -> Result<(Json<Vec<index::CollectionFile>>), errors::Error> {
|
fn browse(
|
||||||
|
db: State<DB>,
|
||||||
|
_auth: Auth,
|
||||||
|
path: PathBuf,
|
||||||
|
) -> Result<(Json<Vec<index::CollectionFile>>), errors::Error> {
|
||||||
let result = index::browse::<DB>(&db, &path)?;
|
let result = index::browse::<DB>(&db, &path)?;
|
||||||
Ok(Json(result))
|
Ok(Json(result))
|
||||||
}
|
}
|
||||||
|
@ -148,7 +180,11 @@ fn flatten_root(db: State<DB>, _auth: Auth) -> Result<(Json<Vec<index::Song>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/flatten/<path..>")]
|
#[get("/flatten/<path..>")]
|
||||||
fn flatten(db: State<DB>, _auth: Auth, path: PathBuf) -> Result<(Json<Vec<index::Song>>), errors::Error> {
|
fn flatten(
|
||||||
|
db: State<DB>,
|
||||||
|
_auth: Auth,
|
||||||
|
path: PathBuf,
|
||||||
|
) -> Result<(Json<Vec<index::Song>>), errors::Error> {
|
||||||
let result = index::flatten::<DB>(&db, &path)?;
|
let result = index::flatten::<DB>(&db, &path)?;
|
||||||
Ok(Json(result))
|
Ok(Json(result))
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue