diff --git a/Cargo.lock b/Cargo.lock index c9fb174..d909775 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,16 +255,64 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.75" +name = "anstream" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" dependencies = [ "proc-macro2", "quote", @@ -426,6 +474,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "build_html" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3108fe6fe7ac796fb7625bdde8fa2b67b5a7731496251ca57c7b8cadd78a16a1" + [[package]] name = "bumpalo" version = "3.14.0" @@ -476,10 +530,58 @@ checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", - "windows-targets", + "wasm-bindgen", + "windows-targets 0.48.5", ] +[[package]] +name = "clap" +version = "4.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "convert_case" version = "0.4.0" @@ -511,6 +613,37 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -620,11 +753,8 @@ dependencies = [ "diesel_derives", "itoa", "libsqlite3-sys", - "mysqlclient-sys", - "percent-encoding", "pq-sys", "time", - "url", ] [[package]] @@ -639,6 +769,17 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "diesel_migrations" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6036b3f0120c5961381b570ee20a02432d7e2d27ea60de9578799cf9156914ac" +dependencies = [ + "diesel", + "migrations_internals", + "migrations_macros", +] + [[package]] name = "diesel_table_macro_syntax" version = "0.1.0" @@ -658,6 +799,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dyn-clone" version = "1.0.16" @@ -716,7 +863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -911,6 +1058,12 @@ dependencies = [ "http 0.2.11", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -1097,7 +1250,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.51.1", ] [[package]] @@ -1198,9 +1351,23 @@ name = "linstrom" version = "0.1.0" dependencies = [ "activitypub_federation", + "anyhow", + "async-trait", "axum 0.7.1", + "build_html", + "chrono", + "clap", "diesel", + "diesel_migrations", + "dotenvy", + "rand", + "serde", + "serde_derive", + "sysinfo", "tokio", + "toml 0.8.8", + "tracing", + "url", ] [[package]] @@ -1254,6 +1421,27 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "migrations_internals" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f23f71580015254b020e856feac3df5878c2c7a8812297edd6c0a485ac9dada" +dependencies = [ + "serde", + "toml 0.7.8", +] + +[[package]] +name = "migrations_macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cce3325ac70e67bbab5bd837a31cae01f1a6db64e0e744a33cb03a543469ef08" +dependencies = [ + "migrations_internals", + "proc-macro2", + "quote", +] + [[package]] name = "mime" version = "0.3.17" @@ -1288,17 +1476,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", -] - -[[package]] -name = "mysqlclient-sys" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61b381528ba293005c42a409dd73d034508e273bf90481f17ec2e964a6e969b" -dependencies = [ - "pkg-config", - "vcpkg", + "windows-sys 0.48.0", ] [[package]] @@ -1319,6 +1497,15 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -1417,7 +1604,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1539,6 +1726,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -1658,7 +1865,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1679,7 +1886,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1759,6 +1966,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1834,7 +2050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1871,6 +2087,21 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sysinfo" +version = "0.30.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba2dbd2894d23b2d78dae768d85e323b557ac3ac71a5d917a31536d8f77ebada" +dependencies = [ + "cfg-if", + "core-foundation-sys", + "libc", + "ntapi", + "once_cell", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -1911,7 +2142,7 @@ dependencies = [ "fastrand", "redox_syscall", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1994,7 +2225,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.5", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2032,6 +2263,65 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", +] + +[[package]] +name = "toml" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.21.0", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "toml_edit" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -2146,6 +2436,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2284,13 +2580,32 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +dependencies = [ + "windows-core 0.52.0", + "windows-targets 0.52.0", +] + [[package]] name = "windows-core" version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -2299,7 +2614,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -2308,13 +2632,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -2323,42 +2662,93 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "winnow" +version = "0.5.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" @@ -2366,7 +2756,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f029edf..ec4bf1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" authors = ["mStar"] license = "EUPL-1.2" -license-file = "LICENSE" description = "An ActivityPub enabled social media server focused on helping with user safety" readme = "README.md" repository = "https://gitlab.com/mstarongitlab/linstrom" @@ -17,3 +16,17 @@ activitypub_federation = "0.4.7" axum = "0.7.1" diesel = { version = "2.1.4", features = ["sqlite", "postgres"] } tokio = { version = "1.34.0", features = ["full"]} +build_html = "2.4.0" +serde = "1.0.193" +url = "2.5.0" +chrono = "0.4.31" +tracing = "0.1.40" +rand = "0.8.5" +anyhow = "1.0.77" +async-trait = "0.1.75" +dotenvy = "0.15.7" +clap = { version = "4.4.12", features = ["derive"] } +toml = "0.8.8" +serde_derive = "1.0.193" +sysinfo = "0.30.3" +diesel_migrations = "2.1.0" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..cb364be --- /dev/null +++ b/config.toml @@ -0,0 +1,4 @@ +[config] +database_path = "src/storage/db.sqlite" +max_workers = 100 +min_workers = 0 \ No newline at end of file diff --git a/migrations/2023-12-29-193430_create_people/down.sql b/migrations/2023-12-29-193430_create_people/down.sql new file mode 100644 index 0000000..d9a93fe --- /dev/null +++ b/migrations/2023-12-29-193430_create_people/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/migrations/2023-12-29-193430_create_people/up.sql b/migrations/2023-12-29-193430_create_people/up.sql new file mode 100644 index 0000000..e191ec7 --- /dev/null +++ b/migrations/2023-12-29-193430_create_people/up.sql @@ -0,0 +1,7 @@ +CREATE TABLE people ( + id STRING primary key, + name STRING not null, + instance STRING, + mail STRING, + pw_hash STRING +) \ No newline at end of file diff --git a/src/apis/mod.rs b/src/apis/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..72aba59 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,163 @@ +// Copyright (c) 2023 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +use anyhow::{anyhow, bail, Error}; +use clap::Parser; +use serde_derive::Deserialize; +use std::{fs, path::PathBuf}; +use sysinfo::System; + +const MEGABYTE: u64 = 1049000; +/// Assumed memory consumption per worker +/// Rather overshoot this than undershoot +const ASSUMED_MEM_PER_WORKER: u64 = 2 * MEGABYTE; +const CPUS_RESERVED_FOR_SYSTEM: u32 = 2; + +#[derive(Debug)] +pub struct Config { + /// Path to the db for diesel to use + database_path: String, + /// Maximum number of workers to use + /// A value of 0 makes stuff single-threaded + max_workers: u32, + /// Minimum number of workers to use + min_workers: u32, +} + +#[derive(Debug, Deserialize)] +struct ConfigRootToml { + config: Option, +} + +#[derive(Debug, Deserialize)] +struct ConfigToml { + /// Path to the db for diesel to use + database_path: Option, + /// Maximum number of workers to use + /// A value of 0 makes stuff single-threaded + max_workers: Option, + /// Minimum number of workers to use + min_workers: Option, +} + +/// An ActivityPub enabled social media server +#[derive(Debug, Parser)] +#[command(author, version, about, long_about = None)] +pub struct CLIArguments { + /// Path to the config file + #[arg(default_value = "config.toml")] + config: PathBuf, + /// Maximum amount of workers to use + /// If not set, the max is calculated depending on system resources + /// A value of 0 will cause the server to be singlethreaded, potentially reducing the performance and responsiveness by a lot + #[arg(long)] + max_workers: Option, + /// Minimum amount of workers to keep active at all times + /// Can potentially increase reaction speed at the cost of resource usage + #[arg(long)] + min_workers: Option, + + #[arg(long)] + db_path: Option, +} + +pub fn read_from_env() -> Result { + let args = CLIArguments::parse(); + + if !args.config.is_file() { + bail!("Config path is not a file"); + }; + let ext = args.config.extension().ok_or(anyhow!( + "Type of config file couldn't be determined. No extension" + ))?; + if ext != "toml" { + bail!("Config file is not a toml file"); + } + + let contents = match fs::read_to_string(&args.config) { + Ok(c) => c, + Err(err) => bail!("Couldn't read config file. Error: {err}"), + }; + + let unsanitized: ConfigRootToml = match toml::from_str(&contents) { + Ok(d) => d, + Err(err) => bail!("Failed to parse config file. Error: {err}"), + }; + Ok(unsanitized.into_config(&args)) +} + +fn calc_max_workers_from_system() -> u32 { + let mut sys = System::new_all(); + sys.refresh_all(); + let available_ram = sys.available_memory() - sys.used_memory(); + let available_cpus = (sys.cpus().len() as u32) - CPUS_RESERVED_FOR_SYSTEM; + let max_workers_ram = (available_ram / ASSUMED_MEM_PER_WORKER) as u32; + // Assume one worker per available CPU + // The lower number of potential workers is what we'll use + if available_cpus > max_workers_ram { + max_workers_ram + } else { + available_cpus + } +} + +impl ConfigRootToml { + fn into_config(&self, cli: &CLIArguments) -> Config { + match &self.config { + Some(config) => { + let db_path = match &cli.db_path { + Some(path) => path.clone(), + None => match &config.database_path { + Some(path) => path.clone(), + None => "config.toml".into(), + }, + }; + let min_workers = match cli.min_workers { + Some(num) => num, + None => match config.min_workers { + Some(num) => num, + None => 1, + }, + }; + let max_workers = match cli.max_workers { + Some(num) => num, + None => match config.max_workers { + Some(num) => num, + None => calc_max_workers_from_system(), + }, + }; + Config { + database_path: db_path, + min_workers, + max_workers, + } + } + None => { + let db_path = match &cli.db_path { + Some(path) => path.clone(), + None => "config.toml".to_string(), + }; + let min_workers = match cli.min_workers { + Some(num) => num, + None => 1, + }; + let max_workers = match cli.max_workers { + Some(num) => num, + None => calc_max_workers_from_system(), + }; + Config { + database_path: db_path.clone(), + min_workers, + max_workers, + } + } + } + } +} diff --git a/src/guardian/mod.rs b/src/guardian/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 3dca236..97e081f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,16 @@ // You should have received a copy of the Licence along with this work. If not, see: // . // See the Licence for the specific language governing permissions and limitations under the Licence. +// +mod objects; +mod apis; mod storage; +mod guardian; +mod config; +mod webui; + fn main() { - println!("Hello, world!"); -} + println!("{:?}", config::read_from_env()); +} \ No newline at end of file diff --git a/src/objects/mod.rs b/src/objects/mod.rs new file mode 100644 index 0000000..f172957 --- /dev/null +++ b/src/objects/mod.rs @@ -0,0 +1,12 @@ +// Copyright (c) 2023 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +pub mod person; +pub mod post; \ No newline at end of file diff --git a/src/objects/person.rs b/src/objects/person.rs new file mode 100644 index 0000000..913bda4 --- /dev/null +++ b/src/objects/person.rs @@ -0,0 +1,17 @@ +// Copyright (c) 2023 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// + +pub struct Person { + name: String, + instance: Option, // If not set, assume local user + id: String, // @@ + mail: Option, + pw_hash: String, // If not set, user uses hardware token +} diff --git a/src/objects/post.rs b/src/objects/post.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 070fec0..dd457b6 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -6,57 +6,33 @@ // You should have received a copy of the Licence along with this work. If not, see: // . // See the Licence for the specific language governing permissions and limitations under the Licence. +// -use tokio::fs::File; -use diesel:: - -pub type MessageID = i64; -pub type MediaID = i64; +use diesel::{prelude::*, sqlite::Sqlite}; +use diesel::pg::PgConnection; +use diesel_migrations::{EmbeddedMigrations, embed_migrations, MigrationHarness}; +use dotenvy::dotenv; +use std::{env, error::Error}; -pub trait StorageAccess { - fn store_message(user: &str, message: &str) -> Result; - fn get_message(user: &str, id: &MessageID) -> Result; - fn delete_message(id: &MessageID) -> Result; - fn edit_message(id: &MessageID, message: &str) -> Result; +pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); - fn store_media(f: &File, nsfw: bool, alt_text: Option<&str>) -> Result; - fn get_media(id: &MediaID) -> Result<(File, bool, Option), E>; - fn delete_media(id: &MediaID) -> Result; - // No edit media because how? Editing media in a message replaces the media, not edits it +pub fn establish_connection(db_url: &str) -> PgConnection { + dotenv().ok(); + let conn = PgConnection::establish(db_url) + .unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); + // TODO: Add migrations here + conn } -pub struct Storage { - db: -} +fn run_migrations_sqlite(connection: &mut impl MigrationHarness) -> Result<(), Box> { -impl StorageAccess for Storage { - fn store_message(user: &str, message: &str) -> Result { - todo!() - } + // This will run the necessary migrations. + // + // See the documentation for `MigrationHarness` for + // all available methods. + connection.run_pending_migrations(MIGRATIONS)?; - fn get_message(user: &str, id: &MessageID) -> Result { - todo!() - } - - fn delete_message(id: &MessageID) -> Result { - todo!() - } - - fn edit_message(id: &MessageID, message: &str) -> Result { - todo!() - } - - fn store_media(f: &File, nsfw: bool, alt_text: Option<&str>) -> Result { - todo!() - } - - fn get_media(id: &MediaID) -> Result<(File, bool, Option), E> { - todo!() - } - - fn delete_media(id: &MediaID) -> Result { - todo!() - } + Ok(()) } \ No newline at end of file diff --git a/src/webui/mod.rs b/src/webui/mod.rs new file mode 100644 index 0000000..3710094 --- /dev/null +++ b/src/webui/mod.rs @@ -0,0 +1,10 @@ +// Copyright (c) 2023 mStar +// +// Licensed under the EUPL, Version 1.2 +// +// You may not use this work except in compliance with the Licence. +// You should have received a copy of the Licence along with this work. If not, see: +// . +// See the Licence for the specific language governing permissions and limitations under the Licence. +// +