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

View file

@ -2,17 +2,17 @@ use core::clone::Clone;
use core::ops::Deref;
use diesel;
use diesel::prelude::*;
use diesel::BelongingToDsl;
use diesel::types::*;
use diesel::BelongingToDsl;
use std::path::Path;
#[cfg(test)]
use db;
use db::ConnectionSource;
use db::{playlists, playlist_songs, users};
use db::{playlist_songs, playlists, users};
use errors::*;
use index::{self, Song};
use vfs::VFSSource;
use errors::*;
#[derive(Insertable)]
#[table_name = "playlists"]
@ -49,7 +49,8 @@ pub struct NewPlaylistSong {
}
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();
@ -71,12 +72,9 @@ pub fn list_playlists<T>(owner: &str, db: &T) -> Result<Vec<String>>
}
}
pub fn save_playlist<T>(playlist_name: &str,
owner: &str,
content: &[String],
db: &T)
-> Result<()>
where T: ConnectionSource + VFSSource
pub fn save_playlist<T>(playlist_name: &str, owner: &str, content: &[String], db: &T) -> Result<()>
where
T: ConnectionSource + VFSSource,
{
let user: User;
let new_playlist: NewPlaylist;
@ -119,9 +117,11 @@ pub fn save_playlist<T>(playlist_name: &str,
for (i, path) in content.iter().enumerate() {
let virtual_path = Path::new(&path);
if let Some(real_path) = vfs.virtual_to_real(virtual_path)
if let Some(real_path) = vfs
.virtual_to_real(virtual_path)
.ok()
.and_then(|p| p.to_str().map(|s| s.to_owned())) {
.and_then(|p| p.to_str().map(|s| s.to_owned()))
{
new_songs.push(NewPlaylistSong {
playlist: playlist.id,
path: real_path,
@ -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>>
where T: ConnectionSource + VFSSource
where
T: ConnectionSource + VFSSource,
{
let vfs = db.get_vfs()?;
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<()>
where T: ConnectionSource + VFSSource
where
T: ConnectionSource + VFSSource,
{
let connection = db.get_connection();

View file

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