Rust 2018
This commit is contained in:
parent
fdf40f2683
commit
4b4ab8145c
14 changed files with 62 additions and 61 deletions
|
@ -2,6 +2,7 @@
|
|||
name = "polaris"
|
||||
version = "0.9.0"
|
||||
authors = ["Antoine Gersant <antoine.gersant@lesforges.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
ui = []
|
||||
|
|
|
@ -7,13 +7,13 @@ use std::io::Read;
|
|||
use std::path;
|
||||
use toml;
|
||||
|
||||
use db::ConnectionSource;
|
||||
use db::DB;
|
||||
use db::{ddns_config, misc_settings, mount_points, users};
|
||||
use ddns::DDNSConfig;
|
||||
use errors::*;
|
||||
use user::*;
|
||||
use vfs::MountPoint;
|
||||
use crate::db::ConnectionSource;
|
||||
use crate::db::DB;
|
||||
use crate::db::{ddns_config, misc_settings, mount_points, users};
|
||||
use crate::ddns::DDNSConfig;
|
||||
use crate::errors::*;
|
||||
use crate::user::*;
|
||||
use crate::vfs::MountPoint;
|
||||
|
||||
#[derive(Debug, Queryable)]
|
||||
pub struct MiscSettings {
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::fs;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
use errors::*;
|
||||
use crate::errors::*;
|
||||
|
||||
mod schema;
|
||||
|
||||
|
@ -85,7 +85,7 @@ impl ConnectionSource for DB {
|
|||
}
|
||||
|
||||
pub fn _get_test_db(name: &str) -> DB {
|
||||
use config;
|
||||
use crate::config;
|
||||
let config_path = Path::new("test/config.toml");
|
||||
let config = config::parse_toml_file(&config_path).unwrap();
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ use std::io;
|
|||
use std::thread;
|
||||
use std::time;
|
||||
|
||||
use db::ddns_config;
|
||||
use db::{ConnectionSource, DB};
|
||||
use errors;
|
||||
use crate::db::ddns_config;
|
||||
use crate::db::{ConnectionSource, DB};
|
||||
use crate::errors;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Insertable, PartialEq, Queryable, Serialize)]
|
||||
#[table_name = "ddns_config"]
|
||||
|
|
14
src/index.rs
14
src/index.rs
|
@ -14,14 +14,14 @@ use std::sync::{Arc, Mutex};
|
|||
use std::thread;
|
||||
use std::time;
|
||||
|
||||
use config::MiscSettings;
|
||||
use crate::config::MiscSettings;
|
||||
#[cfg(test)]
|
||||
use db;
|
||||
use db::{directories, misc_settings, songs};
|
||||
use db::{ConnectionSource, DB};
|
||||
use errors;
|
||||
use metadata;
|
||||
use vfs::{VFSSource, VFS};
|
||||
use crate::db;
|
||||
use crate::db::{directories, misc_settings, songs};
|
||||
use crate::db::{ConnectionSource, DB};
|
||||
use crate::errors;
|
||||
use crate::metadata;
|
||||
use crate::vfs::{VFSSource, VFS};
|
||||
|
||||
const INDEX_BUILDING_INSERT_BUFFER_SIZE: usize = 1000; // Insertions in each transaction
|
||||
const INDEX_BUILDING_CLEAN_BUFFER_SIZE: usize = 500; // Insertions in each transaction
|
||||
|
|
|
@ -6,11 +6,11 @@ use std::collections::HashMap;
|
|||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use db::ConnectionSource;
|
||||
use errors;
|
||||
use index;
|
||||
use user;
|
||||
use vfs::VFSSource;
|
||||
use crate::db::ConnectionSource;
|
||||
use crate::errors;
|
||||
use crate::index;
|
||||
use crate::user;
|
||||
use crate::vfs::VFSSource;
|
||||
|
||||
const LASTFM_API_KEY: &str = "02b96c939a2b451c31dfd67add1f696e";
|
||||
const LASTFM_API_SECRET: &str = "0f25a80ceef4b470b5cb97d99d4b3420";
|
||||
|
|
|
@ -54,7 +54,7 @@ use std::io::prelude::*;
|
|||
use unix_daemonize::{daemonize_redirect, ChdirMode};
|
||||
|
||||
use core::ops::Deref;
|
||||
use errors::*;
|
||||
use crate::errors::*;
|
||||
use getopts::Options;
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
use simplelog::{Level, LevelFilter, SimpleLogger, TermLogger};
|
||||
|
|
|
@ -7,9 +7,9 @@ use regex::Regex;
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use errors::*;
|
||||
use utils;
|
||||
use utils::AudioFormat;
|
||||
use crate::errors::*;
|
||||
use crate::utils;
|
||||
use crate::utils::AudioFormat;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SongTags {
|
||||
|
|
|
@ -7,12 +7,12 @@ use diesel::BelongingToDsl;
|
|||
use std::path::Path;
|
||||
|
||||
#[cfg(test)]
|
||||
use db;
|
||||
use db::ConnectionSource;
|
||||
use db::{playlist_songs, playlists, users};
|
||||
use errors::*;
|
||||
use index::{self, Song};
|
||||
use vfs::VFSSource;
|
||||
use crate::db;
|
||||
use crate::db::ConnectionSource;
|
||||
use crate::db::{playlist_songs, playlists, users};
|
||||
use crate::errors::*;
|
||||
use crate::index::{self, Song};
|
||||
use crate::vfs::VFSSource;
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "playlists"]
|
||||
|
@ -262,7 +262,7 @@ fn test_delete_playlist() {
|
|||
|
||||
#[test]
|
||||
fn test_fill_playlist() {
|
||||
use index;
|
||||
use crate::index;
|
||||
|
||||
let db = db::_get_test_db("fill_playlist.sqlite");
|
||||
index::update(&db).unwrap();
|
||||
|
|
|
@ -10,17 +10,17 @@ use std::str;
|
|||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use config::{self, Config, Preferences};
|
||||
use db::DB;
|
||||
use errors;
|
||||
use index;
|
||||
use lastfm;
|
||||
use playlist;
|
||||
use serve;
|
||||
use thumbnails;
|
||||
use user;
|
||||
use utils;
|
||||
use vfs::VFSSource;
|
||||
use crate::config::{self, Config, Preferences};
|
||||
use crate::db::DB;
|
||||
use crate::errors;
|
||||
use crate::index;
|
||||
use crate::lastfm;
|
||||
use crate::playlist;
|
||||
use crate::serve;
|
||||
use crate::thumbnails;
|
||||
use crate::user;
|
||||
use crate::utils;
|
||||
use crate::vfs::VFSSource;
|
||||
|
||||
const CURRENT_MAJOR_VERSION: i32 = 3;
|
||||
const CURRENT_MINOR_VERSION: i32 = 0;
|
||||
|
|
|
@ -11,8 +11,8 @@ use std::fs::{DirBuilder, File};
|
|||
use std::hash::{Hash, Hasher};
|
||||
use std::path::*;
|
||||
|
||||
use errors::*;
|
||||
use utils;
|
||||
use crate::errors::*;
|
||||
use crate::utils;
|
||||
|
||||
const THUMBNAILS_PATH: &str = "thumbnails";
|
||||
|
||||
|
|
18
src/user.rs
18
src/user.rs
|
@ -4,9 +4,9 @@ use diesel::prelude::*;
|
|||
use rand;
|
||||
use ring::{digest, pbkdf2};
|
||||
|
||||
use db::users;
|
||||
use db::ConnectionSource;
|
||||
use errors::*;
|
||||
use crate::db::users;
|
||||
use crate::db::ConnectionSource;
|
||||
use crate::errors::*;
|
||||
|
||||
#[derive(Debug, Insertable, Queryable)]
|
||||
#[table_name = "users"]
|
||||
|
@ -66,7 +66,7 @@ pub fn auth<T>(db: &T, username: &str, password: &str) -> Result<bool>
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
match users
|
||||
.select((password_hash, password_salt))
|
||||
|
@ -83,7 +83,7 @@ pub fn count<T>(db: &T) -> Result<i64>
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
let count = users.count().get_result(connection.deref())?;
|
||||
Ok(count)
|
||||
|
@ -93,7 +93,7 @@ pub fn is_admin<T>(db: &T, username: &str) -> Result<bool>
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
let is_admin: i32 = users
|
||||
.filter(name.eq(username))
|
||||
|
@ -106,7 +106,7 @@ pub fn lastfm_link<T>(db: &T, username: &str, lastfm_login: &str, session_key: &
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
diesel::update(users.filter(name.eq(username)))
|
||||
.set((
|
||||
|
@ -121,7 +121,7 @@ pub fn get_lastfm_session_key<T>(db: &T, username: &str) -> Result<String>
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
let token = users
|
||||
.filter(name.eq(username))
|
||||
|
@ -137,7 +137,7 @@ pub fn lastfm_unlink<T>(db: &T, username: &str) -> Result<()>
|
|||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use db::users::dsl::*;
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
diesel::update(users.filter(name.eq(username)))
|
||||
.set((lastfm_session_key.eq(""), lastfm_username.eq("")))
|
||||
|
|
|
@ -2,7 +2,7 @@ use app_dirs::{app_root, AppDataType, AppInfo};
|
|||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use errors::*;
|
||||
use crate::errors::*;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
const APP_INFO: AppInfo = AppInfo {
|
||||
|
|
|
@ -4,9 +4,9 @@ use std::collections::HashMap;
|
|||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use db::mount_points;
|
||||
use db::{ConnectionSource, DB};
|
||||
use errors::*;
|
||||
use crate::db::mount_points;
|
||||
use crate::db::{ConnectionSource, DB};
|
||||
use crate::errors::*;
|
||||
|
||||
pub trait VFSSource {
|
||||
fn get_vfs(&self) -> Result<VFS>;
|
||||
|
|
Loading…
Add table
Reference in a new issue