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", "futures",
"fuzzysearch-common", "fuzzysearch-common",
"hamming", "hamming",
"hex",
"hyper", "hyper",
"image", "image",
"img_hash", "img_hash",

View File

@ -28,6 +28,7 @@ bytes = "1"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
hex = "0.4"
warp = "0.3" warp = "0.3"
reqwest = { version = "0.11", features = ["multipart"] } reqwest = { version = "0.11", features = ["multipart"] }

View File

@ -272,6 +272,7 @@ pub async fn search_file(
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int, submission.hash_int,
submission.file_sha256,
artist.name, 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 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 FROM
@ -293,6 +294,7 @@ pub async fn search_file(
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int, submission.hash_int,
submission.file_sha256,
artist.name, 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 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 FROM
@ -314,6 +316,7 @@ pub async fn search_file(
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int, submission.hash_int,
submission.file_sha256,
artist.name, 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 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 FROM
@ -335,6 +338,7 @@ pub async fn search_file(
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
submission.hash_int, submission.hash_int,
submission.file_sha256,
artist.name, 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 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 FROM
@ -361,6 +365,9 @@ pub async fn search_file(
.get::<Option<String>, _>("name") .get::<Option<String>, _>("name")
.map(|artist| vec![artist]), .map(|artist| vec![artist]),
tags: row.get("tags"), tags: row.get("tags"),
sha256: row
.get::<Option<Vec<u8>>, _>("file_sha256")
.map(hex::encode),
distance: None, distance: None,
hash: row.get::<Option<i64>, _>("hash_int"), hash: row.get::<Option<i64>, _>("hash_int"),
searched_hash: None, searched_hash: None,

View File

@ -89,7 +89,8 @@ pub async fn image_query(
submission.rating, submission.rating,
submission.posted_at, submission.posted_at,
hashes.searched_hash, hashes.searched_hash,
hashes.distance hashes.distance,
submission.file_sha256 sha256
FROM hashes FROM hashes
JOIN submission ON hashes.found_hash = submission.hash_int JOIN submission ON hashes.found_hash = submission.hash_int
JOIN artist ON submission.artist_id = artist.id JOIN artist ON submission.artist_id = artist.id
@ -107,7 +108,8 @@ pub async fn image_query(
e621.data->>'rating' rating, e621.data->>'rating' rating,
to_timestamp(data->>'created_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at, to_timestamp(data->>'created_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at,
hashes.searched_hash, hashes.searched_hash,
hashes.distance hashes.distance,
e621.sha256
FROM hashes FROM hashes
JOIN e621 ON hashes.found_hash = e621.hash JOIN e621 ON hashes.found_hash = e621.hash
WHERE e621.hash IN (SELECT hashes.found_hash) WHERE e621.hash IN (SELECT hashes.found_hash)
@ -124,7 +126,8 @@ pub async fn image_query(
weasyl.data->>'rating' rating, weasyl.data->>'rating' rating,
to_timestamp(data->>'posted_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at, to_timestamp(data->>'posted_at', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') posted_at,
hashes.searched_hash, hashes.searched_hash,
hashes.distance hashes.distance,
weasyl.sha256
FROM hashes FROM hashes
JOIN weasyl ON hashes.found_hash = weasyl.hash JOIN weasyl ON hashes.found_hash = weasyl.hash
WHERE weasyl.hash IN (SELECT hashes.found_hash) WHERE weasyl.hash IN (SELECT hashes.found_hash)
@ -144,7 +147,8 @@ pub async fn image_query(
END rating, END rating,
to_timestamp(tweet.data->>'created_at', 'DY Mon DD HH24:MI:SS +0000 YYYY') posted_at, to_timestamp(tweet.data->>'created_at', 'DY Mon DD HH24:MI:SS +0000 YYYY') posted_at,
hashes.searched_hash, hashes.searched_hash,
hashes.distance hashes.distance,
null sha256
FROM hashes FROM hashes
JOIN tweet_media ON hashes.found_hash = tweet_media.hash JOIN tweet_media ON hashes.found_hash = tweet_media.hash
JOIN tweet ON tweet_media.tweet_id = tweet.id JOIN tweet ON tweet_media.tweet_id = tweet.id
@ -174,6 +178,7 @@ pub async fn image_query(
url: row.url.unwrap_or_default(), url: row.url.unwrap_or_default(),
posted_at: row.posted_at, posted_at: row.posted_at,
tags: None, tags: None,
sha256: row.sha256.map(hex::encode),
hash: row.hash, hash: row.hash,
distance: row distance: row
.distance .distance

View File

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