refactor
This commit is contained in:
parent
87ad77907b
commit
db325e7700
12 changed files with 36 additions and 41 deletions
|
@ -3,10 +3,9 @@ use std::cmp::Ordering;
|
|||
use super::api_error;
|
||||
use super::FallibleApiResponse;
|
||||
use super::ToAPI;
|
||||
use mongod::Referencable;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::fs::NamedFile;
|
||||
use rocket::*;
|
||||
use rocket::{get, State};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::cache::RouteCache;
|
||||
|
@ -69,17 +68,9 @@ pub async fn album_route(
|
|||
.await
|
||||
.ok_or_else(|| api_error("No album with that ID found"))?;
|
||||
|
||||
let mut tracks = Album::get_tracks_of_album(&format!("album::{}", album._id))
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|x| {
|
||||
json!({
|
||||
"id": x.id(),
|
||||
"title": x.title,
|
||||
"tracknumber": x.meta.map(|x| x.track_number())
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let tracks = Album::get_tracks_of_album(&format!("album::{}", album._id)).await;
|
||||
|
||||
let mut tracks = to_api(&tracks).await;
|
||||
|
||||
tracks.sort_by(sort_by_tracknumber);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::ToAPI;
|
|||
use fs::NamedFile;
|
||||
use mongod::Model;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::*;
|
||||
use rocket::{fs, get, State};
|
||||
|
||||
use crate::cache::RouteCache;
|
||||
use crate::library::artist::Artist;
|
||||
|
|
|
@ -38,11 +38,11 @@ pub async fn to_api(albums: &[impl ToAPI]) -> Vec<serde_json::Value> {
|
|||
}
|
||||
|
||||
#[get("/")]
|
||||
pub async fn index_redir() -> Redirect {
|
||||
pub fn index_redir() -> Redirect {
|
||||
Redirect::to(uri!("/web"))
|
||||
}
|
||||
|
||||
#[get("/manifest.json")]
|
||||
pub async fn manifest_redir() -> Redirect {
|
||||
pub fn manifest_redir() -> Redirect {
|
||||
Redirect::to(uri!("/web/manifest.json"))
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use super::FallibleApiResponse;
|
|||
use super::ToAPI;
|
||||
use fs::NamedFile;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::*;
|
||||
use rocket::{fs, get, State};
|
||||
|
||||
use crate::library::Libary;
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ pub struct PasswdData {
|
|||
pub async fn passwd_route(passwd: Json<PasswdData>, mut u: User) -> FallibleApiResponse {
|
||||
u.passwd(&passwd.old, &passwd.new)
|
||||
.await
|
||||
.map_err(|_| api_error("Password change failed"))?;
|
||||
.map_err(|()| api_error("Password change failed"))?;
|
||||
|
||||
Ok(json!({
|
||||
"ok": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue