Use mediarepo-api for api types and remove lib config
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
215da027ea
commit
9fde0f08e2
@ -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,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 +0,0 @@
|
||||
pub use mediarepo_socket::types::*;
|
Loading…
Reference in New Issue