mirror of
https://github.com/Dummi26/musicdb.git
synced 2025-03-10 14:13: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>)>)>>,
|
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,
|
||||||
|
@ -178,25 +178,39 @@ 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()
|
||||||
if let Some(v) = cover.get_bytes(
|
.unwrap()
|
||||||
|p| db.lock().unwrap().get_path(p),
|
.cover_bytes(cover_id)
|
||||||
|bytes| {
|
.ok()
|
||||||
|
.and_then(Result::ok)
|
||||||
|
{
|
||||||
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)?;
|
||||||
Ok::<(), std::io::Error>(())
|
} else {
|
||||||
},
|
writeln!(connection.get_mut(), "no")?;
|
||||||
) {
|
}
|
||||||
v?;
|
} 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)?;
|
||||||
|
Ok::<(), std::io::Error>(())
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
v?;
|
||||||
|
} else {
|
||||||
|
writeln!(connection.get_mut(), "no data")?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln!(connection.get_mut(), "no data")?;
|
writeln!(connection.get_mut(), "no cover")?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln!(connection.get_mut(), "no cover")?;
|
writeln!(connection.get_mut(), "bad id")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"song-file" => {
|
"song-file" => {
|
||||||
|
Loading…
Reference in New Issue
Block a user