mirror of
https://github.com/Dummi26/musicdb.git
synced 2025-03-10 05:43:53 +01:00
using source "remote" for server now has covers
This commit is contained in:
parent
a714bfd404
commit
643e337e61
@ -1046,7 +1046,7 @@ pub struct Cover {
|
||||
pub data: Arc<Mutex<(bool, Option<(Instant, Vec<u8>)>)>>,
|
||||
}
|
||||
impl Cover {
|
||||
pub fn get_bytes<O>(
|
||||
pub fn get_bytes_from_file<O>(
|
||||
&self,
|
||||
path: impl FnOnce(&DatabaseLocation) -> PathBuf,
|
||||
conv: impl FnOnce(&Vec<u8>) -> O,
|
||||
|
@ -178,13 +178,24 @@ pub fn handle_one_connection_as_get(
|
||||
if let Some(req) = request.next() {
|
||||
match req {
|
||||
"cover-bytes" => {
|
||||
if let Some(cover) = request
|
||||
.next()
|
||||
.and_then(|id| id.parse().ok())
|
||||
.and_then(|id| db.lock().unwrap().covers().get(&id).cloned())
|
||||
if let Some(cover_id) = request.next().and_then(|id| id.parse().ok()) {
|
||||
let dbl = db.lock().unwrap();
|
||||
if let Some(get_con) = &dbl.remote_server_as_song_file_source {
|
||||
if let Some(bytes) = get_con
|
||||
.lock()
|
||||
.unwrap()
|
||||
.cover_bytes(cover_id)
|
||||
.ok()
|
||||
.and_then(Result::ok)
|
||||
{
|
||||
if let Some(v) = cover.get_bytes(
|
||||
|p| db.lock().unwrap().get_path(p),
|
||||
writeln!(connection.get_mut(), "len: {}", bytes.len())?;
|
||||
connection.get_mut().write_all(&bytes)?;
|
||||
} else {
|
||||
writeln!(connection.get_mut(), "no")?;
|
||||
}
|
||||
} else if let Some(cover) = dbl.covers().get(&cover_id) {
|
||||
if let Some(v) = cover.get_bytes_from_file(
|
||||
|p| dbl.get_path(p),
|
||||
|bytes| {
|
||||
writeln!(connection.get_mut(), "len: {}", bytes.len())?;
|
||||
connection.get_mut().write_all(bytes)?;
|
||||
@ -198,6 +209,9 @@ pub fn handle_one_connection_as_get(
|
||||
} else {
|
||||
writeln!(connection.get_mut(), "no cover")?;
|
||||
}
|
||||
} else {
|
||||
writeln!(connection.get_mut(), "bad id")?;
|
||||
}
|
||||
}
|
||||
"song-file" => {
|
||||
if let Some(bytes) =
|
||||
|
Loading…
Reference in New Issue
Block a user