This commit is contained in:
Antoine Gersant 2018-10-06 16:30:21 -07:00
parent ec69a3568f
commit 15a10f0ba8
3 changed files with 26 additions and 28 deletions

View file

@ -1,2 +1 @@
write_mode = "Overwrite"
hard_tabs = true hard_tabs = true

View file

@ -2,20 +2,20 @@ use core::clone::Clone;
use core::ops::Deref; use core::ops::Deref;
use diesel; use diesel;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::BelongingToDsl;
use diesel::types::*; use diesel::types::*;
use diesel::BelongingToDsl;
use std::path::Path; use std::path::Path;
#[cfg(test)] #[cfg(test)]
use db; use db;
use db::ConnectionSource; use db::ConnectionSource;
use db::{playlists, playlist_songs, users}; use db::{playlist_songs, playlists, users};
use errors::*;
use index::{self, Song}; use index::{self, Song};
use vfs::VFSSource; use vfs::VFSSource;
use errors::*;
#[derive(Insertable)] #[derive(Insertable)]
#[table_name="playlists"] #[table_name = "playlists"]
struct NewPlaylist { struct NewPlaylist {
name: String, name: String,
owner: i32, owner: i32,
@ -27,21 +27,21 @@ pub struct User {
} }
#[derive(Identifiable, Queryable, Associations)] #[derive(Identifiable, Queryable, Associations)]
#[belongs_to(User, foreign_key="owner")] #[belongs_to(User, foreign_key = "owner")]
pub struct Playlist { pub struct Playlist {
id: i32, id: i32,
owner: i32, owner: i32,
} }
#[derive(Identifiable, Queryable, Associations)] #[derive(Identifiable, Queryable, Associations)]
#[belongs_to(Playlist, foreign_key="playlist")] #[belongs_to(Playlist, foreign_key = "playlist")]
pub struct PlaylistSong { pub struct PlaylistSong {
id: i32, id: i32,
playlist: i32, playlist: i32,
} }
#[derive(Insertable)] #[derive(Insertable)]
#[table_name="playlist_songs"] #[table_name = "playlist_songs"]
pub struct NewPlaylistSong { pub struct NewPlaylistSong {
playlist: i32, playlist: i32,
path: String, path: String,
@ -49,7 +49,8 @@ pub struct NewPlaylistSong {
} }
pub fn list_playlists<T>(owner: &str, db: &T) -> Result<Vec<String>> pub fn list_playlists<T>(owner: &str, db: &T) -> Result<Vec<String>>
where T: ConnectionSource + VFSSource where
T: ConnectionSource + VFSSource,
{ {
let connection = db.get_connection(); let connection = db.get_connection();
@ -71,12 +72,9 @@ pub fn list_playlists<T>(owner: &str, db: &T) -> Result<Vec<String>>
} }
} }
pub fn save_playlist<T>(playlist_name: &str, pub fn save_playlist<T>(playlist_name: &str, owner: &str, content: &[String], db: &T) -> Result<()>
owner: &str, where
content: &[String], T: ConnectionSource + VFSSource,
db: &T)
-> Result<()>
where T: ConnectionSource + VFSSource
{ {
let user: User; let user: User;
let new_playlist: NewPlaylist; let new_playlist: NewPlaylist;
@ -119,14 +117,16 @@ pub fn save_playlist<T>(playlist_name: &str,
for (i, path) in content.iter().enumerate() { for (i, path) in content.iter().enumerate() {
let virtual_path = Path::new(&path); let virtual_path = Path::new(&path);
if let Some(real_path) = vfs.virtual_to_real(virtual_path) if let Some(real_path) = vfs
.ok() .virtual_to_real(virtual_path)
.and_then(|p| p.to_str().map(|s| s.to_owned())) { .ok()
.and_then(|p| p.to_str().map(|s| s.to_owned()))
{
new_songs.push(NewPlaylistSong { new_songs.push(NewPlaylistSong {
playlist: playlist.id, playlist: playlist.id,
path: real_path, path: real_path,
ordering: i as i32, ordering: i as i32,
}); });
} }
} }
@ -151,7 +151,8 @@ pub fn save_playlist<T>(playlist_name: &str,
} }
pub fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<Song>> pub fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<Song>>
where T: ConnectionSource + VFSSource where
T: ConnectionSource + VFSSource,
{ {
let vfs = db.get_vfs()?; let vfs = db.get_vfs()?;
let songs: Vec<Song>; let songs: Vec<Song>;
@ -201,7 +202,8 @@ pub fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<
} }
pub fn delete_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<()> pub fn delete_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<()>
where T: ConnectionSource + VFSSource where
T: ConnectionSource + VFSSource,
{ {
let connection = db.get_connection(); let connection = db.get_connection();

View file

@ -84,10 +84,7 @@ impl PartialFile {
Range: Into<PartialFileRange>, Range: Into<PartialFileRange>,
{ {
let range = range.into(); let range = range.into();
PartialFile { PartialFile { file, range }
file,
range,
}
} }
pub fn from_path<P: AsRef<Path>, Range>(path: P, range: Range) -> Result<PartialFile, io::Error> pub fn from_path<P: AsRef<Path>, Range>(path: P, range: Range) -> Result<PartialFile, io::Error>