From 11e8cc5ad5ace95d35d8c4d6ae6d011c0a597f77 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Tue, 17 Jun 2025 19:43:56 -0700 Subject: [PATCH 01/16] Basic server --- Cargo.lock | 7 +++++++ src/404.html | 11 +++++++++++ src/index.html | 11 +++++++++++ src/main.rs | 38 +++++++++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Cargo.lock create mode 100644 src/404.html create mode 100644 src/index.html diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6d4a78d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "FediverseServer" +version = "0.1.0" diff --git a/src/404.html b/src/404.html new file mode 100644 index 0000000..c283fe1 --- /dev/null +++ b/src/404.html @@ -0,0 +1,11 @@ + + + + + Ouch! + + +

404

+

Page not found.

+ + diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..fe442d6 --- /dev/null +++ b/src/index.html @@ -0,0 +1,11 @@ + + + + + Hello! + + +

Hello!

+

Hi from Rust

+ + diff --git a/src/main.rs b/src/main.rs index a51ebad..571fed6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,37 @@ -use std::net; +#![allow(non_snake_case)] +use std::net::{TcpListener, TcpStream}; +use std::io::{BufReader, prelude::*}; +use std::fs; -fn main() { - println!("Hello, world!"); +fn main() -> std::io::Result<()> { + let TCPlistener = TcpListener::bind("127.0.0.1:8080").unwrap(); + for Stream in TCPlistener.incoming() { + ServePage(Stream?); + } + Ok(()) +} + +fn ServePage(mut Stream: TcpStream) { + // Identifying information. + let Buffer = BufReader::new(&Stream); + let HTTPrequest: Vec<_> = Buffer.lines().map(|result| result.unwrap()).take_while(|line| !line.is_empty()).collect(); + println!("{HTTPrequest:#?}"); + + // Response. + #[allow(unused_assignments)] + let mut Status : &str = ""; + #[allow(unused_assignments)] + let mut Contents : String = "".to_string(); + + if HTTPrequest[0] == "GET / HTTP/1.1" { + Status = "HTTP/1.1 200 OK"; + Contents = fs::read_to_string("src/index.html").unwrap(); + } else { + Status = "HTTP/1.1 404 Not Found"; + Contents = fs::read_to_string("src/404.html").unwrap(); + } + let Length = Contents.len(); + let Response : String = format!("{Status}\r\nContent-Length: {Length}\r\n\r\n{Contents}"); + + Stream.write_all(Response.as_bytes()).unwrap(); } -- 2.45.3 From 0ec60694c7015f8a242cb081588deb3f5484e9a4 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Tue, 17 Jun 2025 22:25:45 -0700 Subject: [PATCH 02/16] placed a backend. I think this works? --- Cargo.lock | 1180 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 45 +- 3 files changed, 1192 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d4a78d..aea032b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,3 +5,1183 @@ version = 4 [[package]] name = "FediverseServer" version = "0.1.0" +dependencies = [ + "rouille", +] + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "brotli" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "buf_redux" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" +dependencies = [ + "memchr", + "safemem", +] + +[[package]] +name = "bumpalo" +version = "3.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" + +[[package]] +name = "cc" +version = "1.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-link", +] + +[[package]] +name = "chunked_transfer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "deflate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" +dependencies = [ + "adler32", + "gzip-header", +] + +[[package]] +name = "deranged" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "errno" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "filetime" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +dependencies = [ + "cfg-if", + "libc", + "libredox", + "windows-sys", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + +[[package]] +name = "gzip-header" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95cc527b92e6029a62960ad99aa8a6660faa4555fe5f731aab13aa6a921795a2" +dependencies = [ + "crc32fast", +] + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" + +[[package]] +name = "icu_properties" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "potential_utf", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" + +[[package]] +name = "icu_provider" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +dependencies = [ + "displaydoc", + "icu_locale_core", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", + "redox_syscall", +] + +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + +[[package]] +name = "litemap" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "multipart" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182" +dependencies = [ + "buf_redux", + "httparse", + "log", + "mime", + "mime_guess", + "quick-error", + "rand", + "safemem", + "tempfile", + "twoway", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "potential_utf" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] + +[[package]] +name = "redox_syscall" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rouille" +version = "3.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3716fbf57fc1084d7a706adf4e445298d123e4a44294c4e8213caf1b85fcc921" +dependencies = [ + "base64", + "brotli", + "chrono", + "deflate", + "filetime", + "multipart", + "percent-encoding", + "rand", + "serde", + "serde_derive", + "serde_json", + "sha1_smol", + "threadpool", + "time", + "tiny_http", + "url", +] + +[[package]] +name = "rustix" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "2.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tempfile" +version = "3.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +dependencies = [ + "fastrand", + "getrandom 0.3.3", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +dependencies = [ + "deranged", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" + +[[package]] +name = "tiny_http" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" +dependencies = [ + "ascii", + "chunked_transfer", + "httpdate", + "log", +] + +[[package]] +name = "tinystr" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "twoway" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" +dependencies = [ + "memchr", +] + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "writeable" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" + +[[package]] +name = "yoke" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 419b5a2..7047197 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +rouille = "3.6.2" diff --git a/src/main.rs b/src/main.rs index 571fed6..a5b42d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,37 +1,14 @@ #![allow(non_snake_case)] -use std::net::{TcpListener, TcpStream}; -use std::io::{BufReader, prelude::*}; -use std::fs; +#![allow(unused_braces)] +use rouille::Response; +use rouille::router; +use std::fs::File; -fn main() -> std::io::Result<()> { - let TCPlistener = TcpListener::bind("127.0.0.1:8080").unwrap(); - for Stream in TCPlistener.incoming() { - ServePage(Stream?); - } - Ok(()) -} - -fn ServePage(mut Stream: TcpStream) { - // Identifying information. - let Buffer = BufReader::new(&Stream); - let HTTPrequest: Vec<_> = Buffer.lines().map(|result| result.unwrap()).take_while(|line| !line.is_empty()).collect(); - println!("{HTTPrequest:#?}"); - - // Response. - #[allow(unused_assignments)] - let mut Status : &str = ""; - #[allow(unused_assignments)] - let mut Contents : String = "".to_string(); - - if HTTPrequest[0] == "GET / HTTP/1.1" { - Status = "HTTP/1.1 200 OK"; - Contents = fs::read_to_string("src/index.html").unwrap(); - } else { - Status = "HTTP/1.1 404 Not Found"; - Contents = fs::read_to_string("src/404.html").unwrap(); - } - let Length = Contents.len(); - let Response : String = format!("{Status}\r\nContent-Length: {Length}\r\n\r\n{Contents}"); - - Stream.write_all(Response.as_bytes()).unwrap(); +fn main() { + rouille::start_server("127.0.0.1:8080", move |Request| { + router!(Request, + (GET) (/) => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, + _ => { Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) } + ) + }); } -- 2.45.3 From 0a19ee5c338d36a9835a18248deaa2c2c3f98f3d Mon Sep 17 00:00:00 2001 From: CatAClock Date: Tue, 17 Jun 2025 22:54:35 -0700 Subject: [PATCH 03/16] favicon --- src/404.html | 1 + src/favicon.ico | Bin 0 -> 761 bytes src/index.html | 1 + src/main.rs | 3 ++- 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/favicon.ico diff --git a/src/404.html b/src/404.html index c283fe1..46b0428 100644 --- a/src/404.html +++ b/src/404.html @@ -2,6 +2,7 @@ + Ouch! diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..38e4e573b823af3e612c65c1d0a2d6fde4c8ef62 GIT binary patch literal 761 zcmZ?wbhEHb6krfw_`(1Jj7&^S%*;$IEX*vd%&b7f#=_3QFD7ZME@o|_YGbBpYoX;} zYmgIRnHOa}v(#lymFJvl?^ClPz`6+#ia%L6r!j~yDE{a6a}5c0b_{Se(lcOY1ZvX( zX$3ihf%W?X6W`0&(BzXTMl*fXh@m)7q2zLxpro zh+H7Z0@W$N!_Cdf&d$WZ%*)Hm$Is8f!2t_yHdZcv4t7Kwu(5IR^CP$n3~a1&G8Qn^ Q5SmR+233H80T|ZS09)Q?UH||9 literal 0 HcmV?d00001 diff --git a/src/index.html b/src/index.html index fe442d6..bafeb3e 100644 --- a/src/index.html +++ b/src/index.html @@ -2,6 +2,7 @@ + Hello! diff --git a/src/main.rs b/src/main.rs index a5b42d9..c8202fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,8 @@ use std::fs::File; fn main() { rouille::start_server("127.0.0.1:8080", move |Request| { router!(Request, - (GET) (/) => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, + (GET) ["/"] => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, + (GET) ["/favicon.ico"] => { Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) }, _ => { Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) } ) }); -- 2.45.3 From 610a8853bb4d7e343ee81475ca86edb330c6b57b Mon Sep 17 00:00:00 2001 From: CatAClock Date: Tue, 17 Jun 2025 23:05:11 -0700 Subject: [PATCH 04/16] last minute thing --- src/index.html | 3 ++- src/main.rs | 4 ++++ src/profile.html | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/profile.html diff --git a/src/index.html b/src/index.html index bafeb3e..306ad62 100644 --- a/src/index.html +++ b/src/index.html @@ -7,6 +7,7 @@

