Added preference fields for web theme
This commit is contained in:
parent
2de5b34a48
commit
59366c6b03
7 changed files with 112 additions and 74 deletions
|
@ -854,6 +854,12 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"lastfm_username": {
|
"lastfm_username": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"web_theme_base": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"web_theme_accent": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
14
migrations/2020-01-08-231420_add_theme/down.sql
Normal file
14
migrations/2020-01-08-231420_add_theme/down.sql
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
CREATE TEMPORARY TABLE users_backup(id, name, password_hash, admin, lastfm_username, lastfm_session_key);
|
||||||
|
INSERT INTO users_backup SELECT id, name, password_hash, admin, lastfm_username, lastfm_session_key FROM users;
|
||||||
|
DROP TABLE users;
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
admin INTEGER NOT NULL,
|
||||||
|
lastfm_username TEXT,
|
||||||
|
lastfm_session_key TEXT,
|
||||||
|
UNIQUE(name)
|
||||||
|
);
|
||||||
|
INSERT INTO users SELECT * FROM users_backup;
|
||||||
|
DROP TABLE users_backup;
|
2
migrations/2020-01-08-231420_add_theme/up.sql
Normal file
2
migrations/2020-01-08-231420_add_theme/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE users ADD COLUMN web_theme_base TEXT;
|
||||||
|
ALTER TABLE users ADD COLUMN web_theme_accent TEXT;
|
|
@ -25,7 +25,7 @@ use crate::utils;
|
||||||
use crate::vfs::VFSSource;
|
use crate::vfs::VFSSource;
|
||||||
|
|
||||||
const CURRENT_MAJOR_VERSION: i32 = 3;
|
const CURRENT_MAJOR_VERSION: i32 = 3;
|
||||||
const CURRENT_MINOR_VERSION: i32 = 0;
|
const CURRENT_MINOR_VERSION: i32 = 1;
|
||||||
const COOKIE_SESSION: &str = "session";
|
const COOKIE_SESSION: &str = "session";
|
||||||
|
|
||||||
pub fn get_routes() -> Vec<rocket::Route> {
|
pub fn get_routes() -> Vec<rocket::Route> {
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn version() {
|
||||||
|
|
||||||
let response_body = response.body_string().unwrap();
|
let response_body = response.body_string().unwrap();
|
||||||
let response_json: api::Version = serde_json::from_str(&response_body).unwrap();
|
let response_json: api::Version = serde_json::from_str(&response_body).unwrap();
|
||||||
assert_eq!(response_json, api::Version { major: 3, minor: 0 });
|
assert_eq!(response_json, api::Version { major: 3, minor: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -28,6 +28,8 @@ pub struct MiscSettings {
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Preferences {
|
pub struct Preferences {
|
||||||
pub lastfm_username: Option<String>,
|
pub lastfm_username: Option<String>,
|
||||||
|
pub web_theme_base: Option<String>,
|
||||||
|
pub web_theme_accent: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -250,19 +252,29 @@ where
|
||||||
{
|
{
|
||||||
use self::users::dsl::*;
|
use self::users::dsl::*;
|
||||||
let connection = db.get_connection();
|
let connection = db.get_connection();
|
||||||
let read_lastfm_username = users
|
let (theme_base, theme_accent, read_lastfm_username) = users
|
||||||
.select(lastfm_username)
|
.select((web_theme_base, web_theme_accent, lastfm_username))
|
||||||
.filter(name.eq(username))
|
.filter(name.eq(username))
|
||||||
.get_result(connection.deref())?;
|
.get_result(connection.deref())?;
|
||||||
Ok(Preferences {
|
Ok(Preferences {
|
||||||
|
web_theme_base: theme_base,
|
||||||
|
web_theme_accent: theme_accent,
|
||||||
lastfm_username: read_lastfm_username,
|
lastfm_username: read_lastfm_username,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_preferences<T>(_: &T, _: &str, _: &Preferences) -> Result<()>
|
pub fn write_preferences<T>(db: &T, username: &str, preferences: &Preferences) -> Result<()>
|
||||||
where
|
where
|
||||||
T: ConnectionSource,
|
T: ConnectionSource,
|
||||||
{
|
{
|
||||||
|
use crate::db::users::dsl::*;
|
||||||
|
let connection = db.get_connection();
|
||||||
|
diesel::update(users.filter(name.eq(username)))
|
||||||
|
.set((
|
||||||
|
web_theme_base.eq(&preferences.web_theme_base),
|
||||||
|
web_theme_accent.eq(&preferences.web_theme_accent),
|
||||||
|
))
|
||||||
|
.execute(connection.deref())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,6 +545,8 @@ fn test_preferences_read_write() {
|
||||||
amend(&db, &initial_config).unwrap();
|
amend(&db, &initial_config).unwrap();
|
||||||
|
|
||||||
let new_preferences = Preferences {
|
let new_preferences = Preferences {
|
||||||
|
web_theme_base: Some("very-dark-theme".to_owned()),
|
||||||
|
web_theme_accent: Some("#FF0000".to_owned()),
|
||||||
lastfm_username: None,
|
lastfm_username: None,
|
||||||
};
|
};
|
||||||
write_preferences(&db, "Teddy🐻", &new_preferences).unwrap();
|
write_preferences(&db, "Teddy🐻", &new_preferences).unwrap();
|
||||||
|
|
140
src/db/schema.rs
140
src/db/schema.rs
|
@ -1,98 +1,100 @@
|
||||||
table! {
|
table! {
|
||||||
ddns_config (id) {
|
ddns_config (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
host -> Text,
|
host -> Text,
|
||||||
username -> Text,
|
username -> Text,
|
||||||
password -> Text,
|
password -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
directories (id) {
|
directories (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
path -> Text,
|
path -> Text,
|
||||||
parent -> Nullable<Text>,
|
parent -> Nullable<Text>,
|
||||||
artist -> Nullable<Text>,
|
artist -> Nullable<Text>,
|
||||||
year -> Nullable<Integer>,
|
year -> Nullable<Integer>,
|
||||||
album -> Nullable<Text>,
|
album -> Nullable<Text>,
|
||||||
artwork -> Nullable<Text>,
|
artwork -> Nullable<Text>,
|
||||||
date_added -> Integer,
|
date_added -> Integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
misc_settings (id) {
|
misc_settings (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
auth_secret -> Binary,
|
auth_secret -> Binary,
|
||||||
index_sleep_duration_seconds -> Integer,
|
index_sleep_duration_seconds -> Integer,
|
||||||
index_album_art_pattern -> Text,
|
index_album_art_pattern -> Text,
|
||||||
prefix_url -> Text,
|
prefix_url -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
mount_points (id) {
|
mount_points (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
source -> Text,
|
source -> Text,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
playlist_songs (id) {
|
playlist_songs (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
playlist -> Integer,
|
playlist -> Integer,
|
||||||
path -> Text,
|
path -> Text,
|
||||||
ordering -> Integer,
|
ordering -> Integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
playlists (id) {
|
playlists (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
owner -> Integer,
|
owner -> Integer,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
songs (id) {
|
songs (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
path -> Text,
|
path -> Text,
|
||||||
parent -> Text,
|
parent -> Text,
|
||||||
track_number -> Nullable<Integer>,
|
track_number -> Nullable<Integer>,
|
||||||
disc_number -> Nullable<Integer>,
|
disc_number -> Nullable<Integer>,
|
||||||
title -> Nullable<Text>,
|
title -> Nullable<Text>,
|
||||||
artist -> Nullable<Text>,
|
artist -> Nullable<Text>,
|
||||||
album_artist -> Nullable<Text>,
|
album_artist -> Nullable<Text>,
|
||||||
year -> Nullable<Integer>,
|
year -> Nullable<Integer>,
|
||||||
album -> Nullable<Text>,
|
album -> Nullable<Text>,
|
||||||
artwork -> Nullable<Text>,
|
artwork -> Nullable<Text>,
|
||||||
duration -> Nullable<Integer>,
|
duration -> Nullable<Integer>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
users (id) {
|
users (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
password_hash -> Text,
|
password_hash -> Text,
|
||||||
admin -> Integer,
|
admin -> Integer,
|
||||||
lastfm_username -> Nullable<Text>,
|
lastfm_username -> Nullable<Text>,
|
||||||
lastfm_session_key -> Nullable<Text>,
|
lastfm_session_key -> Nullable<Text>,
|
||||||
}
|
web_theme_base -> Nullable<Text>,
|
||||||
|
web_theme_accent -> Nullable<Text>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
joinable!(playlist_songs -> playlists (playlist));
|
joinable!(playlist_songs -> playlists (playlist));
|
||||||
joinable!(playlists -> users (owner));
|
joinable!(playlists -> users (owner));
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(
|
allow_tables_to_appear_in_same_query!(
|
||||||
ddns_config,
|
ddns_config,
|
||||||
directories,
|
directories,
|
||||||
misc_settings,
|
misc_settings,
|
||||||
mount_points,
|
mount_points,
|
||||||
playlist_songs,
|
playlist_songs,
|
||||||
playlists,
|
playlists,
|
||||||
songs,
|
songs,
|
||||||
users,
|
users,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue