Merge branch 'develop'

pull/4/head
trivernis 3 years ago
commit 7cf30cbfa1

@ -838,6 +838,17 @@ dependencies = [
"tracing-subscriber 0.2.25",
]
[[package]]
name = "mediarepo-api"
version = "0.1.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=af90986e88cc4ef7d797ecc9cfd0c306b2d4c7cd#af90986e88cc4ef7d797ecc9cfd0c306b2d4c7cd"
dependencies = [
"chrono",
"serde",
"thiserror",
"tracing",
]
[[package]]
name = "mediarepo-core"
version = "0.1.0"
@ -888,6 +899,7 @@ name = "mediarepo-socket"
version = "0.1.0"
dependencies = [
"chrono",
"mediarepo-api",
"mediarepo-core",
"mediarepo-model",
"serde",

@ -12,18 +12,14 @@ repository = "https://github.com/Trivernis/mediarepo-daemon"
name = "mediarepo"
path = "src/main.rs"
[lib]
name = "mediarepo"
crate-type = ["lib"]
[dependencies]
tracing = "0.1.29"
toml = {version = "0.5.8", optional=true}
structopt = {version="0.3.23", optional=true}
glob = {version="0.3.0", optional=true}
log = {version="0.4.14", optional=true}
tracing-flame = {version = "0.1.0", optional=true}
tracing-appender = {version="0.2.0", optional=true}
toml = "0.5.8"
structopt ="0.3.23"
glob = "0.3.0"
log = "0.4.14"
tracing-flame = "0.1.0"
tracing-appender = "0.2.0"
[dependencies.mediarepo-core]
@ -31,11 +27,9 @@ path = "./mediarepo-core"
[dependencies.mediarepo-model]
path = "./mediarepo-model"
optional=true
[dependencies.mediarepo-socket]
path = "./mediarepo-socket"
optional=true
[dependencies.tokio]
version = "1.12.0"
@ -43,21 +37,4 @@ features = ["macros", "rt-multi-thread", "io-std", "io-util"]
[dependencies.tracing-subscriber]
version="0.2.3"
optional=true
features = ["env-filter"]
[features]
default = ["runtime"]
runtime = [
"toml",
"structopt",
"mediarepo-model",
"mediarepo-socket",
"tracing-subscriber",
"log",
"glob",
"tracing-flame",
"tracing-appender"
]
library = ["mediarepo-socket"]

@ -761,6 +761,17 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "mediarepo-api"
version = "0.1.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=af90986e88cc4ef7d797ecc9cfd0c306b2d4c7cd#af90986e88cc4ef7d797ecc9cfd0c306b2d4c7cd"
dependencies = [
"chrono",
"serde",
"thiserror",
"tracing",
]
[[package]]
name = "mediarepo-core"
version = "0.1.0"
@ -811,6 +822,7 @@ name = "mediarepo-socket"
version = "0.1.0"
dependencies = [
"chrono",
"mediarepo-api",
"mediarepo-core",
"mediarepo-model",
"serde",

@ -26,3 +26,7 @@ features = ["serde"]
[dependencies.tracing-futures]
version = "0.2.5"
features = ["tokio-executor"]
[dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "af90986e88cc4ef7d797ecc9cfd0c306b2d4c7cd"

@ -0,0 +1,47 @@
use mediarepo_api::types::files::{FileMetadataResponse, ThumbnailMetadataResponse};
use mediarepo_api::types::tags::TagResponse;
use mediarepo_model::file::File;
use mediarepo_model::tag::Tag;
use mediarepo_model::thumbnail::Thumbnail;
pub trait FromModel<M> {
fn from_model(model: M) -> Self;
}
impl FromModel<File> for FileMetadataResponse {
fn from_model(file: File) -> Self {
Self {
id: file.id(),
name: file.name().to_owned(),
comment: file.comment().to_owned(),
hash: file.hash().to_owned(),
file_type: file.file_type() as u32,
mime_type: file.mime_type().to_owned(),
creation_time: file.creation_time().to_owned(),
change_time: file.change_time().to_owned(),
import_time: file.import_time().to_owned(),
}
}
}
impl FromModel<Tag> for TagResponse {
fn from_model(model: Tag) -> Self {
Self {
id: model.id(),
namespace: model.namespace().map(|n| n.name().to_owned()),
name: model.name().to_owned(),
}
}
}
impl FromModel<Thumbnail> for ThumbnailMetadataResponse {
fn from_model(model: Thumbnail) -> Self {
Self {
id: model.id(),
hash: model.hash().to_owned(),
height: model.height(),
width: model.width(),
mime_type: model.mime_type().to_owned(),
}
}
}

@ -1,8 +1,8 @@
use crate::types::responses::InfoResponse;
use mediarepo_api::types::misc::InfoResponse;
use mediarepo_core::rmp_ipc::prelude::*;
mod from_model;
mod namespaces;
pub mod types;
mod utils;
pub fn get_builder(address: &str) -> IPCBuilder {

@ -1,8 +1,9 @@
use crate::types::requests::{
AddFileRequest, FindFilesByTagsRequest, GetFileThumbnailsRequest, ReadFileRequest,
};
use crate::types::responses::{FileResponse, ThumbnailResponse};
use crate::from_model::FromModel;
use crate::utils::{file_by_identifier, get_repo_from_context};
use mediarepo_api::types::files::{
AddFileRequest, FileMetadataResponse, FindFilesByTagsRequest, GetFileThumbnailsRequest,
ReadFileRequest, ThumbnailMetadataResponse,
};
use mediarepo_core::error::RepoError;
use mediarepo_core::rmp_ipc::prelude::*;
use std::path::PathBuf;
@ -33,7 +34,10 @@ impl FilesNamespace {
async fn all_files(ctx: &Context, event: Event) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await;
let files = repo.files().await?;
let responses: Vec<FileResponse> = files.into_iter().map(FileResponse::from).collect();
let responses: Vec<FileMetadataResponse> = files
.into_iter()
.map(FileMetadataResponse::from_model)
.collect();
ctx.emitter
.emit_response_to(event.id(), Self::name(), "all_files", responses)
@ -47,8 +51,12 @@ impl FilesNamespace {
async fn find_files(ctx: &Context, event: Event) -> IPCResult<()> {
let tags = event.data::<FindFilesByTagsRequest>()?;
let repo = get_repo_from_context(ctx).await;
let files = repo.find_files_by_tags(tags.tags).await?;
let responses: Vec<FileResponse> = files.into_iter().map(FileResponse::from).collect();
let tags = tags.tags.into_iter().map(|t| t.name).collect();
let files = repo.find_files_by_tags(tags).await?;
let responses: Vec<FileMetadataResponse> = files
.into_iter()
.map(FileMetadataResponse::from_model)
.collect();
ctx.emitter
.emit_response_to(event.id(), Self::name(), "find_files", responses)
.await?;
@ -68,7 +76,7 @@ impl FilesNamespace {
event.id(),
Self::name(),
"add_file",
FileResponse::from(file),
FileMetadataResponse::from_model(file),
)
.await?;
@ -81,7 +89,7 @@ impl FilesNamespace {
let request = event.data::<ReadFileRequest>()?;
let repo = get_repo_from_context(ctx).await;
let file = file_by_identifier(request, &repo).await?;
let file = file_by_identifier(request.id, &repo).await?;
let mut reader = file.get_reader().await?;
let mut buf = Vec::new();
reader.read_to_end(&mut buf).await?;
@ -98,12 +106,12 @@ impl FilesNamespace {
async fn thumbnails(ctx: &Context, event: Event) -> IPCResult<()> {
let request = event.data::<GetFileThumbnailsRequest>()?;
let repo = get_repo_from_context(ctx).await;
let file = file_by_identifier(request, &repo).await?;
let file = file_by_identifier(request.id, &repo).await?;
let thumbnails = file.thumbnails().await?;
let thumb_responses: Vec<ThumbnailResponse> = thumbnails
let thumb_responses: Vec<ThumbnailMetadataResponse> = thumbnails
.into_iter()
.map(ThumbnailResponse::from)
.map(ThumbnailMetadataResponse::from_model)
.collect();
ctx.emitter
.emit_response_to(event.id(), Self::name(), "get_thumbnails", thumb_responses)

@ -1,6 +1,7 @@
use crate::types::requests::GetFileTagsRequest;
use crate::types::responses::TagResponse;
use crate::from_model::FromModel;
use crate::utils::{file_by_identifier, get_repo_from_context};
use mediarepo_api::types::files::GetFileTagsRequest;
use mediarepo_api::types::tags::TagResponse;
use mediarepo_core::rmp_ipc::prelude::*;
pub struct TagsNamespace;
@ -27,7 +28,7 @@ impl TagsNamespace {
.tags()
.await?
.into_iter()
.map(TagResponse::from)
.map(TagResponse::from_model)
.collect();
ctx.emitter
.emit_response_to(event.id(), Self::name(), "all_tags", tags)
@ -41,9 +42,9 @@ impl TagsNamespace {
async fn tags_for_file(ctx: &Context, event: Event) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await;
let request = event.data::<GetFileTagsRequest>()?;
let file = file_by_identifier(request, &repo).await?;
let file = file_by_identifier(request.id, &repo).await?;
let tags = file.tags().await?;
let responses: Vec<TagResponse> = tags.into_iter().map(TagResponse::from).collect();
let responses: Vec<TagResponse> = tags.into_iter().map(TagResponse::from_model).collect();
ctx.emitter
.emit_response_to(event.id(), Self::name(), "tags_for_file", responses)

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

@ -1,21 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct AddFileRequest {
pub path: String,
}
#[derive(Serialize, Deserialize)]
pub enum FileIdentifier {
ID(i64),
Hash(String),
}
pub type ReadFileRequest = FileIdentifier;
pub type GetFileThumbnailsRequest = FileIdentifier;
pub type GetFileTagsRequest = FileIdentifier;
#[derive(Serialize, Deserialize)]
pub struct FindFilesByTagsRequest {
pub tags: Vec<String>,
}

@ -1,75 +0,0 @@
use chrono::NaiveDateTime;
use mediarepo_model::file::File;
use mediarepo_model::file_type::FileType;
use mediarepo_model::tag::Tag;
use mediarepo_model::thumbnail::Thumbnail;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FileResponse {
pub name: Option<String>,
pub comment: Option<String>,
pub hash: String,
pub file_type: FileType,
pub mime_type: Option<String>,
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(),
mime_type: file.mime_type().clone(),
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(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ThumbnailResponse {
hash: String,
height: i32,
width: i32,
mime: Option<String>,
}
impl From<Thumbnail> for ThumbnailResponse {
fn from(thumb: Thumbnail) -> Self {
Self {
hash: thumb.hash().to_owned(),
height: thumb.height(),
width: thumb.width(),
mime: thumb.mime_type().to_owned(),
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct InfoResponse {
pub name: String,
pub version: String,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct TagResponse {
pub id: i64,
pub name: String,
pub namespace: Option<String>,
}
impl From<Tag> for TagResponse {
fn from(tag: Tag) -> Self {
Self {
id: tag.id(),
name: tag.name().to_owned(),
namespace: tag.namespace().map(|n| n.name().to_owned()),
}
}
}

@ -1,4 +1,4 @@
use crate::types::requests::FileIdentifier;
use mediarepo_api::types::identifier::FileIdentifier;
use mediarepo_core::error::{RepoError, RepoResult};
use mediarepo_core::rmp_ipc::ipc::context::Context;
use mediarepo_model::file::File;

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