Hello!

-

Hi from Rust

+

Hi from Rust.

+ View your profile. diff --git a/src/main.rs b/src/main.rs index c8202fa..487c782 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,13 @@ use std::fs::File; fn main() { rouille::start_server("127.0.0.1:8080", move |Request| { + // Router. Go to the correct pages, else hit the sack. router!(Request, (GET) ["/"] => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, + (GET) ["/Profile"] => { Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) }, + // Get specific images. Because the browser said so. (GET) ["/favicon.ico"] => { Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) }, + // Catch-all. Fuck you. _ => { Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) } ) }); diff --git a/src/profile.html b/src/profile.html new file mode 100644 index 0000000..ccec8d4 --- /dev/null +++ b/src/profile.html @@ -0,0 +1,12 @@ + + + + + + Hello! + + +

Profile!

+

This is totally your profile girl.

+ + -- 2.45.3 From b65fee9d5d0a30b97eec935a7f81fd4d22a41dbb Mon Sep 17 00:00:00 2001 From: CatAClock Date: Wed, 18 Jun 2025 22:13:14 -0700 Subject: [PATCH 05/16] sure --- Cargo.lock | 578 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + README.md | 8 + src/main.rs | 51 ++++- 4 files changed, 622 insertions(+), 16 deletions(-) create mode 100644 README.md diff --git a/Cargo.lock b/Cargo.lock index aea032b..6ae5c05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,9 +6,25 @@ version = 4 name = "FediverseServer" version = "0.1.0" dependencies = [ + "postgres", "rouille", ] +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "adler32" version = "1.2.0" @@ -51,24 +67,65 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" +[[package]] +name = "async-trait" +version = "0.1.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "backtrace" +version = "0.3.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "brotli" version = "3.5.0" @@ -106,6 +163,18 @@ version = "3.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + [[package]] name = "cc" version = "1.2.27" @@ -145,6 +214,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -154,6 +232,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "deflate" version = "1.0.0" @@ -173,6 +261,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -191,9 +290,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.59.0", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "2.3.0" @@ -209,7 +314,7 @@ dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -221,6 +326,70 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.16" @@ -244,6 +413,12 @@ dependencies = [ "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + [[package]] name = "gzip-header" version = "1.0.0" @@ -259,6 +434,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "httparse" version = "1.10.1" @@ -447,12 +631,32 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.5" @@ -475,6 +679,26 @@ dependencies = [ "unicase", ] +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", + "windows-sys 0.59.0", +] + [[package]] name = "multipart" version = "0.18.0" @@ -487,7 +711,7 @@ dependencies = [ "mime", "mime_guess", "quick-error", - "rand", + "rand 0.8.5", "safemem", "tempfile", "twoway", @@ -527,18 +751,123 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "parking_lot" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "postgres" +version = "0.19.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "363e6dfbdd780d3aa3597b6eb430db76bb315fa9bad7fae595bb8def808b8470" +dependencies = [ + "bytes", + "fallible-iterator", + "futures-util", + "log", + "tokio", + "tokio-postgres", +] + +[[package]] +name = "postgres-protocol" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ff0abab4a9b844b93ef7b81f1efc0a366062aaef2cd702c76256b5dc075c54" +dependencies = [ + "base64 0.22.1", + "byteorder", + "bytes", + "fallible-iterator", + "hmac", + "md-5", + "memchr", + "rand 0.9.1", + "sha2", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613283563cd90e1dfc3518d548caee47e0e725455ed619881f5cf21f36de4b48" +dependencies = [ + "bytes", + "fallible-iterator", + "postgres-protocol", +] + [[package]] name = "potential_utf" version = "0.1.2" @@ -600,8 +929,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", ] [[package]] @@ -611,7 +950,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -623,6 +972,15 @@ dependencies = [ "getrandom 0.2.16", ] +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.3", +] + [[package]] name = "redox_syscall" version = "0.5.13" @@ -638,14 +996,14 @@ version = "3.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3716fbf57fc1084d7a706adf4e445298d123e4a44294c4e8213caf1b85fcc921" dependencies = [ - "base64", + "base64 0.13.1", "brotli", "chrono", "deflate", "filetime", "multipart", "percent-encoding", - "rand", + "rand 0.8.5", "serde", "serde_derive", "serde_json", @@ -656,6 +1014,12 @@ dependencies = [ "url", ] +[[package]] +name = "rustc-demangle" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" + [[package]] name = "rustix" version = "1.0.7" @@ -666,7 +1030,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -687,6 +1051,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.219" @@ -725,24 +1095,74 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "slab" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" + [[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.103" @@ -775,7 +1195,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -830,6 +1250,75 @@ dependencies = [ "zerovec", ] +[[package]] +name = "tinyvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-postgres" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c95d533c83082bb6490e0189acaa0bbeef9084e60471b696ca6988cd0541fb0" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand 0.9.1", + "socket2", + "tokio", + "tokio-util", + "whoami", +] + +[[package]] +name = "tokio-util" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "twoway" version = "0.1.8" @@ -839,18 +1328,45 @@ dependencies = [ "memchr", ] +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + [[package]] name = "unicase" version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" + [[package]] name = "url" version = "2.5.4" @@ -868,6 +1384,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -883,6 +1405,12 @@ dependencies = [ "wit-bindgen-rt", ] +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.100" @@ -941,6 +1469,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "whoami" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6994d13118ab492c3c80c1f81928718159254c53c472bf9ce36f8dae4add02a7" +dependencies = [ + "redox_syscall", + "wasite", + "web-sys", +] + [[package]] name = "windows-core" version = "0.61.2" @@ -1000,6 +1549,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index 7047197..6311577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2024" [dependencies] rouille = "3.6.2" +postgres = "0.19.10" diff --git a/README.md b/README.md new file mode 100644 index 0000000..f38c176 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Fediverse-Server + +It's a fucking thing. + +## Dependencies + + - Everything listed in Cargo.toml. + - `postgresql` for your distribution. diff --git a/src/main.rs b/src/main.rs index 487c782..dda938d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,17 +3,56 @@ use rouille::Response; use rouille::router; use std::fs::File; +use postgres::{Client, NoTls}; -fn main() { - rouille::start_server("127.0.0.1:8080", move |Request| { +fn main() -> Result<(), Box>{ + + let mut client = Client::connect("host=localhost user=cataclock", NoTls)?; + + client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL, + data BYTEA + ) + ")?; + + let name = "Ferris"; + let data = None::<&[u8]>; + client.execute( + "INSERT INTO person (name, data) VALUES ($1, $2)", + &[&name, &data], + )?; + + for row in client.query("SELECT id, name, data FROM person", &[])? { + let id: i32 = row.get(0); + let name: &str = row.get(1); + let data: Option<&[u8]> = row.get(2); + + println!("found person: {} {} {:?}", id, name, data); + } + + Ok(()) +} + +fn RouilleHandoff() { + rouille::start_server("127.0.0.1:8080", move |Request| { // Router. Go to the correct pages, else hit the sack. router!(Request, - (GET) ["/"] => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, - (GET) ["/Profile"] => { Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) }, + (GET) ["/"] => { + Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) + }, + (GET) ["/Profile"] => { + Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) + }, // Get specific images. Because the browser said so. - (GET) ["/favicon.ico"] => { Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) }, + (GET) ["/favicon.ico"] => { + Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) + }, // Catch-all. Fuck you. - _ => { Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) } + _ => { + Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) + } ) }); } -- 2.45.3 From 9ec7e0001f244bf8347a8b48473c956e5a0f2e61 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 19 Jun 2025 08:02:53 -0700 Subject: [PATCH 06/16] we up posting our gres --- src/main.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index dda938d..b868619 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,15 +7,25 @@ use postgres::{Client, NoTls}; fn main() -> Result<(), Box>{ - let mut client = Client::connect("host=localhost user=cataclock", NoTls)?; + // TODO: have the user fill in user, password, database name manually. + let mut client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - name TEXT NOT NULL, - data BYTEA - ) - ")?; + // See if a table is already created. + match client.query("SELECT 1 + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_TYPE='BASE TABLE' + AND TABLE_NAME='person'", &[]) { + Ok(_) => (); + Err(_) => { + client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL, + data BYTEA + ) + ")?; + } + } let name = "Ferris"; let data = None::<&[u8]>; -- 2.45.3 From dad35afd6d617097d1369be178e338703777fc98 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 19 Jun 2025 18:28:21 -0700 Subject: [PATCH 07/16] database now creatable. --- src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index b868619..497f027 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,21 +10,24 @@ fn main() -> Result<(), Box>{ // TODO: have the user fill in user, password, database name manually. let mut client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - // See if a table is already created. - match client.query("SELECT 1 + let Table = client.query("SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' - AND TABLE_NAME='person'", &[]) { - Ok(_) => (); - Err(_) => { - client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - name TEXT NOT NULL, - data BYTEA - ) - ")?; - } + AND TABLE_NAME='person'", &[]); + // Check if the table doesn't exists. Or does? + match Table { + Ok(_) => { + // Check if the table exists. + if Table?.len() == 0 { + client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + name TEXT NOT NULL, + data BYTEA + )")?; + } + }, + Err(_) => () } let name = "Ferris"; @@ -42,6 +45,9 @@ fn main() -> Result<(), Box>{ println!("found person: {} {} {:?}", id, name, data); } + RouilleHandoff(); + + // Finish Ok(()) } -- 2.45.3 From e9f02f3ee04a46bd7ae7acae650b9d34dce0eae6 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 19 Jun 2025 20:15:44 -0700 Subject: [PATCH 08/16] synchronous not working?? --- src/main.rs | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 497f027..d99e276 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,15 @@ #![allow(non_snake_case)] #![allow(unused_braces)] -use rouille::Response; -use rouille::router; +use rouille::{post_input, try_or_400, router, Response}; use std::fs::File; use postgres::{Client, NoTls}; fn main() -> Result<(), Box>{ // TODO: have the user fill in user, password, database name manually. - let mut client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; + let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - let Table = client.query("SELECT 1 + let Table = Client.query("SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='person'", &[]); @@ -19,7 +18,7 @@ fn main() -> Result<(), Box>{ Ok(_) => { // Check if the table exists. if Table?.len() == 0 { - client.batch_execute(" + Client.batch_execute(" CREATE TABLE person ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, @@ -30,14 +29,26 @@ fn main() -> Result<(), Box>{ Err(_) => () } - let name = "Ferris"; - let data = None::<&[u8]>; - client.execute( + let mut name = "Ferris"; + let mut data: Option<&[u8]> = None; + Client.execute( + "INSERT INTO person (name, data) VALUES ($1, $2)", + &[&name, &data], + )?; + name = "Dope"; + data = Some(&[8u8, 9u8]); + Client.execute( + "INSERT INTO person (name, data) VALUES ($1, $2)", + &[&name, &data], + )?; + name = "pingas"; + data = Some(&[27u8]); + Client.execute( "INSERT INTO person (name, data) VALUES ($1, $2)", &[&name, &data], )?; - for row in client.query("SELECT id, name, data FROM person", &[])? { + for row in Client.query("SELECT id, name, data FROM person", &[])? { let id: i32 = row.get(0); let name: &str = row.get(1); let data: Option<&[u8]> = row.get(2); @@ -45,22 +56,27 @@ fn main() -> Result<(), Box>{ println!("found person: {} {} {:?}", id, name, data); } - RouilleHandoff(); - - // Finish - Ok(()) -} - -fn RouilleHandoff() { + // Never leave the server. CTRL + C if you have issues. rouille::start_server("127.0.0.1:8080", move |Request| { // Router. Go to the correct pages, else hit the sack. router!(Request, + // Actual Web Pages. (GET) ["/"] => { Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) }, (GET) ["/Profile"] => { Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) }, + // API stuff. + (POST) ["/API/Profile"] => { + // Content-type: multipart/form-data + let Profile = try_or_400!(post_input!(Request, { + ID: u32, + })); + let Que: u32 = Client.query("SELECT name FROM persons WHERE id = $1", &[&Profile.ID]).unwrap()[0].get(0); + let Text: String = "hello world! Your output is: ".to_string() + &Que.to_string(); + Response::text(Text) + }, // Get specific images. Because the browser said so. (GET) ["/favicon.ico"] => { Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) -- 2.45.3 From 099850f75081496bcc9a52715766a9cf20909d2b Mon Sep 17 00:00:00 2001 From: CatAClock Date: Fri, 20 Jun 2025 16:18:14 -0700 Subject: [PATCH 09/16] SQL finally works --- src/main.rs | 97 ++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 60 deletions(-) diff --git a/src/main.rs b/src/main.rs index d99e276..736e425 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,42 @@ use rouille::{post_input, try_or_400, router, Response}; use std::fs::File; use postgres::{Client, NoTls}; -fn main() -> Result<(), Box>{ +fn main(){ + // Never leave the server. CTRL + C if you have issues. + rouille::start_server("127.0.0.1:8080", move |Request| { + // Router. Go to the correct pages, else hit the sack. + router!(Request, + // Actual Web Pages. + (GET) ["/"] => { + Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) + }, + (GET) ["/Profile"] => { + Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) + }, + // API stuff. + (POST) ["/API/Profile"] => { + // Content-type: multipart/form-data + let Profile = try_or_400!(post_input!(Request, { + ID: i32, + })); + let Things = SQL(Profile.ID).unwrap(); + let Text: String = "hello world! Your output is: ".to_string() + &Things.to_string(); + Response::text(Text) + }, + // Get specific images. Because the browser said so. + (GET) ["/favicon.ico"] => { + Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) + }, + // Catch-all. Fuck you. + _ => { + Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) + } + ) + }); +} + +fn SQL(thing: i32) -> Result>{ // TODO: have the user fill in user, password, database name manually. let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; @@ -28,63 +62,6 @@ fn main() -> Result<(), Box>{ }, Err(_) => () } - - let mut name = "Ferris"; - let mut data: Option<&[u8]> = None; - Client.execute( - "INSERT INTO person (name, data) VALUES ($1, $2)", - &[&name, &data], - )?; - name = "Dope"; - data = Some(&[8u8, 9u8]); - Client.execute( - "INSERT INTO person (name, data) VALUES ($1, $2)", - &[&name, &data], - )?; - name = "pingas"; - data = Some(&[27u8]); - Client.execute( - "INSERT INTO person (name, data) VALUES ($1, $2)", - &[&name, &data], - )?; - - for row in Client.query("SELECT id, name, data FROM person", &[])? { - let id: i32 = row.get(0); - let name: &str = row.get(1); - let data: Option<&[u8]> = row.get(2); - - println!("found person: {} {} {:?}", id, name, data); - } - - // Never leave the server. CTRL + C if you have issues. - rouille::start_server("127.0.0.1:8080", move |Request| { - // Router. Go to the correct pages, else hit the sack. - router!(Request, - // Actual Web Pages. - (GET) ["/"] => { - Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) - }, - (GET) ["/Profile"] => { - Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) - }, - // API stuff. - (POST) ["/API/Profile"] => { - // Content-type: multipart/form-data - let Profile = try_or_400!(post_input!(Request, { - ID: u32, - })); - let Que: u32 = Client.query("SELECT name FROM persons WHERE id = $1", &[&Profile.ID]).unwrap()[0].get(0); - let Text: String = "hello world! Your output is: ".to_string() + &Que.to_string(); - Response::text(Text) - }, - // Get specific images. Because the browser said so. - (GET) ["/favicon.ico"] => { - Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) - }, - // Catch-all. Fuck you. - _ => { - Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) - } - ) - }); + let Result: String = Client.query("SELECT name FROM person WHERE id = $1", &[&thing]).unwrap()[0].get(0); + return Ok(Result.to_string()); } -- 2.45.3 From 8e9ed6bac822dd084192fff18c9e78d298585670 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Fri, 20 Jun 2025 17:11:01 -0700 Subject: [PATCH 10/16] Organization and fixing up the drillevator --- src/ActivityPub/Person.rs | 53 ++++++++++++++++++++++++++++++++++ src/ActivityPub/mod.rs | 1 + src/{ => HTTP}/404.html | 0 src/{ => HTTP}/favicon.ico | Bin src/{ => HTTP}/index.html | 0 src/{ => HTTP}/profile.html | 0 src/main.rs | 55 +++++++++++++----------------------- 7 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 src/ActivityPub/Person.rs create mode 100644 src/ActivityPub/mod.rs rename src/{ => HTTP}/404.html (100%) rename src/{ => HTTP}/favicon.ico (100%) rename src/{ => HTTP}/index.html (100%) rename src/{ => HTTP}/profile.html (100%) diff --git a/src/ActivityPub/Person.rs b/src/ActivityPub/Person.rs new file mode 100644 index 0000000..32f05da --- /dev/null +++ b/src/ActivityPub/Person.rs @@ -0,0 +1,53 @@ +use postgres::{Client, NoTls}; + +pub fn GetAccount(ID: i32) -> Result>{ + let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; + + let Table = Client.query("SELECT 1 + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_TYPE='BASE TABLE' + AND TABLE_NAME='person'", &[]); + // Check if the table doesn't exists. Or does? + match Table { + Ok(_) => { + // Check if the table exists. + if Table?.len() == 0 { + Client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + type TEXT NOT NULL, + name TEXT NOT NULL + )")?; + } + }, + Err(_) => () + } + let Result: String = Client.query("SELECT name FROM person WHERE id = $1", &[&ID]).unwrap()[0].get(0); + return Ok(Result.to_string()); +} + +pub fn MakeAccount(Type: String, Name: String) -> Result>{ + let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; + + let Table = Client.query("SELECT 1 + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_TYPE='BASE TABLE' + AND TABLE_NAME='person'", &[]); + // Check if the table doesn't exists. Or does? + match Table { + Ok(_) => { + // Check if the table exists. + if Table?.len() == 0 { + Client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + type TEXT NOT NULL, + name TEXT NOT NULL + )")?; + } + }, + Err(_) => () + } + Client.execute("INSERT INTO person (type, name) VALUES ($1, $2)", &[&Type, &Name])?; + return Ok("Account Created!".to_string()); +} diff --git a/src/ActivityPub/mod.rs b/src/ActivityPub/mod.rs new file mode 100644 index 0000000..c553571 --- /dev/null +++ b/src/ActivityPub/mod.rs @@ -0,0 +1 @@ +pub mod Person; diff --git a/src/404.html b/src/HTTP/404.html similarity index 100% rename from src/404.html rename to src/HTTP/404.html diff --git a/src/favicon.ico b/src/HTTP/favicon.ico similarity index 100% rename from src/favicon.ico rename to src/HTTP/favicon.ico diff --git a/src/index.html b/src/HTTP/index.html similarity index 100% rename from src/index.html rename to src/HTTP/index.html diff --git a/src/profile.html b/src/HTTP/profile.html similarity index 100% rename from src/profile.html rename to src/HTTP/profile.html diff --git a/src/main.rs b/src/main.rs index 736e425..fb71f01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ #![allow(unused_braces)] use rouille::{post_input, try_or_400, router, Response}; use std::fs::File; -use postgres::{Client, NoTls}; +mod ActivityPub; fn main(){ @@ -12,56 +12,39 @@ fn main(){ router!(Request, // Actual Web Pages. (GET) ["/"] => { - Response::from_file("text/html", File::open("src/index.html").unwrap()).with_status_code(200) + Response::from_file("text/html", File::open("src/HTTP/index.html").unwrap()).with_status_code(200) }, (GET) ["/Profile"] => { - Response::from_file("text/html", File::open("src/profile.html").unwrap()).with_status_code(200) + Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200) }, // API stuff. - (POST) ["/API/Profile"] => { + (GET) ["/API/Profile:Get"] => { // Content-type: multipart/form-data let Profile = try_or_400!(post_input!(Request, { ID: i32, })); - let Things = SQL(Profile.ID).unwrap(); - let Text: String = "hello world! Your output is: ".to_string() + &Things.to_string(); - Response::text(Text) + let Things = ActivityPub::Person::GetAccount(Profile.ID).unwrap(); + let Text: String = "Got Account: ".to_string() + &Things.to_string(); + Response::text(Text).with_status_code(200) + }, + (POST) ["/API/Profile:Create"] => { + // Content-type: multipart/form-data + let Profile = try_or_400!(post_input!(Request, { + Type: String, + Name: String, + })); + let Things = ActivityPub::Person::MakeAccount(Profile.Type, Profile.Name).unwrap(); + let Text: String = Things.to_string(); + Response::text(Text).with_status_code(201) }, // Get specific images. Because the browser said so. (GET) ["/favicon.ico"] => { - Response::from_file("image/vnd.microsoft.icon", File::open("src/favicon.ico").unwrap()).with_status_code(200) + Response::from_file("image/vnd.microsoft.icon", File::open("src/HTTP/favicon.ico").unwrap()).with_status_code(200) }, // Catch-all. Fuck you. _ => { - Response::from_file("text/html", File::open("src/404.html").unwrap()).with_status_code(404) + Response::from_file("text/html", File::open("src/HTTP/404.html").unwrap()).with_status_code(404) } ) }); } - -fn SQL(thing: i32) -> Result>{ - // TODO: have the user fill in user, password, database name manually. - let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; - - let Table = Client.query("SELECT 1 - FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_TYPE='BASE TABLE' - AND TABLE_NAME='person'", &[]); - // Check if the table doesn't exists. Or does? - match Table { - Ok(_) => { - // Check if the table exists. - if Table?.len() == 0 { - Client.batch_execute(" - CREATE TABLE person ( - id SERIAL PRIMARY KEY, - name TEXT NOT NULL, - data BYTEA - )")?; - } - }, - Err(_) => () - } - let Result: String = Client.query("SELECT name FROM person WHERE id = $1", &[&thing]).unwrap()[0].get(0); - return Ok(Result.to_string()); -} -- 2.45.3 From be4063d9d5311f750bd114c79d52be6135dc5873 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Fri, 20 Jun 2025 17:31:24 -0700 Subject: [PATCH 11/16] working with things --- src/HTTP/404.html | 4 ++++ src/HTTP/profile.html | 6 +++++- src/HTTP/script.js | 0 src/HTTP/style.css | 11 +++++++++++ src/index.html | 17 +++++++++++++++++ src/main.rs | 4 ++-- 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/HTTP/script.js create mode 100644 src/HTTP/style.css create mode 100644 src/index.html diff --git a/src/HTTP/404.html b/src/HTTP/404.html index 46b0428..2aa1a7a 100644 --- a/src/HTTP/404.html +++ b/src/HTTP/404.html @@ -3,10 +3,14 @@ + Ouch!

