Include file sha256 hashes.

This commit is contained in:
Syfaro 2022-05-19 12:37:21 -04:00
parent 25c457d8dc
commit ab6068e303
5 changed files with 20 additions and 4 deletions

1
Cargo.lock generated
View File

@ -993,6 +993,7 @@ dependencies = [
"futures",
"fuzzysearch-common",
"hamming",
"hex",
"hyper",
"image",
"img_hash",

View File

@ -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"] }

View File

@ -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::<Option<String>, _>("name")
.map(|artist| vec![artist]),
tags: row.get("tags"),
sha256: row
.get::<Option<Vec<u8>>, _>("file_sha256")
.map(hex::encode),
distance: None,
hash: row.get::<Option<i64>, _>("hash_int"),
searched_hash: None,

View File

@ -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

View File

@ -36,6 +36,8 @@ pub struct SearchResult {
pub rating: Option<Rating>,
pub posted_at: Option<chrono::DateTime<chrono::Utc>>,
pub sha256: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<String>>,