Fix fetching of raw byte payloads for read_file and read_thumbnail

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 02653bdae8
commit 7e8b244018

@ -6,6 +6,7 @@ use crate::types::files::{
}; };
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use async_trait::async_trait; use async_trait::async_trait;
use rmp_ipc::payload::{BytePayload, EventSendPayload};
use rmp_ipc::prelude::Context; use rmp_ipc::prelude::Context;
#[derive(Clone)] #[derive(Clone)]
@ -54,13 +55,16 @@ impl FileApi {
/// Reads the file and returns its contents as bytes /// Reads the file and returns its contents as bytes
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub async fn read_file_by_hash(&self, hash: String) -> ApiResult<Vec<u8>> { pub async fn read_file_by_hash(&self, hash: String) -> ApiResult<Vec<u8>> {
self.emit_and_get( let payload: BytePayload = self
"read_file", .emit_and_get(
ReadFileRequest { "read_file",
id: FileIdentifier::Hash(hash), ReadFileRequest {
}, id: FileIdentifier::Hash(hash),
) },
.await )
.await?;
Ok(payload.to_payload_bytes()?)
} }
/// Returns a list of all thumbnails of the file /// 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 /// Reads the thumbnail of the file and returns its contents in bytes
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub async fn read_thumbnail(&self, hash: String) -> ApiResult<Vec<u8>> { pub async fn read_thumbnail(&self, hash: String) -> ApiResult<Vec<u8>> {
self.emit_and_get("read_thumbnail", hash).await let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?;
Ok(payload.to_payload_bytes()?)
} }
} }

Loading…
Cancel
Save