404

Page not found.

+ + + diff --git a/src/HTTP/profile.html b/src/HTTP/profile.html index ccec8d4..633cf7c 100644 --- a/src/HTTP/profile.html +++ b/src/HTTP/profile.html @@ -3,10 +3,14 @@ - Hello! + + Profile

Profile!

This is totally your profile girl.

+ + + diff --git a/src/HTTP/script.js b/src/HTTP/script.js new file mode 100644 index 0000000..e69de29 diff --git a/src/HTTP/style.css b/src/HTTP/style.css new file mode 100644 index 0000000..91307bd --- /dev/null +++ b/src/HTTP/style.css @@ -0,0 +1,11 @@ +body { + text-align: center +} + +h1 { + font-size: 10% +} + +p { + +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..b8ec892 --- /dev/null +++ b/src/index.html @@ -0,0 +1,17 @@ + + + + + + + Main + + +

Hello!

+

Hi from Rust.

+ View your profile. + + + + + diff --git a/src/main.rs b/src/main.rs index fb71f01..e1b7842 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ fn main(){ }, // API stuff. (GET) ["/API/Profile:Get"] => { - // Content-type: multipart/form-data + // Content-type: application/x-www-form-urlencoded let Profile = try_or_400!(post_input!(Request, { ID: i32, })); @@ -28,7 +28,7 @@ fn main(){ Response::text(Text).with_status_code(200) }, (POST) ["/API/Profile:Create"] => { - // Content-type: multipart/form-data + // Content-type: application/x-www-form-urlencoded let Profile = try_or_400!(post_input!(Request, { Type: String, Name: String, -- 2.45.3 From c66a8ae60e3ca0b2e2014c98fe4dcf2e1eb32220 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Fri, 20 Jun 2025 19:26:04 -0700 Subject: [PATCH 12/16] SQL database is now accessable. CSS and JS implemented --- src/HTTP/index.html | 6 +++++- src/HTTP/style.css | 8 ++++++-- src/index.html | 17 ----------------- src/main.rs | 6 ++++++ 4 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 src/index.html diff --git a/src/HTTP/index.html b/src/HTTP/index.html index 306ad62..b8ec892 100644 --- a/src/HTTP/index.html +++ b/src/HTTP/index.html @@ -3,11 +3,15 @@ - Hello! + + Main

Hello!

Hi from Rust.

View your profile. + + + diff --git a/src/HTTP/style.css b/src/HTTP/style.css index 91307bd..5f1a1d2 100644 --- a/src/HTTP/style.css +++ b/src/HTTP/style.css @@ -1,9 +1,13 @@ body { - text-align: center + text-align: center; + justify-content: center; } h1 { - font-size: 10% + font-size: 8ch; + + margin-top: 0; + margin-bottom: 0; } p { diff --git a/src/index.html b/src/index.html deleted file mode 100644 index b8ec892..0000000 --- a/src/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Main - - -

Hello!

-

Hi from Rust.

- View your profile. - - - - - diff --git a/src/main.rs b/src/main.rs index e1b7842..a188a1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,12 @@ fn main(){ (GET) ["/favicon.ico"] => { Response::from_file("image/vnd.microsoft.icon", File::open("src/HTTP/favicon.ico").unwrap()).with_status_code(200) }, + (GET) ["/style.css"] => { + Response::from_file("text/css", File::open("src/HTTP/style.css").unwrap()).with_status_code(200) + }, + (GET) ["/script.js"] => { + Response::from_file("text/javascript", File::open("src/HTTP/script.js").unwrap()).with_status_code(200) + }, // Catch-all. Fuck you. _ => { Response::from_file("text/html", File::open("src/HTTP/404.html").unwrap()).with_status_code(404) -- 2.45.3 From 8906579a636752293e48feb28b368012fcf69252 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Fri, 20 Jun 2025 20:05:04 -0700 Subject: [PATCH 13/16] Core types listed --- src/{ActivityPub/Person.rs => API/mod.rs} | 0 src/ActivityPub/Core.rs | 31 +++++++++++++++++++++++ src/ActivityPub/mod.rs | 2 +- src/main.rs | 5 ++-- 4 files changed, 35 insertions(+), 3 deletions(-) rename src/{ActivityPub/Person.rs => API/mod.rs} (100%) create mode 100644 src/ActivityPub/Core.rs diff --git a/src/ActivityPub/Person.rs b/src/API/mod.rs similarity index 100% rename from src/ActivityPub/Person.rs rename to src/API/mod.rs diff --git a/src/ActivityPub/Core.rs b/src/ActivityPub/Core.rs new file mode 100644 index 0000000..5cdea61 --- /dev/null +++ b/src/ActivityPub/Core.rs @@ -0,0 +1,31 @@ +pub struct Object { + +} + +pub struct Link { + +} + +pub struct Activity { + +} + +pub struct IntransitiveActivity { + +} + +pub struct Collection { + +} + +pub struct OrderedCollection { + +} + +pub struct CollectionPage { + +} + +pub struct OrderedCollectionPage { + +} diff --git a/src/ActivityPub/mod.rs b/src/ActivityPub/mod.rs index c553571..9c07cac 100644 --- a/src/ActivityPub/mod.rs +++ b/src/ActivityPub/mod.rs @@ -1 +1 @@ -pub mod Person; +pub mod Core; diff --git a/src/main.rs b/src/main.rs index a188a1c..d31dfb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use rouille::{post_input, try_or_400, router, Response}; use std::fs::File; mod ActivityPub; +mod API; fn main(){ @@ -23,7 +24,7 @@ fn main(){ let Profile = try_or_400!(post_input!(Request, { ID: i32, })); - let Things = ActivityPub::Person::GetAccount(Profile.ID).unwrap(); + let Things = API::GetAccount(Profile.ID).unwrap(); let Text: String = "Got Account: ".to_string() + &Things.to_string(); Response::text(Text).with_status_code(200) }, @@ -33,7 +34,7 @@ fn main(){ Type: String, Name: String, })); - let Things = ActivityPub::Person::MakeAccount(Profile.Type, Profile.Name).unwrap(); + let Things = API::MakeAccount(Profile.Type, Profile.Name).unwrap(); let Text: String = Things.to_string(); Response::text(Text).with_status_code(201) }, -- 2.45.3 From 1f6176de2e6a2b8a0bc800f3dbe48228197cac5e Mon Sep 17 00:00:00 2001 From: CatAClock Date: Sat, 21 Jun 2025 21:11:35 -0700 Subject: [PATCH 14/16] Base types implemented. Let's get the client working! --- src/ActivityPub/ActivityTypes/mod.rs | 103 ++++++++++++++++ src/ActivityPub/ActorTypes/mod.rs | 19 +++ src/ActivityPub/Core.rs | 31 ----- src/ActivityPub/ObjectTypes/mod.rs | 51 ++++++++ src/ActivityPub/mod.rs | 171 ++++++++++++++++++++++++++- 5 files changed, 343 insertions(+), 32 deletions(-) create mode 100644 src/ActivityPub/ActivityTypes/mod.rs create mode 100644 src/ActivityPub/ActorTypes/mod.rs delete mode 100644 src/ActivityPub/Core.rs create mode 100644 src/ActivityPub/ObjectTypes/mod.rs diff --git a/src/ActivityPub/ActivityTypes/mod.rs b/src/ActivityPub/ActivityTypes/mod.rs new file mode 100644 index 0000000..4c0cbec --- /dev/null +++ b/src/ActivityPub/ActivityTypes/mod.rs @@ -0,0 +1,103 @@ +pub struct Accept { + +} + +pub struct TentativeAccept { + +} + +pub struct Add { + +} + +pub struct Create { + +} + +pub struct Delete { + +} + +pub struct Ignore { + +} + +pub struct Join { + +} + +pub struct Leave { + +} + +pub struct Like { + +} + +pub struct Offer { + +} + +pub struct Invite { + +} + +pub struct Reject { + +} + +pub struct TentativeReject { + +} + +pub struct Remove { + +} + +pub struct Undo { + +} + +pub struct Update { + +} + +pub struct View { + +} + +pub struct Listen { + +} + +pub struct Read { + +} + +pub struct Move { + +} + +pub struct Travel { + +} + +pub struct Announce { + +} + +pub struct Block { + +} + +pub struct Flag { + +} + +pub struct Dislike { + +} + +pub struct Question { + +} diff --git a/src/ActivityPub/ActorTypes/mod.rs b/src/ActivityPub/ActorTypes/mod.rs new file mode 100644 index 0000000..1d546fb --- /dev/null +++ b/src/ActivityPub/ActorTypes/mod.rs @@ -0,0 +1,19 @@ +pub struct Application { + +} + +pub struct Group { + +} + +pub struct Organization { + +} + +pub struct Person { + +} + +pub struct Service { + +} diff --git a/src/ActivityPub/Core.rs b/src/ActivityPub/Core.rs deleted file mode 100644 index 5cdea61..0000000 --- a/src/ActivityPub/Core.rs +++ /dev/null @@ -1,31 +0,0 @@ -pub struct Object { - -} - -pub struct Link { - -} - -pub struct Activity { - -} - -pub struct IntransitiveActivity { - -} - -pub struct Collection { - -} - -pub struct OrderedCollection { - -} - -pub struct CollectionPage { - -} - -pub struct OrderedCollectionPage { - -} diff --git a/src/ActivityPub/ObjectTypes/mod.rs b/src/ActivityPub/ObjectTypes/mod.rs new file mode 100644 index 0000000..364b360 --- /dev/null +++ b/src/ActivityPub/ObjectTypes/mod.rs @@ -0,0 +1,51 @@ +pub struct Relationship { + +} + +pub struct Article { + +} + +pub struct Document { + +} + +pub struct Audio { + +} + +pub struct Image { + +} + +pub struct Video { + +} + +pub struct Note { + +} + +pub struct Page { + +} + +pub struct Event { + +} + +pub struct Place { + +} + +pub struct Mention { + +} + +pub struct Profile { + +} + +pub struct Tombstone { + +} diff --git a/src/ActivityPub/mod.rs b/src/ActivityPub/mod.rs index 9c07cac..b03012c 100644 --- a/src/ActivityPub/mod.rs +++ b/src/ActivityPub/mod.rs @@ -1 +1,170 @@ -pub mod Core; +pub mod ActivityTypes; +pub mod ActorTypes; +pub mod ObjectTypes; + +use crate::ActivityPub::ActorTypes::Person; + +pub struct Object { + r#type: String, + id: String, + + attachment: Option>, + attributedTo: Option>, + audience: Option>, + content: Option, + context: Option, + name: Option, + // dateTime format for string. + endTime: Option, + generator: Option>, + icon: Option>, + image: Option, + inReplyTo: Option, + location: Option>, + preview: Option, + // dateTime format for string. + published: Option, + replies: Option>, + // dateTime format for string. + startTime: Option, + summary: Option, + tag: Option>, + // dateTime format for string. + updated: Option, + url: Option, + to: Option>, + bto: Option>, + cc: Option>, + bcc: Option>, + mediaType: Option, + // dateTime format for string. + duration: Option +} + +impl Object { + fn new(mut Type: String, ID: String) -> Self { + if Type == "" { + Type = "Object".to_string(); + } + Self { r#type: Type.to_string(), id: ID, attachment: None, attributedTo: None, audience: None, content: None, context: None, name: None, endTime: None, generator: None, icon: None, image: None, inReplyTo: None, location: None, preview: None, published: None, replies: None, startTime: None, summary: None, tag: None, updated: None, url: None, to: None, bto: None, cc: None, bcc: None, mediaType: None, duration: None} + } +} + +pub struct Link { + r#type: String, + + href: Option, + // Must meet HTML5 and Web Linking "Link Relation" definitions. + rel: Option>, + mediaType: Option, + name: Option, + // Must meet Language-Tag requirements. + hreflang: Option, + height: Option, + width: Option, + preview: Option +} + +impl Link { + fn new(mut Type: String) -> Self { + if Type == "" { + Type = "Link".to_string(); + } + Self {r#type: Type.to_string(), href: None, rel: None, mediaType: None, name: None, hreflang: None, height: None, width: None, preview: None} + } +} + +pub struct Activity { + Inherit: Object, + actor: Person, + object: Option, + target: Option, + result: Option, + origin: Option, + instrument: Option +} + +impl Activity { + fn new(mut Type: String, ID: String, Actor: Person) -> Self { + if Type == "" { + Type = "Activity".to_string(); + } + Self { Inherit: Object::new(Type, ID), actor: Actor, object: None, target: None, result: None, origin: None, instrument: None} + } +} + +pub struct IntransitiveActivity { + // Object should NEVER be used for this class. + Inherit: Activity +} + +impl IntransitiveActivity { + fn new(mut Type: String, ID: String, Actor: Person) -> Self { + if Type == "" { + Type = "IntransitiveActivity".to_string(); + } + Self {Inherit: Activity::new(Type, ID, Actor)} + } +} + +pub struct Collection { + Inherit: Object, + + totalItems: u32, + current: Option, + first: Option, + last: Option, + items: Option +} + +impl Collection { + fn new(mut Type: String, ID: String, TotalItems: u32) -> Self { + if Type == "" { + Type = "Collection".to_string(); + } + Self { Inherit: Object::new(Type.to_string(), ID), totalItems: TotalItems, current: None, first: None, last: None, items: None} + } +} + +pub struct OrderedCollection { + Inherit: Collection +} + +impl OrderedCollection { + fn new(mut Type: String, ID: String, TotalItems: u32) -> Self { + if Type == "" { + Type = "OrderedCollection".to_string(); + } + Self { Inherit: Collection::new(Type.to_string(), ID, TotalItems)} + } +} + +pub struct CollectionPage { + Inherit: Collection, + partOf: String, + next: Option, + prev: Option +} + +impl CollectionPage { + fn new(mut Type: String, ID: String, TotalItems: u32, PartOf: String) -> Self { + if Type == "" { + Type = "CollectionPage".to_string(); + } + Self { Inherit: Collection::new(Type.to_string(), ID, TotalItems), partOf: PartOf, next: None, prev: None } + } +} + +pub struct OrderedCollectionPage { + Inherit: CollectionPage, + startIndex: Option +} + +impl OrderedCollectionPage { + fn new(mut Type: String, ID: String, TotalItems: u32, PartOf: String) -> Self { + if Type == "" { + Type = "OrderedCollectionPage".to_string(); + } + Self { Inherit: CollectionPage::new(Type.to_string(), ID, TotalItems, PartOf), startIndex: None } + } +} -- 2.45.3 From c929cdceb129601af12d0a01dc2993352bce6e0c Mon Sep 17 00:00:00 2001 From: CatAClock Date: Sun, 22 Jun 2025 22:16:39 -0700 Subject: [PATCH 15/16] Basic login system. Kind of. --- src/API/mod.rs | 34 +++++++++++++++++++++++++++++++++- src/HTTP/404.html | 23 ++++++++++------------- src/HTTP/index.html | 28 ++++++++++++++-------------- src/HTTP/profile.html | 42 +++++++++++++++++++++++++++++------------- src/HTTP/profile.js | 26 ++++++++++++++++++++++++++ src/HTTP/script.js | 0 src/HTTP/style.css | 40 +++++++++++++++++++++++++++++++++++++++- src/main.rs | 25 ++++++++++++++++--------- 8 files changed, 167 insertions(+), 51 deletions(-) create mode 100644 src/HTTP/profile.js delete mode 100644 src/HTTP/script.js diff --git a/src/API/mod.rs b/src/API/mod.rs index 32f05da..23a6bdf 100644 --- a/src/API/mod.rs +++ b/src/API/mod.rs @@ -1,6 +1,38 @@ use postgres::{Client, NoTls}; -pub fn GetAccount(ID: i32) -> Result>{ +pub fn GetAccountWithName(Name: &str) -> Result>{ + let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; + + let Table = Client.query("SELECT 1 + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_TYPE='BASE TABLE' + AND TABLE_NAME='person'", &[]); + // Check if the table doesn't exists. Or does? + match Table { + Ok(_) => { + // Check if the table exists. + if Table?.len() == 0 { + Client.batch_execute(" + CREATE TABLE person ( + id SERIAL PRIMARY KEY, + type TEXT NOT NULL, + name TEXT NOT NULL + )")?; + } + }, + Err(_) => () + } + if Client.query("SELECT name FROM person WHERE name = $1", &[&Name])?.len() != 0 { + let Result: Result = Client.query("SELECT name FROM person WHERE name = $1", &[&Name])?[0].try_get(0); + match Result { + Ok(x) => return Ok(x.to_string()), + Err(_) => return Ok("Other Error Encountered.".to_string()) + } + } + return Ok("Username Not Found.".to_string()); +} + +pub fn GetAccountWithID(ID: i32) -> Result>{ let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; let Table = Client.query("SELECT 1 diff --git a/src/HTTP/404.html b/src/HTTP/404.html index 2aa1a7a..8c82799 100644 --- a/src/HTTP/404.html +++ b/src/HTTP/404.html @@ -1,16 +1,13 @@ - - - - - Ouch! - - -

404

-

Page not found.

- - - - + + + + + Ouch! + + +

404

+

Page not found.

+ diff --git a/src/HTTP/index.html b/src/HTTP/index.html index b8ec892..76d1181 100644 --- a/src/HTTP/index.html +++ b/src/HTTP/index.html @@ -1,17 +1,17 @@ - - - - - Main - - -

Hello!

-

Hi from Rust.

- View your profile. - - - - + + + + + Main + + +

Hello!

+

Hi from Rust.

+ View your profile. + + + + diff --git a/src/HTTP/profile.html b/src/HTTP/profile.html index 633cf7c..883ac51 100644 --- a/src/HTTP/profile.html +++ b/src/HTTP/profile.html @@ -1,16 +1,32 @@ - - - - - Profile - - -

Profile!

-

This is totally your profile girl.

- - - - + + + + + Profile + + +

Profile!

+

Log in. Or don't. Up to you.

+ +
+
+ + +
+
+ + +
+
+ +
+
+ +

+ + + + diff --git a/src/HTTP/profile.js b/src/HTTP/profile.js new file mode 100644 index 0000000..defe3e8 --- /dev/null +++ b/src/HTTP/profile.js @@ -0,0 +1,26 @@ +let Infomation = document.getElementById("Information"); +let Account = document.getElementById("Account"); + +let req = new XMLHttpRequest(); +req.open('GET', document.location, true); +req.send(null); +req.onload = function() { + let headers = req.getAllResponseHeaders(); + const arr = headers.trim().split(/[\r\n]+/); + + // Create a map of header names to values + const headerMap = new Map(); + arr.forEach((line) => { + const parts = line.split(": "); + headerMap.set(parts[0], parts[1]); + }); + + if (headerMap.get("profile") != null) { + if (headerMap.get("profile") == "Username Not Found.") { + Infomation.innerHTML = "User not found. Please check your username and try again!"; + } else { + Account.innerHTML = headerMap.get("profile"); + Infomation.innerHTML = "Welcome!"; + } + } +}; diff --git a/src/HTTP/script.js b/src/HTTP/script.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/HTTP/style.css b/src/HTTP/style.css index 5f1a1d2..1001b4e 100644 --- a/src/HTTP/style.css +++ b/src/HTTP/style.css @@ -10,6 +10,44 @@ h1 { margin-bottom: 0; } -p { +h2 { + font-size: 7ch; + margin-top: 0; + margin-bottom: 0; +} + +h3 { + font-size: 6ch; + + margin-top: 0; + margin-bottom: 0; +} + +h4 { + font-size: 5ch; + + margin-top: 0; + margin-bottom: 0; +} + +h5 { + font-size: 4ch; + + margin-top: 0; + margin-bottom: 0; +} + +h6 { + font-size: 3ch; + + margin-top: 0; + margin-bottom: 0; +} + +p { + font-size: 2ch; + + margin-top: 0; + margin-bottom: 0; } diff --git a/src/main.rs b/src/main.rs index d31dfb8..13a7c99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,25 +16,32 @@ fn main(){ Response::from_file("text/html", File::open("src/HTTP/index.html").unwrap()).with_status_code(200) }, (GET) ["/Profile"] => { - Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200) + let Username = Request.get_param("Username"); + let _Password = Request.get_param("Password"); + match Username { + Some(x) => { + let Name = API::GetAccountWithName(&x).unwrap(); + return Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200).with_additional_header("profile", Name); + }, + None => { + return Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200); + } + } }, // API stuff. (GET) ["/API/Profile:Get"] => { // Content-type: application/x-www-form-urlencoded - let Profile = try_or_400!(post_input!(Request, { - ID: i32, - })); - let Things = API::GetAccount(Profile.ID).unwrap(); + let Profile = Request.get_param("id").unwrap().parse::().unwrap(); + let Things = API::GetAccountWithID(Profile).unwrap(); let Text: String = "Got Account: ".to_string() + &Things.to_string(); Response::text(Text).with_status_code(200) }, (POST) ["/API/Profile:Create"] => { // Content-type: application/x-www-form-urlencoded let Profile = try_or_400!(post_input!(Request, { - Type: String, Name: String, })); - let Things = API::MakeAccount(Profile.Type, Profile.Name).unwrap(); + let Things = API::MakeAccount("Person".to_string(), Profile.Name).unwrap(); let Text: String = Things.to_string(); Response::text(Text).with_status_code(201) }, @@ -45,8 +52,8 @@ fn main(){ (GET) ["/style.css"] => { Response::from_file("text/css", File::open("src/HTTP/style.css").unwrap()).with_status_code(200) }, - (GET) ["/script.js"] => { - Response::from_file("text/javascript", File::open("src/HTTP/script.js").unwrap()).with_status_code(200) + (GET) ["/profile.js"] => { + Response::from_file("text/javascript", File::open("src/HTTP/profile.js").unwrap()).with_status_code(200) }, // Catch-all. Fuck you. _ => { -- 2.45.3 From a0652f93c60ca602fb304b2a66a158c50cb148b2 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Sun, 22 Jun 2025 23:10:27 -0700 Subject: [PATCH 16/16] you can now login --- src/API/mod.rs | 37 +++++++++++++++++++++---------------- src/HTTP/profile.js | 2 ++ src/main.rs | 13 +++++++------ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/API/mod.rs b/src/API/mod.rs index 23a6bdf..d0bd225 100644 --- a/src/API/mod.rs +++ b/src/API/mod.rs @@ -1,6 +1,6 @@ use postgres::{Client, NoTls}; -pub fn GetAccountWithName(Name: &str) -> Result>{ +pub fn Login(Username: &str, Password: &str) -> Result, Box>{ let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; let Table = Client.query("SELECT 1 @@ -15,21 +15,26 @@ pub fn GetAccountWithName(Name: &str) -> Result () } - if Client.query("SELECT name FROM person WHERE name = $1", &[&Name])?.len() != 0 { - let Result: Result = Client.query("SELECT name FROM person WHERE name = $1", &[&Name])?[0].try_get(0); - match Result { - Ok(x) => return Ok(x.to_string()), - Err(_) => return Ok("Other Error Encountered.".to_string()) + if Client.query("SELECT username, password FROM person WHERE username = $1", &[&Username])?.len() != 0 { + let mut Response: Vec = Vec::new(); + if Client.query("SELECT username, password FROM person WHERE password = $1", &[&Password])?.len() != 0 { + let Result = Client.query("SELECT username, password FROM person WHERE password = $1", &[&Password])?[0].clone(); + Response.push(Result.get(0)); + Response.push(Result.get(1)); + return Ok(Response); + } else { + return Ok(vec!["Password Not Correct.".to_string()]); } + } else { + return Ok(vec!["Username Not Found.".to_string()]); } - return Ok("Username Not Found.".to_string()); } pub fn GetAccountWithID(ID: i32) -> Result>{ @@ -47,18 +52,18 @@ pub fn GetAccountWithID(ID: i32) -> Result>{ Client.batch_execute(" CREATE TABLE person ( id SERIAL PRIMARY KEY, - type TEXT NOT NULL, - name TEXT NOT NULL + username TEXT NOT NULL, + password TEXT NOT NULL )")?; } }, Err(_) => () } - let Result: String = Client.query("SELECT name FROM person WHERE id = $1", &[&ID]).unwrap()[0].get(0); + let Result: String = Client.query("SELECT username FROM person WHERE id = $1", &[&ID]).unwrap()[0].get(0); return Ok(Result.to_string()); } -pub fn MakeAccount(Type: String, Name: String) -> Result>{ +pub fn MakeAccount(User: String, Pass: String) -> Result>{ let mut Client = Client::connect("host=/var/run/postgresql,localhost user=postgres password=Password dbname=ActivityPub", NoTls)?; let Table = Client.query("SELECT 1 @@ -73,13 +78,13 @@ pub fn MakeAccount(Type: String, Name: String) -> Result () } - Client.execute("INSERT INTO person (type, name) VALUES ($1, $2)", &[&Type, &Name])?; + Client.execute("INSERT INTO person (username, password) VALUES ($1, $2)", &[&User, &Pass])?; return Ok("Account Created!".to_string()); } diff --git a/src/HTTP/profile.js b/src/HTTP/profile.js index defe3e8..eac77a8 100644 --- a/src/HTTP/profile.js +++ b/src/HTTP/profile.js @@ -18,6 +18,8 @@ req.onload = function() { if (headerMap.get("profile") != null) { if (headerMap.get("profile") == "Username Not Found.") { Infomation.innerHTML = "User not found. Please check your username and try again!"; + } else if (headerMap.get("profile") == "Password Not Correct.") { + Infomation.innerHTML = "Password not correct. Please check your password and try again!"; } else { Account.innerHTML = headerMap.get("profile"); Infomation.innerHTML = "Welcome!"; diff --git a/src/main.rs b/src/main.rs index 13a7c99..a374be3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,14 +17,14 @@ fn main(){ }, (GET) ["/Profile"] => { let Username = Request.get_param("Username"); - let _Password = Request.get_param("Password"); + let Password = Request.get_param("Password").unwrap(); match Username { Some(x) => { - let Name = API::GetAccountWithName(&x).unwrap(); - return Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200).with_additional_header("profile", Name); + let Account: Vec = API::Login(&x, &Password).unwrap(); + Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200).with_additional_header("profile", Account[0].clone()) }, None => { - return Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200); + Response::from_file("text/html", File::open("src/HTTP/profile.html").unwrap()).with_status_code(200) } } }, @@ -39,9 +39,10 @@ fn main(){ (POST) ["/API/Profile:Create"] => { // Content-type: application/x-www-form-urlencoded let Profile = try_or_400!(post_input!(Request, { - Name: String, + Username: String, + Password: String, })); - let Things = API::MakeAccount("Person".to_string(), Profile.Name).unwrap(); + let Things = API::MakeAccount(Profile.Username.to_string(), Profile.Password.to_string()).unwrap(); let Text: String = Things.to_string(); Response::text(Text).with_status_code(201) }, -- 2.45.3