initialization

This commit is contained in:
terminallesbian 2026-02-15 20:44:55 -06:00
commit cf6dcef6c1
11 changed files with 1481 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1323
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

14
Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "garden_server"
version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { version = "1", features = [ "rt-multi-thread", "macros" ]}
tokio-macros = "2.6.0"
warp = { version = "0.4.2", features = [ "server" ] }
bytes = "1"
chrono = "0.4"
chrono-tz = "0.10"
notify-debouncer-full = "0.6"
rss = "2"

View file

@ -0,0 +1 @@
28

View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1 @@
2

1
loam/footsteps/test_page Normal file
View file

@ -0,0 +1 @@
2

39
loam/signatures.md Normal file
View file

@ -0,0 +1,39 @@
---
Thanks for reading! :)testingtest2testingtestingtestingtestingtesting
---
testing
---
testing 2
---
testing 3
---
*Sat, mid January, 2026*
testing 3
---
*Sat, early January, 2026*
testing 5
---
*Saturday, early January, 2026*
testing 5
---
*Sunday, mid January 2026*
testing!

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod site;

99
src/main.rs Normal file
View file

@ -0,0 +1,99 @@
use warp::Filter;
use std::{
fs, fs::File,
path::{
PathBuf,
},
io::Write,
};
use chrono::prelude::*;
use chrono_tz::America::Chicago;
use std::env;
fn sign(working_directory: PathBuf, body: bytes::Bytes) -> Option<usize> {
String::from_utf8(body.to_vec()).ok()
.and_then(|text| File::options().append(true).open(working_directory.join("signatures.md")).ok()
.and_then(|mut f| {
let now = Local::now().with_timezone(&Chicago);
let weekday = match now.weekday() {
Weekday::Mon => "Monday", Weekday::Tue => "Tuesday", Weekday::Wed => "Wednesday", Weekday::Thu => "Thursday",
Weekday::Fri => "Friday", Weekday::Sat => "Saturday", Weekday::Sun => "Sunday"
};
let day = now.day();
let prog = match day {
..=10 => "early",
11..=20 => "mid",
21.. => "late"
};
let month = match now.month() {
1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June",
7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December",
_ => "in the month"
};
let year = now.year();
let text = format!(
"
---
*{weekday}, {prog} {month} {year}*
{text}
"
);
f.write(text.as_bytes()).ok()
})
)
}
fn step(path: PathBuf) -> Option<usize> {
fs::read_to_string(&path).ok().or(Some(String::from("0")))
.and_then(|s| u32::from_str_radix(&s, 10).ok())
.and_then(|n| File::options().write(true).create(true).open(&path)
.and_then(|mut f | f.write((n + 1).to_string().as_bytes())).ok()
)
}
#[tokio::main]
async fn main() {
let args: Vec<_> = env::args().collect();
let default_dir = String::from(".");
let dir = args.get(1).unwrap_or(&default_dir);
let working_directory = PathBuf::from(dir);
File::open(working_directory.join("signatures.md")).expect("there isn't a guestbook (signatures.md) here... am I in the right place?");
let wd1 = working_directory.clone(); // FUCKED
let sign = warp::post().and(warp::path("sign"))
.and(warp::body::content_length_limit(1024)).and(warp::body::bytes())
.map(move |body: bytes::Bytes| {
if let Some(_) = sign(wd1.clone(), body) {
println!("successfully signed!");
warp::reply::with_status(warp::reply(), warp::http::StatusCode::ACCEPTED)
} else {
println!("failed to sign :(");
warp::reply::with_status(warp::reply(), warp::http::StatusCode::BAD_REQUEST)
}
});
let step = warp::post().and(warp::path("step")).and(warp::path::param())
.map(move |page: String| {
let path = working_directory.join("footsteps").join(&page);
if let Some(_) = step(path) {
println!("successfully stepped through {page}");
warp::reply::with_status(warp::reply(), warp::http::StatusCode::ACCEPTED)
} else {
println!("failed to step through {page} :(");
warp::reply::with_status(warp::reply(), warp::http::StatusCode::BAD_REQUEST)
}
});
let fail = warp::post().map(|| { println!("bad request"); format!("Invalid request. Try loam/sign or loam/step/<page>") } );
let routes = warp::path("loam").and(sign.or(step)).or(fail).with(warp::trace::request());
println!("starting...");
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await
}

0
src/site.rs Normal file
View file