From acdad7ac7e1fb0410e21a453398720cfdfb1bc6d Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 29 Jan 2022 20:40:15 +0100 Subject: [PATCH] Fix warnings Signed-off-by: trivernis --- .../mediarepo-core/src/content_descriptor.rs | 3 +- .../mediarepo-core/src/context.rs | 6 ++- mediarepo-daemon/mediarepo-core/src/error.rs | 3 +- .../mediarepo-core/src/fs/drop_file.rs | 1 + .../mediarepo-core/src/fs/file_hash_store.rs | 8 ++-- .../mediarepo-core/src/fs/thumbnail_store.rs | 6 ++- .../mediarepo-core/src/settings/mod.rs | 18 ++++---- .../mediarepo-core/src/settings/paths.rs | 3 +- .../mediarepo-core/src/settings/server.rs | 3 +- .../mediarepo-core/src/settings/v1.rs | 6 ++- .../mediarepo-core/src/type_keys.rs | 6 ++- mediarepo-daemon/mediarepo-core/src/utils.rs | 6 ++- .../mediarepo-database/src/lib.rs | 6 ++- .../mediarepo-database/src/queries/tags.rs | 10 +++-- .../mediarepo-logic/src/dao/file/add.rs | 10 +++-- .../mediarepo-logic/src/dao/file/delete.rs | 12 ++--- .../mediarepo-logic/src/dao/file/find.rs | 12 ++--- .../mediarepo-logic/src/dao/file/mod.rs | 10 +++-- .../mediarepo-logic/src/dao/file/update.rs | 18 ++++---- .../mediarepo-logic/src/dao/job/mod.rs | 14 +++--- .../mediarepo-logic/src/dao/mod.rs | 16 ++++--- .../mediarepo-logic/src/dao/repo/mod.rs | 45 ++++++++++--------- .../mediarepo-logic/src/dao/tag/mappings.rs | 10 +++-- .../mediarepo-logic/src/dao/tag/mod.rs | 14 +++--- .../mediarepo-logic/src/dto/file.rs | 4 +- .../mediarepo-logic/src/dto/file_metadata.rs | 1 + .../mediarepo-logic/src/dto/mod.rs | 11 ++--- .../mediarepo-logic/src/dto/tag.rs | 7 +-- .../mediarepo-logic/src/dto/thumbnail.rs | 6 ++- .../mediarepo-logic/src/namespace.rs | 10 +++-- mediarepo-daemon/mediarepo-logic/src/tag.rs | 11 ++--- .../mediarepo-logic/src/type_keys.rs | 4 +- mediarepo-daemon/mediarepo-socket/src/lib.rs | 12 ++--- .../src/namespaces/files/mod.rs | 16 ++++--- .../src/namespaces/files/searching.rs | 7 +-- .../src/namespaces/files/sorting.rs | 14 +++--- .../mediarepo-socket/src/namespaces/jobs.rs | 3 +- .../mediarepo-socket/src/namespaces/tags.rs | 8 ++-- .../mediarepo-socket/src/utils.rs | 8 ++-- mediarepo-daemon/src/logging.rs | 15 ++++--- mediarepo-daemon/src/main.rs | 6 +-- mediarepo-daemon/src/utils.rs | 8 ++-- 42 files changed, 233 insertions(+), 164 deletions(-) diff --git a/mediarepo-daemon/mediarepo-core/src/content_descriptor.rs b/mediarepo-daemon/mediarepo-core/src/content_descriptor.rs index 73c1ea3..e89f47e 100644 --- a/mediarepo-daemon/mediarepo-core/src/content_descriptor.rs +++ b/mediarepo-daemon/mediarepo-core/src/content_descriptor.rs @@ -1,6 +1,7 @@ -use crate::error::RepoResult; use multihash::{Code, MultihashDigest}; +use crate::error::RepoResult; + /// Creates a new content descriptor for the given file pub fn create_content_descriptor(bytes: &[u8]) -> Vec { Code::Sha2_256.digest(bytes).to_bytes() diff --git a/mediarepo-daemon/mediarepo-core/src/context.rs b/mediarepo-daemon/mediarepo-core/src/context.rs index cc3e52d..77b1e0f 100644 --- a/mediarepo-daemon/mediarepo-core/src/context.rs +++ b/mediarepo-daemon/mediarepo-core/src/context.rs @@ -1,8 +1,10 @@ -use crate::settings::Settings; -use sea_orm::DatabaseConnection; use std::sync::Arc; + +use sea_orm::DatabaseConnection; use tokio::sync::Mutex; +use crate::settings::Settings; + #[derive(Clone, Default)] pub struct Context { pub settings: Arc>, diff --git a/mediarepo-daemon/mediarepo-core/src/error.rs b/mediarepo-daemon/mediarepo-core/src/error.rs index b3e1d82..820e854 100644 --- a/mediarepo-daemon/mediarepo-core/src/error.rs +++ b/mediarepo-daemon/mediarepo-core/src/error.rs @@ -1,5 +1,6 @@ -use sea_orm::DbErr; use std::fmt::{Debug, Formatter}; + +use sea_orm::DbErr; use thiserror::Error; pub type RepoResult = Result; diff --git a/mediarepo-daemon/mediarepo-core/src/fs/drop_file.rs b/mediarepo-daemon/mediarepo-core/src/fs/drop_file.rs index 53fb266..ee6bdb3 100644 --- a/mediarepo-daemon/mediarepo-core/src/fs/drop_file.rs +++ b/mediarepo-daemon/mediarepo-core/src/fs/drop_file.rs @@ -1,5 +1,6 @@ use std::io::Result; use std::path::{Path, PathBuf}; + use tokio::fs::{File, OpenOptions}; /// A file that only exists while being owned. diff --git a/mediarepo-daemon/mediarepo-core/src/fs/file_hash_store.rs b/mediarepo-daemon/mediarepo-core/src/fs/file_hash_store.rs index b23fcf7..71034dc 100644 --- a/mediarepo-daemon/mediarepo-core/src/fs/file_hash_store.rs +++ b/mediarepo-daemon/mediarepo-core/src/fs/file_hash_store.rs @@ -1,11 +1,13 @@ -use crate::content_descriptor::{create_content_descriptor, encode_content_descriptor}; -use crate::error::RepoResult; -use crate::utils::get_folder_size; use std::path::PathBuf; + use tokio::fs; use tokio::fs::{File, OpenOptions}; use tokio::io::{AsyncRead, AsyncReadExt, BufReader}; +use crate::content_descriptor::{create_content_descriptor, encode_content_descriptor}; +use crate::error::RepoResult; +use crate::utils::get_folder_size; + #[derive(Clone, Debug)] pub struct FileHashStore { path: PathBuf, diff --git a/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs b/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs index 6a500ea..7b150c2 100644 --- a/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs +++ b/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs @@ -1,12 +1,14 @@ -use crate::error::RepoResult; -use crate::utils::get_folder_size; use std::fmt::Debug; use std::io::Result; use std::path::PathBuf; + use tokio::fs; use tokio::fs::OpenOptions; use tokio::io::{AsyncWriteExt, BufWriter}; +use crate::error::RepoResult; +use crate::utils::get_folder_size; + #[derive(Clone, Debug)] pub struct ThumbnailStore { path: PathBuf, diff --git a/mediarepo-daemon/mediarepo-core/src/settings/mod.rs b/mediarepo-daemon/mediarepo-core/src/settings/mod.rs index 329e32a..66a8960 100644 --- a/mediarepo-daemon/mediarepo-core/src/settings/mod.rs +++ b/mediarepo-daemon/mediarepo-core/src/settings/mod.rs @@ -1,19 +1,21 @@ -mod logging; -mod paths; -mod server; -pub mod v1; +use std::fs; +use std::path::PathBuf; -use crate::error::RepoResult; -use crate::settings::v1::SettingsV1; use config::{Config, FileFormat}; use serde::{Deserialize, Serialize}; -use std::fs; -use std::path::PathBuf; pub use logging::*; pub use paths::*; pub use server::*; +use crate::error::RepoResult; +use crate::settings::v1::SettingsV1; + +mod logging; +mod paths; +mod server; +pub mod v1; + #[derive(Clone, Debug, Deserialize, Serialize, Default)] pub struct Settings { pub server: ServerSettings, diff --git a/mediarepo-daemon/mediarepo-core/src/settings/paths.rs b/mediarepo-daemon/mediarepo-core/src/settings/paths.rs index 5e14e75..162e096 100644 --- a/mediarepo-daemon/mediarepo-core/src/settings/paths.rs +++ b/mediarepo-daemon/mediarepo-core/src/settings/paths.rs @@ -1,6 +1,7 @@ -use serde::{Deserialize, Serialize}; use std::path::PathBuf; +use serde::{Deserialize, Serialize}; + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PathSettings { pub(crate) database_directory: String, diff --git a/mediarepo-daemon/mediarepo-core/src/settings/server.rs b/mediarepo-daemon/mediarepo-core/src/settings/server.rs index c722a11..32de932 100644 --- a/mediarepo-daemon/mediarepo-core/src/settings/server.rs +++ b/mediarepo-daemon/mediarepo-core/src/settings/server.rs @@ -1,6 +1,7 @@ -use serde::{Deserialize, Serialize}; use std::net::IpAddr; +use serde::{Deserialize, Serialize}; + #[derive(Clone, Debug, Deserialize, Serialize, Default)] pub struct ServerSettings { pub tcp: TcpServerSettings, diff --git a/mediarepo-daemon/mediarepo-core/src/settings/v1.rs b/mediarepo-daemon/mediarepo-core/src/settings/v1.rs index ccbb35e..f14cb68 100644 --- a/mediarepo-daemon/mediarepo-core/src/settings/v1.rs +++ b/mediarepo-daemon/mediarepo-core/src/settings/v1.rs @@ -1,7 +1,9 @@ -use crate::error::RepoResult; -use serde::{Deserialize, Serialize}; use std::net::IpAddr; +use serde::{Deserialize, Serialize}; + +use crate::error::RepoResult; + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SettingsV1 { pub listen_address: IpAddr, diff --git a/mediarepo-daemon/mediarepo-core/src/type_keys.rs b/mediarepo-daemon/mediarepo-core/src/type_keys.rs index 5aa447d..8cebd2c 100644 --- a/mediarepo-daemon/mediarepo-core/src/type_keys.rs +++ b/mediarepo-daemon/mediarepo-core/src/type_keys.rs @@ -1,10 +1,12 @@ -use crate::settings::Settings; -use mediarepo_api::types::repo::SizeType; use std::collections::HashMap; use std::path::PathBuf; + +use mediarepo_api::types::repo::SizeType; use tokio_graceful_shutdown::SubsystemHandle; use typemap_rev::TypeMapKey; +use crate::settings::Settings; + pub struct SettingsKey; impl TypeMapKey for SettingsKey { diff --git a/mediarepo-daemon/mediarepo-core/src/utils.rs b/mediarepo-daemon/mediarepo-core/src/utils.rs index 609f7c2..4d901e8 100644 --- a/mediarepo-daemon/mediarepo-core/src/utils.rs +++ b/mediarepo-daemon/mediarepo-core/src/utils.rs @@ -1,9 +1,11 @@ -use crate::error::RepoResult; -use futures::future; use std::path::PathBuf; + +use futures::future; use tokio::fs::{self, OpenOptions}; use tokio::io::{AsyncBufReadExt, BufReader}; +use crate::error::RepoResult; + /// Parses a normalized tag into its two components of namespace and tag pub fn parse_namespace_and_tag(norm_tag: String) -> (Option, String) { norm_tag diff --git a/mediarepo-daemon/mediarepo-database/src/lib.rs b/mediarepo-daemon/mediarepo-database/src/lib.rs index ea5fb18..4e946a3 100644 --- a/mediarepo-daemon/mediarepo-database/src/lib.rs +++ b/mediarepo-daemon/mediarepo-database/src/lib.rs @@ -1,7 +1,9 @@ -use mediarepo_core::error::RepoDatabaseResult; +use std::time::Duration; + use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use sqlx::migrate::MigrateDatabase; -use std::time::Duration; + +use mediarepo_core::error::RepoDatabaseResult; pub mod entities; pub mod queries; diff --git a/mediarepo-daemon/mediarepo-database/src/queries/tags.rs b/mediarepo-daemon/mediarepo-database/src/queries/tags.rs index d3726c5..c901031 100644 --- a/mediarepo-daemon/mediarepo-database/src/queries/tags.rs +++ b/mediarepo-daemon/mediarepo-database/src/queries/tags.rs @@ -1,11 +1,13 @@ -use mediarepo_core::error::RepoResult; -use sea_orm::DbBackend; -use sea_orm::FromQueryResult; -use sea_orm::{DatabaseConnection, Statement}; use std::collections::HashMap; use std::fmt::Display; use std::iter::FromIterator; +use sea_orm::{DatabaseConnection, Statement}; +use sea_orm::DbBackend; +use sea_orm::FromQueryResult; + +use mediarepo_core::error::RepoResult; + #[derive(Debug, FromQueryResult)] struct CIDNamespaceTag { cd_id: i64, diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/file/add.rs b/mediarepo-daemon/mediarepo-logic/src/dao/file/add.rs index c89fb64..6bb93c8 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/file/add.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/file/add.rs @@ -1,12 +1,14 @@ -use crate::dto::{AddFileDto, FileDto}; +use std::io::Cursor; + use chrono::{Local, NaiveDateTime}; -use mediarepo_core::error::RepoResult; -use mediarepo_database::entities::{content_descriptor, file, file_metadata}; use sea_orm::ActiveValue::Set; use sea_orm::{ActiveModelTrait, ConnectionTrait, DatabaseTransaction}; -use std::io::Cursor; + +use mediarepo_core::error::RepoResult; +use mediarepo_database::entities::{content_descriptor, file, file_metadata}; use crate::dao::file::FileDao; +use crate::dto::{AddFileDto, FileDto}; impl FileDao { #[tracing::instrument(level = "debug", skip(self))] diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/file/delete.rs b/mediarepo-daemon/mediarepo-logic/src/dao/file/delete.rs index 337b7e7..81c914a 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/file/delete.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/file/delete.rs @@ -1,11 +1,13 @@ -use crate::dao::file::{map_file_and_cd, FileDao}; -use crate::dto::FileDto; -use mediarepo_core::error::{RepoError, RepoResult}; +use sea_orm::ConnectionTrait; +use sea_orm::prelude::*; + +use mediarepo_core::error::{RepoResult}; use mediarepo_database::entities::{ content_descriptor, content_descriptor_tag, file, file_metadata, }; -use sea_orm::prelude::*; -use sea_orm::ConnectionTrait; + +use crate::dao::file::{FileDao}; +use crate::dto::FileDto; impl FileDao { #[tracing::instrument(level = "debug", skip(self))] diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/file/find.rs b/mediarepo-daemon/mediarepo-logic/src/dao/file/find.rs index 2156063..f96457d 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/file/find.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/file/find.rs @@ -1,14 +1,16 @@ -use crate::dao::file::{map_cd_and_file, FileDao}; -use crate::dto::FileDto; use chrono::NaiveDateTime; +use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect}; +use sea_orm::Condition; +use sea_orm::sea_query::{Alias, Expr, Query, SimpleExpr}; + use mediarepo_core::error::RepoResult; use mediarepo_database::entities::content_descriptor; use mediarepo_database::entities::content_descriptor_tag; use mediarepo_database::entities::file; use mediarepo_database::entities::file_metadata; -use sea_orm::sea_query::{Alias, Expr, Query, SimpleExpr}; -use sea_orm::Condition; -use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect}; + +use crate::dao::file::{FileDao, map_cd_and_file}; +use crate::dto::FileDto; macro_rules! apply_ordering_comparator { ($column:expr, $filter:expr) => { diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/file/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/file/mod.rs index 3a601cb..210cf50 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/file/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/file/mod.rs @@ -1,10 +1,12 @@ -use crate::dao::{DaoContext, DaoProvider}; -use crate::dto::{FileDto, FileMetadataDto, ThumbnailDto}; -use mediarepo_core::error::RepoResult; -use mediarepo_database::entities::{content_descriptor, file, file_metadata}; use sea_orm::prelude::*; use tokio::io::AsyncReadExt; +use mediarepo_core::error::RepoResult; +use mediarepo_database::entities::{content_descriptor, file, file_metadata}; + +use crate::dao::{DaoContext, DaoProvider}; +use crate::dto::{FileDto, FileMetadataDto, ThumbnailDto}; + pub mod add; pub mod delete; pub mod find; diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/file/update.rs b/mediarepo-daemon/mediarepo-logic/src/dao/file/update.rs index 69b4b72..c143964 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/file/update.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/file/update.rs @@ -1,18 +1,20 @@ -use crate::dto::{FileDto, FileMetadataDto, ThumbnailDto, UpdateFileDto, UpdateFileMetadataDto}; +use std::fmt::Debug; +use std::io::Cursor; +use std::str::FromStr; + +use sea_orm::prelude::*; +use sea_orm::ActiveValue::{Set, Unchanged}; +use sea_orm::{ConnectionTrait, NotSet}; + use mediarepo_core::error::{RepoError, RepoResult}; use mediarepo_core::fs::thumbnail_store::Dimensions; use mediarepo_core::thumbnailer; -use mediarepo_core::thumbnailer::{Thumbnail, ThumbnailSize}; +use mediarepo_core::thumbnailer::{ThumbnailSize}; use mediarepo_database::entities::{content_descriptor, file, file_metadata}; -use sea_orm::prelude::*; -use sea_orm::ActiveValue::{Set, Unchanged}; -use sea_orm::{ConnectionTrait, NotSet}; -use std::fmt::Debug; -use std::io::Cursor; -use std::str::FromStr; use crate::dao::file::FileDao; use crate::dao::opt_to_active_val; +use crate::dto::{FileDto, FileMetadataDto, ThumbnailDto, UpdateFileDto, UpdateFileMetadataDto}; impl FileDao { #[tracing::instrument(level = "debug", skip(self))] diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/job/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/job/mod.rs index e69f477..1098fdb 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/job/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/job/mod.rs @@ -1,12 +1,14 @@ -use crate::dao::{DaoContext, DaoProvider}; +use sea_orm::ActiveValue::Set; +use sea_orm::ConnectionTrait; +use sea_orm::prelude::*; + use mediarepo_core::content_descriptor::{ convert_v1_descriptor_to_v2, encode_content_descriptor, is_v1_content_descriptor, }; use mediarepo_core::error::RepoResult; use mediarepo_database::entities::content_descriptor; -use sea_orm::prelude::*; -use sea_orm::ActiveValue::Set; -use sea_orm::ConnectionTrait; + +use crate::dao::{DaoContext, DaoProvider}; pub struct JobDao { ctx: DaoContext, @@ -30,13 +32,13 @@ impl JobDao { tracing::info!("Converting content descriptors to v2 format..."); let mut converted_count = 0; - for mut cd in cds { + for cd in cds { if is_v1_content_descriptor(&cd.descriptor) { let trx = self.ctx.db.begin().await?; let src_cd = cd.descriptor; let dst_cd = convert_v1_descriptor_to_v2(&src_cd)?; - let active_model = content_descriptor::ActiveModel { + let _active_model = content_descriptor::ActiveModel { id: Set(cd.id), descriptor: Set(dst_cd.clone()), }; diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/mod.rs index 38101a4..f3cf620 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/mod.rs @@ -1,14 +1,16 @@ -pub mod file; -pub mod job; -pub mod repo; -pub mod tag; +use sea_orm::{ActiveValue, DatabaseConnection}; + +use mediarepo_core::fs::file_hash_store::FileHashStore; +use mediarepo_core::fs::thumbnail_store::ThumbnailStore; use crate::dao::file::FileDao; use crate::dao::job::JobDao; use crate::dao::tag::TagDao; -use mediarepo_core::fs::file_hash_store::FileHashStore; -use mediarepo_core::fs::thumbnail_store::ThumbnailStore; -use sea_orm::{ActiveValue, DatabaseConnection}; + +pub mod file; +pub mod job; +pub mod repo; +pub mod tag; #[derive(Clone)] pub struct DaoContext { diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/repo/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/repo/mod.rs index af954b9..2954366 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/repo/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/repo/mod.rs @@ -1,29 +1,30 @@ -use crate::dao::{DaoContext, DaoProvider}; -use crate::file_metadata::FileMetadata; -use crate::namespace::Namespace; -use crate::tag::Tag; -use chrono::{Local, NaiveDateTime}; -use mediarepo_core::content_descriptor::{ - convert_v1_descriptor_to_v2, encode_content_descriptor, is_v1_content_descriptor, -}; -use mediarepo_core::error::{RepoError, RepoResult}; -use mediarepo_core::fs::file_hash_store::FileHashStore; -use mediarepo_core::fs::thumbnail_store::{Dimensions, ThumbnailStore}; -use mediarepo_core::itertools::Itertools; -use mediarepo_core::thumbnailer::ThumbnailSize; -use mediarepo_core::utils::parse_namespace_and_tag; -use mediarepo_database::entities::content_descriptor; -use mediarepo_database::get_database; -use mediarepo_database::queries::analysis::{get_all_counts, Counts}; -use sea_orm::DatabaseConnection; use std::collections::{HashMap, HashSet}; use std::fmt::Debug; -use std::io::Cursor; + use std::iter::FromIterator; use std::path::PathBuf; -use std::str::FromStr; -use tokio::fs::OpenOptions; -use tokio::io::AsyncReadExt; + + + +use sea_orm::DatabaseConnection; + + + + +use mediarepo_core::error::{RepoResult}; +use mediarepo_core::fs::file_hash_store::FileHashStore; +use mediarepo_core::fs::thumbnail_store::{ThumbnailStore}; +use mediarepo_core::itertools::Itertools; + +use mediarepo_core::utils::parse_namespace_and_tag; + +use mediarepo_database::get_database; +use mediarepo_database::queries::analysis::{Counts, get_all_counts}; + +use crate::dao::{DaoContext, DaoProvider}; +use crate::file_metadata::FileMetadata; +use crate::namespace::Namespace; +use crate::tag::Tag; #[derive(Clone)] pub struct Repo { diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mappings.rs b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mappings.rs index e76f6c9..0e2f488 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mappings.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mappings.rs @@ -1,9 +1,11 @@ -use crate::dao::tag::TagDao; +use sea_orm::{ConnectionTrait, DatabaseTransaction}; +use sea_orm::ActiveValue::Set; +use sea_orm::prelude::*; + use mediarepo_core::error::RepoResult; use mediarepo_database::entities::content_descriptor_tag; -use sea_orm::prelude::*; -use sea_orm::ActiveValue::Set; -use sea_orm::{ConnectionTrait, DatabaseTransaction}; + +use crate::dao::tag::TagDao; impl TagDao { #[tracing::instrument(level = "debug", skip(self))] diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs index 37429e3..ac71383 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs @@ -1,12 +1,14 @@ -pub mod mappings; +use sea_orm::prelude::*; +use sea_orm::QuerySelect; +use sea_orm::{JoinType}; -use crate::dao::{DaoContext, DaoProvider}; -use crate::dto::TagDto; use mediarepo_core::error::RepoResult; use mediarepo_database::entities::{content_descriptor, content_descriptor_tag, namespace, tag}; -use sea_orm::prelude::*; -use sea_orm::QuerySelect; -use sea_orm::{DatabaseConnection, JoinType}; + +use crate::dao::{DaoContext, DaoProvider}; +use crate::dto::TagDto; + +pub mod mappings; pub struct TagDao { ctx: DaoContext, diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/file.rs b/mediarepo-daemon/mediarepo-logic/src/dto/file.rs index b926201..ced7cca 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/file.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/file.rs @@ -1,11 +1,13 @@ -use crate::dto::FileMetadataDto; use chrono::NaiveDateTime; + use mediarepo_core::content_descriptor::encode_content_descriptor; use mediarepo_core::mediarepo_api::types::files::FileStatus as ApiFileStatus; use mediarepo_database::entities::content_descriptor; use mediarepo_database::entities::file; use mediarepo_database::entities::file_metadata; +use crate::dto::FileMetadataDto; + #[derive(Clone, Debug)] pub struct FileDto { model: file::Model, diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs b/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs index e5cedc2..1bfb161 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs @@ -1,4 +1,5 @@ use chrono::NaiveDateTime; + use mediarepo_database::entities::file_metadata; #[derive(Clone, Debug)] diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs index e14493c..0d7a962 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs @@ -1,11 +1,12 @@ +pub use file::*; +pub use file_metadata::*; +pub use namespace::*; +pub use tag::*; +pub use thumbnail::*; + mod file; mod file_metadata; mod tag; mod namespace; mod thumbnail; -pub use file::*; -pub use file_metadata::*; -pub use tag::*; -pub use namespace::*; -pub use thumbnail::*; \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs b/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs index 9a37e8a..df59a5f 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs @@ -1,5 +1,6 @@ -pub use mediarepo_database::entities::tag; pub use mediarepo_database::entities::namespace; +pub use mediarepo_database::entities::tag; + use crate::dto::NamespaceDto; #[derive(Clone, Debug)] @@ -12,7 +13,7 @@ impl TagDto { pub(crate) fn new(model: tag::Model, namespace_model: Option) -> Self { Self { model, - namespace: namespace_model.map(NamespaceDto::new) + namespace: namespace_model.map(NamespaceDto::new), } } @@ -27,4 +28,4 @@ impl TagDto { pub fn namespace(&self) -> Option<&NamespaceDto> { self.namespace.as_ref() } -} \ No newline at end of file +} diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs b/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs index 2ac6166..328302b 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs @@ -1,10 +1,12 @@ -use mediarepo_core::error::RepoResult; -use mediarepo_core::fs::thumbnail_store::Dimensions; use std::path::PathBuf; + use tokio::fs; use tokio::fs::{File, OpenOptions}; use tokio::io::BufReader; +use mediarepo_core::error::RepoResult; +use mediarepo_core::fs::thumbnail_store::Dimensions; + #[derive(Clone, Debug)] pub struct ThumbnailDto { path: PathBuf, diff --git a/mediarepo-daemon/mediarepo-logic/src/namespace.rs b/mediarepo-daemon/mediarepo-logic/src/namespace.rs index 1b67661..8f173c7 100644 --- a/mediarepo-daemon/mediarepo-logic/src/namespace.rs +++ b/mediarepo-daemon/mediarepo-logic/src/namespace.rs @@ -1,10 +1,12 @@ -use mediarepo_core::error::RepoResult; -use mediarepo_database::entities::namespace; -use sea_orm::prelude::*; +use std::fmt::Debug; + use sea_orm::{ Condition, ConnectionTrait, DatabaseBackend, DatabaseConnection, InsertResult, Set, Statement, }; -use std::fmt::Debug; +use sea_orm::prelude::*; + +use mediarepo_core::error::RepoResult; +use mediarepo_database::entities::namespace; #[derive(Clone)] pub struct Namespace { diff --git a/mediarepo-daemon/mediarepo-logic/src/tag.rs b/mediarepo-daemon/mediarepo-logic/src/tag.rs index 95b30d5..378c854 100644 --- a/mediarepo-daemon/mediarepo-logic/src/tag.rs +++ b/mediarepo-daemon/mediarepo-logic/src/tag.rs @@ -1,15 +1,16 @@ use std::fmt::Debug; +use sea_orm::{Condition, DatabaseBackend, DatabaseConnection, JoinType, Set, Statement}; +use sea_orm::{InsertResult, QuerySelect}; +use sea_orm::prelude::*; +use sea_orm::query::ConnectionTrait; +use sea_orm::sea_query::Expr; + use mediarepo_core::error::RepoResult; use mediarepo_database::entities::content_descriptor; use mediarepo_database::entities::content_descriptor_tag; use mediarepo_database::entities::namespace; use mediarepo_database::entities::tag; -use sea_orm::prelude::*; -use sea_orm::query::ConnectionTrait; -use sea_orm::sea_query::Expr; -use sea_orm::{Condition, DatabaseBackend, DatabaseConnection, JoinType, Set, Statement}; -use sea_orm::{InsertResult, QuerySelect}; use crate::namespace::Namespace; diff --git a/mediarepo-daemon/mediarepo-logic/src/type_keys.rs b/mediarepo-daemon/mediarepo-logic/src/type_keys.rs index f70f645..bd12d0c 100644 --- a/mediarepo-daemon/mediarepo-logic/src/type_keys.rs +++ b/mediarepo-daemon/mediarepo-logic/src/type_keys.rs @@ -1,7 +1,9 @@ -use crate::dao::repo::Repo; use std::sync::Arc; + use typemap_rev::TypeMapKey; +use crate::dao::repo::Repo; + pub struct RepoKey; impl TypeMapKey for RepoKey { diff --git a/mediarepo-daemon/mediarepo-socket/src/lib.rs b/mediarepo-daemon/mediarepo-socket/src/lib.rs index 70082ca..4979eda 100644 --- a/mediarepo-daemon/mediarepo-socket/src/lib.rs +++ b/mediarepo-daemon/mediarepo-socket/src/lib.rs @@ -1,3 +1,10 @@ +use std::net::SocketAddr; +use std::path::PathBuf; +use std::sync::Arc; + +use tokio::net::TcpListener; +use tokio::task::JoinHandle; + use mediarepo_core::bromine::prelude::*; use mediarepo_core::error::{RepoError, RepoResult}; use mediarepo_core::mediarepo_api::types::misc::InfoResponse; @@ -6,11 +13,6 @@ use mediarepo_core::tokio_graceful_shutdown::SubsystemHandle; use mediarepo_core::type_keys::{RepoPathKey, SettingsKey, SizeMetadataKey, SubsystemKey}; use mediarepo_logic::dao::repo::Repo; use mediarepo_logic::type_keys::RepoKey; -use std::net::SocketAddr; -use std::path::PathBuf; -use std::sync::Arc; -use tokio::net::TcpListener; -use tokio::task::JoinHandle; mod from_model; mod namespaces; diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/mod.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/mod.rs index 973daf4..c379b58 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/mod.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/mod.rs @@ -1,10 +1,5 @@ -mod searching; -mod sorting; +use tokio::io::AsyncReadExt; -use crate::from_model::FromModel; -use crate::namespaces::files::searching::find_files_for_filters; -use crate::namespaces::files::sorting::sort_files_by_properties; -use crate::utils::{cd_by_identifier, file_by_identifier, get_repo_from_context}; use mediarepo_core::bromine::prelude::*; use mediarepo_core::content_descriptor::{create_content_descriptor, encode_content_descriptor}; use mediarepo_core::error::RepoError; @@ -21,7 +16,14 @@ use mediarepo_core::thumbnailer::ThumbnailSize; use mediarepo_core::utils::parse_namespace_and_tag; use mediarepo_logic::dao::DaoProvider; use mediarepo_logic::dto::{AddFileDto, UpdateFileDto, UpdateFileMetadataDto}; -use tokio::io::AsyncReadExt; + +use crate::from_model::FromModel; +use crate::namespaces::files::searching::find_files_for_filters; +use crate::namespaces::files::sorting::sort_files_by_properties; +use crate::utils::{cd_by_identifier, file_by_identifier, get_repo_from_context}; + +mod searching; +mod sorting; pub struct FilesNamespace; diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/searching.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/searching.rs index 9ffa99e..ab6d66b 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/searching.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/searching.rs @@ -1,15 +1,16 @@ +use std::collections::HashMap; + use mediarepo_core::content_descriptor::decode_content_descriptor; use mediarepo_core::error::RepoResult; use mediarepo_core::mediarepo_api::types::files::FileStatus as ApiFileStatus; use mediarepo_core::mediarepo_api::types::filtering::{ FilterExpression, FilterQuery, PropertyQuery, TagQuery, ValueComparator, }; -use mediarepo_logic::dao::file::find::NegatableComparator::{Is, IsNot}; +use mediarepo_logic::dao::DaoProvider; use mediarepo_logic::dao::file::find::{FilterFileProperty, FilterProperty, OrderingComparator}; +use mediarepo_logic::dao::file::find::NegatableComparator::{Is, IsNot}; use mediarepo_logic::dao::repo::Repo; -use mediarepo_logic::dao::DaoProvider; use mediarepo_logic::dto::{FileDto, FileStatus}; -use std::collections::HashMap; #[tracing::instrument(level = "debug", skip(repo))] pub async fn find_files_for_filters( diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/sorting.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/sorting.rs index e80bbe1..5f56c5d 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files/sorting.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files/sorting.rs @@ -1,18 +1,20 @@ +use std::cmp::Ordering; +use std::collections::HashMap; +use std::iter::FromIterator; + use chrono::NaiveDateTime; use compare::Compare; +use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; + use mediarepo_core::error::RepoResult; use mediarepo_core::mediarepo_api::types::filtering::{SortDirection, SortKey}; use mediarepo_database::queries::tags::{ get_cids_with_namespaced_tags, get_content_descriptors_with_tag_count, }; -use mediarepo_logic::dao::repo::Repo; use mediarepo_logic::dao::DaoProvider; +use mediarepo_logic::dao::repo::Repo; use mediarepo_logic::dto::{FileDto, FileMetadataDto}; -use mediarepo_logic::file_metadata::FileMetadata; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -use std::cmp::Ordering; -use std::collections::HashMap; -use std::iter::FromIterator; + pub struct FileSortContext { name: Option, diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/jobs.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/jobs.rs index 83231bf..208c5ce 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/jobs.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/jobs.rs @@ -1,4 +1,3 @@ -use crate::utils::{calculate_size, get_repo_from_context}; use mediarepo_core::bromine::prelude::*; use mediarepo_core::error::RepoResult; use mediarepo_core::mediarepo_api::types::jobs::{JobType, RunJobRequest}; @@ -6,6 +5,8 @@ use mediarepo_core::mediarepo_api::types::repo::SizeType; use mediarepo_core::type_keys::SizeMetadataKey; use mediarepo_logic::dao::DaoProvider; +use crate::utils::{calculate_size, get_repo_from_context}; + pub struct JobsNamespace; impl NamespaceProvider for JobsNamespace { diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs index 29ad8c8..269dcd4 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs @@ -1,5 +1,5 @@ -use crate::from_model::FromModel; -use crate::utils::{file_by_identifier, get_repo_from_context}; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; + use mediarepo_core::bromine::prelude::*; use mediarepo_core::content_descriptor::decode_content_descriptor; use mediarepo_core::mediarepo_api::types::files::{GetFileTagsRequest, GetFilesTagsRequest}; @@ -7,7 +7,9 @@ use mediarepo_core::mediarepo_api::types::tags::{ ChangeFileTagsRequest, NamespaceResponse, TagResponse, }; use mediarepo_logic::dao::DaoProvider; -use rayon::iter::{IntoParallelIterator, ParallelIterator}; + +use crate::from_model::FromModel; +use crate::utils::{file_by_identifier, get_repo_from_context}; pub struct TagsNamespace; diff --git a/mediarepo-daemon/mediarepo-socket/src/utils.rs b/mediarepo-daemon/mediarepo-socket/src/utils.rs index 3769fb1..5e48cdc 100644 --- a/mediarepo-daemon/mediarepo-socket/src/utils.rs +++ b/mediarepo-daemon/mediarepo-socket/src/utils.rs @@ -1,3 +1,7 @@ +use std::sync::Arc; + +use tokio::fs; + use mediarepo_core::bromine::ipc::context::Context; use mediarepo_core::content_descriptor::decode_content_descriptor; use mediarepo_core::error::{RepoError, RepoResult}; @@ -5,12 +9,10 @@ use mediarepo_core::mediarepo_api::types::identifier::FileIdentifier; use mediarepo_core::mediarepo_api::types::repo::SizeType; use mediarepo_core::type_keys::{RepoPathKey, SettingsKey}; use mediarepo_core::utils::get_folder_size; -use mediarepo_logic::dao::repo::Repo; use mediarepo_logic::dao::DaoProvider; +use mediarepo_logic::dao::repo::Repo; use mediarepo_logic::dto::FileDto; use mediarepo_logic::type_keys::RepoKey; -use std::sync::Arc; -use tokio::fs; pub async fn get_repo_from_context(ctx: &Context) -> Arc { let data = ctx.data.read().await; diff --git a/mediarepo-daemon/src/logging.rs b/mediarepo-daemon/src/logging.rs index 9e1692a..dfb5846 100644 --- a/mediarepo-daemon/src/logging.rs +++ b/mediarepo-daemon/src/logging.rs @@ -1,21 +1,22 @@ -use console_subscriber::ConsoleLayer; -use rolling_file::RollingConditionBasic; use std::fs; use std::path::PathBuf; -use mediarepo_core::settings::LoggingSettings; +use console_subscriber::ConsoleLayer; +use rolling_file::RollingConditionBasic; use tracing::Level; use tracing_appender::non_blocking::{NonBlocking, WorkerGuard}; use tracing_flame::FlameLayer; use tracing_log::LogTracer; -use tracing_subscriber::filter::{self, Targets}; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{ fmt::{self}, Layer, Registry, }; +use tracing_subscriber::filter::{self, Targets}; +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; + +use mediarepo_core::settings::LoggingSettings; #[allow(dyn_drop)] pub type DropGuard = Box; diff --git a/mediarepo-daemon/src/main.rs b/mediarepo-daemon/src/main.rs index 9de1330..757dffe 100644 --- a/mediarepo-daemon/src/main.rs +++ b/mediarepo-daemon/src/main.rs @@ -1,7 +1,10 @@ +use std::env; use std::path::PathBuf; +use std::time::Duration; use structopt::StructOpt; use tokio::fs; +use tokio::io::AsyncWriteExt; use tokio::runtime; use tokio::runtime::Runtime; @@ -11,9 +14,6 @@ use mediarepo_core::settings::{PathSettings, Settings}; use mediarepo_core::tokio_graceful_shutdown::{SubsystemHandle, Toplevel}; use mediarepo_logic::dao::repo::Repo; use mediarepo_socket::start_tcp_server; -use std::env; -use std::time::Duration; -use tokio::io::AsyncWriteExt; use crate::utils::{create_paths_for_repo, get_repo, load_settings}; diff --git a/mediarepo-daemon/src/utils.rs b/mediarepo-daemon/src/utils.rs index 8c96c9a..130947a 100644 --- a/mediarepo-daemon/src/utils.rs +++ b/mediarepo-daemon/src/utils.rs @@ -1,9 +1,11 @@ +use std::path::PathBuf; + +use tokio::fs; + use mediarepo_core::error::RepoResult; -use mediarepo_core::settings::v1::SettingsV1; use mediarepo_core::settings::{PathSettings, Settings}; +use mediarepo_core::settings::v1::SettingsV1; use mediarepo_logic::dao::repo::Repo; -use std::path::PathBuf; -use tokio::fs; /// Loads the settings from a toml path pub fn load_settings(root_path: &PathBuf) -> RepoResult {