update client + remake web-ui (server, incomplete)

This commit is contained in:
Mark
2024-05-15 22:58:30 +02:00
parent 55e0e02622
commit 6eb884e7a5
29 changed files with 584 additions and 843 deletions

14
musicdb-server/Cargo.toml Executable file → Normal file
View File

@@ -7,14 +7,14 @@ edition = "2021"
[dependencies]
musicdb-lib = { path = "../musicdb-lib", features = ["playback"] }
axum = { version = "0.6.19", features = ["headers"] }
clap = { version = "4.4.6", features = ["derive"] }
futures = "0.3.28"
headers = "0.3.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
tokio-stream = "0.1.14"
tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
trace = "0.1.7"
tokio = { version = "1.37.0", optional = true, features = ["rt"] }
rocket = { version = "0.5.0", optional = true }
html-escape = { version = "0.2.13", optional = true }
[features]
default = ["website"]
website = ["dep:tokio", "dep:rocket", "dep:html-escape"]

View File

@@ -0,0 +1,6 @@
[build]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get --assume-yes install libasound2-dev libasound2-dev:$CROSS_DEB_ARCH"
]
default-target = "aarch64-unknown-linux-gnu"

View File

@@ -1,3 +0,0 @@
<h3>\:name</h3>
<button hx-post="/queue/add-album/\:id" hx-swap="none">Queue</button>
\:songs

View File

@@ -1 +0,0 @@
<button hx-get="/album-view/\:id" hx-target="#album-view">\:name</button>

View File

@@ -1,2 +0,0 @@
<h3>\:name</h3>
\:albums

View File

@@ -1,2 +0,0 @@
<h3>Artists</h3>
\:artists

View File

@@ -1 +0,0 @@
<button hx-get="/artist-view/\:id" hx-target="#artist-view">\:name</button>

View File

@@ -1,3 +0,0 @@
<h2>Queue</h2>
<div>Now Playing: <b>\:currentTitle</b></div>
\:content

View File

@@ -1,11 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small>\:name</small>
\?shuffled? (shuffled)\;\;
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,11 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small><b>\:name</b></small>
\?shuffled? (shuffled)\;\;
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small>repeat \:total times</small>
</div>
\:inner
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small><b>repeat \:total times</b></small>
</div>
\:inner
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small>repeat forever</small>
</div>
\:inner
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small><b>repeat forever</b></small>
</div>
\:inner
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small>random</small>
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small><b>random</b></small>
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small>shuffle</small>
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,10 +0,0 @@
<div>
<small>&gt;&gt;</small>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<small><b>shuffle</b></small>
</div>
\:content
<div>
<small>&lt;&lt;</small>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
</div>

View File

@@ -1,5 +0,0 @@
<div>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
\:title
</div>

View File

@@ -1,5 +0,0 @@
<div>
<button hx-post="/queue/remove/\:path" hx-swap="none">x</button>
<button hx-post="/queue/goto/\:path" hx-swap="none">&#x23F5;</button>
<b>\:title</b>
</div>

View File

@@ -1,24 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
<title>MusicDb</title>
</head>
<body>
<div hx-sse="connect:/sse">
<div hx-sse="swap:playing">(loading)</div>
<button hx-post="/resume" hx-swap="none">&#x23F5;</button>
<button hx-post="/pause" hx-swap="none">&#x23F8;</button>
<button hx-post="/stop" hx-swap="none">&#x23F9;</button>
<button hx-post="/next" hx-swap="none">&#x23ED;</button>
<button hx-post="/queue/clear" hx-swap="none">-</button>
<div hx-sse="swap:queue">(loading)</div>
<div hx-sse="swap:artists">(loading)</div>
<div id="artist-view"></div>
<div id="album-view"></div>
</div>
</body>
</html>

View File

@@ -1 +0,0 @@
<button hx-post="/queue/add-song/\:id" hx-swap="none">\:title</button>

View File

@@ -1,3 +1,4 @@
#[cfg(feature = "website")]
mod web;
use std::{
@@ -5,7 +6,6 @@ use std::{
path::PathBuf,
process::exit,
sync::{Arc, Mutex},
thread,
};
use clap::Parser;
@@ -47,8 +47,7 @@ struct Args {
advanced_cache_song_lookahead_limit: u32,
}
#[tokio::main]
async fn main() {
fn main() {
// parse args
let args = Args::parse();
let mut database = if args.init {
@@ -88,11 +87,25 @@ async fn main() {
);
};
if let Some(addr) = &args.web {
let (s, mut r) = tokio::sync::mpsc::channel(2);
let db = Arc::clone(&database);
thread::spawn(move || run_server(database, Some(s)));
if let Some(sender) = r.recv().await {
web::main(db, sender, *addr).await;
#[cfg(not(feature = "website"))]
{
let _ = addr;
eprintln!("Website support requires the 'website' feature to be enabled when compiling the server!");
std::process::exit(80);
}
#[cfg(feature = "website")]
{
let (s, r) = std::sync::mpsc::sync_channel(1);
let db = Arc::clone(&database);
std::thread::spawn(move || {
run_server(database, Some(Box::new(move |c| s.send(c).unwrap())))
});
let sender = r.recv().unwrap();
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(web::main(db, sender, *addr));
}
} else {
run_server(database, None);

File diff suppressed because it is too large Load Diff