summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/async_lib.rs34
-rw-r--r--src/async_lib/client.rs4
-rw-r--r--src/async_lib/traits.rs3
-rw-r--r--src/lib.rs6
-rw-r--r--src/sync_lib.rs34
-rw-r--r--src/sync_lib/traits.rs3
-rw-r--r--src/sync_lib/types.rs249
-rw-r--r--src/types.rs (renamed from src/async_lib/types.rs)34
8 files changed, 78 insertions, 289 deletions
diff --git a/src/async_lib.rs b/src/async_lib.rs
index 6bbdd22..55f23c2 100644
--- a/src/async_lib.rs
+++ b/src/async_lib.rs
@@ -1,6 +1,38 @@
pub mod client;
pub mod traits;
-pub mod types;
+
+use thiserror::Error;
+
+/// Error wrapper
+#[derive(Error, Debug)]
+pub enum HydrusError {
+ #[error("failed to connect to Hydrus")]
+ NetworkError(reqwest::Error),
+ #[error("failed to encode/Deserialize data")]
+ DeserializeError(serde_json::Error),
+ #[error("io error")]
+ IOError(std::io::Error),
+ #[error("api or session key needed")]
+ KeyNotSupplied,
+}
+
+impl From<serde_json::Error> for HydrusError {
+ fn from(value: serde_json::Error) -> Self {
+ HydrusError::DeserializeError(value)
+ }
+}
+
+impl From<std::io::Error> for HydrusError {
+ fn from(value: std::io::Error) -> Self {
+ HydrusError::IOError(value)
+ }
+}
+
+impl From<reqwest::Error> for HydrusError {
+ fn from(value: reqwest::Error) -> Self {
+ HydrusError::NetworkError(value)
+ }
+}
#[cfg(test)]
mod tests {
diff --git a/src/async_lib/client.rs b/src/async_lib/client.rs
index 58e3b83..51ed963 100644
--- a/src/async_lib/client.rs
+++ b/src/async_lib/client.rs
@@ -5,7 +5,9 @@ use reqwest::{Body, RequestBuilder};
use serde::Deserialize;
use tokio_util::codec::{BytesCodec, FramedRead};
-use crate::async_lib::{traits::*, types::*};
+use crate::async_lib::HydrusError;
+use crate::async_lib::traits::*;
+use crate::types::*;
type Result<T> = std::result::Result<T, HydrusError>;
diff --git a/src/async_lib/traits.rs b/src/async_lib/traits.rs
index 8177968..92ff30d 100644
--- a/src/async_lib/traits.rs
+++ b/src/async_lib/traits.rs
@@ -1,6 +1,7 @@
use std::{collections::HashMap, path::PathBuf};
-use crate::async_lib::types::*;
+use crate::async_lib::HydrusError;
+use crate::types::*;
use async_trait::async_trait;
type Result<T> = std::result::Result<T, HydrusError>;
diff --git a/src/lib.rs b/src/lib.rs
index d059b6b..5d0e463 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,8 +1,10 @@
//! crate with hydrus client and traits necessary for fully using hydrus API
-/// async traits, types and client implementation
+/// async traits and client implementation
#[cfg(feature = "async")]
pub mod async_lib;
-/// sync traits, types and client implementation
+/// sync traits and client implementation
#[cfg(feature = "sync")]
pub mod sync_lib;
+/// types for hydrus API
+pub mod types;
diff --git a/src/sync_lib.rs b/src/sync_lib.rs
index fd28c4c..368e5b7 100644
--- a/src/sync_lib.rs
+++ b/src/sync_lib.rs
@@ -1,3 +1,35 @@
pub mod client;
pub mod traits;
-pub mod types;
+
+use thiserror::Error;
+
+/// Error wrapper
+#[derive(Error, Debug)]
+pub enum HydrusError {
+ #[error("failed to connect to Hydrus")]
+ NetworkError(ureq::Error),
+ #[error("failed to encode/Deserialize data")]
+ DeserializeError(serde_json::Error),
+ #[error("io error")]
+ IOError(std::io::Error),
+ #[error("api or session key needed")]
+ KeyNotSupplied,
+}
+
+impl From<serde_json::Error> for HydrusError {
+ fn from(value: serde_json::Error) -> Self {
+ HydrusError::DeserializeError(value)
+ }
+}
+
+impl From<std::io::Error> for HydrusError {
+ fn from(value: std::io::Error) -> Self {
+ HydrusError::IOError(value)
+ }
+}
+
+impl From<ureq::Error> for HydrusError {
+ fn from(value: ureq::Error) -> Self {
+ HydrusError::NetworkError(value)
+ }
+}
diff --git a/src/sync_lib/traits.rs b/src/sync_lib/traits.rs
index 1f8e1dd..4cc40ca 100644
--- a/src/sync_lib/traits.rs
+++ b/src/sync_lib/traits.rs
@@ -1,6 +1,7 @@
use std::{collections::HashMap, path::PathBuf};
-use crate::sync_lib::types::*;
+use crate::sync_lib::HydrusError;
+use crate::types::*;
type Result<T> = std::result::Result<T, HydrusError>;
diff --git a/src/sync_lib/types.rs b/src/sync_lib/types.rs
deleted file mode 100644
index 7762065..0000000
--- a/src/sync_lib/types.rs
+++ /dev/null
@@ -1,249 +0,0 @@
-use std::path::PathBuf;
-
-use serde::{Deserialize, Serialize};
-use serde_repr::{Deserialize_repr, Serialize_repr};
-use thiserror::Error;
-
-/// Error wrapper
-#[derive(Error, Debug)]
-pub enum HydrusError {
- #[error("failed to connect to Hydrus")]
- NetworkError(reqwest::Error),
- #[error("failed to encode/Deserialize data")]
- DeserializeError(serde_json::Error),
- #[error("io error")]
- IOError(std::io::Error),
- #[error("api or session key needed")]
- KeyNotSupplied,
-}
-
-impl From<serde_json::Error> for HydrusError {
- fn from(value: serde_json::Error) -> Self {
- HydrusError::DeserializeError(value)
- }
-}
-
-impl From<std::io::Error> for HydrusError {
- fn from(value: std::io::Error) -> Self {
- HydrusError::IOError(value)
- }
-}
-
-impl From<reqwest::Error> for HydrusError {
- fn from(value: reqwest::Error) -> Self {
- HydrusError::NetworkError(value)
- }
-}
-
-/// Hydrus serivce permissions object
-#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
-#[repr(u8)]
-pub enum HydrusPermissions {
- ImportAndEditURLs = 0,
- ImportAndEditFiles,
- EditFileTags,
- SearchAndFetchFiles,
- ManagePages,
- ManageCookiesAndHeaders,
- ManageDatabase,
- EditFileNotes,
- EditFileRelationships,
- EditFileRatings,
- ManagePopups,
- EditFileTimes,
- CommitPending,
- SeeLocalPaths,
- Null = 255,
-}
-
-/// Hydrus key information struct
-#[derive(Deserialize, Debug)]
-pub struct KeyInfo {
- pub name: String,
- pub permits_everything: bool,
- pub basic_permissions: Vec<HydrusPermissions>,
- pub human_permissions: String,
-}
-
-/// Hydrus service type object
-#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
-#[repr(u8)]
-pub enum ServiceType {
- TagRepository = 0,
- FileRepository,
- LocalFileDomain,
- LocalTagDomain = 5,
- NumericalRating,
- BoolRating,
- AllKnownTags = 10,
- AllKnownFiles,
- LocalBooru,
- IPFS,
- Trash,
- AllLocalFiles,
- FileNotes = 17,
- ClientAPI,
- DeletedFromAnywhere,
- LocalUpdates,
- AllMyFiles,
- IncDecRating,
- ServerAdmin = 99,
- Null = 255,
-}
-
-/// Hydrus service struct
-#[derive(Deserialize, Debug, Clone)]
-pub struct Service {
- pub name: String,
- #[serde(default)]
- pub service_key: String,
- pub r#type: ServiceType,
- pub type_pretty: String,
- #[serde(default)]
- pub star_shape: Option<String>,
- #[serde(default)]
- pub min_stars: Option<u8>,
- #[serde(default)]
- pub max_stars: Option<u8>,
-}
-
-/// Hydrus file domains
-pub enum FileDomain {
- FileServiceKey(String),
- FileServiceKeys(Vec<String>),
- DeletedFileServiceKey(String),
- DeletedFileServiceKeys(Vec<String>),
-}
-
-/// Payload for importing a file via providing a local path
-#[derive(Serialize, Debug, Default)]
-pub struct AddFileRequest {
- pub path: PathBuf,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub delete_after_successful_import: Option<bool>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub file_service_key: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub file_service_keys: Option<Vec<String>>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub deleted_file_service_key: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub deleted_file_service_keys: Option<Vec<String>>,
-}
-/// File importing status
-#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
-#[repr(u8)]
-pub enum AddFileStatus {
- SuccessfulImport = 1,
- AlreadyInDatabase,
- PreviouslyDeleted,
- FailedToImport,
- FileVetoed = 7,
-}
-/// File importing api response
-#[derive(Deserialize)]
-pub struct AddFileResponse {
- pub status: AddFileStatus,
- pub hash: String,
- pub note: String,
-}
-
-/// Hydrus file object
-#[derive(Debug, Clone, Serialize)]
-pub enum HydrusFile {
- #[serde(rename(serialize = "file_id"))]
- FileId(String),
- #[serde(rename(serialize = "file_ids"))]
- FileIds(Vec<String>),
- #[serde(rename(serialize = "hash"))]
- Hash(String),
- #[serde(rename(serialize = "hashes"))]
- Hashes(Vec<String>),
-}
-
-impl Default for HydrusFile {
- fn default() -> Self {
- Self::FileId(String::from(""))
- }
-}
-
-/// Payload for various file-related requests
-#[derive(Debug, Default)]
-pub struct FileRequest {
- pub file: HydrusFile,
- pub delete_after_successful_import: Option<bool>,
- pub file_service_key: Option<String>,
- pub file_service_keys: Option<Vec<String>>,
- pub deleted_file_service_key: Option<String>,
- pub deleted_file_service_keys: Option<Vec<String>>,
- pub reason: Option<String>,
-}
-
-impl Serialize for FileRequest {
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where
- S: serde::Serializer,
- {
- use serde::ser::SerializeMap;
- let mut map = serializer.serialize_map(Some(1))?;
-
- match &self.file {
- HydrusFile::FileId(id) => map.serialize_entry("file_id", &id)?,
- HydrusFile::FileIds(ids) => map.serialize_entry("file_ids", &ids)?,
- HydrusFile::Hash(hash) => map.serialize_entry("hash", &hash)?,
- HydrusFile::Hashes(hashes) => map.serialize_entry("hashes", &hashes)?,
- }
-
- if let Some(val) = &self.reason {
- map.serialize_entry("reason", &val)?;
- }
-
- if let Some(val) = &self.file_service_key {
- map.serialize_entry("file_service_key", &val)?;
- }
-
- if let Some(val) = &self.file_service_keys {
- map.serialize_entry("file_service_keys", &val)?;
- }
-
- if let Some(val) = &self.deleted_file_service_key {
- map.serialize_entry("deleted_file_service_key", &val)?;
- }
-
- if let Some(val) = &self.deleted_file_service_keys {
- map.serialize_entry("deleted_file_service_keys", &val)?;
- }
-
- map.end()
- }
-}
-
-#[derive(Debug, Deserialize)]
-pub struct HashResponse {
- pub hash: String,
- #[serde(default)]
- pub perceptual_hashes: Option<Vec<String>>,
- #[serde(default)]
- pub pixel_hash: Option<String>,
-}
-
-#[derive(Debug, Deserialize_repr)]
-#[repr(u8)]
-pub enum UrlStatus {
- NotInDatabase = 0,
- AlreadyInDatabase = 2,
- PreviouslyDeleted,
-}
-
-#[derive(Debug, Deserialize)]
-pub struct UrlFileStatus {
- pub status: UrlStatus,
- pub hash: String,
- pub note: String,
-}
-
-#[derive(Debug, Deserialize)]
-pub struct FilesUrlResponse {
- pub normalised_url: String,
- pub url_file_statuses: Vec<UrlFileStatus>,
-}
diff --git a/src/async_lib/types.rs b/src/types.rs
index 7762065..e27836e 100644
--- a/src/async_lib/types.rs
+++ b/src/types.rs
@@ -2,40 +2,8 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
-use thiserror::Error;
-/// Error wrapper
-#[derive(Error, Debug)]
-pub enum HydrusError {
- #[error("failed to connect to Hydrus")]
- NetworkError(reqwest::Error),
- #[error("failed to encode/Deserialize data")]
- DeserializeError(serde_json::Error),
- #[error("io error")]
- IOError(std::io::Error),
- #[error("api or session key needed")]
- KeyNotSupplied,
-}
-
-impl From<serde_json::Error> for HydrusError {
- fn from(value: serde_json::Error) -> Self {
- HydrusError::DeserializeError(value)
- }
-}
-
-impl From<std::io::Error> for HydrusError {
- fn from(value: std::io::Error) -> Self {
- HydrusError::IOError(value)
- }
-}
-
-impl From<reqwest::Error> for HydrusError {
- fn from(value: reqwest::Error) -> Self {
- HydrusError::NetworkError(value)
- }
-}
-
-/// Hydrus serivce permissions object
+/// Hydrus service permissions object
#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum HydrusPermissions {