From 7e8b2440183495f4518c58bb7f9fb451688f24ee Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 24 Oct 2021 13:37:42 +0200 Subject: [PATCH] Fix fetching of raw byte payloads for read_file and read_thumbnail Signed-off-by: trivernis --- mediarepo-api/src/client_api/file.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index 5ffc039..52033d3 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -6,6 +6,7 @@ use crate::types::files::{ }; use crate::types::identifier::FileIdentifier; use async_trait::async_trait; +use rmp_ipc::payload::{BytePayload, EventSendPayload}; use rmp_ipc::prelude::Context; #[derive(Clone)] @@ -54,13 +55,16 @@ impl FileApi { /// Reads the file and returns its contents as bytes #[tracing::instrument(level = "debug", skip(self))] pub async fn read_file_by_hash(&self, hash: String) -> ApiResult> { - self.emit_and_get( - "read_file", - ReadFileRequest { - id: FileIdentifier::Hash(hash), - }, - ) - .await + let payload: BytePayload = self + .emit_and_get( + "read_file", + ReadFileRequest { + id: FileIdentifier::Hash(hash), + }, + ) + .await?; + + Ok(payload.to_payload_bytes()?) } /// Returns a list of all thumbnails of the file @@ -81,6 +85,7 @@ impl FileApi { /// Reads the thumbnail of the file and returns its contents in bytes #[tracing::instrument(level = "debug", skip(self))] pub async fn read_thumbnail(&self, hash: String) -> ApiResult> { - self.emit_and_get("read_thumbnail", hash).await + let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?; + Ok(payload.to_payload_bytes()?) } }