Add all_files event

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

@ -219,6 +219,7 @@ dependencies = [
"libc", "libc",
"num-integer", "num-integer",
"num-traits", "num-traits",
"serde",
"time", "time",
"winapi", "winapi",
] ]
@ -714,6 +715,7 @@ dependencies = [
"mediarepo-core", "mediarepo-core",
"mediarepo-database", "mediarepo-database",
"sea-orm", "sea-orm",
"serde",
"tokio", "tokio",
"typemap_rev", "typemap_rev",
] ]
@ -722,7 +724,11 @@ dependencies = [
name = "mediarepo-socket" name = "mediarepo-socket"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"mediarepo-core",
"mediarepo-model",
"rmp-ipc", "rmp-ipc",
"serde",
"tokio", "tokio",
] ]

@ -1,3 +1,4 @@
use rmp_ipc::error::Error;
use sea_orm::DbErr; use sea_orm::DbErr;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use thiserror::Error; use thiserror::Error;
@ -66,3 +67,9 @@ impl From<&str> for RepoError {
Self::Raw(StringError(s.to_string())) Self::Raw(StringError(s.to_string()))
} }
} }
impl From<RepoError> for rmp_ipc::error::Error {
fn from(e: RepoError) -> Error {
rmp_ipc::error::Error::Message(format!("{:?}", e))
}
}

@ -667,6 +667,7 @@ dependencies = [
"mediarepo-core", "mediarepo-core",
"mediarepo-database", "mediarepo-database",
"sea-orm", "sea-orm",
"serde",
"tokio", "tokio",
"typemap_rev", "typemap_rev",
] ]

@ -8,6 +8,7 @@ edition = "2018"
[dependencies] [dependencies]
chrono = "0.4.19" chrono = "0.4.19"
typemap_rev = "0.1.5" typemap_rev = "0.1.5"
serde = "1.0.130"
[dependencies.mediarepo-core] [dependencies.mediarepo-core]
path = "../mediarepo-core" path = "../mediarepo-core"

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

File diff suppressed because it is too large Load Diff

@ -7,7 +7,19 @@ edition = "2018"
[dependencies] [dependencies]
rmp-ipc = "0.4.1" rmp-ipc = "0.4.1"
serde = "1.0.130"
[dependencies.mediarepo-core]
path = "../mediarepo-core"
[dependencies.mediarepo-model]
path = "../mediarepo-model"
[dependencies.tokio] [dependencies.tokio]
version = "1.12.0" version = "1.12.0"
features = ["net"] features = ["net"]
[dependencies.chrono]
version = "0.4.19"
features = ["serde"]

@ -1,5 +1,26 @@
use rmp_ipc::NamespaceBuilder; use crate::types::file_response::FileResponse;
use mediarepo_model::type_keys::RepoKey;
use rmp_ipc::context::Context;
use rmp_ipc::error::Result;
use rmp_ipc::{Event, NamespaceBuilder};
pub const FILES_NAMESPACE: &str = "files";
pub fn build(builder: NamespaceBuilder) -> NamespaceBuilder { pub fn build(builder: NamespaceBuilder) -> NamespaceBuilder {
builder builder.on("all_files", |c, e| Box::pin(all_files(c, e)))
}
/// Returns a list of all files
async fn all_files(ctx: &Context, event: Event) -> Result<()> {
let files = {
let data = ctx.data.read().await;
let repo = data.get::<RepoKey>().unwrap();
repo.files().await?
};
let responses: Vec<FileResponse> = files.into_iter().map(FileResponse::from).collect();
ctx.emitter
.emit_response_to(event.id(), FILES_NAMESPACE, "all_files", responses)
.await?;
Ok(())
} }

@ -1,9 +1,10 @@
use crate::namespaces::files::FILES_NAMESPACE;
use rmp_ipc::IPCBuilder; use rmp_ipc::IPCBuilder;
pub mod files; pub mod files;
pub fn build_namespaces(builder: IPCBuilder) -> IPCBuilder { pub fn build_namespaces(builder: IPCBuilder) -> IPCBuilder {
let builder = files::build(builder.namespace("files")).build(); let builder = files::build(builder.namespace(FILES_NAMESPACE)).build();
builder builder
} }

@ -0,0 +1,29 @@
use chrono::NaiveDateTime;
use mediarepo_model::file::File;
use mediarepo_model::file_type::FileType;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FileResponse {
pub name: Option<String>,
pub comment: Option<String>,
pub hash: String,
pub file_type: FileType,
pub creation_time: NaiveDateTime,
pub change_time: NaiveDateTime,
pub import_time: NaiveDateTime,
}
impl From<File> for FileResponse {
fn from(file: File) -> Self {
FileResponse {
hash: file.hash().to_owned(),
file_type: file.file_type(),
name: file.name().to_owned(),
creation_time: file.creation_time().to_owned(),
change_time: file.change_time().to_owned(),
import_time: file.import_time().to_owned(),
comment: file.comment().to_owned(),
}
}
}
Loading…
Cancel
Save