Fix compile errors and add api client

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

@ -9,7 +9,6 @@ license = "gpl-3"
[dependencies] [dependencies]
tracing = "0.1.29" tracing = "0.1.29"
thiserror = "1.0.30" thiserror = "1.0.30"
chrono = "0.4.19"
rmp-ipc = {version = "0.7.2", optional=true} rmp-ipc = {version = "0.7.2", optional=true}
tauri = {version = "1.0.0-beta.8", optional=true} tauri = {version = "1.0.0-beta.8", optional=true}
@ -17,5 +16,10 @@ tauri = {version = "1.0.0-beta.8", optional=true}
version = "1.0.130" version = "1.0.130"
features = ["serde_derive"] features = ["serde_derive"]
[dependencies.chrono]
version = "0.4.19"
features = ["serde"]
[features] [features]
tauri-plugin = ["tauri", "rmp-ipc"] tauri-plugin = ["client-api","tauri", "rmp-ipc"]
client-api = ["rmp-ipc"]

@ -0,0 +1,9 @@
use thiserror::Error;
pub type ApiResult<T> = Result<T, ApiError>;
#[derive(Debug, Error)]
pub enum ApiError {
#[error(transparent)]
IPC(#[from] rmp_ipc::error::Error)
}

@ -0,0 +1,24 @@
pub mod error;
use rmp_ipc::ipc::context::Context;
use rmp_ipc::IPCBuilder;
use crate::client_api::error::ApiResult;
#[derive(Clone)]
pub struct ApiClient {
ctx: Context,
}
impl ApiClient {
/// Creates a new client from an existing ipc context
pub fn new(ctx: Context) -> Self {
Self {ctx}
}
/// Connects to the ipc Socket
pub async fn connect(address: &str) -> ApiResult<Self> {
let ctx = IPCBuilder::new().address(address).build_client().await?;
Ok(Self::new(ctx))
}
}

@ -1,4 +1,7 @@
pub mod types; pub mod types;
#[cfg(feature = "client-api")]
pub mod client_api;
#[cfg(feature = "tauri-plugin")] #[cfg(feature = "tauri-plugin")]
pub mod tauri_plugin; pub mod tauri_plugin;

@ -1,3 +1,4 @@
use serde::{Serialize, Deserialize};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
@ -48,7 +49,7 @@ pub struct FileMetadataResponse {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ThumbnailMetadataResponse { pub struct ThumbnailMetadataResponse {
pub id: i64, pub id: i64,
pub hash: Strin, pub hash: String,
pub height: i32, pub height: i32,
pub width: i32, pub width: i32,
pub mime_type: Option<String>, pub mime_type: Option<String>,

@ -1,3 +1,5 @@
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum FileIdentifier { pub enum FileIdentifier {
ID(i64), ID(i64),

@ -1,3 +1,5 @@
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct InfoResponse { pub struct InfoResponse {
pub name: String, pub name: String,

@ -1,3 +1,5 @@
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TagResponse { pub struct TagResponse {
pub id: i64, pub id: i64,

Loading…
Cancel
Save