Add command to get thumbnails of a specific size

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 89bf781bd9
commit 5f14077fed

@ -26,9 +26,12 @@ impl AsyncStreamProtocolListener for ApiProtocolListener {
type RemoteAddressType = String;
type Stream = ApiProtocolStream;
#[tracing::instrument]
async fn protocol_bind(address: Self::AddressType) -> Result<Self> {
if let Some(addr) = address.to_socket_addrs().ok().and_then(|mut a| a.next()) {
let listener = TcpListener::bind(addr).await?;
tracing::info!("Connecting via TCP");
Ok(Self::Tcp(listener))
} else {
#[cfg(unix)]
@ -37,6 +40,7 @@ impl AsyncStreamProtocolListener for ApiProtocolListener {
use tokio::net::UnixListener;
let path = PathBuf::from(address);
let listener = UnixListener::bind(path)?;
tracing::info!("Connecting via unix domain socket");
Ok(Self::UnixSocket(listener))
}

@ -71,6 +71,29 @@ pub async fn read_thumbnail(
}
}
#[tauri::command]
pub async fn get_thumbnail_of_size(
api_state: ApiAccess<'_>,
buffer_state: BufferAccess<'_>,
file_id: i64,
min_size: (u32, u32),
max_size: (u32, u32),
) -> PluginResult<String> {
let api = api_state.api().await?;
let (thumb, data) = api
.file
.get_thumbnail_of_size(FileIdentifier::ID(file_id), min_size, max_size)
.await?;
let uri = add_once_buffer(
buffer_state,
thumb.hash,
thumb.mime_type.unwrap_or(String::from("image/png")),
data,
);
Ok(uri)
}
#[tauri::command]
pub async fn update_file_name(
api_state: ApiAccess<'_>,

@ -34,6 +34,7 @@ impl<R: Runtime> MediarepoPlugin<R> {
read_file_by_hash,
get_file_thumbnails,
read_thumbnail,
get_thumbnail_of_size,
get_repositories,
get_all_tags,
get_tags_for_file,
@ -85,7 +86,7 @@ impl<R: Runtime> Plugin<R> for MediarepoPlugin<R> {
Ok(())
}
#[tracing::instrument(skip_all)]
#[tracing::instrument(level = "trace", skip_all)]
fn extend_api(&mut self, message: Invoke<R>) {
(self.invoke_handler)(message)
}

Loading…
Cancel
Save