Compare commits
27 Commits
blog-title
..
s3
| Author | SHA1 | Date | |
|---|---|---|---|
| 15cb3cf156 | |||
| 613ccbcd94 | |||
| b9a09a2511 | |||
| 213628e400 | |||
| d6bb2bfb72 | |||
| 33bd290679 | |||
| 85ab5393fd | |||
| 98c73bb6df | |||
| 3e9d9a459f | |||
| a394c3f210 | |||
| a1a19e091a | |||
| ec030d500d | |||
| cfa74f84e7 | |||
| 97cbe7f446 | |||
| 7e4d081027 | |||
| 1e5ae92135 | |||
| 036ee6fac4 | |||
| 6028295748 | |||
| aa4cfd374d | |||
| 3303a4af84 | |||
| 37a136787b | |||
| 300ff37694 | |||
| c1d9d39dc1 | |||
| 93d6ee04d4 | |||
| 35b951967d | |||
| 771d4325c2 | |||
| 1536a6d3f3 |
Generated
+262
-35
@@ -115,6 +115,12 @@ dependencies = [
|
||||
"const-random",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.6"
|
||||
@@ -166,6 +172,12 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "1.6.0"
|
||||
@@ -219,15 +231,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "atom_syndication"
|
||||
version = "0.11.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21fb6a0b39c6517edafe46f8137e53c51742425a4dae1c73ee12264a37ad7541"
|
||||
checksum = "91a85f2ee28cbd1ecf91288460f6dc74661fd99b4e9a559836a667ccf63aa38c"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"derive_builder",
|
||||
"diligent-date-parser",
|
||||
"never",
|
||||
"quick-xml",
|
||||
"quick-xml 0.27.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -241,6 +253,22 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "attohttpc"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69e13a99a7e6e070bb114f7ff381e58c7ccc188630121fc4c2fe4bcf24cd072"
|
||||
dependencies = [
|
||||
"http 0.2.8",
|
||||
"log 0.4.17",
|
||||
"native-tls",
|
||||
"openssl",
|
||||
"serde 1.0.152",
|
||||
"serde_json",
|
||||
"url 2.3.1",
|
||||
"wildmatch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
@@ -267,6 +295,31 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "aws-creds"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460a75eac8f3cb7683e0a9a588a83c3ff039331ea7bfbfbfcecf1dacab276e11"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"attohttpc",
|
||||
"dirs",
|
||||
"rust-ini 0.17.0",
|
||||
"serde 1.0.152",
|
||||
"serde-xml-rs",
|
||||
"serde_derive",
|
||||
"url 2.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aws-region"
|
||||
version = "0.23.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10110ddbd800fb47e6bef95e88fc13495795d252f585272a4fa3ac4f5b2e0a4d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.1.8"
|
||||
@@ -389,6 +442,16 @@ dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block_on_proc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b872f3528eeeb4370ee73b51194dc1cd93680c2d0eb6c7a223889038d2c1a167"
|
||||
dependencies = [
|
||||
"quote 1.0.23",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blowfish"
|
||||
version = "0.9.1"
|
||||
@@ -578,7 +641,7 @@ checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"nom 5.1.2",
|
||||
"rust-ini",
|
||||
"rust-ini 0.13.0",
|
||||
"serde 1.0.152",
|
||||
"serde-hjson",
|
||||
"serde_json",
|
||||
@@ -636,7 +699,7 @@ dependencies = [
|
||||
"aes-gcm",
|
||||
"base64 0.13.1",
|
||||
"hkdf",
|
||||
"hmac",
|
||||
"hmac 0.10.1",
|
||||
"percent-encoding 2.2.0",
|
||||
"rand 0.8.5",
|
||||
"sha2",
|
||||
@@ -876,6 +939,16 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-mac"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctr"
|
||||
version = "0.6.0"
|
||||
@@ -947,9 +1020,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.12.4"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c"
|
||||
checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
@@ -957,9 +1030,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.12.4"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e91455b86830a1c21799d94524df0845183fa55bafd9aa137b01c7d1065fa36"
|
||||
checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
@@ -971,9 +1044,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.12.4"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
|
||||
checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote 1.0.23",
|
||||
@@ -1024,18 +1097,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.10.2"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d13202debe11181040ae9063d739fa32cfcaaebe2275fe387703460ae2365b30"
|
||||
checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
|
||||
dependencies = [
|
||||
"derive_builder_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.10.2"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66e616858f6187ed828df7c64a6d71720d83767a7f19740b2d1b6fe6327b36e5"
|
||||
checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2 1.0.49",
|
||||
@@ -1045,9 +1118,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_macro"
|
||||
version = "0.10.2"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58a94ace95092c5acb1e97a7e846b310cfbd499652f72297da7493f618a98d73"
|
||||
checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
|
||||
dependencies = [
|
||||
"derive_builder_core",
|
||||
"syn 1.0.107",
|
||||
@@ -1150,6 +1223,35 @@ dependencies = [
|
||||
"chrono",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dlv-list"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b"
|
||||
dependencies = [
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
@@ -1632,9 +1734,9 @@ checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "guid"
|
||||
@@ -1745,6 +1847,15 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
dependencies = [
|
||||
"ahash 0.4.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
@@ -1763,12 +1874,6 @@ dependencies = [
|
||||
"ahash 0.7.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@@ -1800,7 +1905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
"hmac 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1809,7 +1914,17 @@ version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
|
||||
dependencies = [
|
||||
"crypto-mac",
|
||||
"crypto-mac 0.10.1",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b"
|
||||
dependencies = [
|
||||
"crypto-mac 0.11.1",
|
||||
"digest",
|
||||
]
|
||||
|
||||
@@ -2555,6 +2670,17 @@ version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
|
||||
|
||||
[[package]]
|
||||
name = "maybe-async"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f1b8c13cb1f814b634a96b2c725449fe7ed464a7b8781de8688be5ffbd3f305"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.49",
|
||||
"quote 1.0.23",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
@@ -2647,6 +2773,15 @@ dependencies = [
|
||||
"unicase 2.6.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minidom"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "332592c2149fc7dd40a64fc9ef6f0d65607284b474cef9817d1fc8c7e7b3608e"
|
||||
dependencies = [
|
||||
"quick-xml 0.20.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
@@ -3069,6 +3204,16 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-multimap"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485"
|
||||
dependencies = [
|
||||
"dlv-list",
|
||||
"hashbrown 0.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
@@ -3300,6 +3445,7 @@ dependencies = [
|
||||
"rocket_i18n",
|
||||
"rsass",
|
||||
"ructe",
|
||||
"rust-s3",
|
||||
"scheduled-thread-pool",
|
||||
"serde 1.0.152",
|
||||
"serde_json",
|
||||
@@ -3354,7 +3500,6 @@ dependencies = [
|
||||
"serde_json",
|
||||
"shrinkwraprs",
|
||||
"syntect",
|
||||
"thiserror",
|
||||
"tokio 1.24.1",
|
||||
"tracing",
|
||||
"url 2.3.1",
|
||||
@@ -3400,7 +3545,6 @@ dependencies = [
|
||||
"diesel_migrations",
|
||||
"glob",
|
||||
"guid-create",
|
||||
"heck",
|
||||
"itertools 0.10.5",
|
||||
"lazy_static",
|
||||
"ldap3",
|
||||
@@ -3417,6 +3561,7 @@ dependencies = [
|
||||
"riker",
|
||||
"rocket",
|
||||
"rocket_i18n",
|
||||
"rust-s3",
|
||||
"scheduled-thread-pool",
|
||||
"serde 1.0.152",
|
||||
"serde_derive",
|
||||
@@ -3562,9 +3707,18 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.22.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
|
||||
checksum = "26aab6b48e2590e4a64d1ed808749ba06257882b461d01ca71baeb747074a6dd"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffc053f057dd768a56f62cd7e434c42c831d296968997e9ac1f76ea7c2d14c41"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"memchr",
|
||||
@@ -3844,6 +3998,17 @@ dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom 0.2.8",
|
||||
"redox_syscall 0.2.16",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.0"
|
||||
@@ -3975,6 +4140,7 @@ dependencies = [
|
||||
"tokio 1.24.1",
|
||||
"tokio-native-tls",
|
||||
"tokio-socks",
|
||||
"tokio-util 0.7.4",
|
||||
"tower-service",
|
||||
"url 2.3.1",
|
||||
"wasm-bindgen",
|
||||
@@ -4132,10 +4298,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rsass"
|
||||
version = "0.25.2"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ab003a9ff922b4d7b1f5f383bc54645887ad278f534dfc65e071096fcb30023"
|
||||
checksum = "665387d3be91521de331a04cc7118c8c129ffe43c5f4e8a61e78990850046b5a"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"fastrand",
|
||||
"lazy_static",
|
||||
"nom 7.1.2",
|
||||
@@ -4149,9 +4316,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ructe"
|
||||
version = "0.14.2"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef279e568db5dad3a1867112fedc63e2f0567991e82beec01c04ade6bd53c08a"
|
||||
checksum = "85517cd381cf0c34694881d8aaf173107c6af7670e66cec18d7a1a8bfce3b758"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"bytecount",
|
||||
@@ -4166,6 +4333,48 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
|
||||
|
||||
[[package]]
|
||||
name = "rust-ini"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"ordered-multimap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-s3"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a4e82923ed07143871571852a390742200607e5058ce633afec89752f9c3f82"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"aws-creds",
|
||||
"aws-region",
|
||||
"base64 0.13.1",
|
||||
"block_on_proc",
|
||||
"cfg-if 1.0.0",
|
||||
"hex",
|
||||
"hmac 0.11.0",
|
||||
"http 0.2.8",
|
||||
"log 0.4.17",
|
||||
"maybe-async",
|
||||
"md5",
|
||||
"minidom",
|
||||
"percent-encoding 2.2.0",
|
||||
"reqwest 0.11.13",
|
||||
"serde 1.0.152",
|
||||
"serde-xml-rs",
|
||||
"serde_derive",
|
||||
"sha2",
|
||||
"time 0.3.17",
|
||||
"tokio 1.24.1",
|
||||
"tokio-stream",
|
||||
"url 2.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-stemmers"
|
||||
version = "1.2.0"
|
||||
@@ -4309,6 +4518,18 @@ dependencies = [
|
||||
"serde 0.8.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-xml-rs"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65162e9059be2f6a3421ebbb4fef3e74b7d9e7c60c50a0e292c6239f19f1edfa"
|
||||
dependencies = [
|
||||
"log 0.4.17",
|
||||
"serde 1.0.152",
|
||||
"thiserror",
|
||||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.152"
|
||||
@@ -5686,6 +5907,12 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wildmatch"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
|
||||
+5
-3
@@ -6,7 +6,7 @@ repository = "https://github.com/Plume-org/Plume"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
atom_syndication = "0.11.0"
|
||||
atom_syndication = "0.12.0"
|
||||
clap = "2.33"
|
||||
dotenv = "0.15.0"
|
||||
gettext = "0.4.0"
|
||||
@@ -19,6 +19,7 @@ rocket = "0.4.11"
|
||||
rocket_contrib = { version = "0.4.11", features = ["json"] }
|
||||
rocket_i18n = "0.4.1"
|
||||
scheduled-thread-pool = "0.2.6"
|
||||
rust-s3 = { version = "0.29.0", no-default-features = true, features = ["blocking"], optional = true}
|
||||
serde = "1.0.137"
|
||||
serde_json = "1.0.81"
|
||||
shrinkwraprs = "0.3.0"
|
||||
@@ -64,8 +65,8 @@ git = "https://git.joinplu.me/plume/rocket_csrf"
|
||||
rev = "0.1.2"
|
||||
|
||||
[build-dependencies]
|
||||
ructe = "0.14.0"
|
||||
rsass = "0.25"
|
||||
ructe = "0.15.0"
|
||||
rsass = "0.26"
|
||||
|
||||
[features]
|
||||
default = ["postgres"]
|
||||
@@ -74,6 +75,7 @@ sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
||||
debug-mailer = []
|
||||
test = []
|
||||
search-lindera = ["plume-models/search-lindera"]
|
||||
s3 = ["rust-s3"]
|
||||
|
||||
[workspace]
|
||||
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
ALTER TABLE users DROP CONSTRAINT users_fqn;
|
||||
ALTER TABLE blogs DROP CONSTRAINT blogs_actor_id;
|
||||
ALTER TABLE blogs DROP CONSTRAINT blogs_fqn;
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
ALTER TABLE users ADD CONSTRAINT users_fqn UNIQUE (fqn);
|
||||
ALTER TABLE blogs ADD CONSTRAINT blogs_actor_id UNIQUE (actor_id);
|
||||
ALTER TABLE blogs ADD CONSTRAINT blogs_fqn UNIQUE (fqn);
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
DROP INDEX users_fqn;
|
||||
DROP INDEX blogs_actor_id;
|
||||
DROP INDEX blogs_fqn;
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
CREATE UNIQUE INDEX users_fqn ON users (fqn);
|
||||
CREATE UNIQUE INDEX blogs_actor_id ON blogs (actor_id);
|
||||
CREATE UNIQUE INDEX blogs_fqn ON blogs (fqn);
|
||||
@@ -0,0 +1,262 @@
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
|
||||
use plume_models::{blogs::Blog, instance::Instance, lists::*, users::User, Connection};
|
||||
|
||||
pub fn command<'a, 'b>() -> App<'a, 'b> {
|
||||
SubCommand::with_name("lists")
|
||||
.about("Manage lists")
|
||||
.subcommand(
|
||||
SubCommand::with_name("new")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of this list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("type")
|
||||
.short("t")
|
||||
.long("type")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
r#"The type of this list (one of "user", "blog", "word" or "prefix")"#,
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help("Username of whom this list is for. Empty for an instance list"),
|
||||
)
|
||||
.about("Create a new list"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("delete")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the list to delete"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help("Username of whom this list was for. Empty for instance list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("yes")
|
||||
.short("y")
|
||||
.long("yes")
|
||||
.help("Confirm the deletion"),
|
||||
)
|
||||
.about("Delete a list"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("add")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the list to add an element to"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help("Username of whom this list is for. Empty for instance list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("value")
|
||||
.short("v")
|
||||
.long("value")
|
||||
.takes_value(true)
|
||||
.help("The value to add"),
|
||||
)
|
||||
.about("Add element to a list"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("rm")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the list to remove an element from"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help("Username of whom this list is for. Empty for instance list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("value")
|
||||
.short("v")
|
||||
.long("value")
|
||||
.takes_value(true)
|
||||
.help("The value to remove"),
|
||||
)
|
||||
.about("Remove element from list"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
||||
let conn = conn;
|
||||
match args.subcommand() {
|
||||
("new", Some(x)) => new(x, conn),
|
||||
("delete", Some(x)) => delete(x, conn),
|
||||
("add", Some(x)) => add(x, conn),
|
||||
("rm", Some(x)) => rm(x, conn),
|
||||
("", None) => command().print_help().unwrap(),
|
||||
_ => println!("Unknown subcommand"),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_list_identifier(args: &ArgMatches<'_>) -> (String, Option<String>) {
|
||||
let name = args
|
||||
.value_of("name")
|
||||
.map(String::from)
|
||||
.expect("No name provided for the list");
|
||||
let user = args.value_of("user").map(String::from);
|
||||
(name, user)
|
||||
}
|
||||
|
||||
fn get_list_type(args: &ArgMatches<'_>) -> ListType {
|
||||
let typ = args
|
||||
.value_of("type")
|
||||
.map(String::from)
|
||||
.expect("No name type for the list");
|
||||
match typ.as_str() {
|
||||
"user" => ListType::User,
|
||||
"blog" => ListType::Blog,
|
||||
"word" => ListType::Word,
|
||||
"prefix" => ListType::Prefix,
|
||||
_ => panic!("Invalid list type: {}", typ),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_value(args: &ArgMatches<'_>) -> String {
|
||||
args.value_of("value")
|
||||
.map(String::from)
|
||||
.expect("No query provided")
|
||||
}
|
||||
|
||||
fn resolve_user(username: &str, conn: &Connection) -> User {
|
||||
let instance = Instance::get_local_uncached(conn).expect("Failed to load local instance");
|
||||
|
||||
User::find_by_name(conn, username, instance.id).expect("User not found")
|
||||
}
|
||||
|
||||
fn new(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_list_identifier(args);
|
||||
let typ = get_list_type(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
List::new(conn, &name, user.as_ref(), typ).expect("failed to create list");
|
||||
}
|
||||
|
||||
fn delete(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_list_identifier(args);
|
||||
|
||||
if !args.is_present("yes") {
|
||||
panic!("Warning, this operation is destructive. Add --yes to confirm you want to do it.")
|
||||
}
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let list =
|
||||
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||
|
||||
list.delete(conn).expect("Failed to update list");
|
||||
}
|
||||
|
||||
fn add(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_list_identifier(args);
|
||||
let value = get_value(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let list =
|
||||
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||
|
||||
match list.kind() {
|
||||
ListType::Blog => {
|
||||
let blog_id = Blog::find_by_fqn(conn, &value).expect("unknown blog").id;
|
||||
if !list.contains_blog(conn, blog_id).unwrap() {
|
||||
list.add_blogs(conn, &[blog_id]).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::User => {
|
||||
let user_id = User::find_by_fqn(conn, &value).expect("unknown user").id;
|
||||
if !list.contains_user(conn, user_id).unwrap() {
|
||||
list.add_users(conn, &[user_id]).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::Word => {
|
||||
if !list.contains_word(conn, &value).unwrap() {
|
||||
list.add_words(conn, &[&value]).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::Prefix => {
|
||||
if !list.contains_prefix(conn, &value).unwrap() {
|
||||
list.add_prefixes(conn, &[&value]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rm(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_list_identifier(args);
|
||||
let value = get_value(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let list =
|
||||
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||
|
||||
match list.kind() {
|
||||
ListType::Blog => {
|
||||
let blog_id = Blog::find_by_fqn(conn, &value).expect("unknown blog").id;
|
||||
let mut blogs = list.list_blogs(conn).unwrap();
|
||||
if let Some(index) = blogs.iter().position(|b| b.id == blog_id) {
|
||||
blogs.swap_remove(index);
|
||||
let blogs = blogs.iter().map(|b| b.id).collect::<Vec<_>>();
|
||||
list.set_blogs(conn, &blogs).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::User => {
|
||||
let user_id = User::find_by_fqn(conn, &value).expect("unknown user").id;
|
||||
let mut users = list.list_users(conn).unwrap();
|
||||
if let Some(index) = users.iter().position(|u| u.id == user_id) {
|
||||
users.swap_remove(index);
|
||||
let users = users.iter().map(|u| u.id).collect::<Vec<_>>();
|
||||
list.set_users(conn, &users).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::Word => {
|
||||
let mut words = list.list_words(conn).unwrap();
|
||||
if let Some(index) = words.iter().position(|w| *w == value) {
|
||||
words.swap_remove(index);
|
||||
let words = words.iter().map(String::as_str).collect::<Vec<_>>();
|
||||
list.set_words(conn, &words).unwrap();
|
||||
}
|
||||
}
|
||||
ListType::Prefix => {
|
||||
let mut prefixes = list.list_prefixes(conn).unwrap();
|
||||
if let Some(index) = prefixes.iter().position(|p| *p == value) {
|
||||
prefixes.swap_remove(index);
|
||||
let prefixes = prefixes.iter().map(String::as_str).collect::<Vec<_>>();
|
||||
list.set_prefixes(conn, &prefixes).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,10 @@ use plume_models::{instance::Instance, Connection as Conn, CONFIG};
|
||||
use std::io::{self, prelude::*};
|
||||
|
||||
mod instance;
|
||||
mod list;
|
||||
mod migration;
|
||||
mod search;
|
||||
mod timeline;
|
||||
mod users;
|
||||
|
||||
fn main() {
|
||||
@@ -16,6 +18,8 @@ fn main() {
|
||||
.subcommand(instance::command())
|
||||
.subcommand(migration::command())
|
||||
.subcommand(search::command())
|
||||
.subcommand(timeline::command())
|
||||
.subcommand(list::command())
|
||||
.subcommand(users::command());
|
||||
let matches = app.clone().get_matches();
|
||||
|
||||
@@ -37,6 +41,10 @@ fn main() {
|
||||
("search", Some(args)) => {
|
||||
search::run(args, &conn.expect("Couldn't connect to the database."))
|
||||
}
|
||||
("timeline", Some(args)) => {
|
||||
timeline::run(args, &conn.expect("Couldn't connect to the database."))
|
||||
}
|
||||
("lists", Some(args)) => list::run(args, &conn.expect("Couldn't connect to the database.")),
|
||||
("users", Some(args)) => {
|
||||
users::run(args, &conn.expect("Couldn't connect to the database."))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
|
||||
use plume_models::{instance::Instance, posts::Post, timeline::*, users::*, Connection};
|
||||
|
||||
pub fn command<'a, 'b>() -> App<'a, 'b> {
|
||||
SubCommand::with_name("timeline")
|
||||
.about("Manage public timeline")
|
||||
.subcommand(
|
||||
SubCommand::with_name("new")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of this timeline"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("query")
|
||||
.short("q")
|
||||
.long("query")
|
||||
.takes_value(true)
|
||||
.help("The query posts in this timelines have to match"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"Username of whom this timeline is for. Empty for an instance timeline",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("preload-count")
|
||||
.short("p")
|
||||
.long("preload-count")
|
||||
.takes_value(true)
|
||||
.help("Number of posts to try to preload in this timeline at its creation"),
|
||||
)
|
||||
.about("Create a new timeline"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("delete")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the timeline to delete"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"Username of whom this timeline was for. Empty for instance timeline",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("yes")
|
||||
.short("y")
|
||||
.long("yes")
|
||||
.help("Confirm the deletion"),
|
||||
)
|
||||
.about("Delete a timeline"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("edit")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the timeline to edit"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help("Username of whom this timeline is for. Empty for instance timeline"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("query")
|
||||
.short("q")
|
||||
.long("query")
|
||||
.takes_value(true)
|
||||
.help("The query posts in this timelines have to match"),
|
||||
)
|
||||
.about("Edit the query of a timeline"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("repopulate")
|
||||
.arg(
|
||||
Arg::with_name("name")
|
||||
.short("n")
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of the timeline to repopulate"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("user")
|
||||
.short("u")
|
||||
.long("user")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"Username of whom this timeline was for. Empty for instance timeline",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("preload-count")
|
||||
.short("p")
|
||||
.long("preload-count")
|
||||
.takes_value(true)
|
||||
.help("Number of posts to try to preload in this timeline at its creation"),
|
||||
)
|
||||
.about("Repopulate a timeline. Run this after modifying a list the timeline depends on."),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
||||
let conn = conn;
|
||||
match args.subcommand() {
|
||||
("new", Some(x)) => new(x, conn),
|
||||
("edit", Some(x)) => edit(x, conn),
|
||||
("delete", Some(x)) => delete(x, conn),
|
||||
("repopulate", Some(x)) => repopulate(x, conn),
|
||||
("", None) => command().print_help().unwrap(),
|
||||
_ => println!("Unknown subcommand"),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_timeline_identifier(args: &ArgMatches<'_>) -> (String, Option<String>) {
|
||||
let name = args
|
||||
.value_of("name")
|
||||
.map(String::from)
|
||||
.expect("No name provided for the timeline");
|
||||
let user = args.value_of("user").map(String::from);
|
||||
(name, user)
|
||||
}
|
||||
|
||||
fn get_query(args: &ArgMatches<'_>) -> String {
|
||||
let query = args
|
||||
.value_of("query")
|
||||
.map(String::from)
|
||||
.expect("No query provided");
|
||||
|
||||
match TimelineQuery::parse(&query) {
|
||||
Ok(_) => (),
|
||||
Err(QueryError::SyntaxError(start, end, message)) => panic!(
|
||||
"Query parsing error between {} and {}: {}",
|
||||
start, end, message
|
||||
),
|
||||
Err(QueryError::UnexpectedEndOfQuery) => {
|
||||
panic!("Query parsing error: unexpected end of query")
|
||||
}
|
||||
Err(QueryError::RuntimeError(message)) => panic!("Query parsing error: {}", message),
|
||||
}
|
||||
|
||||
query
|
||||
}
|
||||
|
||||
fn get_preload_count(args: &ArgMatches<'_>) -> usize {
|
||||
args.value_of("preload-count")
|
||||
.map(|arg| arg.parse().expect("invalid preload-count"))
|
||||
.unwrap_or(plume_models::ITEMS_PER_PAGE as usize)
|
||||
}
|
||||
|
||||
fn resolve_user(username: &str, conn: &Connection) -> User {
|
||||
let instance = Instance::get_local_uncached(conn).expect("Failed to load local instance");
|
||||
|
||||
User::find_by_name(conn, username, instance.id).expect("User not found")
|
||||
}
|
||||
|
||||
fn preload(timeline: Timeline, count: usize, conn: &Connection) {
|
||||
timeline.remove_all_posts(conn).unwrap();
|
||||
|
||||
if count == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut posts = Vec::with_capacity(count as usize);
|
||||
for post in Post::list_filtered(conn, None, None, None)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.rev()
|
||||
{
|
||||
if timeline.matches(conn, &post, Kind::Original).unwrap() {
|
||||
posts.push(post);
|
||||
if posts.len() >= count {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for post in posts.iter().rev() {
|
||||
timeline.add_post(conn, post).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn new(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_timeline_identifier(args);
|
||||
let query = get_query(args);
|
||||
let preload_count = get_preload_count(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let timeline = if let Some(user) = user {
|
||||
Timeline::new_for_user(conn, user.id, name, query)
|
||||
} else {
|
||||
Timeline::new_for_instance(conn, name, query)
|
||||
}
|
||||
.expect("Failed to create new timeline");
|
||||
|
||||
preload(timeline, preload_count, conn);
|
||||
}
|
||||
|
||||
fn edit(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_timeline_identifier(args);
|
||||
let query = get_query(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let mut timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||
.expect("timeline not found");
|
||||
|
||||
timeline.query = query;
|
||||
|
||||
timeline.update(conn).expect("Failed to update timeline");
|
||||
}
|
||||
|
||||
fn delete(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_timeline_identifier(args);
|
||||
|
||||
if !args.is_present("yes") {
|
||||
panic!("Warning, this operation is destructive. Add --yes to confirm you want to do it.")
|
||||
}
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||
.expect("timeline not found");
|
||||
|
||||
timeline.delete(conn).expect("Failed to update timeline");
|
||||
}
|
||||
|
||||
fn repopulate(args: &ArgMatches<'_>, conn: &Connection) {
|
||||
let (name, user) = get_timeline_identifier(args);
|
||||
let preload_count = get_preload_count(args);
|
||||
|
||||
let user = user.map(|user| resolve_user(&user, conn));
|
||||
|
||||
let timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||
.expect("timeline not found");
|
||||
preload(timeline, preload_count, conn);
|
||||
}
|
||||
@@ -25,7 +25,6 @@ url = "2.2.2"
|
||||
flume = "0.10.13"
|
||||
tokio = { version = "1.19.2", features = ["full"] }
|
||||
futures = "0.3.25"
|
||||
thiserror = "1.0.38"
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
|
||||
@@ -18,11 +18,6 @@ use rocket::{
|
||||
response::{Responder, Response},
|
||||
Outcome,
|
||||
};
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
fmt,
|
||||
str::FromStr,
|
||||
};
|
||||
use tokio::{
|
||||
runtime,
|
||||
time::{sleep, Duration},
|
||||
@@ -246,97 +241,6 @@ pub trait IntoId {
|
||||
fn into_id(self) -> Id;
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum PreferredUsernameError {
|
||||
#[error("preferredUsername must be longer than 2 characters")]
|
||||
TooShort,
|
||||
#[error("Invaliad character at {character:?}: {position:?}")]
|
||||
InvalidCharacter { character: char, position: usize },
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Shrinkwrap, PartialEq, Eq, Clone, Serialize, Deserialize, Debug)]
|
||||
pub struct PreferredUsername(String);
|
||||
|
||||
// Mastodon allows only /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i for `preferredUsername`
|
||||
impl PreferredUsername {
|
||||
fn validate(name: &str) -> std::result::Result<(), PreferredUsernameError> {
|
||||
let len = name.len();
|
||||
if len < 3 {
|
||||
return Err(PreferredUsernameError::TooShort);
|
||||
}
|
||||
match name.chars().enumerate().find(|(pos, c)| {
|
||||
if pos == &0 || pos == &(len - 1) {
|
||||
c != &'_' && !c.is_ascii_alphanumeric()
|
||||
} else {
|
||||
match c {
|
||||
'_' | '\\' | '.' | '-' => false,
|
||||
_ => !c.is_ascii_alphanumeric(),
|
||||
}
|
||||
}
|
||||
}) {
|
||||
Some((pos, c)) => Err(PreferredUsernameError::InvalidCharacter {
|
||||
character: c,
|
||||
position: pos,
|
||||
}),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// The given string must be match against /\A[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?\z/i in Ruby's RegExp which is required by Mastodon.
|
||||
pub unsafe fn new_unchecked(name: String) -> Self {
|
||||
Self(name)
|
||||
}
|
||||
|
||||
pub fn new(name: String) -> std::result::Result<Self, PreferredUsernameError> {
|
||||
Self::validate(&name).map(|_| unsafe { Self::new_unchecked(name) })
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PreferredUsername {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for PreferredUsername {
|
||||
type Error = PreferredUsernameError;
|
||||
|
||||
fn try_from(name: String) -> std::result::Result<Self, Self::Error> {
|
||||
Self::new(name)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for PreferredUsername {
|
||||
type Error = PreferredUsernameError;
|
||||
|
||||
fn try_from(name: &str) -> std::result::Result<Self, Self::Error> {
|
||||
Self::new(name.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PreferredUsername> for String {
|
||||
fn from(preferred_username: PreferredUsername) -> Self {
|
||||
preferred_username.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for PreferredUsername {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for PreferredUsername {
|
||||
type Err = PreferredUsernameError;
|
||||
|
||||
fn from_str(name: &str) -> std::result::Result<Self, Self::Err> {
|
||||
name.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ApSignature {
|
||||
@@ -620,35 +524,6 @@ mod tests {
|
||||
use assert_json_diff::assert_json_eq;
|
||||
use serde_json::{from_str, json, to_value};
|
||||
|
||||
#[test]
|
||||
fn preferred_username() {
|
||||
assert!(PreferredUsername::new("".into()).is_err());
|
||||
assert!(PreferredUsername::new("a".into()).is_err());
|
||||
assert!(PreferredUsername::new("ab".into()).is_err());
|
||||
assert_eq!(
|
||||
"abc",
|
||||
PreferredUsername::new("abc".into()).unwrap().as_str()
|
||||
);
|
||||
assert_eq!(
|
||||
"abcd",
|
||||
PreferredUsername::new("abcd".into()).unwrap().as_str()
|
||||
);
|
||||
assert!(PreferredUsername::new("abc-".into()).is_err());
|
||||
assert!(PreferredUsername::new("日本語".into()).is_err());
|
||||
assert_eq!("abc", "abc".parse::<PreferredUsername>().unwrap().as_str());
|
||||
assert!("abc-".parse::<PreferredUsername>().is_err());
|
||||
assert_eq!(
|
||||
PreferredUsername::new("admin".into()).unwrap(),
|
||||
PreferredUsername("admin".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefferred_username_to_string() {
|
||||
let pu = PreferredUsername::new("admin".into()).unwrap();
|
||||
assert_eq!("admin".to_string(), pu.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn se_ap_signature() {
|
||||
let ap_signature = ApSignature {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use activitystreams::iri_string::percent_encode::PercentEncodedForIri;
|
||||
use openssl::rand::rand_bytes;
|
||||
use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag};
|
||||
use regex_syntax::is_word_character;
|
||||
use rocket::http::uri::Uri;
|
||||
use std::collections::HashSet;
|
||||
use syntect::html::{ClassStyle, ClassedHTMLGenerator};
|
||||
use syntect::parsing::SyntaxSet;
|
||||
@@ -21,7 +21,51 @@ pub fn random_hex() -> String {
|
||||
* Intended to be used for generating Post ap_url.
|
||||
*/
|
||||
pub fn iri_percent_encode_seg(segment: &str) -> String {
|
||||
PercentEncodedForIri::from_path_segment(segment).to_string()
|
||||
segment.chars().map(iri_percent_encode_seg_char).collect()
|
||||
}
|
||||
|
||||
pub fn iri_percent_encode_seg_char(c: char) -> String {
|
||||
if c.is_alphanumeric() {
|
||||
c.to_string()
|
||||
} else {
|
||||
match c {
|
||||
'-'
|
||||
| '.'
|
||||
| '_'
|
||||
| '~'
|
||||
| '\u{A0}'..='\u{D7FF}'
|
||||
| '\u{20000}'..='\u{2FFFD}'
|
||||
| '\u{30000}'..='\u{3FFFD}'
|
||||
| '\u{40000}'..='\u{4FFFD}'
|
||||
| '\u{50000}'..='\u{5FFFD}'
|
||||
| '\u{60000}'..='\u{6FFFD}'
|
||||
| '\u{70000}'..='\u{7FFFD}'
|
||||
| '\u{80000}'..='\u{8FFFD}'
|
||||
| '\u{90000}'..='\u{9FFFD}'
|
||||
| '\u{A0000}'..='\u{AFFFD}'
|
||||
| '\u{B0000}'..='\u{BFFFD}'
|
||||
| '\u{C0000}'..='\u{CFFFD}'
|
||||
| '\u{D0000}'..='\u{DFFFD}'
|
||||
| '\u{E0000}'..='\u{EFFFD}'
|
||||
| '!'
|
||||
| '$'
|
||||
| '&'
|
||||
| '\''
|
||||
| '('
|
||||
| ')'
|
||||
| '*'
|
||||
| '+'
|
||||
| ','
|
||||
| ';'
|
||||
| '='
|
||||
| ':'
|
||||
| '@' => c.to_string(),
|
||||
_ => {
|
||||
let s = c.to_string();
|
||||
Uri::percent_encode(&s).to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -18,6 +18,7 @@ rocket_i18n = "0.4.1"
|
||||
reqwest = "0.11.11"
|
||||
scheduled-thread-pool = "0.2.6"
|
||||
serde = "1.0.137"
|
||||
rust-s3 = { version = "0.29.0", no-default-features = true, features = ["blocking"] }
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0.81"
|
||||
tantivy = "0.13.3"
|
||||
@@ -27,7 +28,7 @@ webfinger = "0.4.1"
|
||||
whatlang = "0.16.2"
|
||||
shrinkwraprs = "0.3.0"
|
||||
diesel-derive-newtype = "1.0.0"
|
||||
glob = "0.3.0"
|
||||
glob = "0.3.1"
|
||||
lindera-tantivy = { version = "0.7.1", optional = true }
|
||||
tracing = "0.1.35"
|
||||
riker = "0.4.2"
|
||||
@@ -35,7 +36,6 @@ once_cell = "1.12.0"
|
||||
lettre = "0.9.6"
|
||||
native-tls = "0.2.10"
|
||||
activitystreams = "=0.7.0-alpha.20"
|
||||
heck = "0.4.0"
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
|
||||
+60
-83
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
db_conn::DbConn, instance::*, medias::Media, posts::Post, safe_string::SafeString,
|
||||
schema::blogs, users::User, Connection, Error, Fqn, PlumeRocket, Result, CONFIG,
|
||||
ITEMS_PER_PAGE,
|
||||
instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs, users::User,
|
||||
Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
||||
};
|
||||
use activitystreams::{
|
||||
actor::{ApActor, ApActorExt, AsApActor, Group},
|
||||
@@ -43,14 +42,14 @@ pub struct Blog {
|
||||
pub ap_url: String,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: String,
|
||||
pub fqn: Fqn,
|
||||
pub fqn: String,
|
||||
pub summary_html: SafeString,
|
||||
pub icon_id: Option<i32>,
|
||||
pub banner_id: Option<i32>,
|
||||
pub theme: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[derive(Default, Insertable)]
|
||||
#[table_name = "blogs"]
|
||||
pub struct NewBlog {
|
||||
pub actor_id: String,
|
||||
@@ -62,7 +61,6 @@ pub struct NewBlog {
|
||||
pub ap_url: String,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: String,
|
||||
pub fqn: Fqn,
|
||||
pub summary_html: SafeString,
|
||||
pub icon_id: Option<i32>,
|
||||
pub banner_id: Option<i32>,
|
||||
@@ -86,13 +84,15 @@ impl Blog {
|
||||
inserted.ap_url = instance.compute_box(BLOG_PREFIX, &inserted.actor_id, "");
|
||||
}
|
||||
|
||||
if inserted.fqn.to_string().is_empty() {
|
||||
// This might not enough for some titles such as all-Japanese title,
|
||||
// but better than doing nothing.
|
||||
if inserted.fqn.is_empty() {
|
||||
if instance.local {
|
||||
inserted.fqn = Fqn::make_local(&inserted.title)?;
|
||||
inserted.fqn = iri_percent_encode_seg(&inserted.actor_id);
|
||||
} else {
|
||||
inserted.fqn = Fqn::make_remote(&inserted.title, instance.public_domain)?;
|
||||
inserted.fqn = format!(
|
||||
"{}@{}",
|
||||
iri_percent_encode_seg(&inserted.actor_id),
|
||||
instance.public_domain
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ impl Blog {
|
||||
find_by!(blogs, find_by_ap_url, ap_url as &str);
|
||||
find_by!(blogs, find_by_name, actor_id as &str, instance_id as i32);
|
||||
|
||||
pub fn slug(title: &str) -> String {
|
||||
iri_percent_encode_seg(title)
|
||||
pub fn slug(title: &str) -> &str {
|
||||
title
|
||||
}
|
||||
|
||||
pub fn get_instance(&self, conn: &Connection) -> Result<Instance> {
|
||||
@@ -142,10 +142,10 @@ impl Blog {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn find_by_fqn(conn: &DbConn, fqn: &str) -> Result<Blog> {
|
||||
pub fn find_by_fqn(conn: &Connection, fqn: &str) -> Result<Blog> {
|
||||
let from_db = blogs::table
|
||||
.filter(blogs::fqn.eq(fqn))
|
||||
.first(&**conn)
|
||||
.first(conn)
|
||||
.optional()?;
|
||||
if let Some(from_db) = from_db {
|
||||
Ok(from_db)
|
||||
@@ -154,7 +154,7 @@ impl Blog {
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch_from_webfinger(conn: &DbConn, acct: &str) -> Result<Blog> {
|
||||
fn fetch_from_webfinger(conn: &Connection, acct: &str) -> Result<Blog> {
|
||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
||||
.links
|
||||
.into_iter()
|
||||
@@ -173,7 +173,7 @@ impl Blog {
|
||||
|
||||
pub fn to_activity(&self, conn: &Connection) -> Result<CustomGroup> {
|
||||
let mut blog = ApActor::new(self.inbox_url.parse()?, Group::new());
|
||||
blog.set_preferred_username(self.fqn.to_string());
|
||||
blog.set_preferred_username(iri_percent_encode_seg(&self.actor_id));
|
||||
blog.set_name(self.title.clone());
|
||||
blog.set_outbox(self.outbox_url.parse()?);
|
||||
blog.set_summary(self.summary_html.to_string());
|
||||
@@ -372,15 +372,15 @@ impl IntoId for Blog {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Blog {
|
||||
impl FromId<Connection> for Blog {
|
||||
type Error = Error;
|
||||
type Object = CustomGroup;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, acct: CustomGroup) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, acct: CustomGroup) -> Result<Self> {
|
||||
let (name, outbox_url, inbox_url) = {
|
||||
let actor = acct.ap_actor_ref();
|
||||
let name = actor
|
||||
@@ -398,18 +398,22 @@ impl FromId<DbConn> for Blog {
|
||||
)
|
||||
};
|
||||
|
||||
let actor_id = iri_percent_encode_seg(
|
||||
&acct
|
||||
.name()
|
||||
.and_then(|name| name.to_as_string())
|
||||
.ok_or(Error::MissingApProperty)?,
|
||||
);
|
||||
let mut new_blog = NewBlog {
|
||||
actor_id: name.to_string(),
|
||||
outbox_url,
|
||||
inbox_url,
|
||||
public_key: acct.ext_one.public_key.public_key_pem.to_string(),
|
||||
private_key: None,
|
||||
theme: None,
|
||||
..NewBlog::default()
|
||||
};
|
||||
|
||||
let object = ApObject::new(acct.inner);
|
||||
let title = object
|
||||
new_blog.title = object
|
||||
.name()
|
||||
.and_then(|name| name.to_as_string())
|
||||
.unwrap_or(name.clone());
|
||||
let summary_html = SafeString::new(
|
||||
.unwrap_or(name);
|
||||
new_blog.summary_html = SafeString::new(
|
||||
&object
|
||||
.summary()
|
||||
.and_then(|summary| summary.to_as_string())
|
||||
@@ -431,6 +435,7 @@ impl FromId<DbConn> for Blog {
|
||||
})
|
||||
})
|
||||
.map(|m| m.id);
|
||||
new_blog.icon_id = icon_id;
|
||||
|
||||
let banner_id = object
|
||||
.image()
|
||||
@@ -447,12 +452,13 @@ impl FromId<DbConn> for Blog {
|
||||
})
|
||||
})
|
||||
.map(|m| m.id);
|
||||
new_blog.banner_id = banner_id;
|
||||
|
||||
let summary = acct.ext_two.source.content;
|
||||
new_blog.summary = acct.ext_two.source.content;
|
||||
|
||||
let any_base = AnyBase::from_extended(object)?;
|
||||
let id = any_base.id().ok_or(Error::MissingApProperty)?;
|
||||
let ap_url = id.to_string();
|
||||
new_blog.ap_url = id.to_string();
|
||||
|
||||
let inst = id
|
||||
.authority_components()
|
||||
@@ -476,29 +482,7 @@ impl FromId<DbConn> for Blog {
|
||||
},
|
||||
)
|
||||
})?;
|
||||
let instance_id = instance.id;
|
||||
let fqn = if instance.local {
|
||||
Fqn::new_local(name)?
|
||||
} else {
|
||||
Fqn::new_remote(name, instance.public_domain)?
|
||||
};
|
||||
|
||||
let new_blog = NewBlog {
|
||||
actor_id,
|
||||
outbox_url,
|
||||
inbox_url,
|
||||
fqn,
|
||||
public_key: acct.ext_one.public_key.public_key_pem.to_string(),
|
||||
private_key: None,
|
||||
theme: None,
|
||||
title,
|
||||
summary,
|
||||
ap_url,
|
||||
summary_html,
|
||||
icon_id,
|
||||
banner_id,
|
||||
instance_id,
|
||||
};
|
||||
new_blog.instance_id = instance.id;
|
||||
|
||||
Blog::insert(conn, new_blog)
|
||||
}
|
||||
@@ -554,19 +538,12 @@ impl NewBlog {
|
||||
let (pub_key, priv_key) = sign::gen_keypair();
|
||||
Ok(NewBlog {
|
||||
actor_id,
|
||||
fqn: Fqn::make_local(&title)?,
|
||||
title,
|
||||
summary,
|
||||
instance_id,
|
||||
public_key: String::from_utf8(pub_key).or(Err(Error::Signature))?,
|
||||
private_key: Some(String::from_utf8(priv_key).or(Err(Error::Signature))?),
|
||||
outbox_url: Default::default(),
|
||||
inbox_url: Default::default(),
|
||||
ap_url: Default::default(),
|
||||
summary_html: Default::default(),
|
||||
icon_id: Default::default(),
|
||||
banner_id: Default::default(),
|
||||
theme: Default::default(),
|
||||
..NewBlog::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -588,8 +565,8 @@ pub(crate) mod tests {
|
||||
let mut blog1 = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Blog%20Name".to_owned(),
|
||||
"Blog Name".to_owned(),
|
||||
"BlogName".to_owned(),
|
||||
"Blog name".to_owned(),
|
||||
"This is a small blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
)
|
||||
@@ -599,7 +576,7 @@ pub(crate) mod tests {
|
||||
let blog2 = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"My%20Blog".to_owned(),
|
||||
"MyBlog".to_owned(),
|
||||
"My blog".to_owned(),
|
||||
"Welcome to my blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -610,7 +587,7 @@ pub(crate) mod tests {
|
||||
let blog3 = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Why%20I%20Like%20Plume".to_owned(),
|
||||
"WhyILikePlume".to_owned(),
|
||||
"Why I like Plume".to_owned(),
|
||||
"In this blog I will explay you why I like Plume so much".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -705,7 +682,7 @@ pub(crate) mod tests {
|
||||
let blog = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Some%20Name".to_owned(),
|
||||
"SomeName".to_owned(),
|
||||
"Some name".to_owned(),
|
||||
"This is some blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -732,7 +709,7 @@ pub(crate) mod tests {
|
||||
let b1 = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Some%20Name".to_owned(),
|
||||
"SomeName".to_owned(),
|
||||
"Some name".to_owned(),
|
||||
"This is some blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -833,7 +810,7 @@ pub(crate) mod tests {
|
||||
let blog = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Some%20Name".to_owned(),
|
||||
"SomeName".to_owned(),
|
||||
"Some name".to_owned(),
|
||||
"This is some blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -853,10 +830,10 @@ pub(crate) mod tests {
|
||||
conn.test_transaction::<_, (), _>(|| {
|
||||
fill_database(conn);
|
||||
|
||||
let _ = Blog::insert(
|
||||
let blog = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Some%20Name".to_owned(),
|
||||
"SomeName".to_owned(),
|
||||
"Some name".to_owned(),
|
||||
"This is some blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -865,6 +842,7 @@ pub(crate) mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(blog.fqn, "SomeName");
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -890,7 +868,7 @@ pub(crate) mod tests {
|
||||
let b1 = Blog::insert(
|
||||
conn,
|
||||
NewBlog::new_local(
|
||||
"Some%20Name".to_owned(),
|
||||
"SomeName".to_owned(),
|
||||
"Some name".to_owned(),
|
||||
"This is some blog".to_owned(),
|
||||
Instance::get_local().unwrap().id,
|
||||
@@ -990,7 +968,6 @@ pub(crate) mod tests {
|
||||
let _: Blog = blogs[0].save_changes(&**conn).unwrap();
|
||||
let ap_repr = blogs[0].to_activity(conn).unwrap();
|
||||
blogs[0].delete(conn).unwrap();
|
||||
eprintln!("{:#?}", &ap_repr);
|
||||
let blog = Blog::from_activity(conn, ap_repr).unwrap();
|
||||
|
||||
assert_eq!(blog.actor_id, blogs[0].actor_id);
|
||||
@@ -1024,19 +1001,19 @@ pub(crate) mod tests {
|
||||
"type": "Image",
|
||||
"url": "https://plu.me/aaa.png"
|
||||
},
|
||||
"id": "https://plu.me/~/Blog%20Name/",
|
||||
"id": "https://plu.me/~/BlogName/",
|
||||
"image": {
|
||||
"attributedTo": "https://plu.me/@/admin/",
|
||||
"type": "Image",
|
||||
"url": "https://plu.me/bbb.png"
|
||||
},
|
||||
"inbox": "https://plu.me/~/Blog%20Name/inbox",
|
||||
"name": "Blog Name",
|
||||
"outbox": "https://plu.me/~/Blog%20Name/outbox",
|
||||
"inbox": "https://plu.me/~/BlogName/inbox",
|
||||
"name": "Blog name",
|
||||
"outbox": "https://plu.me/~/BlogName/outbox",
|
||||
"preferredUsername": "BlogName",
|
||||
"publicKey": {
|
||||
"id": "https://plu.me/~/Blog%20Name/#main-key",
|
||||
"owner": "https://plu.me/~/Blog%20Name/",
|
||||
"id": "https://plu.me/~/BlogName/#main-key",
|
||||
"owner": "https://plu.me/~/BlogName/",
|
||||
"publicKeyPem": blog.public_key
|
||||
},
|
||||
"source": {
|
||||
@@ -1064,8 +1041,8 @@ pub(crate) mod tests {
|
||||
let expected = json!({
|
||||
"items": [],
|
||||
"totalItems": 0,
|
||||
"first": "https://plu.me/~/Blog%20Name/outbox?page=1",
|
||||
"last": "https://plu.me/~/Blog%20Name/outbox?page=0",
|
||||
"first": "https://plu.me/~/BlogName/outbox?page=1",
|
||||
"last": "https://plu.me/~/BlogName/outbox?page=0",
|
||||
"type": "OrderedCollection"
|
||||
});
|
||||
|
||||
@@ -1084,8 +1061,8 @@ pub(crate) mod tests {
|
||||
let act = blog.outbox_collection_page(conn, (33, 36))?;
|
||||
|
||||
let expected = json!({
|
||||
"next": "https://plu.me/~/Blog%20Name/outbox?page=3",
|
||||
"prev": "https://plu.me/~/Blog%20Name/outbox?page=1",
|
||||
"next": "https://plu.me/~/BlogName/outbox?page=3",
|
||||
"prev": "https://plu.me/~/BlogName/outbox?page=1",
|
||||
"items": [],
|
||||
"type": "OrderedCollectionPage"
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
comment_seers::{CommentSeers, NewCommentSeers},
|
||||
db_conn::DbConn,
|
||||
instance::Instance,
|
||||
medias::Media,
|
||||
mentions::Mention,
|
||||
@@ -111,7 +110,7 @@ impl Comment {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn to_activity(&self, conn: &DbConn) -> Result<Note> {
|
||||
pub fn to_activity(&self, conn: &Connection) -> Result<Note> {
|
||||
let author = User::get(conn, self.author_id)?;
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||
self.content.get().as_ref(),
|
||||
@@ -149,7 +148,7 @@ impl Comment {
|
||||
Ok(note)
|
||||
}
|
||||
|
||||
pub fn create_activity(&self, conn: &DbConn) -> Result<Create> {
|
||||
pub fn create_activity(&self, conn: &Connection) -> Result<Create> {
|
||||
let author = User::get(conn, self.author_id)?;
|
||||
|
||||
let note = self.to_activity(conn)?;
|
||||
@@ -217,15 +216,15 @@ impl Comment {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Comment {
|
||||
impl FromId<Connection> for Comment {
|
||||
type Error = Error;
|
||||
type Object = Note;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, note: Note) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, note: Note) -> Result<Self> {
|
||||
let comm = {
|
||||
let previous_url = note
|
||||
.in_reply_to()
|
||||
@@ -354,21 +353,21 @@ impl FromId<DbConn> for Comment {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Create, &DbConn> for Comment {
|
||||
impl AsObject<User, Create, &Connection> for Comment {
|
||||
type Error = Error;
|
||||
type Output = Self;
|
||||
|
||||
fn activity(self, _conn: &DbConn, _actor: User, _id: &str) -> Result<Self> {
|
||||
fn activity(self, _conn: &Connection, _actor: User, _id: &str) -> Result<Self> {
|
||||
// The actual creation takes place in the FromId impl
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Delete, &DbConn> for Comment {
|
||||
impl AsObject<User, Delete, &Connection> for Comment {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
if self.author_id != actor.id {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
@@ -387,8 +386,8 @@ impl AsObject<User, Delete, &DbConn> for Comment {
|
||||
diesel::update(comments::table)
|
||||
.filter(comments::in_response_to_id.eq(self.id))
|
||||
.set(comments::in_response_to_id.eq(self.in_response_to_id))
|
||||
.execute(&**conn)?;
|
||||
diesel::delete(&self).execute(&**conn)?;
|
||||
.execute(conn)?;
|
||||
diesel::delete(&self).execute(conn)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -423,6 +422,7 @@ impl CommentTree {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::blogs::Blog;
|
||||
use crate::db_conn::DbConn;
|
||||
use crate::inbox::{inbox, tests::fill_database, InboxResult};
|
||||
use crate::safe_string::SafeString;
|
||||
use crate::tests::{db, format_datetime};
|
||||
@@ -463,13 +463,13 @@ mod tests {
|
||||
assert_json_eq!(to_value(&act).unwrap(), json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}/activity", original_comm.id),
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", original_comm.id),
|
||||
"object": {
|
||||
"attributedTo": "https://plu.me/@/admin/",
|
||||
"content": r###"<p dir="auto">My comment, mentioning to <a href="https://plu.me/@/user/" title="user">@user</a></p>
|
||||
"###,
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}", original_comm.id),
|
||||
"inReplyTo": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||
"inReplyTo": "https://plu.me/~/BlogName/testing",
|
||||
"published": format_datetime(&original_comm.creation_date),
|
||||
"summary": "My CW",
|
||||
"tag": [
|
||||
@@ -505,12 +505,12 @@ mod tests {
|
||||
assert_json_eq!(to_value(&reply_act).unwrap(), json!({
|
||||
"actor": "https://plu.me/@/user/",
|
||||
"cc": ["https://plu.me/@/user/followers"],
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}/activity", reply.id),
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", reply.id),
|
||||
"object": {
|
||||
"attributedTo": "https://plu.me/@/user/",
|
||||
"content": "",
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}", reply.id),
|
||||
"inReplyTo": format!("https://plu.me/~/Blog%20Name/testing/comment/{}", original_comm.id),
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", reply.id),
|
||||
"inReplyTo": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||
"published": format_datetime(&reply.creation_date),
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
@@ -554,8 +554,8 @@ mod tests {
|
||||
"attributedTo": "https://plu.me/@/admin/",
|
||||
"content": r###"<p dir="auto">My comment, mentioning to <a href="https://plu.me/@/user/" title="user">@user</a></p>
|
||||
"###,
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}", comment.id),
|
||||
"inReplyTo": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id),
|
||||
"inReplyTo": "https://plu.me/~/BlogName/testing",
|
||||
"published": format_datetime(&comment.creation_date),
|
||||
"summary": "My CW",
|
||||
"tag": [
|
||||
@@ -584,9 +584,9 @@ mod tests {
|
||||
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}#delete", comment.id),
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}#delete", comment.id),
|
||||
"object": {
|
||||
"id": format!("https://plu.me/~/Blog%20Name/testing/comment/{}", comment.id),
|
||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id),
|
||||
"type": "Tombstone"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
|
||||
+104
-6
@@ -6,6 +6,10 @@ use rocket::Config as RocketConfig;
|
||||
use std::collections::HashSet;
|
||||
use std::env::{self, var};
|
||||
|
||||
use s3::{Bucket, Region};
|
||||
use s3::creds::Credentials;
|
||||
|
||||
|
||||
#[cfg(not(test))]
|
||||
const DB_NAME: &str = "plume";
|
||||
#[cfg(test)]
|
||||
@@ -27,13 +31,23 @@ pub struct Config {
|
||||
pub mail: Option<MailConfig>,
|
||||
pub ldap: Option<LdapConfig>,
|
||||
pub proxy: Option<ProxyConfig>,
|
||||
pub s3: Option<S3Config>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn proxy(&self) -> Option<&reqwest::Proxy> {
|
||||
self.proxy.as_ref().map(|p| &p.proxy)
|
||||
}
|
||||
}
|
||||
|
||||
fn string_to_bool(val: &str, name: &str) -> bool {
|
||||
match val {
|
||||
"1" | "true" | "TRUE" => true,
|
||||
"0" | "false" | "FALSE" => false,
|
||||
_ => panic!("Invalid configuration: {} is not boolean", name),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InvalidRocketConfig {
|
||||
Env,
|
||||
@@ -41,7 +55,7 @@ pub enum InvalidRocketConfig {
|
||||
SecretKey,
|
||||
}
|
||||
|
||||
pub fn get_rocket_config() -> Result<RocketConfig, InvalidRocketConfig> {
|
||||
fn get_rocket_config() -> Result<RocketConfig, InvalidRocketConfig> {
|
||||
let mut c = RocketConfig::active().map_err(|_| InvalidRocketConfig::Env)?;
|
||||
|
||||
let address = var("ROCKET_ADDRESS").unwrap_or_else(|_| "localhost".to_owned());
|
||||
@@ -288,11 +302,7 @@ fn get_ldap_config() -> Option<LdapConfig> {
|
||||
match (addr, base_dn) {
|
||||
(Some(addr), Some(base_dn)) => {
|
||||
let tls = var("LDAP_TLS").unwrap_or_else(|_| "false".to_owned());
|
||||
let tls = match tls.as_ref() {
|
||||
"1" | "true" | "TRUE" => true,
|
||||
"0" | "false" | "FALSE" => false,
|
||||
_ => panic!("Invalid LDAP configuration : tls"),
|
||||
};
|
||||
let tls = string_to_bool(&tls, "LDAP_TLS");
|
||||
let user_name_attr = var("LDAP_USER_NAME_ATTR").unwrap_or_else(|_| "cn".to_owned());
|
||||
let mail_attr = var("LDAP_USER_MAIL_ATTR").unwrap_or_else(|_| "mail".to_owned());
|
||||
Some(LdapConfig {
|
||||
@@ -349,6 +359,93 @@ fn get_proxy_config() -> Option<ProxyConfig> {
|
||||
})
|
||||
}
|
||||
|
||||
pub struct S3Config {
|
||||
pub bucket: String,
|
||||
pub access_key_id: String,
|
||||
pub access_key_secret: String,
|
||||
|
||||
// region? If not set, default to us-east-1
|
||||
pub region: String,
|
||||
// hostname for s3. If not set, default to $region.amazonaws.com
|
||||
pub hostname: String,
|
||||
// may be useful when using self hosted s3. Won't work with recent AWS buckets
|
||||
pub path_style: bool,
|
||||
pub protocol: String,
|
||||
|
||||
// options below this comment are not used yet
|
||||
// upload directly from user to S3, without going through Plume. Uses PostObject endpoint
|
||||
pub direct_upload: bool,
|
||||
// download directly from s3 to user, wihout going through Plume. Require public read on bucket
|
||||
pub direct_download: bool,
|
||||
// use this hostname for downloads, can be used with caching proxy in front of s3
|
||||
pub alias: Option<String>,
|
||||
}
|
||||
|
||||
impl S3Config {
|
||||
pub fn get_bucket(&self) -> Bucket {
|
||||
let region = Region::Custom {
|
||||
region: self.region.clone(),
|
||||
endpoint: format!("{}://{}", self.protocol, self.hostname),
|
||||
};
|
||||
let credentials = Credentials {
|
||||
access_key: Some(self.access_key_id.clone()),
|
||||
secret_key: Some(self.access_key_secret.clone()),
|
||||
security_token: None,
|
||||
session_token: None,
|
||||
};
|
||||
|
||||
if self.path_style {
|
||||
Bucket::new_with_path_style(&self.bucket, region, credentials)
|
||||
} else {
|
||||
Bucket::new(&self.bucket, region, credentials)
|
||||
}.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_s3_config() -> Option<S3Config> {
|
||||
let bucket = var("S3_BUCKET").ok();
|
||||
let access_key_id = var("AWS_ACCESS_KEY_ID").ok();
|
||||
let access_key_secret = var("AWS_SECRET_ACCESS_KEY").ok();
|
||||
if bucket.is_none() && access_key_id.is_none() && access_key_secret.is_none() {
|
||||
return None;
|
||||
}
|
||||
if bucket.is_none() || access_key_id.is_none() || access_key_secret.is_none() {
|
||||
panic!("Invalid S3 configuration: some required values are set, but not others");
|
||||
}
|
||||
let bucket = bucket.unwrap();
|
||||
let access_key_id = access_key_id.unwrap();
|
||||
let access_key_secret = access_key_secret.unwrap();
|
||||
|
||||
let region = var("S3_REGION").unwrap_or_else(|_| "us-east-1".to_owned());
|
||||
let hostname = var("S3_HOSTNAME").unwrap_or_else(|_| format!("{}.amazonaws.com", region));
|
||||
|
||||
let protocol = var("S3_PROTOCOL").unwrap_or_else(|_| "https".to_owned());
|
||||
if protocol != "http" && protocol != "https" {
|
||||
panic!("Invalid S3 configuration: invalid protocol {}", protocol);
|
||||
}
|
||||
|
||||
let path_style = var("S3_PATH_STYLE").unwrap_or_else(|_| "false".to_owned());
|
||||
let path_style = string_to_bool(&path_style, "S3_PATH_STYLE");
|
||||
let direct_upload = var("S3_DIRECT_UPLOAD").unwrap_or_else(|_| "false".to_owned());
|
||||
let direct_upload = string_to_bool(&direct_upload, "S3_DIRECT_UPLOAD");
|
||||
let direct_download = var("S3_DIRECT_DOWNLOAD").unwrap_or_else(|_| "false".to_owned());
|
||||
let direct_download = string_to_bool(&direct_download, "S3_DIRECT_DOWNLOAD");
|
||||
|
||||
let alias = var("S3_ALIAS_HOST").ok();
|
||||
Some(S3Config {
|
||||
bucket,
|
||||
access_key_id,
|
||||
access_key_secret,
|
||||
region,
|
||||
hostname,
|
||||
protocol,
|
||||
path_style,
|
||||
direct_upload,
|
||||
direct_download,
|
||||
alias,
|
||||
})
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: Config = Config {
|
||||
base_url: var("BASE_URL").unwrap_or_else(|_| format!(
|
||||
@@ -380,5 +477,6 @@ lazy_static! {
|
||||
mail: get_mail_config(),
|
||||
ldap: get_ldap_config(),
|
||||
proxy: get_proxy_config(),
|
||||
s3: get_s3_config(),
|
||||
};
|
||||
}
|
||||
|
||||
+14
-12
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ap_url, db_conn::DbConn, instance::Instance, notifications::*, schema::follows, users::User,
|
||||
Connection, Error, Result, CONFIG,
|
||||
ap_url, instance::Instance, notifications::*, schema::follows, users::User, Connection, Error,
|
||||
Result, CONFIG,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Accept, ActorAndObjectRef, Follow as FollowAct, Undo},
|
||||
@@ -150,11 +150,11 @@ impl Follow {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, FollowAct, &DbConn> for User {
|
||||
impl AsObject<User, FollowAct, &Connection> for User {
|
||||
type Error = Error;
|
||||
type Output = Follow;
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> {
|
||||
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Follow> {
|
||||
// Mastodon (at least) requires the full Follow object when accepting it,
|
||||
// so we rebuilt it here
|
||||
let follow = FollowAct::new(actor.ap_url.parse::<IriString>()?, id.parse::<IriString>()?);
|
||||
@@ -162,15 +162,15 @@ impl AsObject<User, FollowAct, &DbConn> for User {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Follow {
|
||||
impl FromId<Connection> for Follow {
|
||||
type Error = Error;
|
||||
type Object = FollowAct;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Follow::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, follow: FollowAct) -> Result<Self> {
|
||||
let actor = User::from_id(
|
||||
conn,
|
||||
follow
|
||||
@@ -202,18 +202,18 @@ impl FromId<DbConn> for Follow {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Undo, &DbConn> for Follow {
|
||||
impl AsObject<User, Undo, &Connection> for Follow {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
let conn = conn;
|
||||
if self.follower_id == actor.id {
|
||||
diesel::delete(&self).execute(&**conn)?;
|
||||
diesel::delete(&self).execute(conn)?;
|
||||
|
||||
// delete associated notification if any
|
||||
if let Ok(notif) = Notification::find(conn, notification_kind::FOLLOW, self.id) {
|
||||
diesel::delete(¬if).execute(&**conn)?;
|
||||
diesel::delete(¬if).execute(conn)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -232,7 +232,9 @@ impl IntoId for Follow {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{tests::db, users::tests as user_tests, users::tests::fill_database};
|
||||
use crate::{
|
||||
db_conn::DbConn, tests::db, users::tests as user_tests, users::tests::fill_database,
|
||||
};
|
||||
use assert_json_diff::assert_json_eq;
|
||||
use diesel::Connection;
|
||||
use serde_json::{json, to_value};
|
||||
|
||||
@@ -47,7 +47,7 @@ impl_into_inbox_result! {
|
||||
}
|
||||
|
||||
pub fn inbox(conn: &DbConn, act: serde_json::Value) -> Result<InboxResult, Error> {
|
||||
Inbox::handle(conn, act)
|
||||
Inbox::handle(&**conn, act)
|
||||
.with::<User, Announce, Post>(CONFIG.proxy())
|
||||
.with::<User, Create, Comment>(CONFIG.proxy())
|
||||
.with::<User, Create, Post>(CONFIG.proxy())
|
||||
@@ -268,7 +268,7 @@ pub(crate) mod tests {
|
||||
"actor": users[0].ap_url,
|
||||
"object": {
|
||||
"type": "Article",
|
||||
"id": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/~/BlogName/testing",
|
||||
"attributedTo": [users[0].ap_url, blogs[0].ap_url],
|
||||
"content": "Hello.",
|
||||
"name": "My Article",
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, result::Error::NotFound, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use once_cell::sync::OnceCell;
|
||||
use plume_common::utils::md_to_html;
|
||||
use plume_common::utils::{iri_percent_encode_seg, md_to_html};
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[derive(Clone, Identifiable, Queryable)]
|
||||
@@ -173,8 +173,8 @@ impl Instance {
|
||||
"{instance}/{prefix}/{name}/{box_name}",
|
||||
instance = self.public_domain,
|
||||
prefix = prefix,
|
||||
name = name,
|
||||
box_name = box_name
|
||||
name = iri_percent_encode_seg(name),
|
||||
box_name = iri_percent_encode_seg(box_name)
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
+7
-114
@@ -17,18 +17,12 @@ extern crate serde_json;
|
||||
extern crate tantivy;
|
||||
|
||||
use activitystreams::iri_string;
|
||||
use diesel::backend::Backend;
|
||||
use diesel::sql_types::Text;
|
||||
use diesel::types::{FromSql, ToSql};
|
||||
use heck::ToUpperCamelCase;
|
||||
pub use lettre;
|
||||
pub use lettre::smtp;
|
||||
use once_cell::sync::Lazy;
|
||||
use plume_common::activity_pub::PreferredUsernameError;
|
||||
use plume_common::activity_pub::{inbox::InboxError, request, sign, PreferredUsername};
|
||||
use plume_common::activity_pub::{inbox::InboxError, request, sign};
|
||||
use posts::PostEvent;
|
||||
use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder};
|
||||
use std::{fmt, io::Write, string::ToString};
|
||||
use users::UserEvent;
|
||||
|
||||
#[cfg(not(any(feature = "sqlite", feature = "postgres")))]
|
||||
@@ -75,6 +69,7 @@ pub enum Error {
|
||||
Webfinger,
|
||||
Expired,
|
||||
UserAlreadyExists,
|
||||
Anyhow(anyhow::Error),
|
||||
}
|
||||
|
||||
impl From<bcrypt::BcryptError> for Error {
|
||||
@@ -176,10 +171,9 @@ impl From<request::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PreferredUsernameError> for Error {
|
||||
fn from(err: PreferredUsernameError) -> Error {
|
||||
tracing::trace!("{:?}", err);
|
||||
Error::InvalidValue
|
||||
impl From<anyhow::Error> for Error {
|
||||
fn from(err: anyhow::Error) -> Error {
|
||||
Error::Anyhow(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +308,7 @@ macro_rules! last {
|
||||
}
|
||||
|
||||
mod config;
|
||||
pub use config::{get_rocket_config, Config, SearchTokenizerConfig, CONFIG};
|
||||
pub use config::CONFIG;
|
||||
|
||||
pub fn ap_url(url: &str) -> String {
|
||||
format!("https://{}", url)
|
||||
@@ -347,97 +341,10 @@ impl SmtpNewWithAddr for smtp::SmtpClient {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(AsExpression, PartialEq, Eq, Clone, FromSqlRow, Debug)]
|
||||
#[sql_type = "Text"]
|
||||
pub enum Fqn {
|
||||
Local(PreferredUsername),
|
||||
Remote(PreferredUsername, String),
|
||||
}
|
||||
|
||||
impl Fqn {
|
||||
pub fn new_local(username: String) -> Result<Self> {
|
||||
Ok(Self::Local(
|
||||
PreferredUsername::new(username)?,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_remote(username: String, domain: String) -> Result<Self> {
|
||||
Ok(Self::Remote(
|
||||
PreferredUsername::new(username)?,
|
||||
domain,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn make_local_string(base: &str) -> String {
|
||||
base.to_upper_camel_case()
|
||||
.chars()
|
||||
.filter(|c| c.is_ascii_alphanumeric())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn make_local(base: &str) -> Result<Self> {
|
||||
Self::new_local(Self::make_local_string(base))
|
||||
}
|
||||
|
||||
pub fn make_remote(base: &str, domain: String) -> Result<Self> {
|
||||
Self::new_remote(Self::make_local_string(base), domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Fqn> for String {
|
||||
fn from(fqn: &Fqn) -> Self {
|
||||
match fqn {
|
||||
Fqn::Local(username) => username.to_string(),
|
||||
Fqn::Remote(username, domain) => format!("{}@{}", username, domain),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Fqn {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
String::from(self).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> ToSql<Text, DB> for Fqn
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
{
|
||||
fn to_sql<W: Write>(
|
||||
&self,
|
||||
out: &mut diesel::serialize::Output<W, DB>,
|
||||
) -> diesel::serialize::Result {
|
||||
let fqn = match self {
|
||||
Self::Local(username) => username.to_string(),
|
||||
Self::Remote(username, domain) => format!("{}@{}", username, domain),
|
||||
};
|
||||
ToSql::<Text, DB>::to_sql::<W>(&fqn, out)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> FromSql<Text, DB> for Fqn
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
String: FromSql<Text, DB>,
|
||||
{
|
||||
/// We use PreferredUsername::new_unchecked() because, even if bytes is invalid as `preferredUsername`,
|
||||
/// we need return some value.
|
||||
fn from_sql(bytes: Option<&<DB as Backend>::RawValue>) -> diesel::deserialize::Result<Self> {
|
||||
let value = <String as FromSql<Text, DB>>::from_sql(bytes)?;
|
||||
Ok(match value.rsplit_once('@') {
|
||||
None => Self::Local(unsafe { PreferredUsername::new_unchecked(value) }),
|
||||
Some((username, domain)) => Self::Remote(
|
||||
unsafe { PreferredUsername::new_unchecked(username.into()) },
|
||||
domain.into(),
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
mod tests {
|
||||
use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, Connection as Conn, CONFIG, Fqn};
|
||||
use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, Connection as Conn, CONFIG};
|
||||
use chrono::{naive::NaiveDateTime, Datelike, Timelike};
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
use plume_common::utils::random_hex;
|
||||
@@ -498,20 +405,6 @@ mod tests {
|
||||
dt.second()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fqn() {
|
||||
assert_eq!(
|
||||
Fqn::new_local("admin".to_string()).unwrap(),
|
||||
Fqn::new_local("admin".to_string()).unwrap()
|
||||
);
|
||||
assert!(Fqn::new_local("admin".to_string()).is_ok());
|
||||
let fqn = Fqn::new_local("admin".to_string()).unwrap();
|
||||
assert_eq!("admin".to_string(), String::from(&fqn));
|
||||
let fqn = Fqn::new_local("admin".to_string()).unwrap();
|
||||
assert_eq!("admin".to_string(), ToString::to_string(&fqn));
|
||||
assert_eq!("admin".to_string(), fqn.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub mod admin;
|
||||
|
||||
+16
-16
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::likes, timeline::*,
|
||||
users::User, Connection, Error, Result, CONFIG,
|
||||
instance::Instance, notifications::*, posts::Post, schema::likes, timeline::*, users::User,
|
||||
Connection, Error, Result, CONFIG,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{ActorAndObjectRef, Like as LikeAct, Undo},
|
||||
@@ -85,11 +85,11 @@ impl Like {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, LikeAct, &DbConn> for Post {
|
||||
impl AsObject<User, LikeAct, &Connection> for Post {
|
||||
type Error = Error;
|
||||
type Output = Like;
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Like> {
|
||||
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Like> {
|
||||
let res = Like::insert(
|
||||
conn,
|
||||
NewLike {
|
||||
@@ -105,15 +105,15 @@ impl AsObject<User, LikeAct, &DbConn> for Post {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Like {
|
||||
impl FromId<Connection> for Like {
|
||||
type Error = Error;
|
||||
type Object = LikeAct;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Like::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, act: LikeAct) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, act: LikeAct) -> Result<Self> {
|
||||
let res = Like::insert(
|
||||
conn,
|
||||
NewLike {
|
||||
@@ -154,17 +154,17 @@ impl FromId<DbConn> for Like {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Undo, &DbConn> for Like {
|
||||
impl AsObject<User, Undo, &Connection> for Like {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
if actor.id == self.user_id {
|
||||
diesel::delete(&self).execute(&**conn)?;
|
||||
diesel::delete(&self).execute(conn)?;
|
||||
|
||||
// delete associated notification if any
|
||||
if let Ok(notif) = Notification::find(conn, notification_kind::LIKE, self.id) {
|
||||
diesel::delete(¬if).execute(&**conn)?;
|
||||
diesel::delete(¬if).execute(conn)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -205,8 +205,8 @@ mod tests {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/Blog%20Name/testing",
|
||||
"object": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
|
||||
"object": "https://plu.me/~/BlogName/testing",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Like",
|
||||
});
|
||||
@@ -229,12 +229,12 @@ mod tests {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/Blog%20Name/testing#delete",
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing#delete",
|
||||
"object": {
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/Blog%20Name/testing",
|
||||
"object": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
|
||||
"object": "https://plu.me/~/BlogName/testing",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Like",
|
||||
},
|
||||
|
||||
@@ -297,6 +297,28 @@ impl List {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
||||
if let Some(user_id) = self.user_id {
|
||||
diesel::delete(
|
||||
lists::table
|
||||
.filter(lists::user_id.eq(user_id))
|
||||
.filter(lists::name.eq(&self.name)),
|
||||
)
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
.map_err(Error::from)
|
||||
} else {
|
||||
diesel::delete(
|
||||
lists::table
|
||||
.filter(lists::user_id.is_null())
|
||||
.filter(lists::name.eq(&self.name)),
|
||||
)
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
.map_err(Error::from)
|
||||
}
|
||||
}
|
||||
|
||||
func! {set: set_users, User, add_users}
|
||||
func! {set: set_blogs, Blog, add_blogs}
|
||||
func! {set: set_words, Word, add_words}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ap_url, db_conn::DbConn, instance::Instance, safe_string::SafeString, schema::medias,
|
||||
users::User, Connection, Error, Result, CONFIG,
|
||||
ap_url, instance::Instance, safe_string::SafeString, schema::medias, users::User, Connection,
|
||||
Error, Result, CONFIG,
|
||||
};
|
||||
use activitystreams::{object::Image, prelude::*};
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
@@ -170,7 +170,12 @@ impl Media {
|
||||
|
||||
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
||||
if !self.is_remote {
|
||||
fs::remove_file(self.file_path.as_str())?;
|
||||
if let Some(config) = &CONFIG.s3 {
|
||||
config.get_bucket()
|
||||
.delete_object_blocking(&self.file_path)?;
|
||||
} else {
|
||||
fs::remove_file(self.file_path.as_str())?;
|
||||
}
|
||||
}
|
||||
diesel::delete(self)
|
||||
.execute(conn)
|
||||
@@ -206,7 +211,7 @@ impl Media {
|
||||
}
|
||||
|
||||
// TODO: merge with save_remote?
|
||||
pub fn from_activity(conn: &DbConn, image: &Image) -> Result<Media> {
|
||||
pub fn from_activity(conn: &Connection, image: &Image) -> Result<Media> {
|
||||
let remote_url = image
|
||||
.url()
|
||||
.and_then(|url| url.to_as_uri())
|
||||
@@ -258,7 +263,7 @@ impl Media {
|
||||
updated = true;
|
||||
}
|
||||
if updated {
|
||||
diesel::update(&media).set(&media).execute(&**conn)?;
|
||||
diesel::update(&media).set(&media).execute(conn)?;
|
||||
}
|
||||
Ok(media)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
comments::Comment, db_conn::DbConn, notifications::*, posts::Post, schema::mentions,
|
||||
users::User, Connection, Error, Result,
|
||||
comments::Comment, notifications::*, posts::Post, schema::mentions, users::User, Connection,
|
||||
Error, Result,
|
||||
};
|
||||
use activitystreams::{
|
||||
base::BaseExt,
|
||||
@@ -60,7 +60,7 @@ impl Mention {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_activity(conn: &DbConn, ment: &str) -> Result<link::Mention> {
|
||||
pub fn build_activity(conn: &Connection, ment: &str) -> Result<link::Mention> {
|
||||
let user = User::find_by_fqn(conn, ment)?;
|
||||
let mut mention = link::Mention::new();
|
||||
mention.set_href(user.ap_url.parse::<IriString>()?);
|
||||
|
||||
+35
-34
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
ap_url, blogs::Blog, db_conn::DbConn, instance::Instance, medias::Media, mentions::Mention,
|
||||
post_authors::*, safe_string::SafeString, schema::posts, tags::*, timeline::*, users::User,
|
||||
Connection, Error, Fqn, PostEvent::*, Result, CONFIG, POST_CHAN,
|
||||
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
|
||||
safe_string::SafeString, schema::posts, tags::*, timeline::*, users::User, Connection, Error,
|
||||
PostEvent::*, Result, CONFIG, POST_CHAN,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Create, Delete, Update},
|
||||
@@ -28,7 +28,7 @@ use riker::actors::{Publish, Tell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
static BLOG_FQN_CACHE: Lazy<Mutex<HashMap<i32, Fqn>>> = Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
static BLOG_FQN_CACHE: Lazy<Mutex<HashMap<i32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
#[derive(Queryable, Identifiable, Clone, AsChangeset, Debug)]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
@@ -255,7 +255,7 @@ impl Post {
|
||||
ap_url(&format!(
|
||||
"{}/~/{}/{}/",
|
||||
CONFIG.base_url,
|
||||
&blog.fqn,
|
||||
iri_percent_encode_seg(&blog.fqn),
|
||||
iri_percent_encode_seg(slug)
|
||||
))
|
||||
}
|
||||
@@ -298,9 +298,9 @@ impl Post {
|
||||
/// This caches query result. The best way to cache query result is holding it in `Post`s field
|
||||
/// but Diesel doesn't allow it currently.
|
||||
/// If sometime Diesel allow it, this method should be removed.
|
||||
pub fn get_blog_fqn(&self, conn: &Connection) -> Fqn {
|
||||
pub fn get_blog_fqn(&self, conn: &Connection) -> String {
|
||||
if let Some(blog_fqn) = BLOG_FQN_CACHE.lock().unwrap().get(&self.blog_id) {
|
||||
return blog_fqn.to_owned();
|
||||
return blog_fqn.to_string();
|
||||
}
|
||||
let blog_fqn = self.get_blog(conn).unwrap().fqn;
|
||||
BLOG_FQN_CACHE
|
||||
@@ -615,15 +615,15 @@ impl Post {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Post {
|
||||
impl FromId<Connection> for Post {
|
||||
type Error = Error;
|
||||
type Object = LicensedArticle;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, article: LicensedArticle) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, article: LicensedArticle) -> Result<Self> {
|
||||
let license = article.ext_one.license.unwrap_or_default();
|
||||
let article = article.inner;
|
||||
|
||||
@@ -821,21 +821,21 @@ impl FromId<DbConn> for Post {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Create, &DbConn> for Post {
|
||||
impl AsObject<User, Create, &Connection> for Post {
|
||||
type Error = Error;
|
||||
type Output = Self;
|
||||
|
||||
fn activity(self, _conn: &DbConn, _actor: User, _id: &str) -> Result<Self::Output> {
|
||||
fn activity(self, _conn: &Connection, _actor: User, _id: &str) -> Result<Self::Output> {
|
||||
// TODO: check that _actor is actually one of the author?
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Delete, &DbConn> for Post {
|
||||
impl AsObject<User, Delete, &Connection> for Post {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<Self::Output> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<Self::Output> {
|
||||
let can_delete = self
|
||||
.get_authors(conn)?
|
||||
.into_iter()
|
||||
@@ -859,16 +859,16 @@ pub struct PostUpdate {
|
||||
pub tags: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for PostUpdate {
|
||||
impl FromId<Connection> for PostUpdate {
|
||||
type Error = Error;
|
||||
type Object = LicensedArticle;
|
||||
|
||||
fn from_db(_: &DbConn, _: &str) -> Result<Self> {
|
||||
fn from_db(_: &Connection, _: &str) -> Result<Self> {
|
||||
// Always fail because we always want to deserialize the AP object
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, updated: Self::Object) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, updated: Self::Object) -> Result<Self> {
|
||||
let mut post_update = PostUpdate {
|
||||
ap_url: updated
|
||||
.ap_object_ref()
|
||||
@@ -923,11 +923,11 @@ impl FromId<DbConn> for PostUpdate {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Update, &DbConn> for PostUpdate {
|
||||
impl AsObject<User, Update, &Connection> for PostUpdate {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
let mut post =
|
||||
Post::from_id(conn, &self.ap_url, None, CONFIG.proxy()).map_err(|(_, e)| e)?;
|
||||
|
||||
@@ -1027,6 +1027,7 @@ impl From<PostEvent> for Arc<Post> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::db_conn::DbConn;
|
||||
use crate::inbox::{inbox, tests::fill_database, InboxResult};
|
||||
use crate::mentions::{Mention, NewMention};
|
||||
use crate::safe_string::SafeString;
|
||||
@@ -1109,10 +1110,10 @@ mod tests {
|
||||
let act = post.to_activity(&conn)?;
|
||||
|
||||
let expected = json!({
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/Blog%20Name/"],
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/BlogName/"],
|
||||
"cc": [],
|
||||
"content": "Hello",
|
||||
"id": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/~/BlogName/testing",
|
||||
"license": "WTFPL",
|
||||
"name": "Testing",
|
||||
"published": format_datetime(&post.creation_date),
|
||||
@@ -1130,7 +1131,7 @@ mod tests {
|
||||
],
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Article",
|
||||
"url": "https://plu.me/~/Blog%20Name/testing"
|
||||
"url": "https://plu.me/~/BlogName/testing"
|
||||
});
|
||||
|
||||
assert_json_eq!(to_value(act)?, expected);
|
||||
@@ -1149,12 +1150,12 @@ mod tests {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": [],
|
||||
"id": "https://plu.me/~/Blog%20Name/testing/activity",
|
||||
"id": "https://plu.me/~/BlogName/testing/activity",
|
||||
"object": {
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/Blog%20Name/"],
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/BlogName/"],
|
||||
"cc": [],
|
||||
"content": "Hello",
|
||||
"id": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/~/BlogName/testing",
|
||||
"license": "WTFPL",
|
||||
"name": "Testing",
|
||||
"published": format_datetime(&post.creation_date),
|
||||
@@ -1172,7 +1173,7 @@ mod tests {
|
||||
],
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Article",
|
||||
"url": "https://plu.me/~/Blog%20Name/testing"
|
||||
"url": "https://plu.me/~/BlogName/testing"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Create"
|
||||
@@ -1194,12 +1195,12 @@ mod tests {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": [],
|
||||
"id": "https://plu.me/~/Blog%20Name/testing/update-",
|
||||
"id": "https://plu.me/~/BlogName/testing/update-",
|
||||
"object": {
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/Blog%20Name/"],
|
||||
"attributedTo": ["https://plu.me/@/admin/", "https://plu.me/~/BlogName/"],
|
||||
"cc": [],
|
||||
"content": "Hello",
|
||||
"id": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/~/BlogName/testing",
|
||||
"license": "WTFPL",
|
||||
"name": "Testing",
|
||||
"published": format_datetime(&post.creation_date),
|
||||
@@ -1217,7 +1218,7 @@ mod tests {
|
||||
],
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Article",
|
||||
"url": "https://plu.me/~/Blog%20Name/testing"
|
||||
"url": "https://plu.me/~/BlogName/testing"
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Update"
|
||||
@@ -1226,10 +1227,10 @@ mod tests {
|
||||
|
||||
let id = actual["id"].to_string();
|
||||
let (id_pre, id_post) = id.rsplit_once('-').unwrap();
|
||||
assert_eq!(post.ap_url, "https://plu.me/~/Blog%20Name/testing");
|
||||
assert_eq!(post.ap_url, "https://plu.me/~/BlogName/testing");
|
||||
assert_eq!(
|
||||
id_pre,
|
||||
to_value("\"https://plu.me/~/Blog%20Name/testing/update")
|
||||
to_value("\"https://plu.me/~/BlogName/testing/update")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.unwrap()
|
||||
@@ -1259,9 +1260,9 @@ mod tests {
|
||||
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"id": "https://plu.me/~/Blog%20Name/testing#delete",
|
||||
"id": "https://plu.me/~/BlogName/testing#delete",
|
||||
"object": {
|
||||
"id": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/~/BlogName/testing",
|
||||
"type": "Tombstone"
|
||||
},
|
||||
"to": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::reshares,
|
||||
timeline::*, users::User, Connection, Error, Result, CONFIG,
|
||||
instance::Instance, notifications::*, posts::Post, schema::reshares, timeline::*, users::User,
|
||||
Connection, Error, Result, CONFIG,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{ActorAndObjectRef, Announce, Undo},
|
||||
@@ -113,11 +113,11 @@ impl Reshare {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Announce, &DbConn> for Post {
|
||||
impl AsObject<User, Announce, &Connection> for Post {
|
||||
type Error = Error;
|
||||
type Output = Reshare;
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Reshare> {
|
||||
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Reshare> {
|
||||
let conn = conn;
|
||||
let reshare = Reshare::insert(
|
||||
conn,
|
||||
@@ -134,15 +134,15 @@ impl AsObject<User, Announce, &DbConn> for Post {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromId<DbConn> for Reshare {
|
||||
impl FromId<Connection> for Reshare {
|
||||
type Error = Error;
|
||||
type Object = Announce;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Reshare::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, act: Announce) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, act: Announce) -> Result<Self> {
|
||||
let res = Reshare::insert(
|
||||
conn,
|
||||
NewReshare {
|
||||
@@ -183,17 +183,17 @@ impl FromId<DbConn> for Reshare {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Undo, &DbConn> for Reshare {
|
||||
impl AsObject<User, Undo, &Connection> for Reshare {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
if actor.id == self.user_id {
|
||||
diesel::delete(&self).execute(&**conn)?;
|
||||
diesel::delete(&self).execute(conn)?;
|
||||
|
||||
// delete associated notification if any
|
||||
if let Ok(notif) = Notification::find(conn, notification_kind::RESHARE, self.id) {
|
||||
diesel::delete(¬if).execute(&**conn)?;
|
||||
diesel::delete(¬if).execute(conn)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -235,8 +235,8 @@ mod test {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/Blog%20Name/testing",
|
||||
"object": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing",
|
||||
"object": "https://plu.me/~/BlogName/testing",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Announce",
|
||||
});
|
||||
@@ -259,12 +259,12 @@ mod test {
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/Blog%20Name/testing#delete",
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing#delete",
|
||||
"object": {
|
||||
"actor": "https://plu.me/@/admin/",
|
||||
"cc": ["https://plu.me/@/admin/followers"],
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/Blog%20Name/testing",
|
||||
"object": "https://plu.me/~/Blog%20Name/testing",
|
||||
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing",
|
||||
"object": "https://plu.me/~/BlogName/testing",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Announce"
|
||||
},
|
||||
|
||||
@@ -51,14 +51,6 @@ table! {
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
comment_seers (id) {
|
||||
id -> Int4,
|
||||
comment_id -> Int4,
|
||||
user_id -> Int4,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
comments (id) {
|
||||
id -> Int4,
|
||||
@@ -74,6 +66,14 @@ table! {
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
comment_seers (id) {
|
||||
id -> Int4,
|
||||
comment_id -> Int4,
|
||||
user_id -> Int4,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
email_blocklist (id) {
|
||||
id -> Int4,
|
||||
@@ -314,8 +314,8 @@ allow_tables_to_appear_in_same_query!(
|
||||
apps,
|
||||
blog_authors,
|
||||
blogs,
|
||||
comment_seers,
|
||||
comments,
|
||||
comment_seers,
|
||||
email_blocklist,
|
||||
email_signups,
|
||||
follows,
|
||||
|
||||
@@ -77,7 +77,6 @@ impl ActorFactoryArgs<(Arc<Searcher>, DbPool)> for SearchActor {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::diesel::Connection;
|
||||
use crate::Fqn;
|
||||
use crate::{
|
||||
blog_authors::{BlogAuthor, NewBlogAuthor},
|
||||
blogs::{Blog, NewBlog},
|
||||
@@ -191,22 +190,13 @@ mod tests {
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let title = random_hex();
|
||||
let blog = NewBlog {
|
||||
instance_id: instance.id,
|
||||
actor_id: random_hex(),
|
||||
ap_url: random_hex(),
|
||||
inbox_url: random_hex(),
|
||||
outbox_url: random_hex(),
|
||||
fqn: Fqn::make_local(&title).unwrap(),
|
||||
title,
|
||||
summary: Default::default(),
|
||||
summary_html: Default::default(),
|
||||
private_key: Default::default(),
|
||||
public_key: Default::default(),
|
||||
icon_id: Default::default(),
|
||||
banner_id: Default::default(),
|
||||
theme: Default::default(),
|
||||
..Default::default()
|
||||
};
|
||||
let blog = Blog::insert(conn, blog).unwrap();
|
||||
BlogAuthor::insert(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::{
|
||||
db_conn::DbConn,
|
||||
lists::List,
|
||||
posts::Post,
|
||||
schema::{posts, timeline, timeline_definition},
|
||||
@@ -12,7 +11,7 @@ use std::ops::Deref;
|
||||
pub(crate) mod query;
|
||||
|
||||
pub use self::query::Kind;
|
||||
use self::query::{QueryError, TimelineQuery};
|
||||
pub use self::query::{QueryError, TimelineQuery};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Queryable, Identifiable, AsChangeset)]
|
||||
#[table_name = "timeline_definition"]
|
||||
@@ -220,7 +219,7 @@ impl Timeline {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn add_to_all_timelines(conn: &DbConn, post: &Post, kind: Kind<'_>) -> Result<()> {
|
||||
pub fn add_to_all_timelines(conn: &Connection, post: &Post, kind: Kind<'_>) -> Result<()> {
|
||||
let timelines = timeline_definition::table
|
||||
.load::<Self>(conn.deref())
|
||||
.map_err(Error::from)?;
|
||||
@@ -246,7 +245,26 @@ impl Timeline {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn matches(&self, conn: &DbConn, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
||||
pub fn remove_post(&self, conn: &Connection, post: &Post) -> Result<bool> {
|
||||
if self.includes_post(conn, post)? {
|
||||
return Ok(false);
|
||||
}
|
||||
diesel::delete(
|
||||
timeline::table
|
||||
.filter(timeline::timeline_id.eq(self.id))
|
||||
.filter(timeline::post_id.eq(post.id)),
|
||||
)
|
||||
.execute(conn)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn remove_all_posts(&self, conn: &Connection) -> Result<u64> {
|
||||
let count = diesel::delete(timeline::table.filter(timeline::timeline_id.eq(self.id)))
|
||||
.execute(conn)?;
|
||||
Ok(count as u64)
|
||||
}
|
||||
|
||||
pub fn matches(&self, conn: &Connection, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
||||
let query = TimelineQuery::parse(&self.query)?;
|
||||
query.matches(conn, self, post, kind)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use crate::{
|
||||
blogs::Blog,
|
||||
db_conn::DbConn,
|
||||
lists::{self, ListType},
|
||||
posts::Post,
|
||||
tags::Tag,
|
||||
timeline::Timeline,
|
||||
users::User,
|
||||
Result,
|
||||
Connection, Result,
|
||||
};
|
||||
use plume_common::activity_pub::inbox::AsActor;
|
||||
use whatlang::{self, Lang};
|
||||
@@ -155,7 +154,7 @@ enum TQ<'a> {
|
||||
impl<'a> TQ<'a> {
|
||||
fn matches(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
conn: &Connection,
|
||||
timeline: &Timeline,
|
||||
post: &Post,
|
||||
kind: Kind<'_>,
|
||||
@@ -200,7 +199,7 @@ enum Arg<'a> {
|
||||
impl<'a> Arg<'a> {
|
||||
pub fn matches(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
conn: &Connection,
|
||||
timeline: &Timeline,
|
||||
post: &Post,
|
||||
kind: Kind<'_>,
|
||||
@@ -225,7 +224,7 @@ enum WithList {
|
||||
impl WithList {
|
||||
pub fn matches(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
conn: &Connection,
|
||||
timeline: &Timeline,
|
||||
post: &Post,
|
||||
list: &List<'_>,
|
||||
@@ -361,7 +360,7 @@ enum Bool {
|
||||
impl Bool {
|
||||
pub fn matches(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
conn: &Connection,
|
||||
timeline: &Timeline,
|
||||
post: &Post,
|
||||
kind: Kind<'_>,
|
||||
@@ -654,7 +653,7 @@ impl<'a> TimelineQuery<'a> {
|
||||
|
||||
pub fn matches(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
conn: &Connection,
|
||||
timeline: &Timeline,
|
||||
post: &Post,
|
||||
kind: Kind<'_>,
|
||||
|
||||
+37
-11
@@ -15,7 +15,10 @@ use activitystreams::{
|
||||
prelude::*,
|
||||
};
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use diesel::{self, BelongingToDsl, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
||||
use diesel::{
|
||||
self, BelongingToDsl, BoolExpressionMethods, ExpressionMethods, OptionalExtension, QueryDsl,
|
||||
RunQueryDsl, TextExpressionMethods,
|
||||
};
|
||||
use ldap3::{LdapConn, Scope, SearchEntry};
|
||||
use openssl::{
|
||||
hash::MessageDigest,
|
||||
@@ -186,15 +189,16 @@ impl User {
|
||||
pub fn count_local(conn: &Connection) -> Result<i64> {
|
||||
users::table
|
||||
.filter(users::instance_id.eq(Instance::get_local()?.id))
|
||||
.filter(users::role.ne(Role::Instance as i32))
|
||||
.count()
|
||||
.get_result(conn)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn find_by_fqn(conn: &DbConn, fqn: &str) -> Result<User> {
|
||||
pub fn find_by_fqn(conn: &Connection, fqn: &str) -> Result<User> {
|
||||
let from_db = users::table
|
||||
.filter(users::fqn.eq(fqn))
|
||||
.first(&**conn)
|
||||
.first(conn)
|
||||
.optional()?;
|
||||
if let Some(from_db) = from_db {
|
||||
Ok(from_db)
|
||||
@@ -203,6 +207,27 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn search_local_by_name(
|
||||
conn: &Connection,
|
||||
name: &str,
|
||||
(min, max): (i32, i32),
|
||||
) -> Result<Vec<User>> {
|
||||
users::table
|
||||
.filter(users::instance_id.eq(Instance::get_local()?.id))
|
||||
.filter(users::role.ne(Role::Instance as i32))
|
||||
// TODO: use `ilike` instead of `like` for PostgreSQL
|
||||
.filter(
|
||||
users::username
|
||||
.like(format!("%{}%", name))
|
||||
.or(users::display_name.like(format!("%{}%", name))),
|
||||
)
|
||||
.order(users::username.asc())
|
||||
.offset(min.into())
|
||||
.limit((max - min).into())
|
||||
.load::<User>(conn)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Should create user record with normalized(lowercased) email
|
||||
*/
|
||||
@@ -219,7 +244,7 @@ impl User {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
fn fetch_from_webfinger(conn: &DbConn, acct: &str) -> Result<User> {
|
||||
fn fetch_from_webfinger(conn: &Connection, acct: &str) -> Result<User> {
|
||||
let link = resolve(acct.to_owned(), true)?
|
||||
.links
|
||||
.into_iter()
|
||||
@@ -431,6 +456,7 @@ impl User {
|
||||
pub fn get_local_page(conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<User>> {
|
||||
users::table
|
||||
.filter(users::instance_id.eq(Instance::get_local()?.id))
|
||||
.filter(users::role.ne(Role::Instance as i32))
|
||||
.order(users::username.asc())
|
||||
.offset(min.into())
|
||||
.limit((max - min).into())
|
||||
@@ -761,7 +787,7 @@ impl User {
|
||||
actor.set_url(ap_url.clone());
|
||||
actor.set_inbox(self.inbox_url.parse()?);
|
||||
actor.set_outbox(self.outbox_url.parse()?);
|
||||
actor.set_preferred_username(&self.fqn);
|
||||
actor.set_preferred_username(self.username.clone());
|
||||
actor.set_followers(self.followers_endpoint.parse()?);
|
||||
|
||||
if let Some(shared_inbox_url) = self.shared_inbox_url.clone() {
|
||||
@@ -921,15 +947,15 @@ impl IntoId for User {
|
||||
|
||||
impl Eq for User {}
|
||||
|
||||
impl FromId<DbConn> for User {
|
||||
impl FromId<Connection> for User {
|
||||
type Error = Error;
|
||||
type Object = CustomPerson;
|
||||
|
||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
||||
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity(conn: &DbConn, acct: CustomPerson) -> Result<Self> {
|
||||
fn from_activity(conn: &Connection, acct: CustomPerson) -> Result<Self> {
|
||||
let actor = acct.ap_actor_ref();
|
||||
let username = actor
|
||||
.preferred_username()
|
||||
@@ -1030,7 +1056,7 @@ impl FromId<DbConn> for User {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsActor<&DbConn> for User {
|
||||
impl AsActor<&Connection> for User {
|
||||
fn get_inbox_url(&self) -> String {
|
||||
self.inbox_url.clone()
|
||||
}
|
||||
@@ -1046,11 +1072,11 @@ impl AsActor<&DbConn> for User {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Delete, &DbConn> for User {
|
||||
impl AsObject<User, Delete, &Connection> for User {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
||||
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||
if self.id == actor.id {
|
||||
self.delete(conn).map(|_| ())
|
||||
} else {
|
||||
|
||||
+32
-32
@@ -16,7 +16,7 @@ use plume_models::{
|
||||
migrations::IMPORTED_MIGRATIONS,
|
||||
remote_fetch_actor::RemoteFetchActor,
|
||||
search::{actor::SearchActor, Searcher as UnmanagedSearcher},
|
||||
Config, Connection, CONFIG,
|
||||
Connection, CONFIG,
|
||||
};
|
||||
use rocket_csrf::CsrfFairingBuilder;
|
||||
use scheduled_thread_pool::ScheduledThreadPool;
|
||||
@@ -47,12 +47,12 @@ include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
||||
compile_i18n!();
|
||||
|
||||
/// Initializes a database pool.
|
||||
fn init_pool(config: &Config) -> Option<DbPool> {
|
||||
fn init_pool() -> Option<DbPool> {
|
||||
let manager = ConnectionManager::<Connection>::new(CONFIG.database_url.as_str());
|
||||
let mut builder = DbPool::builder()
|
||||
.connection_customizer(Box::new(PragmaForeignKey))
|
||||
.min_idle(config.db_min_idle);
|
||||
if let Some(max_size) = config.db_max_size {
|
||||
.min_idle(CONFIG.db_min_idle);
|
||||
if let Some(max_size) = CONFIG.db_max_size {
|
||||
builder = builder.max_size(max_size);
|
||||
};
|
||||
let pool = builder.build(manager).ok()?;
|
||||
@@ -63,8 +63,28 @@ fn init_pool(config: &Config) -> Option<DbPool> {
|
||||
Some(pool)
|
||||
}
|
||||
|
||||
pub(crate) fn init_rocket(config: &Config) -> rocket::Rocket {
|
||||
let dbpool = init_pool(config).expect("main: database pool initialization error");
|
||||
pub(crate) fn init_rocket() -> rocket::Rocket {
|
||||
match dotenv::dotenv() {
|
||||
Ok(path) => eprintln!("Configuration read from {}", path.display()),
|
||||
Err(ref e) if e.not_found() => eprintln!("no .env was found"),
|
||||
e => e.map(|_| ()).unwrap(),
|
||||
}
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
App::new("Plume")
|
||||
.bin_name("plume")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("Plume backend server")
|
||||
.after_help(
|
||||
r#"
|
||||
The plume command should be run inside the directory
|
||||
containing the `.env` configuration file and `static` directory.
|
||||
See https://docs.joinplu.me/installation/config
|
||||
and https://docs.joinplu.me/installation/init for more info.
|
||||
"#,
|
||||
)
|
||||
.get_matches();
|
||||
let dbpool = init_pool().expect("main: database pool initialization error");
|
||||
if IMPORTED_MIGRATIONS
|
||||
.is_pending(&dbpool.get().unwrap())
|
||||
.unwrap_or(true)
|
||||
@@ -84,8 +104,8 @@ Then try to restart Plume.
|
||||
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
|
||||
// we want a fast exit here, so
|
||||
let searcher = Arc::new(UnmanagedSearcher::open_or_recreate(
|
||||
&config.search_index,
|
||||
&config.search_tokenizers,
|
||||
&CONFIG.search_index,
|
||||
&CONFIG.search_tokenizers,
|
||||
));
|
||||
RemoteFetchActor::init(dbpool.clone());
|
||||
SearchActor::init(searcher.clone(), dbpool.clone());
|
||||
@@ -105,12 +125,12 @@ Then try to restart Plume.
|
||||
.expect("Error setting Ctrl-c handler");
|
||||
|
||||
let mail = mail::init();
|
||||
if mail.is_none() && config.rocket.as_ref().unwrap().environment.is_prod() {
|
||||
if mail.is_none() && CONFIG.rocket.as_ref().unwrap().environment.is_prod() {
|
||||
warn!("Warning: the email server is not configured (or not completely).");
|
||||
warn!("Please refer to the documentation to see how to configure it.");
|
||||
}
|
||||
|
||||
rocket::custom(config.rocket.clone().unwrap())
|
||||
rocket::custom(CONFIG.rocket.clone().unwrap())
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
@@ -137,6 +157,7 @@ Then try to restart Plume.
|
||||
routes::instance::admin_mod,
|
||||
routes::instance::admin_instances,
|
||||
routes::instance::admin_users,
|
||||
routes::instance::admin_search_users,
|
||||
routes::instance::admin_email_blocklist,
|
||||
routes::instance::add_email_blocklist,
|
||||
routes::instance::delete_email_blocklist,
|
||||
@@ -260,28 +281,7 @@ Then try to restart Plume.
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match dotenv::dotenv() {
|
||||
Ok(path) => eprintln!("Configuration read from {}", path.display()),
|
||||
Err(ref e) if e.not_found() => eprintln!("no .env was found"),
|
||||
e => e.map(|_| ()).unwrap(),
|
||||
}
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
App::new("Plume")
|
||||
.bin_name("plume")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about("Plume backend server")
|
||||
.after_help(
|
||||
r#"
|
||||
The plume command should be run inside the directory
|
||||
containing the `.env` configuration file and `static` directory.
|
||||
See https://docs.joinplu.me/installation/config
|
||||
and https://docs.joinplu.me/installation/init for more info.
|
||||
"#,
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let rocket = init_rocket(&CONFIG);
|
||||
let rocket = init_rocket();
|
||||
|
||||
#[cfg(feature = "test")]
|
||||
let rocket = rocket.mount("/test", routes![test_routes::health,]);
|
||||
|
||||
+33
-127
@@ -1,7 +1,4 @@
|
||||
use activitystreams::{
|
||||
collection::{OrderedCollection, OrderedCollectionPage},
|
||||
iri_string::{spec::IriSpec, validate::iri_reference},
|
||||
};
|
||||
use activitystreams::collection::{OrderedCollection, OrderedCollectionPage};
|
||||
use diesel::SaveChangesDsl;
|
||||
use rocket::{
|
||||
http::ContentType,
|
||||
@@ -83,7 +80,7 @@ pub struct NewBlogForm {
|
||||
|
||||
fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
||||
let slug = Blog::slug(title);
|
||||
if slug.is_empty() || iri_reference::<IriSpec>(&slug).is_err() {
|
||||
if slug.is_empty() {
|
||||
Err(ValidationError::new("empty_slug"))
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -104,7 +101,7 @@ pub fn create(
|
||||
Ok(_) => ValidationErrors::new(),
|
||||
Err(e) => e,
|
||||
};
|
||||
if Blog::find_by_fqn(&conn, &slug).is_ok() {
|
||||
if Blog::find_by_fqn(&conn, slug).is_ok() {
|
||||
errors.add(
|
||||
"title",
|
||||
ValidationError {
|
||||
@@ -125,7 +122,7 @@ pub fn create(
|
||||
let blog = Blog::insert(
|
||||
&conn,
|
||||
NewBlog::new_local(
|
||||
slug.clone(),
|
||||
slug.into(),
|
||||
form.title.to_string(),
|
||||
String::from(""),
|
||||
Instance::get_local()
|
||||
@@ -147,7 +144,7 @@ pub fn create(
|
||||
.expect("blog::create: author error");
|
||||
|
||||
Flash::success(
|
||||
Redirect::to(uri!(details: name = &slug, page = _)),
|
||||
Redirect::to(uri!(details: name = slug, page = _)),
|
||||
&i18n!(intl, "Your blog was successfully created!"),
|
||||
)
|
||||
.into()
|
||||
@@ -382,8 +379,6 @@ pub fn atom_feed(name: String, conn: DbConn) -> Option<Content<String>> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::env::var;
|
||||
|
||||
use super::valid_slug;
|
||||
use crate::init_rocket;
|
||||
use diesel::Connection;
|
||||
@@ -392,107 +387,62 @@ mod tests {
|
||||
blog_authors::{BlogAuthor, NewBlogAuthor},
|
||||
blogs::{Blog, NewBlog},
|
||||
db_conn::{DbConn, DbPool},
|
||||
get_rocket_config,
|
||||
instance::{Instance, NewInstance},
|
||||
post_authors::{NewPostAuthor, PostAuthor},
|
||||
posts::{NewPost, Post},
|
||||
safe_string::SafeString,
|
||||
search::Searcher,
|
||||
users::{NewUser, User, AUTH_COOKIE},
|
||||
Config, Fqn, SearchTokenizerConfig,
|
||||
Connection as Conn, CONFIG,
|
||||
};
|
||||
use rocket::{
|
||||
http::{ContentType, Cookie, Cookies, SameSite, Status},
|
||||
http::{Cookie, Cookies, SameSite},
|
||||
local::{Client, LocalRequest},
|
||||
};
|
||||
|
||||
type Models = (Instance, User, Blog, Post);
|
||||
|
||||
fn setup() -> (Client, Models) {
|
||||
dotenv::from_path(".env.test").unwrap();
|
||||
let config = Config {
|
||||
base_url: var("BASE_URL").unwrap(),
|
||||
db_name: "plume",
|
||||
db_max_size: None,
|
||||
db_min_idle: None,
|
||||
signup: Default::default(),
|
||||
database_url: var("DATABASE_URL").unwrap(),
|
||||
search_index: format!("/tmp/plume_test-{}", random_hex()),
|
||||
search_tokenizers: SearchTokenizerConfig::init(),
|
||||
rocket: get_rocket_config(),
|
||||
logo: Default::default(),
|
||||
default_theme: Default::default(),
|
||||
media_directory: format!("/tmp/plume_test-{}", random_hex()),
|
||||
mail: None,
|
||||
ldap: None,
|
||||
proxy: None,
|
||||
};
|
||||
let _ = Searcher::create(&config.search_index, &config.search_tokenizers).unwrap();
|
||||
let rocket = init_rocket(&config);
|
||||
#[test]
|
||||
fn edit_link_within_post_card() {
|
||||
let conn = Conn::establish(CONFIG.database_url.as_str()).unwrap();
|
||||
Instance::insert(
|
||||
&conn,
|
||||
NewInstance {
|
||||
public_domain: "example.org".to_string(),
|
||||
name: "Plume".to_string(),
|
||||
local: true,
|
||||
long_description: SafeString::new(""),
|
||||
short_description: SafeString::new(""),
|
||||
default_license: "CC-BY-SA".to_string(),
|
||||
open_registrations: true,
|
||||
short_description_html: String::new(),
|
||||
long_description_html: String::new(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let rocket = init_rocket();
|
||||
let client = Client::new(rocket).expect("valid rocket instance");
|
||||
let dbpool = client.rocket().state::<DbPool>().unwrap();
|
||||
let conn = &DbConn(dbpool.get().unwrap());
|
||||
|
||||
(client, create_models(conn))
|
||||
}
|
||||
let (_instance, user, blog, post) = create_models(conn);
|
||||
|
||||
fn teardown((client, (instance, user, _blog, _post)): (&Client, Models)) {
|
||||
let rocket = client.rocket();
|
||||
|
||||
let dbpool = rocket.state::<DbPool>().unwrap();
|
||||
let conn = &DbConn(dbpool.get().unwrap());
|
||||
|
||||
user.delete(conn).unwrap();
|
||||
let _ = diesel::delete(&instance);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_link_within_post_card() {
|
||||
let (client, (instance, user, blog, post)) = setup();
|
||||
|
||||
let blog_path = uri!(super::activity_details: name = &blog.fqn.to_string()).to_string();
|
||||
let blog_path = uri!(super::activity_details: name = &blog.fqn).to_string();
|
||||
let edit_link = uri!(
|
||||
super::super::posts::edit: blog = &blog.fqn.to_string(),
|
||||
super::super::posts::edit: blog = &blog.fqn,
|
||||
slug = &post.slug
|
||||
)
|
||||
.to_string();
|
||||
|
||||
let mut response = client.get(&blog_path).dispatch();
|
||||
let body = response.body_string().unwrap();
|
||||
let body_not_contain_edit_link = !body.contains(&edit_link);
|
||||
assert!(!body.contains(&edit_link));
|
||||
|
||||
let request = client.get(&blog_path);
|
||||
login(&request, &user);
|
||||
let mut response = request.dispatch();
|
||||
let body = response.body_string().unwrap();
|
||||
eprintln!("{:?}", &blog.fqn);
|
||||
let body_contains_edit_lnk = body.contains(&edit_link);
|
||||
|
||||
teardown((&client, (instance, user, blog, post)));
|
||||
|
||||
assert!(body_not_contain_edit_link);
|
||||
assert!(body_contains_edit_lnk);
|
||||
assert!(body.contains(&edit_link));
|
||||
}
|
||||
|
||||
fn create_models(conn: &DbConn) -> Models {
|
||||
Instance::find_by_domain(conn, "example.org").unwrap_or_else(|_| {
|
||||
Instance::insert(
|
||||
conn,
|
||||
NewInstance {
|
||||
public_domain: "example.org".to_string(),
|
||||
name: "Plume".to_string(),
|
||||
local: true,
|
||||
long_description: SafeString::new(""),
|
||||
short_description: SafeString::new(""),
|
||||
default_license: "CC-BY-SA".to_string(),
|
||||
open_registrations: true,
|
||||
short_description_html: String::new(),
|
||||
long_description_html: String::new(),
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
fn create_models(conn: &DbConn) -> (Instance, User, Blog, Post) {
|
||||
conn.transaction::<(Instance, User, Blog, Post), diesel::result::Error, _>(|| {
|
||||
let instance = Instance::get_local().unwrap_or_else(|_| {
|
||||
let instance = Instance::insert(
|
||||
@@ -520,26 +470,16 @@ mod tests {
|
||||
inbox_url: random_hex(),
|
||||
outbox_url: random_hex(),
|
||||
followers_endpoint: random_hex(),
|
||||
fqn: random_hex(),
|
||||
..Default::default()
|
||||
};
|
||||
let user = User::insert(conn, user).unwrap();
|
||||
let title = random_hex();
|
||||
let blog = NewBlog {
|
||||
instance_id: instance.id,
|
||||
fqn: Fqn::make_local(&title).unwrap(),
|
||||
title,
|
||||
actor_id: random_hex(),
|
||||
ap_url: random_hex(),
|
||||
inbox_url: random_hex(),
|
||||
outbox_url: random_hex(),
|
||||
summary: Default::default(),
|
||||
summary_html: Default::default(),
|
||||
public_key: Default::default(),
|
||||
private_key: Default::default(),
|
||||
icon_id: Default::default(),
|
||||
banner_id: Default::default(),
|
||||
theme: Default::default(),
|
||||
..Default::default()
|
||||
};
|
||||
let blog = Blog::insert(conn, blog).unwrap();
|
||||
BlogAuthor::insert(
|
||||
@@ -595,38 +535,4 @@ mod tests {
|
||||
assert!(valid_slug("Blog Title").is_ok());
|
||||
assert!(valid_slug("ブログ タイトル").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_blog_with_same_title_twice() {
|
||||
let (client, (instance, user, blog, post)) = setup();
|
||||
|
||||
let new_path = uri!(super::new).to_string();
|
||||
let request = client.get(new_path);
|
||||
login(&request, &user);
|
||||
let mut response = request.dispatch();
|
||||
let body = response.body_string().unwrap();
|
||||
let prefix = r#"<input type="hidden" name="csrf-token" value=""#;
|
||||
let pos = body.find(prefix).unwrap();
|
||||
let token = body[pos + prefix.len()..pos + prefix.len() + 123].to_string();
|
||||
|
||||
let create_path = uri!(super::create).to_string();
|
||||
let response = client
|
||||
.post(&create_path)
|
||||
.body(format!("title=My%20Blog&csrf-token={}", &token))
|
||||
.header(ContentType::Form)
|
||||
.dispatch();
|
||||
let first_attempt = response;
|
||||
|
||||
let response = client
|
||||
.post(&create_path)
|
||||
.body(format!("title=My%20Blog&csrf-token={}", &token))
|
||||
.header(ContentType::Form)
|
||||
.dispatch();
|
||||
let second_attempt = response;
|
||||
|
||||
teardown((&client, (instance, user, blog, post)));
|
||||
|
||||
assert_eq!(first_attempt.status(), Status::SeeOther);
|
||||
assert_eq!(second_attempt.status(), Status::SeeOther);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-3
@@ -160,7 +160,7 @@ pub fn toggle_block(
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/admin/users?<page>")]
|
||||
#[get("/admin/users?<page>", rank = 2)]
|
||||
pub fn admin_users(
|
||||
_mod: Moderator,
|
||||
page: Option<Page>,
|
||||
@@ -171,6 +171,30 @@ pub fn admin_users(
|
||||
Ok(render!(instance::users(
|
||||
&(&conn, &rockets).to_context(),
|
||||
User::get_local_page(&conn, page.limits())?,
|
||||
None,
|
||||
page.0,
|
||||
Page::total(User::count_local(&conn)? as i32)
|
||||
)))
|
||||
}
|
||||
#[get("/admin/users?<user>&<page>", rank = 1)]
|
||||
pub fn admin_search_users(
|
||||
_mod: Moderator,
|
||||
user: String,
|
||||
page: Option<Page>,
|
||||
conn: DbConn,
|
||||
rockets: PlumeRocket,
|
||||
) -> Result<Ructe, ErrorPage> {
|
||||
let page = page.unwrap_or_default();
|
||||
let users = if user.is_empty() {
|
||||
User::get_local_page(&conn, page.limits())?
|
||||
} else {
|
||||
User::search_local_by_name(&conn, &user, page.limits())?
|
||||
};
|
||||
|
||||
Ok(render!(instance::users(
|
||||
&(&conn, &rockets).to_context(),
|
||||
users,
|
||||
Some(user.as_str()),
|
||||
page.0,
|
||||
Page::total(User::count_local(&conn)? as i32)
|
||||
)))
|
||||
@@ -407,7 +431,7 @@ pub fn interact(conn: DbConn, user: Option<User>, target: String) -> Option<Redi
|
||||
|
||||
if let Ok(post) = Post::from_id(&conn, &target, None, CONFIG.proxy()) {
|
||||
return Some(Redirect::to(uri!(
|
||||
super::posts::details: blog = post.get_blog(&conn).expect("Can't retrieve blog").fqn.to_string(),
|
||||
super::posts::details: blog = post.get_blog(&conn).expect("Can't retrieve blog").fqn,
|
||||
slug = &post.slug,
|
||||
responding_to = _
|
||||
)));
|
||||
@@ -418,7 +442,7 @@ pub fn interact(conn: DbConn, user: Option<User>, target: String) -> Option<Redi
|
||||
let post = comment.get_post(&conn).expect("Can't retrieve post");
|
||||
return Some(Redirect::to(uri!(
|
||||
super::posts::details: blog =
|
||||
post.get_blog(&conn).expect("Can't retrieve blog").fqn.to_string(),
|
||||
post.get_blog(&conn).expect("Can't retrieve blog").fqn,
|
||||
slug = &post.slug,
|
||||
responding_to = comment.id
|
||||
)));
|
||||
|
||||
+30
-7
@@ -9,7 +9,7 @@ use rocket::{
|
||||
http::{
|
||||
hyper::header::{CacheControl, CacheDirective, ETag, EntityTag},
|
||||
uri::{FromUriParam, Query},
|
||||
RawStr, Status,
|
||||
ContentType, RawStr, Status,
|
||||
},
|
||||
request::{self, FromFormValue, FromRequest, Request},
|
||||
response::{self, Flash, NamedFile, Redirect, Responder, Response},
|
||||
@@ -204,10 +204,16 @@ pub mod timelines;
|
||||
pub mod user;
|
||||
pub mod well_known;
|
||||
|
||||
#[derive(Responder)]
|
||||
enum FileKind {
|
||||
Local(NamedFile),
|
||||
S3(Vec<u8>, ContentType),
|
||||
}
|
||||
|
||||
#[derive(Responder)]
|
||||
#[response()]
|
||||
pub struct CachedFile {
|
||||
inner: NamedFile,
|
||||
inner: FileKind,
|
||||
cache_control: CacheControl,
|
||||
}
|
||||
|
||||
@@ -253,19 +259,36 @@ pub fn plume_static_files(file: PathBuf, build_id: &RawStr) -> Option<CachedFile
|
||||
}
|
||||
#[get("/static/media/<file..>")]
|
||||
pub fn plume_media_files(file: PathBuf) -> Option<CachedFile> {
|
||||
NamedFile::open(Path::new(&CONFIG.media_directory).join(file))
|
||||
.ok()
|
||||
.map(|f| CachedFile {
|
||||
inner: f,
|
||||
if let Some(config) = &CONFIG.s3 {
|
||||
let ct = file.extension()
|
||||
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy()))
|
||||
.unwrap_or(ContentType::Binary);
|
||||
|
||||
let (data, code) = config.get_bucket()
|
||||
.get_object_blocking(format!("plume-media/{}", file.to_string_lossy())).ok()?;
|
||||
if code != 200 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(CachedFile {
|
||||
inner: FileKind::S3 ( data, ct),
|
||||
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),
|
||||
})
|
||||
} else {
|
||||
NamedFile::open(Path::new(&CONFIG.media_directory).join(file))
|
||||
.ok()
|
||||
.map(|f| CachedFile {
|
||||
inner: FileKind::Local(f),
|
||||
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),
|
||||
})
|
||||
}
|
||||
}
|
||||
#[get("/static/<file..>", rank = 3)]
|
||||
pub fn static_files(file: PathBuf) -> Option<CachedFile> {
|
||||
NamedFile::open(Path::new("static/").join(file))
|
||||
.ok()
|
||||
.map(|f| CachedFile {
|
||||
inner: f,
|
||||
inner: FileKind::Local(f),
|
||||
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<meta content="@blog.summary_html" property="og:description" />
|
||||
<meta content="@blog.icon_url(ctx.0)" property="og:image" />
|
||||
|
||||
<link href='@Instance::get_local().unwrap().compute_box("~", &blog.fqn.to_string(), "atom.xml")' rel='alternate' type='application/atom+xml'>
|
||||
<link href='@Instance::get_local().unwrap().compute_box("~", &blog.fqn, "atom.xml")' rel='alternate' type='application/atom+xml'>
|
||||
<link href='@blog.ap_url' rel='alternate' type='application/activity+json'>
|
||||
<link href='@blog.ap_url' rel='canonical'>
|
||||
@if !ctx.2.clone().map(|u| u.hide_custom_css).unwrap_or(false) {
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
}
|
||||
}, {
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn.to_string(), page = _)" dir="auto">@blog.title</a>
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn, page = _)" dir="auto">@blog.title</a>
|
||||
}, {
|
||||
<div class="hidden">
|
||||
@for author in authors {
|
||||
@@ -58,8 +58,8 @@
|
||||
</h1>
|
||||
|
||||
@if ctx.2.clone().and_then(|u| u.is_author_in(ctx.0, &blog).ok()).unwrap_or(false) {
|
||||
<a href="@uri!(posts::new: blog = &blog.fqn.to_string())" class="button" dir="auto">@i18n!(ctx.1, "New article")</a>
|
||||
<a href="@uri!(blogs::edit: name = &blog.fqn.to_string())" class="button" dir="auto">@i18n!(ctx.1, "Edit")</a>
|
||||
<a href="@uri!(posts::new: blog = &blog.fqn)" class="button" dir="auto">@i18n!(ctx.1, "New article")</a>
|
||||
<a href="@uri!(blogs::edit: name = &blog.fqn)" class="button" dir="auto">@i18n!(ctx.1, "Edit")</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<section>
|
||||
<h2 dir="auto">
|
||||
@i18n!(ctx.1, "Latest articles")
|
||||
<small><a href="@uri!(blogs::atom_feed: name = &blog.fqn.to_string())" title="Atom feed">@icon!("rss")</a></small>
|
||||
<small><a href="@uri!(blogs::atom_feed: name = &blog.fqn)" title="Atom feed">@icon!("rss")</a></small>
|
||||
</h2>
|
||||
@if posts.is_empty() {
|
||||
<p dir="auto">@i18n!(ctx.1, "No posts to see here yet.")</p>
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
@(ctx: BaseContext, blog: &Blog, medias: Vec<Media>, form: &EditForm, errors: ValidationErrors)
|
||||
|
||||
@:base(ctx, i18n!(ctx.1, "Edit \"{}\""; &blog.title), {}, {
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn.to_string(), page = _)">@blog.title</a>
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn, page = _)">@blog.title</a>
|
||||
}, {
|
||||
<h1>@i18n!(ctx.1, "Edit \"{}\""; &blog.title)</h1>
|
||||
<form method="post" action="@uri!(blogs::update: name = &blog.fqn.to_string())">
|
||||
<form method="post" action="@uri!(blogs::update: name = &blog.fqn)">
|
||||
<!-- Rocket hack to use various HTTP methods -->
|
||||
<input type=hidden name="_method" value="put">
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
<h2>@i18n!(ctx.1, "Danger zone")</h2>
|
||||
<p>@i18n!(ctx.1, "Be very careful, any action taken here can't be reversed.")</p>
|
||||
<form method="post" action="@uri!(blogs::delete: name = &blog.fqn.to_string())" onsubmit="return confirm('@i18n!(ctx.1, "Are you sure that you want to permanently delete this blog?")')">
|
||||
<form method="post" action="@uri!(blogs::delete: name = &blog.fqn)" onsubmit="return confirm('@i18n!(ctx.1, "Are you sure that you want to permanently delete this blog?")')">
|
||||
<input type="submit" class="inline-block button destructive" value="@i18n!(ctx.1, "Permanently delete this blog")">
|
||||
</form>
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@use crate::template_utils::*;
|
||||
@use crate::routes::*;
|
||||
|
||||
@(ctx: BaseContext, users: Vec<User>, page: i32, n_pages: i32)
|
||||
@(ctx: BaseContext, users: Vec<User>, user: Option<&str>, page: i32, n_pages: i32)
|
||||
|
||||
@:base(ctx, i18n!(ctx.1, "Users"), {}, {}, {
|
||||
<h1>@i18n!(ctx.1, "Users")</h1>
|
||||
@@ -15,6 +15,13 @@
|
||||
(&uri!(instance::admin_email_blocklist: page=_).to_string(), i18n!(ctx.1, "Email blocklist"), false)
|
||||
])
|
||||
|
||||
<form method="get" action="@uri!(instance::admin_search_users: page = _, user = user.unwrap_or_default())">
|
||||
<header>
|
||||
<input type="search" name="user" value="@user.unwrap_or_default()">
|
||||
<input type="submit" value="@i18n!(ctx.1, "Search users")">
|
||||
</header>
|
||||
</form>
|
||||
|
||||
<form method="post" action="@uri!(instance::edit_users)">
|
||||
<header>
|
||||
<select name="action">
|
||||
@@ -46,5 +53,9 @@
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
@paginate(ctx.1, page, n_pages)
|
||||
@if user.is_some() {
|
||||
@paginate_param(ctx.1, page, n_pages, Some(format!("user={}", encode_query_param(user.unwrap_or_default()))))
|
||||
} else {
|
||||
@paginate(ctx.1, page, n_pages)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
|
||||
<div class="card h-entry">
|
||||
@if article.cover_id.is_some() {
|
||||
<a class="cover-link" href="@uri!(posts::details: blog = article.get_blog_fqn(ctx.0).to_string(), slug = &article.slug, responding_to = _)">
|
||||
<a class="cover-link" href="@uri!(posts::details: blog = article.get_blog_fqn(ctx.0), slug = &article.slug, responding_to = _)">
|
||||
<div class="cover" style="background-image: url('@Html(article.cover_url(ctx.0).unwrap_or_default())')"></div>
|
||||
</a>
|
||||
}
|
||||
<header dir="auto">
|
||||
<h3 class="p-name">
|
||||
<a class="u-url" href="@uri!(posts::details: blog = article.get_blog_fqn(ctx.0).to_string(), slug = &article.slug, responding_to = _)">
|
||||
<a class="u-url" href="@uri!(posts::details: blog = article.get_blog_fqn(ctx.0), slug = &article.slug, responding_to = _)">
|
||||
@article.title
|
||||
</a>
|
||||
</h3>
|
||||
@if ctx.2.clone().and_then(|u| article.is_author(ctx.0, u.id).ok()).unwrap_or(false) {
|
||||
<div class="controls">
|
||||
<a class="button" href="@uri!(posts::edit: blog = &article.get_blog_fqn(ctx.0).to_string(), slug = &article.slug)">@i18n!(ctx.1, "Edit")</a>
|
||||
<a class="button" href="@uri!(posts::edit: blog = &article.get_blog_fqn(ctx.0), slug = &article.slug)">@i18n!(ctx.1, "Edit")</a>
|
||||
</div>
|
||||
}
|
||||
</header>
|
||||
@@ -35,7 +35,7 @@
|
||||
@if article.published {
|
||||
⋅ <span class="dt-published" datetime="@article.creation_date.format("%F %T")">@article.creation_date.format("%B %e, %Y")</span>
|
||||
}
|
||||
⋅ <a href="@uri!(blogs::details: name = &article.get_blog_fqn(ctx.0).to_string(), page = _)">@article.get_blog(ctx.0).unwrap().title</a>
|
||||
⋅ <a href="@uri!(blogs::details: name = &article.get_blog_fqn(ctx.0), page = _)">@article.get_blog(ctx.0).unwrap().title</a>
|
||||
⋅
|
||||
</div>
|
||||
@if !article.published {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
@if article.cover_id.is_some() {
|
||||
<meta property="og:image" content="@Html(article.cover_url(ctx.0).unwrap_or_default())"/>
|
||||
}
|
||||
<meta property="og:url" content="@uri!(posts::details: blog = &blog.fqn.to_string(), slug = &article.slug, responding_to = _)"/>
|
||||
<meta property="og:url" content="@uri!(posts::details: blog = &blog.fqn, slug = &article.slug, responding_to = _)"/>
|
||||
<meta property="og:description" content="@article.subtitle"/>
|
||||
<link rel="canonical" href="@article.ap_url"/>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
}
|
||||
}
|
||||
}, {
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn.to_string(), page = _)">@blog.title</a>
|
||||
<a href="@uri!(blogs::details: name = &blog.fqn, page = _)">@blog.title</a>
|
||||
}, {
|
||||
<div class="h-entry">
|
||||
<header
|
||||
@@ -78,7 +78,7 @@
|
||||
</section>
|
||||
@if ctx.2.is_some() {
|
||||
<section class="actions">
|
||||
<form id="likes" class="likes" action="@uri!(likes::create: blog = &blog.fqn.to_string(), slug = &article.slug)#likes" method="POST">
|
||||
<form id="likes" class="likes" action="@uri!(likes::create: blog = &blog.fqn, slug = &article.slug)#likes" method="POST">
|
||||
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)">
|
||||
@n_likes
|
||||
</p>
|
||||
@@ -89,7 +89,7 @@
|
||||
<button type="submit" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</button>
|
||||
}
|
||||
</form>
|
||||
<form id="reshares" class="reshares" action="@uri!(reshares::create: blog = &blog.fqn.to_string(), slug = &article.slug)#reshares" method="POST">
|
||||
<form id="reshares" class="reshares" action="@uri!(reshares::create: blog = &blog.fqn, slug = &article.slug)#reshares" method="POST">
|
||||
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boosts"; n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts"; n_reshares)">
|
||||
@n_reshares
|
||||
</p>
|
||||
@@ -104,7 +104,7 @@
|
||||
} else {
|
||||
<p class="center">@Html(i18n!(ctx.1, "{0}Log in{1}, or {2}use your Fediverse account{3} to interact with this article";
|
||||
format!("<a href='{}'>", escape(&uri!(session::new: m = _).to_string())), "</a>",
|
||||
format!("<a href='{}'>", escape(&uri!(posts::remote_interact: blog_name = &blog.fqn.to_string(), slug = &article.slug).to_string())), "</a>"
|
||||
format!("<a href='{}'>", escape(&uri!(posts::remote_interact: blog_name = &blog.fqn, slug = &article.slug).to_string())), "</a>"
|
||||
))
|
||||
</p>
|
||||
<section class="actions">
|
||||
@@ -112,14 +112,14 @@
|
||||
<p aria-label="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)" title="@i18n!(ctx.1, "One like", "{0} likes"; n_likes)">
|
||||
@n_likes
|
||||
</p>
|
||||
<a href="@uri!(posts::remote_interact: blog_name = &blog.fqn.to_string(), slug = &article.slug)" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</a>
|
||||
<a href="@uri!(posts::remote_interact: blog_name = &blog.fqn, slug = &article.slug)" class="action">@icon!("heart") @i18n!(ctx.1, "Add yours")</a>
|
||||
</div>
|
||||
|
||||
<div id="reshares" class="reshares">
|
||||
<p aria-label="@i18n!(ctx.1, "One boost", "{0} boost"; n_reshares)" title="@i18n!(ctx.1, "One boost", "{0} boosts"; n_reshares)">
|
||||
@n_reshares
|
||||
</p>
|
||||
<a href="@uri!(posts::remote_interact: blog_name = &blog.fqn.to_string(), slug = &article.slug)" class="action">@icon!("repeat") @i18n!(ctx.1, "Boost")</a>
|
||||
<a href="@uri!(posts::remote_interact: blog_name = &blog.fqn, slug = &article.slug)" class="action">@icon!("repeat") @i18n!(ctx.1, "Boost")</a>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
@@ -144,7 +144,7 @@
|
||||
<h2>@i18n!(ctx.1, "Comments")</h2>
|
||||
|
||||
@if ctx.2.is_some() {
|
||||
<form method="post" action="@uri!(comments::create: blog_name = &blog.fqn.to_string(), slug = &article.slug)#comments">
|
||||
<form method="post" action="@uri!(comments::create: blog_name = &blog.fqn, slug = &article.slug)#comments">
|
||||
@(Input::new("warning", i18n!(ctx.1, "Content warning"))
|
||||
.default(&comment_form.warning)
|
||||
.error(&comment_errors)
|
||||
@@ -162,7 +162,7 @@
|
||||
|
||||
@if !comments.is_empty() {
|
||||
@for comm in comments {
|
||||
@:comment(ctx, &comm, Some(&article.ap_url), &blog.fqn.to_string(), &article.slug)
|
||||
@:comment(ctx, &comm, Some(&article.ap_url), &blog.fqn, &article.slug)
|
||||
}
|
||||
} else {
|
||||
<p class="center" dir="auto">@i18n!(ctx.1, "No comments yet. Be the first to react!")</p>
|
||||
@@ -173,7 +173,7 @@
|
||||
@if ctx.2.clone().and_then(|u| article.is_author(ctx.0, u.id).ok()).unwrap_or(false) {
|
||||
<aside class="bottom-bar">
|
||||
<div>
|
||||
<form class="inline" method="post" action="@uri!(posts::delete: blog_name = &blog.fqn.to_string(), slug = &article.slug)">
|
||||
<form class="inline" method="post" action="@uri!(posts::delete: blog_name = &blog.fqn, slug = &article.slug)">
|
||||
<input class="button destructive" onclick="return confirm('@i18n!(ctx.1, "Are you sure?")')" type="submit" value="@i18n!(ctx.1, "Delete")">
|
||||
</form>
|
||||
</div>
|
||||
@@ -186,9 +186,9 @@
|
||||
</div>
|
||||
<div>
|
||||
@if !article.published {
|
||||
<a class="button secondary" href="@uri!(posts::edit: blog = &blog.fqn.to_string(), slug = &article.slug)">@i18n!(ctx.1, "Publish")</a>
|
||||
<a class="button secondary" href="@uri!(posts::edit: blog = &blog.fqn, slug = &article.slug)">@i18n!(ctx.1, "Publish")</a>
|
||||
}
|
||||
<a class="button" href="@uri!(posts::edit: blog = &blog.fqn.to_string(), slug = &article.slug)">@i18n!(ctx.1, "Edit")</a>
|
||||
<a class="button" href="@uri!(posts::edit: blog = &blog.fqn, slug = &article.slug)">@i18n!(ctx.1, "Edit")</a>
|
||||
</div>
|
||||
</aside>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user