diff --git a/Cargo.lock b/Cargo.lock index d909775..5175d83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,13 +4,12 @@ version = 3 [[package]] name = "activitypub_federation" -version = "0.4.7" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41a0b760e573d41d9f6aec4280e4c0d273d4ce724eb00c3e4c9fb1b98d3ede47" +checksum = "8bac58c1d61b6e2358adbd043c78ba853428102b489acb7b6cb74ee6f2ae668f" dependencies = [ "activitystreams-kinds", "actix-web", - "anyhow", "async-trait", "axum 0.6.20", "base64 0.21.5", @@ -19,13 +18,16 @@ dependencies = [ "derive_builder", "dyn-clone", "enum_delegate", + "futures", "futures-core", "http 0.2.11", + "http-body-util", "http-signature-normalization", "http-signature-normalization-reqwest", "httpdate", "hyper 0.14.27", "itertools", + "moka", "once_cell", "openssl", "pin-project-lite", @@ -71,9 +73,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.4.0" +version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92ef85799cba03f76e4f7c10f533e66d87c9a7e7055f3391f09000ad8351bc9" +checksum = "129d4c88e98860e1758c5de288d1632b07970a16d59bdf7b8d66053d582bb71f" dependencies = [ "actix-codec", "actix-rt", @@ -167,9 +169,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4a5b5e29603ca8c94a77c65cf874718ceb60292c5a5c3e5f4ace041af462b9" +checksum = "e43428f3bf11dee6d166b00ec2df4e3aa8cc1606aaa0b7433c146852e2f4e03b" dependencies = [ "actix-codec", "actix-http", @@ -309,14 +311,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] -name = "async-trait" -version = "0.1.75" +name = "async-lock" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-trait" +version = "0.1.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -486,6 +497,12 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "bytecount" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" + [[package]] name = "byteorder" version = "1.5.0" @@ -507,6 +524,37 @@ dependencies = [ "bytes", ] +[[package]] +name = "camino" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceed8ef69d8518a5dda55c07425450b58a4e1946f4951eab6d7191ee86c2443d" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + [[package]] name = "cc" version = "1.0.83" @@ -567,7 +615,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -613,6 +661,16 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.4" @@ -750,10 +808,12 @@ checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8" dependencies = [ "bitflags 2.4.1", "byteorder", + "chrono", "diesel_derives", "itoa", "libsqlite3-sys", "pq-sys", + "r2d2", "time", ] @@ -766,7 +826,7 @@ dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -786,7 +846,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -866,6 +926,21 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "2.0.1" @@ -903,55 +978,83 @@ dependencies = [ ] [[package]] -name = "futures-channel" -version = "0.3.29" +name = "futures" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -990,6 +1093,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.22" @@ -1137,10 +1246,11 @@ dependencies = [ [[package]] name = "http-signature-normalization-reqwest" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c382c69a07b21accae86298d520579403af6479b1cd1c389e3ee11f01d48627" +checksum = "10cfb84663420ec12c4422820bfdf5e8e5e57467892587f43ac432e73ebce880" dependencies = [ + "async-trait", "base64 0.13.1", "http-signature-normalization", "httpdate", @@ -1296,9 +1406,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itertools" -version = "0.10.5" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" dependencies = [ "either", ] @@ -1363,6 +1473,7 @@ dependencies = [ "rand", "serde", "serde_derive", + "serde_json", "sysinfo", "tokio", "toml 0.8.8", @@ -1409,6 +1520,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "matchit" version = "0.7.3" @@ -1479,6 +1599,30 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "moka" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f353abec74660d4b8533c2516c86eb062f1ec8ca49a2758f4f2b1b60b06b0c6e" +dependencies = [ + "async-lock", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "futures-util", + "once_cell", + "parking_lot", + "quanta", + "rustc_version", + "skeptic", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -1536,15 +1680,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.60" +version = "0.10.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800" +checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -1563,7 +1707,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1574,9 +1718,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.96" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" +checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" dependencies = [ "cc", "libc", @@ -1636,7 +1780,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1680,22 +1824,60 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] [[package]] -name = "quote" -version = "1.0.33" +name = "pulldown-cmark" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" +dependencies = [ + "bitflags 1.3.2", + "memchr", + "unicase", +] + +[[package]] +name = "quanta" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab" +dependencies = [ + "crossbeam-utils", + "libc", + "mach2", + "once_cell", + "raw-cpuid", + "wasi", + "web-sys", + "winapi", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] +[[package]] +name = "r2d2" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" +dependencies = [ + "log", + "parking_lot", + "scheduled-thread-pool", +] + [[package]] name = "rand" version = "0.8.5" @@ -1726,6 +1908,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "raw-cpuid" +version = "10.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "rayon" version = "1.8.0" @@ -1786,9 +1977,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ "base64 0.21.5", "bytes", @@ -1880,6 +2071,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.22" @@ -1889,6 +2089,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "scheduled-thread-pool" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" +dependencies = [ + "parking_lot", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1923,32 +2132,35 @@ name = "semver" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +dependencies = [ + "serde", +] [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "indexmap", "itoa", @@ -2018,6 +2230,21 @@ dependencies = [ "libc", ] +[[package]] +name = "skeptic" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8" +dependencies = [ + "bytecount", + "cargo_metadata", + "error-chain", + "glob", + "pulldown-cmark", + "tempfile", + "walkdir", +] + [[package]] name = "slab" version = "0.4.9" @@ -2072,9 +2299,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -2123,6 +2350,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + [[package]] name = "task-local-extensions" version = "0.1.4" @@ -2147,22 +2380,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2211,9 +2444,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.34.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -2236,7 +2469,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2370,7 +2603,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2382,6 +2615,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + [[package]] name = "try-lock" version = "0.2.4" @@ -2442,6 +2681,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +dependencies = [ + "getrandom", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -2454,6 +2702,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2490,7 +2748,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -2524,7 +2782,7 @@ checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2574,6 +2832,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2776,5 +3043,5 @@ checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] diff --git a/Cargo.toml b/Cargo.toml index ec4bf1e..09d4e63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,9 @@ exclude = ["/.vscode", "/FeatureTargets.md"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -activitypub_federation = "0.4.7" +activitypub_federation = "0.5.0" axum = "0.7.1" -diesel = { version = "2.1.4", features = ["sqlite", "postgres"] } +diesel = { version = "2.1.4", features = ["sqlite", "postgres", "r2d2", "chrono"] } tokio = { version = "1.34.0", features = ["full"]} build_html = "2.4.0" serde = "1.0.193" @@ -30,3 +30,4 @@ toml = "0.8.8" serde_derive = "1.0.193" sysinfo = "0.30.3" diesel_migrations = "2.1.0" +serde_json = "1.0.111" diff --git a/diesel-devel b/diesel-devel deleted file mode 100755 index 9d151dd..0000000 --- a/diesel-devel +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/bash -touch db.sqlite -DATABASE_URL="db.sqlite";diesel --config-file diesel_devel.toml $@ \ No newline at end of file diff --git a/diesel.toml b/diesel.toml index 16af524..643b3d2 100644 --- a/diesel.toml +++ b/diesel.toml @@ -2,8 +2,8 @@ # see https://diesel.rs/guides/configuring-diesel-cli [print_schema] -file = "src/storage/diesel_db/postgres.rs" +file = "src/storage/pg_schemas.rs" custom_type_derives = ["diesel::query_builder::QueryId"] [migrations_directory] -dir = "migrations/postgres" +dir = "migrations" diff --git a/diesel_devel.toml b/diesel_devel.toml deleted file mode 100644 index 9c2e757..0000000 --- a/diesel_devel.toml +++ /dev/null @@ -1,9 +0,0 @@ -# For documentation on how to configure this file, -# see https://diesel.rs/guides/configuring-diesel-cli - -[print_schema] -file = "src/storage/diesel_db/sqlite.rs" -custom_type_derives = ["diesel::query_builder::QueryId"] - -[migrations_directory] -dir = "migrations/sqlite" diff --git a/migrations/postgres/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql similarity index 100% rename from migrations/postgres/00000000000000_diesel_initial_setup/down.sql rename to migrations/00000000000000_diesel_initial_setup/down.sql diff --git a/migrations/postgres/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql similarity index 100% rename from migrations/postgres/00000000000000_diesel_initial_setup/up.sql rename to migrations/00000000000000_diesel_initial_setup/up.sql diff --git a/migrations/postgres/2023-12-29-193430_create_people/down.sql b/migrations/2023-12-29-193430_create_people/down.sql similarity index 100% rename from migrations/postgres/2023-12-29-193430_create_people/down.sql rename to migrations/2023-12-29-193430_create_people/down.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..59891d1 --- /dev/null +++ b/migrations/2023-12-29-193430_create_people/up.sql @@ -0,0 +1,13 @@ +create table people ( + ap_id text primary key, + name text not null, + instance text, + mail text, + pw_hash text, + inbox text not null, + public_key text not null, + private_key text, + last_refreshed_at timestamp not null, + local boolean not null, + followers text[] not null +) \ No newline at end of file diff --git a/migrations/sqlite/2023-12-31-223546_create_people/down.sql b/migrations/2024-01-06-210647_create_posts/down.sql similarity index 71% rename from migrations/sqlite/2023-12-31-223546_create_people/down.sql rename to migrations/2024-01-06-210647_create_posts/down.sql index fa02ff1..d9a93fe 100644 --- a/migrations/sqlite/2023-12-31-223546_create_people/down.sql +++ b/migrations/2024-01-06-210647_create_posts/down.sql @@ -1,2 +1 @@ -- This file should undo anything in `up.sql` -DROP TABLE people; \ No newline at end of file diff --git a/migrations/2024-01-06-210647_create_posts/up.sql b/migrations/2024-01-06-210647_create_posts/up.sql new file mode 100644 index 0000000..b37f10d --- /dev/null +++ b/migrations/2024-01-06-210647_create_posts/up.sql @@ -0,0 +1 @@ +-- Your SQL goes here diff --git a/migrations/postgres/.keep b/migrations/postgres/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/postgres/2023-12-29-193430_create_people/up.sql b/migrations/postgres/2023-12-29-193430_create_people/up.sql deleted file mode 100644 index 4b82ad1..0000000 --- a/migrations/postgres/2023-12-29-193430_create_people/up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE people ( - id TEXT primary key, - name TEXT not null, - instance TEXT, - mail TEXT, - pw_hash TEXT, - is_local BOOLEAN -) \ No newline at end of file diff --git a/migrations/sqlite/.keep b/migrations/sqlite/.keep deleted file mode 100644 index 3710094..0000000 --- a/migrations/sqlite/.keep +++ /dev/null @@ -1,10 +0,0 @@ -// 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. -// - diff --git a/migrations/sqlite/00000000000000_diesel_initial_setup/down.sql b/migrations/sqlite/00000000000000_diesel_initial_setup/down.sql deleted file mode 100644 index a9f5260..0000000 --- a/migrations/sqlite/00000000000000_diesel_initial_setup/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - -DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); -DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/migrations/sqlite/00000000000000_diesel_initial_setup/up.sql b/migrations/sqlite/00000000000000_diesel_initial_setup/up.sql deleted file mode 100644 index d68895b..0000000 --- a/migrations/sqlite/00000000000000_diesel_initial_setup/up.sql +++ /dev/null @@ -1,36 +0,0 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - - - - --- Sets up a trigger for the given table to automatically set a column called --- `updated_at` whenever the row is modified (unless `updated_at` was included --- in the modified columns) --- --- # Example --- --- ```sql --- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); --- --- SELECT diesel_manage_updated_at('users'); --- ``` -CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ -BEGIN - EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s - FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ -BEGIN - IF ( - NEW IS DISTINCT FROM OLD AND - NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at - ) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; diff --git a/migrations/sqlite/2023-12-31-223546_create_people/up.sql b/migrations/sqlite/2023-12-31-223546_create_people/up.sql deleted file mode 100644 index 4c3ff7b..0000000 --- a/migrations/sqlite/2023-12-31-223546_create_people/up.sql +++ /dev/null @@ -1,9 +0,0 @@ --- Your SQL goes here -CREATE TABLE people ( - id STRING primary key, - name STRING not null, - instance STRING, - mail STRING, - pw_hash STRING, - is_local BOOLEAN -) \ No newline at end of file diff --git a/src/apis/ap.rs b/src/apis/ap.rs index e69de29..67d393f 100644 --- a/src/apis/ap.rs +++ b/src/apis/ap.rs @@ -0,0 +1,14 @@ +// Routes +// User info: /:user +// Inbox: /:user/inbox +// Webfinger: /.well-known/webfinger + +use axum::Router; + +pub fn register(router: Router) -> Router { + router +} + +fn get_user() -> String { + "Foo".into() +} \ No newline at end of file diff --git a/src/apis/key.rs b/src/apis/key.rs index e69de29..ec626c5 100644 --- a/src/apis/key.rs +++ b/src/apis/key.rs @@ -0,0 +1,370 @@ +// admin/meta +// admin/abuse-user-reports +// admin/accounts/create +// admin/accounts/delete +// admin/accounts/find-by-email +// admin/ad/create +// admin/ad/delete +// admin/ad/list +// admin/ad/update +// admin/announcements/create +// admin/announcements/delete +// admin/announcements/list +// admin/announcements/update +// admin/avatar-decorations/create +// admin/avatar-decorations/delete +// admin/avatar-decorations/list +// admin/avatar-decorations/update +// admin/delete-all-files-of-a-user +// admin/unset-user-avatar +// admin/unset-user-banner +// admin/drive/clean-remote-files +// admin/drive/cleanup +// admin/drive/files +// admin/drive/show-file +// admin/emoji/add-aliases-bulk +// admin/emoji/add +// admin/emoji/copy +// admin/emoji/delete-bulk +// admin/emoji/delete +// admin/emoji/import-zip +// admin/emoji/list-remote +// admin/emoji/list +// admin/emoji/remove-aliases-bulk +// admin/emoji/set-aliases-bulk +// admin/emoji/set-category-bulk +// admin/emoji/set-license-bulk +// admin/emoji/update +// admin/federation/delete-all-files +// admin/federation/refresh-remote-instance-metadata +// admin/federation/remove-all-following +// admin/federation/update-instance +// admin/get-index-stats +// admin/get-table-stats +// admin/get-user-ips +// admin/invite/create +// admin/invite/list +// admin/promo/create +// admin/queue/clear +// admin/queue/deliver-delayed +// admin/queue/inbox-delayed +// admin/queue/promote +// admin/queue/stats +// admin/relays/add +// admin/relays/list +// admin/relays/remove +// admin/reset-password +// admin/resolve-abuse-user-report +// admin/send-email +// admin/server-info +// admin/show-moderation-logs +// admin/show-user +// admin/show-users +// admin/nsfw-user +// admin/unnsfw-user +// admin/silence-user +// admin/unsilence-user +// admin/suspend-user +// admin/approve-user +// admin/unsuspend-user +// admin/update-meta +// admin/delete-account +// admin/update-user-note +// admin/roles/create +// admin/roles/delete +// admin/roles/list +// admin/roles/show +// admin/roles/update +// admin/roles/assign +// admin/roles/unassign +// admin/roles/update-default-policies +// admin/roles/users +// announcements +// antennas/create +// antennas/delete +// antennas/list +// antennas/notes +// antennas/show +// antennas/update +// ap/get +// ap/show +// app/create +// app/show +// auth/accept +// auth/session/generate +// auth/session/show +// auth/session/userkey +// blocking/create +// blocking/delete +// blocking/list +// channels/create +// channels/featured +// channels/follow +// channels/followed +// channels/owned +// channels/show +// channels/timeline +// channels/unfollow +// channels/update +// channels/favorite +// channels/unfavorite +// channels/my-favorites +// channels/search +// charts/active-users +// charts/ap-request +// charts/drive +// charts/federation +// charts/instance +// charts/notes +// charts/user/drive +// charts/user/following +// charts/user/notes +// charts/user/pv +// charts/user/reactions +// charts/users +// clips/add-note +// clips/remove-note +// clips/create +// clips/delete +// clips/list +// clips/notes +// clips/show +// clips/update +// clips/favorite +// clips/unfavorite +// clips/my-favorites +// drive +// drive/files +// drive/files/attached-notes +// drive/files/check-existence +// drive/files/create +// drive/files/delete +// drive/files/find-by-hash +// drive/files/find +// drive/files/show +// drive/files/update +// drive/files/upload-from-url +// drive/folders +// drive/folders/create +// drive/folders/delete +// drive/folders/find +// drive/folders/show +// drive/folders/update +// drive/stream +// email-address/available +// endpoint +// endpoints +// export-custom-emojis +// federation/followers +// federation/following +// federation/instances +// federation/show-instance +// federation/update-remote-user +// federation/users +// federation/stats +// following/create +// following/delete +// following/update +// following/update-all +// following/invalidate +// following/requests/accept +// following/requests/cancel +// following/requests/list +// following/requests/reject +// gallery/featured +// gallery/popular +// gallery/posts +// gallery/posts/create +// gallery/posts/delete +// gallery/posts/like +// gallery/posts/show +// gallery/posts/unlike +// gallery/posts/update +// get-online-users-count +// get-avatar-decorations +// hashtags/list +// hashtags/search +// hashtags/show +// hashtags/trend +// hashtags/users +// i +// i/2fa/done +// i/2fa/key-done +// i/2fa/password-less +// i/2fa/register-key +// i/2fa/register +// i/2fa/update-key +// i/2fa/remove-key +// i/2fa/unregister +// i/apps +// i/authorized-apps +// i/claim-achievement +// i/change-password +// i/delete-account +// i/export-data +// i/export-blocking +// i/export-following +// i/export-mute +// i/export-notes +// i/export-favorites +// i/export-user-lists +// i/export-antennas +// i/favorites +// i/gallery/likes +// i/gallery/posts +// i/import-blocking +// i/import-following +// i/import-notes +// i/import-muting +// i/import-user-lists +// i/import-antennas +// i/notifications +// i/notifications-grouped +// i/page-likes +// i/pages +// i/pin +// i/read-all-unread-notes +// i/read-announcement +// i/regenerate-token +// i/registry/get-all +// i/registry/get-unsecure +// i/registry/get-detail +// i/registry/get +// i/registry/keys-with-type +// i/registry/keys +// i/registry/remove +// i/registry/scopes-with-domain +// i/registry/set +// i/revoke-token +// i/signin-history +// i/unpin +// i/update-email +// i/update +// i/move +// i/webhooks/create +// i/webhooks/list +// i/webhooks/show +// i/webhooks/update +// i/webhooks/delete +// invite/create +// invite/delete +// invite/list +// invite/limit +// meta +// emojis +// emoji +// miauth/gen-token +// mute/create +// mute/delete +// mute/list +// renote-mute/create +// renote-mute/delete +// renote-mute/list +// my/apps +// notes +// notes/children +// notes/clips +// notes/conversation +// notes/create +// notes/delete +// notes/favorites/create +// notes/favorites/delete +// notes/featured +// notes/global-timeline +// notes/bubble-timeline +// notes/hybrid-timeline +// notes/local-timeline +// notes/mentions +// notes/polls/recommendation +// notes/polls/vote +// notes/reactions +// notes/reactions/create +// notes/reactions/delete +// notes/like +// notes/renotes +// notes/replies +// notes/search-by-tag +// notes/search +// notes/show +// notes/state +// notes/thread-muting/create +// notes/thread-muting/delete +// notes/timeline +// notes/translate +// notes/unrenote +// notes/user-list-timeline +// notes/edit +// notes/versions +// notifications/create +// notifications/mark-all-as-read +// notifications/test-notification +// page-push +// pages/create +// pages/delete +// pages/featured +// pages/like +// pages/show +// pages/unlike +// pages/update +// flash/create +// flash/delete +// flash/featured +// flash/like +// flash/show +// flash/unlike +// flash/update +// flash/my +// flash/my-likes +// ping +// pinned-users +// promo/read +// roles/list +// roles/show +// roles/users +// roles/notes +// request-reset-password +// reset-db +// reset-password +// server-info +// stats +// sw/show-registration +// sw/update-registration +// sw/register +// sw/unregister +// test +// username/available +// users +// users/clips +// users/followers +// users/following +// users/gallery/posts +// users/get-frequently-replied-users +// users/featured-notes +// users/lists/create +// users/lists/delete +// users/lists/list +// users/lists/pull +// users/lists/push +// users/lists/show +// users/lists/favorite +// users/lists/unfavorite +// users/lists/update +// users/lists/create-from-public +// users/lists/update-membership +// users/lists/get-memberships +// users/notes +// users/pages +// users/flashs +// users/reactions +// users/recommendation +// users/relation +// users/report-abuse +// users/search-by-username-and-host +// users/search +// users/show +// users/achievements +// users/update-memo +// fetch-rss +// fetch-external-resources +// retention +// sponsors \ No newline at end of file diff --git a/src/apis/mod.rs b/src/apis/mod.rs index 141699d..f6ac97e 100644 --- a/src/apis/mod.rs +++ b/src/apis/mod.rs @@ -1,4 +1,4 @@ pub mod ap; pub mod key; pub mod oma; -pub mod masto; \ No newline at end of file +pub mod masto; diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..37a3127 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,20 @@ +use std::fmt::{Display, Formatter}; + +/// Necessary because of this issue: https://github.com/actix/actix-web/issues/1711 +#[derive(Debug)] +pub struct Error(pub(crate) anyhow::Error); + +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} + +impl From for Error +where + T: Into, +{ + fn from(t: T) -> Self { + Error(t.into()) + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 13c53c5..8e66edc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,9 +16,11 @@ mod storage; mod guardian; mod config; mod webui; +mod error; -fn main() -> Result<(), Error> { +#[tokio::main] +async fn main() -> Result<(), Error> { let conf = config::read_from_env()?; let _db = storage::establish_connection(&conf.database_path)?; Ok(()) diff --git a/src/objects/person.rs b/src/objects/person.rs index 913bda4..29d5894 100644 --- a/src/objects/person.rs +++ b/src/objects/person.rs @@ -8,10 +8,23 @@ // See the Licence for the specific language governing permissions and limitations under the Licence. // +use activitypub_federation::{kinds::actor::PersonType, fetch::object_id::ObjectId, protocol::public_key::PublicKey}; +use serde_derive::{Deserialize, Serialize}; +use url::Url; + +use crate::storage::pg_models::PersonPG; + + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] 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 + pub kind: PersonType, + pub preferred_username: String, + pub id: ObjectId, + pub inbox: Url, + pub public_key: PublicKey, } + +pub trait IntoPerson { + fn into_person(&self) -> Person; +} \ No newline at end of file diff --git a/src/objects/post.rs b/src/objects/post.rs index e69de29..c99bcfd 100644 --- a/src/objects/post.rs +++ b/src/objects/post.rs @@ -0,0 +1,25 @@ +use activitypub_federation::{kinds::object::NoteType, fetch::object_id::ObjectId}; +use serde_derive::{Deserialize, Serialize}; +use url::Url; + +use crate::storage::pg_person::PersonPG; + +#[derive(Deserialize, Serialize, Debug)] +pub struct Post { + #[serde(rename = "type")] + pub kind: NoteType, + pub id: ObjectId<>, + pub(crate) attributed_to: ObjectId, + #[serde(deserialize_with = "deserialize_one_or_many")] + pub(crate) to: Vec, + pub content: String, + pub in_reply_to: Option>, + tag: Vec +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Mention { + pub href: Url, + #[serde(rename = "type")] + pub kind: MentionType, +} \ No newline at end of file diff --git a/src/storage/diesel_db/mod.rs b/src/storage/diesel_db/mod.rs deleted file mode 100644 index c2a3090..0000000 --- a/src/storage/diesel_db/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -// 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. -// - -mod sqlite; -mod postgres; \ No newline at end of file diff --git a/src/storage/diesel_db/postgres.rs b/src/storage/diesel_db/postgres.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/storage/diesel_db/sqlite.rs b/src/storage/diesel_db/sqlite.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/storage/mod.rs b/src/storage/mod.rs index a0a5868..8e84491 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -8,37 +8,39 @@ // See the Licence for the specific language governing permissions and limitations under the Licence. // -pub mod diesel_db; +// TODO: Once diesel-async supports sqlite (see https://github.com/weiznich/diesel_async/discussions/95), convert to async +pub mod pg_schemas; +pub mod pg_person; +pub mod pg_post; use anyhow::{Error, bail}; -use diesel::{prelude::*, pg::{PgConnection, Pg}, sqlite::Sqlite}; +use diesel::{pg::Pg, r2d2::{Pool, ConnectionManager, self}}; +use diesel::PgConnection; use diesel_migrations::{EmbeddedMigrations, embed_migrations, MigrationHarness}; -pub const POSTGRES_MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations/postgres"); +pub const POSTGRES_MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); -pub enum DB { - Postgres(PgConnection), - Sqlite(SqliteConnection) + +#[derive(Clone)] +pub struct Storage { + pub pool: Pool>, } /// Try and connect to a database at the given url /// The url can be a path to an sqlite db file or an url to a postgres db -pub fn establish_connection(db_url: &str) -> Result { - if db_url.starts_with("postgres") { - Ok(DB::Postgres(establish_connection_postgres(db_url)?)) - } else { - Ok(DB::Sqlite(establish_connection_sqlite(db_url)?)) +pub fn establish_connection(db_url: &str) -> Result { + let manager = ConnectionManager::::new(db_url); + let pool = match r2d2::Pool::builder().build(manager) { + Ok(a) => a, + Err(err) => bail!("Error while creating the connection pool. Error {}", err) + }; + match pool.get() { + Ok(mut conn) => {run_migrations_postgres(&mut conn)?;} + Err(e) => bail!(e) } -} - -/// Try and connect to a postgres db -pub fn establish_connection_postgres(db_url: &str) -> Result { - //SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)) - let mut conn = PgConnection::establish(db_url) - .unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)); - run_migrations_postgres(&mut conn)?; - //c.run_pending_migrations(MIGRATIONS)?; - Ok(conn) + Ok(Storage{ + pool + }) } fn run_migrations_postgres(conn: &mut impl MigrationHarness) -> Result<(), Error> { @@ -47,20 +49,3 @@ fn run_migrations_postgres(conn: &mut impl MigrationHarness) -> Result<(), E Err(e) => bail!("Migrations failed. Error {}", e) } } - -/// Try and connect to a sqlite db -pub fn establish_connection_sqlite(db_url: &str) -> Result { - //SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)) - let mut conn = SqliteConnection::establish(db_url) - .unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e)); - run_migrations_sqlite(&mut conn)?; - //c.run_pending_migrations(MIGRATIONS)?; - Ok(conn) -} - -fn run_migrations_sqlite(conn: &mut impl MigrationHarness) -> Result<(), Error> { - match conn.run_pending_migrations(POSTGRES_MIGRATIONS) { - Ok(_) => Ok(()), - Err(e) => bail!("Migrations failed. Error {}", e) - } -} \ No newline at end of file diff --git a/src/storage/pg_person.rs b/src/storage/pg_person.rs new file mode 100644 index 0000000..221babc --- /dev/null +++ b/src/storage/pg_person.rs @@ -0,0 +1,98 @@ +use activitypub_federation::{traits::Object, config::Data, fetch::object_id::ObjectId, protocol::verification::verify_domains_match}; +use anyhow::{anyhow, Error}; +use chrono::{Utc, NaiveDateTime, DateTime}; +use diesel::prelude::*; +use url::Url; + +use crate::objects::person::Person; + +use super::{Storage, pg_schemas}; + + +#[derive(Queryable, Selectable, Debug, Clone)] +#[diesel(table_name = crate::storage::pg_schemas::people)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct PersonPG { + pub ap_id: String, + pub name: String, + pub instance: Option, // Also url + pub mail: Option, + pub pw_hash: Option, + pub inbox: String, // Is an url but diesel no likey + pub public_key: String, + pub private_key: Option, + pub last_refreshed_at: NaiveDateTime, + pub local: bool, + pub followers: Vec> // Strings are URLs. This is stupid. I wish I could simply use Vec instead +} + +#[async_trait::async_trait] +impl Object for PersonPG { + type DataType = Storage; + type Kind = Person; + type Error = Error; + + fn last_refreshed_at(&self) -> Option> { + Some(self.last_refreshed_at.and_utc()) + } + + async fn read_from_id( + object_id: Url, + data: &Data, + ) -> Result, Self::Error> { + use pg_schemas::people::dsl::*; + let pool = data.pool.clone(); + let mut conn = pool.get()?; + let results: Vec = people + .filter(ap_id.eq(object_id.as_str())) + .limit(1) + .select(PersonPG::as_select()) + .load(&mut conn) + .expect(format!("Error loading person from id {}", object_id).as_str()); + if results.len() == 1 { + Ok(Some(results[0].clone())) + } else { + Ok(None) + } + } + + async fn into_json(self, _data: &Data) -> Result { + Ok(Person { + kind: Default::default(), + preferred_username: self.name.clone(), + id: ObjectId::parse(&self.ap_id)?, + inbox: Url::parse(&self.inbox)?, + public_key: serde_json::from_str(&self.public_key).unwrap(), + }) + } + + async fn verify( + json: &Self::Kind, + expected_domain: &Url, + _data: &Data, + ) -> Result<(), Self::Error> { + Ok(verify_domains_match(&json.id.inner(), &expected_domain)?) + + } + + async fn from_json( + json: Self::Kind, + _data: &Data, + ) -> Result { + Ok( + PersonPG { + ap_id: json.id.inner().to_string(), + name: json.preferred_username, + instance: Some(json.inbox.authority().to_string()), + mail: None, + pw_hash: None, + inbox: json.inbox.to_string(), + public_key: serde_json::to_string(&json.public_key).unwrap(), + private_key: None, + last_refreshed_at: Utc::now().naive_utc(), + local: false, + followers: vec![] + } + ) + } +} \ No newline at end of file diff --git a/src/storage/pg_post.rs b/src/storage/pg_post.rs new file mode 100644 index 0000000..19d1784 --- /dev/null +++ b/src/storage/pg_post.rs @@ -0,0 +1,7 @@ +pub struct PostPG { + pub ap_id: String, + pub text: String, + pub creator: String, + pub local: bool, + pub instance: Option +} \ No newline at end of file diff --git a/src/storage/pg_schemas.rs b/src/storage/pg_schemas.rs new file mode 100644 index 0000000..9527311 --- /dev/null +++ b/src/storage/pg_schemas.rs @@ -0,0 +1,17 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + people (ap_id) { + ap_id -> Text, + name -> Text, + instance -> Nullable, + mail -> Nullable, + pw_hash -> Nullable, + inbox -> Text, + public_key -> Text, + private_key -> Nullable, + last_refreshed_at -> Timestamp, + local -> Bool, + followers -> Array>, + } +}