Update rmp-ipc and add more tracing

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent e4ba7f2674
commit ba04083d2c

@ -1,6 +1,6 @@
[package]
name = "mediarepo-api"
version = "0.11.1"
version = "0.12.0"
edition = "2018"
license = "gpl-3"
@ -10,7 +10,7 @@ license = "gpl-3"
tracing = "0.1.29"
thiserror = "1.0.30"
async-trait = {version = "0.1.51", optional=true}
rmp-ipc = {version = "0.10.0", optional=true}
rmp-ipc = {version = "0.11.0", optional=true}
parking_lot = {version="0.11.2", optional=true}
serde_json = {version="1.0.68", optional=true}
directories = {version="4.0.1", optional=true}

@ -32,6 +32,7 @@ fn build_uri_runtime() -> PluginResult<TokioRuntime> {
Ok(runtime)
}
#[tracing::instrument(level = "debug", skip_all)]
fn once_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let buf_state = app.state::<BufferState>();
let resource_key = request.uri().trim_start_matches("once://");
@ -51,17 +52,20 @@ fn once_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Resp
}
}
#[tracing::instrument(level = "debug", skip_all)]
async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let api_state = app.state::<ApiState>();
let buf_state = app.state::<BufferState>();
let hash = request.uri().trim_start_matches("content://");
if let Some(buffer) = buf_state.get_entry(hash) {
tracing::debug!("Fetching content from cache");
ResponseBuilder::new()
.status(200)
.mimetype(&buffer.mime)
.body(buffer.buf)
} else {
tracing::debug!("Fetching content from daemon");
let api = api_state.api().await?;
let file = api
.file
@ -72,6 +76,7 @@ async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Re
.file
.read_file(FileIdentifier::Hash(hash.to_string()))
.await?;
tracing::debug!("Received {} content bytes", bytes.len());
buf_state.add_entry(hash.to_string(), mime.clone(), bytes.clone());
ResponseBuilder::new()
.mimetype(&mime)
@ -80,6 +85,7 @@ async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Re
}
}
#[tracing::instrument(level = "debug", skip_all)]
async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let api_state = app.state::<ApiState>();
let buf_state = app.state::<BufferState>();
@ -104,11 +110,13 @@ async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Resu
.unwrap_or(250);
if let Some(buffer) = buf_state.get_entry(request.uri()) {
tracing::debug!("Fetching content from cache");
ResponseBuilder::new()
.status(200)
.mimetype(&buffer.mime)
.body(buffer.buf)
} else {
tracing::debug!("Fetching content from daemon");
let api = api_state.api().await?;
let (thumb, bytes) = api
.file
@ -118,6 +126,7 @@ async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Resu
((height as f32 * 1.2) as u32, (width as f32 * 1.2) as u32),
)
.await?;
tracing::debug!("Received {} content bytes", bytes.len());
buf_state.add_entry(
request.uri().to_string(),
thumb.mime_type.clone(),

Loading…
Cancel
Save