mirror of
https://github.com/agersant/polaris
synced 2024-12-02 17:49:10 +00:00
Got rid of modules
This commit is contained in:
parent
9c69353f69
commit
db0b6d684c
5 changed files with 17 additions and 14 deletions
|
@ -11,8 +11,8 @@ use mount::Mount;
|
|||
use rustc_serialize::json;
|
||||
use url::percent_encoding::percent_decode;
|
||||
|
||||
use collection;
|
||||
use collection::CollectionError;
|
||||
use collection::*;
|
||||
use error::*;
|
||||
|
||||
impl From<CollectionError> for IronError {
|
||||
fn from(err: CollectionError) -> IronError {
|
||||
|
@ -24,7 +24,7 @@ impl From<CollectionError> for IronError {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_api_handler(collection: Arc<Mutex<collection::Collection>>) -> Mount {
|
||||
pub fn get_api_handler(collection: Arc<Mutex<Collection>>) -> Mount {
|
||||
let mut mount = Mount::new();
|
||||
{
|
||||
let collection = collection.clone();
|
||||
|
@ -49,7 +49,7 @@ fn path_from_request(request: &Request) -> Result<PathBuf, Utf8Error> {
|
|||
Ok(PathBuf::from(decoded_path.deref()))
|
||||
}
|
||||
|
||||
fn browse(request: &mut Request, collection: &mut collection::Collection) -> IronResult<Response> {
|
||||
fn browse(request: &mut Request, collection: &mut Collection) -> IronResult<Response> {
|
||||
let path = path_from_request(request);
|
||||
if path.is_err() {
|
||||
return Ok(Response::with(status::BadRequest));
|
||||
|
@ -67,7 +67,7 @@ fn browse(request: &mut Request, collection: &mut collection::Collection) -> Iro
|
|||
Ok(Response::with((status::Ok, result_json)))
|
||||
}
|
||||
|
||||
fn flatten(request: &mut Request, collection: &mut collection::Collection) -> IronResult<Response> {
|
||||
fn flatten(request: &mut Request, collection: &mut Collection) -> IronResult<Response> {
|
||||
let path = path_from_request(request);
|
||||
if path.is_err() {
|
||||
return Ok(Response::with((status::BadRequest)));
|
|
@ -1,10 +1,8 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub use self::error::CollectionError;
|
||||
|
||||
mod error;
|
||||
mod vfs;
|
||||
use vfs::*;
|
||||
use error::*;
|
||||
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct Song {
|
||||
|
@ -23,13 +21,13 @@ pub enum CollectionFile {
|
|||
}
|
||||
|
||||
pub struct Collection {
|
||||
vfs: vfs::Vfs,
|
||||
vfs: Vfs,
|
||||
}
|
||||
|
||||
impl Collection {
|
||||
pub fn new() -> Collection {
|
||||
Collection{
|
||||
vfs: vfs::Vfs::new(),
|
||||
vfs: Vfs::new(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,14 +14,19 @@ use staticfile::Static;
|
|||
|
||||
mod api;
|
||||
mod collection;
|
||||
mod error;
|
||||
mod vfs;
|
||||
|
||||
use api::*;
|
||||
use collection::*;
|
||||
|
||||
fn main() {
|
||||
|
||||
let collection = collection::Collection::new();
|
||||
let collection = Collection::new();
|
||||
let collection = Arc::new(Mutex::new(collection));
|
||||
|
||||
let mut mount = Mount::new();
|
||||
let api_handler = api::get_api_handler( collection );
|
||||
let api_handler = get_api_handler( collection );
|
||||
mount.mount("/static/", Static::new("samplemusic/"))
|
||||
.mount("/api/", api_handler);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
|
||||
use collection::error::CollectionError;
|
||||
use error::*;
|
||||
|
||||
pub struct Vfs {
|
||||
mount_points: HashMap<String, PathBuf>,
|
Loading…
Reference in a new issue