diff --git a/Cargo.lock b/Cargo.lock index ab8973f..cce7a63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -993,6 +993,7 @@ dependencies = [ "futures", "fuzzysearch-common", "hamming", + "hex", "hyper", "image", "img_hash", diff --git a/fuzzysearch-api/Cargo.toml b/fuzzysearch-api/Cargo.toml index 193ccf7..de04b30 100644 --- a/fuzzysearch-api/Cargo.toml +++ b/fuzzysearch-api/Cargo.toml @@ -28,6 +28,7 @@ bytes = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" +hex = "0.4" warp = "0.3" reqwest = { version = "0.11", features = ["multipart"] } diff --git a/fuzzysearch-api/src/handlers.rs b/fuzzysearch-api/src/handlers.rs index 3f5243d..0979c85 100644 --- a/fuzzysearch-api/src/handlers.rs +++ b/fuzzysearch-api/src/handlers.rs @@ -272,6 +272,7 @@ pub async fn search_file( submission.rating, submission.posted_at, submission.hash_int, + submission.file_sha256, artist.name, array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags FROM @@ -293,6 +294,7 @@ pub async fn search_file( submission.rating, submission.posted_at, submission.hash_int, + submission.file_sha256, artist.name, array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags FROM @@ -314,6 +316,7 @@ pub async fn search_file( submission.rating, submission.posted_at, submission.hash_int, + submission.file_sha256, artist.name, array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags FROM @@ -335,6 +338,7 @@ pub async fn search_file( submission.rating, submission.posted_at, submission.hash_int, + submission.file_sha256, artist.name, array(SELECT tag.name FROM tag_to_post JOIN tag ON tag_to_post.tag_id = tag.id WHERE tag_to_post.post_id = submission.id) tags FROM @@ -361,6 +365,9 @@ pub async fn search_file( .get::, _>("name") .map(|artist| vec![artist]), tags: row.get("tags"), + sha256: row + .get::>, _>("file_sha256") + .map(hex::encode), distance: None, hash: row.get::, _>("hash_int"), searched_hash: None, diff --git a/fuzzysearch-api/src/models.rs b/fuzzysearch-api/src/models.rs index b815b09..adafed9 100644 --- a/fuzzysearch-api/src/models.rs +++ b/fuzzysearch-api/src/models.rs @@ -89,7 +89,8 @@ pub async fn image_query( submission.rating, submission.posted_at, hashes.searched_hash, - hashes.distance + hashes.distance, + submission.file_sha256 sha256 FROM hashes JOIN submission ON hashes.found_hash = submission.hash_int JOIN artist ON submission.artist_id = artist.id @@ -107,7 +108,8 @@ pub async fn image_query( e621.data->>'rating' rating, to_timestamp(data->>'created_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at, hashes.searched_hash, - hashes.distance + hashes.distance, + e621.sha256 FROM hashes JOIN e621 ON hashes.found_hash = e621.hash WHERE e621.hash IN (SELECT hashes.found_hash) @@ -124,7 +126,8 @@ pub async fn image_query( weasyl.data->>'rating' rating, to_timestamp(data->>'posted_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at, hashes.searched_hash, - hashes.distance + hashes.distance, + weasyl.sha256 FROM hashes JOIN weasyl ON hashes.found_hash = weasyl.hash WHERE weasyl.hash IN (SELECT hashes.found_hash) @@ -144,7 +147,8 @@ pub async fn image_query( END rating, to_timestamp(tweet.data->>'created_at', 'DY Mon DD HH24:MI:SS +0000 YYYY') posted_at, hashes.searched_hash, - hashes.distance + hashes.distance, + null sha256 FROM hashes JOIN tweet_media ON hashes.found_hash = tweet_media.hash JOIN tweet ON tweet_media.tweet_id = tweet.id @@ -174,6 +178,7 @@ pub async fn image_query( url: row.url.unwrap_or_default(), posted_at: row.posted_at, tags: None, + sha256: row.sha256.map(hex::encode), hash: row.hash, distance: row .distance diff --git a/fuzzysearch-common/src/types.rs b/fuzzysearch-common/src/types.rs index 4a078d0..ed967f8 100644 --- a/fuzzysearch-common/src/types.rs +++ b/fuzzysearch-common/src/types.rs @@ -36,6 +36,8 @@ pub struct SearchResult { pub rating: Option, pub posted_at: Option>, + pub sha256: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>,