summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakka <jakka@jakka.su>2025-10-01 00:25:24 +0300
committerjakka <jakka@jakka.su>2025-10-01 00:25:24 +0300
commitc177ba7a49caf63582719a4086e5032e2c939cfa (patch)
treeb922d01ef0061137f79101ff1de513ba402fbfa2
parent6b0a6c0ca36c181d55c78a5dca46f1890c9cce38 (diff)
reconfigured the library, moved async client and trait to their own module. in the future sync and async implementations will be separated
-rw-r--r--Cargo.lock181
-rw-r--r--Cargo.toml16
-rw-r--r--src/client_async.rs (renamed from src/client.rs)26
-rw-r--r--src/lib.rs8
-rw-r--r--src/tests.rs4
-rw-r--r--src/traits_async.rs (renamed from src/traits.rs)9
-rw-r--r--src/types.rs21
7 files changed, 254 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c2bf6b2..6b05a94 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -90,6 +90,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
+name = "cookie"
+version = "0.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
+dependencies = [
+ "percent-encoding",
+ "time",
+ "version_check",
+]
+
+[[package]]
+name = "cookie_store"
+version = "0.22.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fc4bff745c9b4c7fb1e97b25d13153da2bc7796260141df62378998d070207f"
+dependencies = [
+ "cookie",
+ "document-features",
+ "idna",
+ "indexmap",
+ "log",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "time",
+ "url",
+]
+
+[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -106,6 +135,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
+name = "crc32fast"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "deranged"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071"
+dependencies = [
+ "powerfmt",
+]
+
+[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -117,6 +164,15 @@ dependencies = [
]
[[package]]
+name = "document-features"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d"
+dependencies = [
+ "litrs",
+]
+
+[[package]]
name = "encoding_rs"
version = "0.8.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -154,6 +210,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
[[package]]
+name = "flate2"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -350,6 +416,7 @@ dependencies = [
"thiserror",
"tokio",
"tokio-util",
+ "ureq",
"urlencoding",
]
@@ -612,6 +679,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"
[[package]]
+name = "litrs"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed"
+
+[[package]]
name = "log"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -667,6 +740,12 @@ dependencies = [
]
[[package]]
+name = "num-conv"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
+
+[[package]]
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -759,6 +838,12 @@ dependencies = [
]
[[package]]
+name = "powerfmt"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
+
+[[package]]
name = "proc-macro2"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -864,7 +949,9 @@ version = "0.23.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc"
dependencies = [
+ "log",
"once_cell",
+ "ring",
"rustls-pki-types",
"rustls-webpki",
"subtle",
@@ -872,6 +959,15 @@ dependencies = [
]
[[package]]
+name = "rustls-pemfile"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50"
+dependencies = [
+ "rustls-pki-types",
+]
+
+[[package]]
name = "rustls-pki-types"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1127,6 +1223,37 @@ dependencies = [
]
[[package]]
+name = "time"
+version = "0.3.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
+dependencies = [
+ "deranged",
+ "itoa",
+ "num-conv",
+ "powerfmt",
+ "serde",
+ "time-core",
+ "time-macros",
+]
+
+[[package]]
+name = "time-core"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
+
+[[package]]
+name = "time-macros"
+version = "0.2.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3"
+dependencies = [
+ "num-conv",
+ "time-core",
+]
+
+[[package]]
name = "tinystr"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1281,6 +1408,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
+name = "ureq"
+version = "3.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "99ba1025f18a4a3fc3e9b48c868e9beb4f24f4b4b1a325bada26bd4119f46537"
+dependencies = [
+ "base64",
+ "cookie_store",
+ "flate2",
+ "log",
+ "percent-encoding",
+ "rustls",
+ "rustls-pemfile",
+ "rustls-pki-types",
+ "serde",
+ "serde_json",
+ "ureq-proto",
+ "utf-8",
+ "webpki-roots",
+]
+
+[[package]]
+name = "ureq-proto"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60b4531c118335662134346048ddb0e54cc86bd7e81866757873055f0e38f5d2"
+dependencies = [
+ "base64",
+ "http",
+ "httparse",
+ "log",
+]
+
+[[package]]
name = "url"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1299,6 +1459,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
+name = "utf-8"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
+
+[[package]]
name = "utf8_iter"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1311,6 +1477,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
+name = "version_check"
+version = "0.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
+
+[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1439,6 +1611,15 @@ dependencies = [
]
[[package]]
+name = "webpki-roots"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e8983c3ab33d6fb807cfcdad2491c4ea8cbc8ed839181c7dfd9c67c83e261b2"
+dependencies = [
+ "rustls-pki-types",
+]
+
+[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index c3db673..02c7815 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,12 +4,20 @@ version = "0.1.0"
edition = "2024"
[dependencies]
-async-trait = "0.1.89"
-reqwest = { version = "0.12.23", features = ["json", "stream"] }
+async-trait = { version = "0.1.89", optional = true }
+reqwest = { version = "0.12.23", features = [
+ "json",
+ "stream",
+], optional = true }
serde = { version = "1.0.225", features = ["derive"] }
serde_json = "1.0.145"
serde_repr = "0.1.20"
thiserror = "2.0.16"
-tokio = { version = "1.47.1", features = ["rt", "macros"] }
-tokio-util = "0.7.16"
+tokio = { version = "1.47.1", features = ["rt", "macros"], optional = true }
+tokio-util = { version = "0.7.16", optional = true }
+ureq = { version = "3.1.2", features = ["json"], optional = true }
urlencoding = "2.1.3"
+
+[features]
+async = ["dep:async-trait", "dep:reqwest", "dep:tokio", "dep:tokio-util"]
+sync = ["dep:ureq"]
diff --git a/src/client.rs b/src/client_async.rs
index c73b962..c189a06 100644
--- a/src/client.rs
+++ b/src/client_async.rs
@@ -5,7 +5,7 @@ use reqwest::{Body, RequestBuilder};
use serde::Deserialize;
use tokio_util::codec::{BytesCodec, FramedRead};
-use crate::{traits::*, types::*};
+use crate::{traits_async::*, types::*};
type Result<T> = std::result::Result<T, HydrusError>;
@@ -81,7 +81,7 @@ impl AccessManagement for HydrusClient {
req_url.push_str("request_new_permissions");
let mut request = self.client.get(req_url);
- request = request.query(&[("name", &urlencoding::encode(&name))]);
+ request = request.query(&[("name", &urlencoding::encode(name))]);
if permissions.is_empty() {
request = request.query(&[("permit_everything", "true")]);
@@ -425,3 +425,25 @@ impl ImportingAndDeletingFiles for HydrusClient {
.await?)
}
}
+
+#[async_trait]
+impl ImportingAndEditingUrls for HydrusClient {
+ async fn get_url_files(
+ &self,
+ url: &str,
+ doublecheck_file_system: Option<bool>,
+ ) -> Result<FilesUrlResponse> {
+ let mut req_url = self.url.to_owned();
+ req_url.push_str("add_urls/get_url_files");
+
+ let mut request = self.set_get_request_key(&req_url)?;
+
+ request = request.query(&[("url", url)]);
+
+ if let Some(doublecheck) = doublecheck_file_system {
+ request = request.query(&[("doublecheck_file_system", doublecheck)]);
+ }
+
+ Ok(request.send().await?.json::<FilesUrlResponse>().await?)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 3d70b70..c2a0350 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,11 @@
//! crate with hydrus client and traits necessary for accesing hydrus API
-/// this crates hydrus client implementation
-pub mod client;
+/// this crate's hydrus client async implementation
+#[cfg(feature = "async")]
+pub mod client_async;
/// traits for accessing hydrus API
-pub mod traits;
+#[cfg(feature = "async")]
+pub mod traits_async;
/// various objects for de/serializing requests
pub mod types;
diff --git a/src/tests.rs b/src/tests.rs
index 5e8d9a7..8cb725e 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,5 +1,5 @@
-use crate::client::HydrusClient;
-use crate::{traits::*, types::*};
+use crate::client_async::HydrusClient;
+use crate::{traits_async::*, types::*};
#[tokio::test]
async fn test_service_name_info() {
diff --git a/src/traits.rs b/src/traits_async.rs
index 6cdf094..9c4de18 100644
--- a/src/traits.rs
+++ b/src/traits_async.rs
@@ -60,3 +60,12 @@ pub trait ImportingAndDeletingFiles {
/// Generate hashes for an arbitrary file by sending the file.
async fn generate_hashes_for_file(&self, file: PathBuf) -> Result<HashResponse>;
}
+
+#[async_trait]
+pub trait ImportingAndEditingUrls {
+ async fn get_url_files(
+ &self,
+ url: &str,
+ doublecheck_file_system: Option<bool>,
+ ) -> Result<FilesUrlResponse>;
+}
diff --git a/src/types.rs b/src/types.rs
index df2c387..7762065 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -226,3 +226,24 @@ pub struct HashResponse {
#[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>,
+}