using source "remote" for server now has covers

This commit is contained in:
Mark 2024-05-28 15:49:37 +02:00
parent a714bfd404
commit 643e337e61
2 changed files with 30 additions and 16 deletions

View File

@ -1046,7 +1046,7 @@ pub struct Cover {
pub data: Arc<Mutex<(bool, Option<(Instant, Vec<u8>)>)>>, pub data: Arc<Mutex<(bool, Option<(Instant, Vec<u8>)>)>>,
} }
impl Cover { impl Cover {
pub fn get_bytes<O>( pub fn get_bytes_from_file<O>(
&self, &self,
path: impl FnOnce(&DatabaseLocation) -> PathBuf, path: impl FnOnce(&DatabaseLocation) -> PathBuf,
conv: impl FnOnce(&Vec<u8>) -> O, conv: impl FnOnce(&Vec<u8>) -> O,

View File

@ -178,13 +178,24 @@ pub fn handle_one_connection_as_get(
if let Some(req) = request.next() { if let Some(req) = request.next() {
match req { match req {
"cover-bytes" => { "cover-bytes" => {
if let Some(cover) = request if let Some(cover_id) = request.next().and_then(|id| id.parse().ok()) {
.next() let dbl = db.lock().unwrap();
.and_then(|id| id.parse().ok()) if let Some(get_con) = &dbl.remote_server_as_song_file_source {
.and_then(|id| db.lock().unwrap().covers().get(&id).cloned()) if let Some(bytes) = get_con
.lock()
.unwrap()
.cover_bytes(cover_id)
.ok()
.and_then(Result::ok)
{ {
if let Some(v) = cover.get_bytes( writeln!(connection.get_mut(), "len: {}", bytes.len())?;
|p| db.lock().unwrap().get_path(p), 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| { |bytes| {
writeln!(connection.get_mut(), "len: {}", bytes.len())?; writeln!(connection.get_mut(), "len: {}", bytes.len())?;
connection.get_mut().write_all(bytes)?; connection.get_mut().write_all(bytes)?;
@ -198,6 +209,9 @@ pub fn handle_one_connection_as_get(
} else { } else {
writeln!(connection.get_mut(), "no cover")?; writeln!(connection.get_mut(), "no cover")?;
} }
} else {
writeln!(connection.get_mut(), "bad id")?;
}
} }
"song-file" => { "song-file" => {
if let Some(bytes) = if let Some(bytes) =