From 04506fbd53bb513e9ca1866f80572bbe6932028d Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sun, 6 Sep 2020 15:40:25 -0400 Subject: [PATCH] Get file hash, size. --- Cargo.lock | 3 ++- src/main.rs | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a34a487..72f98d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,7 +398,7 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "furaffinity-rs" version = "0.1.0" -source = "git+https://github.com/Syfaro/furaffinity-rs#3e17efcbc75f18f11e425eacb4bfafcceff4be72" +source = "git+https://github.com/Syfaro/furaffinity-rs#6ebc01a0e45b9067bd25e5dbd624b9a6dffb8658" dependencies = [ "cfscrape", "chrono", @@ -408,6 +408,7 @@ dependencies = [ "regex", "reqwest", "scraper", + "sha2", "tokio", ] diff --git a/src/main.rs b/src/main.rs index 4bcb94c..2f8d879 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,8 +83,10 @@ async fn insert_submission( let hash = sub.hash.clone(); let url = sub.content.url(); - client.execute("INSERT INTO submission (id, artist_id, url, filename, hash, rating, posted_at, description, hash_int, file_id) VALUES ($1, $2, $3, $4, decode($5, 'base64'), $6, $7, $8, $9, CASE WHEN isnumeric(split_part($4, '.', 1)) THEN split_part($4, '.', 1)::int ELSE null END)", &[ - &sub.id, &artist_id, &url, &sub.filename, &hash, &sub.rating.serialize(), &sub.posted_at, &sub.description, &sub.hash_num, + let size = sub.file_size.map(|size| size as i32); + + client.execute("INSERT INTO submission (id, artist_id, url, filename, hash, rating, posted_at, description, hash_int, file_id, file_size, file_sha256) VALUES ($1, $2, $3, $4, decode($5, 'base64'), $6, $7, $8, $9, CASE WHEN isnumeric(split_part($4, '.', 1)) THEN split_part($4, '.', 1)::int ELSE null END, $10, $11)", &[ + &sub.id, &artist_id, &url, &sub.filename, &hash, &sub.rating.serialize(), &sub.posted_at, &sub.description, &sub.hash_num, &size, &sub.file_sha256, ]).await?; let stmt = client @@ -133,7 +135,7 @@ async fn request( async fn web() { use hyper::service::{make_service_fn, service_fn}; - let addr = ([127, 0, 0, 1], 3000).into(); + let addr: std::net::SocketAddr = std::env::var("HTTP_HOST").unwrap().parse().unwrap(); let service = make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(request)) });