Expose socket types

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 33c753b135
commit 957e618d84

@ -5,6 +5,15 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "mediarepo"
path = "src/main.rs"
[lib]
name = "mediarepo"
crate-type = ["lib"]
[dependencies]
toml = "0.5.8"
structopt = "0.3.23"

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialOrd, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, PartialEq)]
pub enum FileType {
Unknown = 0,
Image = 1,

@ -1,13 +1,17 @@
use crate::types::file_response::FileResponse;
use crate::types::requests::AddFileRequest;
use crate::types::responses::FileResponse;
use mediarepo_model::type_keys::RepoKey;
use rmp_ipc::context::Context;
use rmp_ipc::error::Result;
use rmp_ipc::{Event, NamespaceBuilder};
use std::path::PathBuf;
pub const FILES_NAMESPACE: &str = "files";
pub fn build(builder: NamespaceBuilder) -> NamespaceBuilder {
builder.on("all_files", |c, e| Box::pin(all_files(c, e)))
builder
.on("all_files", |c, e| Box::pin(all_files(c, e)))
.on("add_file", |c, e| Box::pin(add_file(c, e)))
}
/// Returns a list of all files
@ -24,3 +28,24 @@ async fn all_files(ctx: &Context, event: Event) -> Result<()> {
Ok(())
}
/// Adds a file to the repository
async fn add_file(ctx: &Context, event: Event) -> Result<()> {
let request = event.data::<AddFileRequest>()?;
let path = PathBuf::from(request.path);
let file = {
let data = ctx.data.read().await;
let repo = data.get::<RepoKey>().unwrap();
repo.add_file_by_path(path).await?
};
ctx.emitter
.emit_response_to(
event.id(),
FILES_NAMESPACE,
"add_file",
FileResponse::from(file),
)
.await?;
Ok(())
}

@ -1 +1,2 @@
pub mod file_response;
pub mod requests;
pub mod responses;

@ -0,0 +1,6 @@
use serde::Deserialize;
#[derive(Deserialize)]
pub struct AddFileRequest {
pub path: String,
}

@ -1,9 +1,9 @@
use chrono::NaiveDateTime;
use mediarepo_model::file::File;
use mediarepo_model::file_type::FileType;
use serde::{Deserialize, Serialize};
use serde::Serialize;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize)]
pub struct FileResponse {
pub name: Option<String>,
pub comment: Option<String>,

@ -0,0 +1 @@
pub use mediarepo_socket::types::*;
Loading…
Cancel
Save