aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-10-30 18:24:09 -0400
committerXe Iaso <me@christine.website>2022-10-30 18:24:09 -0400
commit23c64aebf57b3a9f9db4c08af001f01af25d732d (patch)
tree6a3e6aafe2eef06aaea2faa5b8c7711be328c86e /src
parent5d2935617a0e4bf615a8ffc0f7c1f96d9479cbd8 (diff)
downloadxesite-23c64aebf57b3a9f9db4c08af001f01af25d732d.tar.xz
xesite-23c64aebf57b3a9f9db4c08af001f01af25d732d.zip
various site updates
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'src')
-rw-r--r--src/bin/fetch_mastodon_post.rs9
-rw-r--r--src/lib.rs8
-rw-r--r--src/main.rs8
3 files changed, 9 insertions, 16 deletions
diff --git a/src/bin/fetch_mastodon_post.rs b/src/bin/fetch_mastodon_post.rs
index 06faa57..408d90c 100644
--- a/src/bin/fetch_mastodon_post.rs
+++ b/src/bin/fetch_mastodon_post.rs
@@ -1,5 +1,4 @@
use color_eyre::Result;
-use sha2::{Digest, Sha256};
use std::{env, fs};
use tracing::debug;
use xesite_types::mastodon::{Toot, User};
@@ -32,10 +31,13 @@ async fn main() -> Result<()> {
let post_hash = xesite::hash_string(post_url);
+ debug!("wrote post to ./data/toots/{post_hash}.json");
+
let mut fout = fs::File::create(&format!("./data/toots/{post_hash}.json"))?;
serde_json::to_writer_pretty(&mut fout, &toot)?;
let user_url = format!("{}.json", toot.attributed_to);
+ debug!("fetching {user_url} ...");
let user: User = reqwest::get(&user_url)
.await?
@@ -45,11 +47,12 @@ async fn main() -> Result<()> {
fs::create_dir_all("./data/users")?;
- debug!("got user {} ({})", user.name, user.preferred_username);
+ debug!("got user {} ({})", user.preferred_username, user.name);
let user_hash = xesite::hash_string(user_url);
- let mut fout = fs::File::create(&format!("./data/toots/{user_hash}.json"))?;
+ debug!("wrote post to ./data/users/{user_hash}.json");
+ let mut fout = fs::File::create(&format!("./data/users/{user_hash}.json"))?;
serde_json::to_writer_pretty(&mut fout, &user)?;
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 1fc1661..c96e6e0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1 @@
-use sha2::{Digest, Sha256};
-
-pub fn hash_string(inp: String) -> String {
- let mut h = Sha256::new();
- h.update(&inp.as_bytes());
- hex::encode(h.finalize())
-}
+pub use xesite_markdown::hash_string;
diff --git a/src/main.rs b/src/main.rs
index d5b94c0..a35db42 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,10 +4,7 @@ extern crate tracing;
use axum::{
body,
extract::Extension,
- http::{
- header::{self, HeaderValue, CONTENT_TYPE},
- Method,
- },
+ http::header::{self, HeaderValue, CONTENT_TYPE},
response::{Html, Response},
routing::{get, get_service},
Router,
@@ -20,11 +17,10 @@ use std::{
net::{IpAddr, SocketAddr},
str::FromStr,
sync::Arc,
- time::Duration,
};
use tokio::net::UnixListener;
use tower_http::{
- cors::{Any, CorsLayer},
+ cors::CorsLayer,
services::{ServeDir, ServeFile},
set_header::SetResponseHeaderLayer,
trace::TraceLayer,