parent
216120ca1d
commit
33c753b135
File diff suppressed because it is too large
Load Diff
@ -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 {
|
||||
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;
|
||||
|
||||
pub mod files;
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub mod file_response;
|
Loading…
Reference in New Issue