A first attempt at using deser-hjson. Fixes #1270

This commit is contained in:
Dessalines 2021-02-16 19:52:56 -05:00
parent 37ea778776
commit f19c7a2e72
26 changed files with 285 additions and 220 deletions

View file

@ -1,5 +1,5 @@
tab_spaces = 2 tab_spaces = 2
edition="2018" edition="2018"
imports_layout="HorizontalVertical" imports_layout="HorizontalVertical"
merge_imports=true imports_granularity="Crate"
reorder_imports=true reorder_imports=true

233
Cargo.lock generated
View file

@ -8,7 +8,7 @@ checksum = "fe7ceed015dfca322d3bcec3653909c77557e7e57df72e98cb8806e2c93cc919"
dependencies = [ dependencies = [
"chrono", "chrono",
"mime", "mime",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"url", "url",
@ -21,7 +21,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb8e19a0810cc25df3535061a08b7d8f8a734d309ea4411c57a9767e4a2ffa0e" checksum = "bb8e19a0810cc25df3535061a08b7d8f8a734d309ea4411c57a9767e4a2ffa0e"
dependencies = [ dependencies = [
"activitystreams", "activitystreams",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
] ]
@ -128,7 +128,7 @@ dependencies = [
"pin-project 1.0.4", "pin-project 1.0.4",
"rand 0.7.3", "rand 0.7.3",
"regex", "regex",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"sha-1 0.9.3", "sha-1 0.9.3",
@ -156,7 +156,7 @@ dependencies = [
"http", "http",
"log", "log",
"regex", "regex",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -300,7 +300,7 @@ dependencies = [
"pin-project 1.0.4", "pin-project 1.0.4",
"regex", "regex",
"rustls", "rustls",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"socket2", "socket2",
@ -389,12 +389,6 @@ version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "async-mutex" name = "async-mutex"
version = "1.4.0" version = "1.4.0"
@ -464,7 +458,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"rand 0.7.3", "rand 0.7.3",
"rustls", "rustls",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
] ]
@ -494,7 +488,7 @@ dependencies = [
"log", "log",
"num_cpus", "num_cpus",
"rand 0.7.3", "rand 0.7.3",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio 0.2.25", "tokio 0.2.25",
@ -513,7 +507,7 @@ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
"log", "log",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio 0.2.25", "tokio 0.2.25",
@ -733,8 +727,8 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [ dependencies = [
"libc", "libc",
"num-integer", "num-integer",
"num-traits 0.2.14", "num-traits",
"serde 1.0.123", "serde",
"time 0.1.44", "time 0.1.44",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -781,18 +775,6 @@ dependencies = [
"xdg", "xdg",
] ]
[[package]]
name = "config"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3"
dependencies = [
"lazy_static",
"nom 5.1.2",
"serde 1.0.123",
"serde-hjson",
]
[[package]] [[package]]
name = "const_fn" name = "const_fn"
version = "0.4.5" version = "0.4.5"
@ -995,6 +977,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "deser-hjson"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d995b60ff81bc6af01a98f0bf5db70a7418a1ac8bd74ada633968f388139da5e"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "diesel" name = "diesel"
version = "1.4.5" version = "1.4.5"
@ -1590,7 +1581,7 @@ dependencies = [
"jpeg-decoder", "jpeg-decoder",
"num-iter", "num-iter",
"num-rational", "num-rational",
"num-traits 0.2.14", "num-traits",
"png", "png",
"scoped_threadpool", "scoped_threadpool",
"tiff", "tiff",
@ -1684,7 +1675,7 @@ dependencies = [
"base64 0.12.3", "base64 0.12.3",
"pem", "pem",
"ring", "ring",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"simple_asn1", "simple_asn1",
] ]
@ -1745,7 +1736,7 @@ dependencies = [
"openssl", "openssl",
"rand 0.8.3", "rand 0.8.3",
"reqwest", "reqwest",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"sha2", "sha2",
"strum", "strum",
@ -1792,7 +1783,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"rand 0.8.3", "rand 0.8.3",
"reqwest", "reqwest",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"sha2", "sha2",
"strum", "strum",
@ -1816,7 +1807,7 @@ dependencies = [
"lemmy_utils", "lemmy_utils",
"log", "log",
"regex", "regex",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"sha2", "sha2",
"strum", "strum",
@ -1831,7 +1822,7 @@ dependencies = [
"chrono", "chrono",
"diesel", "diesel",
"log", "log",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"url", "url",
] ]
@ -1844,7 +1835,7 @@ dependencies = [
"lemmy_db_queries", "lemmy_db_queries",
"lemmy_db_schema", "lemmy_db_schema",
"log", "log",
"serde 1.0.123", "serde",
"url", "url",
] ]
@ -1855,7 +1846,7 @@ dependencies = [
"diesel", "diesel",
"lemmy_db_queries", "lemmy_db_queries",
"lemmy_db_schema", "lemmy_db_schema",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -1865,7 +1856,7 @@ dependencies = [
"diesel", "diesel",
"lemmy_db_queries", "lemmy_db_queries",
"lemmy_db_schema", "lemmy_db_schema",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -1889,7 +1880,7 @@ dependencies = [
"lemmy_websocket", "lemmy_websocket",
"log", "log",
"rss", "rss",
"serde 1.0.123", "serde",
"sha2", "sha2",
"strum", "strum",
"url", "url",
@ -1925,7 +1916,7 @@ dependencies = [
"log", "log",
"openssl", "openssl",
"reqwest", "reqwest",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"strum", "strum",
"tokio 0.3.7", "tokio 0.3.7",
@ -1946,7 +1937,7 @@ dependencies = [
"lemmy_db_views_moderator", "lemmy_db_views_moderator",
"lemmy_utils", "lemmy_utils",
"log", "log",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"url", "url",
] ]
@ -1960,7 +1951,7 @@ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
"comrak", "comrak",
"config", "deser-hjson",
"diesel", "diesel",
"futures", "futures",
"http", "http",
@ -1969,12 +1960,13 @@ dependencies = [
"lazy_static", "lazy_static",
"lettre", "lettre",
"log", "log",
"merge",
"openssl", "openssl",
"percent-encoding", "percent-encoding",
"rand 0.8.3", "rand 0.8.3",
"regex", "regex",
"reqwest", "reqwest",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"strum", "strum",
"strum_macros", "strum_macros",
@ -2001,7 +1993,7 @@ dependencies = [
"log", "log",
"rand 0.8.3", "rand 0.8.3",
"reqwest", "reqwest",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"strum", "strum",
"strum_macros", "strum_macros",
@ -2020,46 +2012,23 @@ dependencies = [
"idna", "idna",
"mime", "mime",
"native-tls", "native-tls",
"nom 6.1.0", "nom",
"once_cell", "once_cell",
"quoted_printable", "quoted_printable",
"r2d2", "r2d2",
"rand 0.8.3", "rand 0.8.3",
"regex", "regex",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"uuid", "uuid",
] ]
[[package]]
name = "lexical-core"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if 0.1.10",
"ryu",
"static_assertions",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.84" version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
[[package]]
name = "linked-hash-map"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd"
dependencies = [
"serde 0.8.23",
"serde_test",
]
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
version = "0.5.4" version = "0.5.4"
@ -2102,7 +2071,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
dependencies = [ dependencies = [
"linked-hash-map 0.5.4", "linked-hash-map",
] ]
[[package]] [[package]]
@ -2144,6 +2113,28 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "merge"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10bbef93abb1da61525bbc45eeaff6473a41907d19f8f9aa5168d214e10693e9"
dependencies = [
"merge_derive",
"num-traits",
]
[[package]]
name = "merge_derive"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "209d075476da2e63b4b29e72a2ef627b840589588e71400a25e3565c4f849d07"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "migrations_internals" name = "migrations_internals"
version = "1.4.1" version = "1.4.1"
@ -2271,17 +2262,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"lexical-core",
"memchr",
"version_check",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "6.1.0" version = "6.1.0"
@ -2301,7 +2281,7 @@ checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-integer", "num-integer",
"num-traits 0.2.14", "num-traits",
] ]
[[package]] [[package]]
@ -2311,7 +2291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-traits 0.2.14", "num-traits",
] ]
[[package]] [[package]]
@ -2322,7 +2302,7 @@ checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-integer", "num-integer",
"num-traits 0.2.14", "num-traits",
] ]
[[package]] [[package]]
@ -2333,16 +2313,7 @@ checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"num-integer", "num-integer",
"num-traits 0.2.14", "num-traits",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.14",
] ]
[[package]] [[package]]
@ -2597,6 +2568,30 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.19" version = "0.5.19"
@ -2838,7 +2833,7 @@ dependencies = [
"native-tls", "native-tls",
"percent-encoding", "percent-encoding",
"pin-project-lite 0.2.4", "pin-project-lite 0.2.4",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"tokio 0.2.25", "tokio 0.2.25",
@ -3008,12 +3003,6 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.123" version = "1.0.123"
@ -3023,19 +3012,6 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"linked-hash-map 0.3.0",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.123" version = "1.0.123"
@ -3056,16 +3032,7 @@ dependencies = [
"indexmap", "indexmap",
"itoa", "itoa",
"ryu", "ryu",
"serde 1.0.123", "serde",
]
[[package]]
name = "serde_test"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5"
dependencies = [
"serde 0.8.23",
] ]
[[package]] [[package]]
@ -3077,7 +3044,7 @@ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
"ryu", "ryu",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -3147,7 +3114,7 @@ checksum = "692ca13de57ce0613a363c8c2f1de925adebc81b04c923ac60c5488bb44abe4b"
dependencies = [ dependencies = [
"chrono", "chrono",
"num-bigint", "num-bigint",
"num-traits 0.2.14", "num-traits",
] ]
[[package]] [[package]]
@ -3188,12 +3155,6 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "stdweb" name = "stdweb"
version = "0.4.20" version = "0.4.20"
@ -3216,7 +3177,7 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde 1.0.123", "serde",
"serde_derive", "serde_derive",
"syn", "syn",
] ]
@ -3230,7 +3191,7 @@ dependencies = [
"base-x", "base-x",
"proc-macro2", "proc-macro2",
"quote", "quote",
"serde 1.0.123", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"sha1", "sha1",
@ -3666,7 +3627,7 @@ dependencies = [
"idna", "idna",
"matches", "matches",
"percent-encoding", "percent-encoding",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -3676,7 +3637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [ dependencies = [
"getrandom 0.2.2", "getrandom 0.2.2",
"serde 1.0.123", "serde",
] ]
[[package]] [[package]]
@ -3720,7 +3681,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"serde 1.0.123", "serde",
"serde_json", "serde_json",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]

View file

@ -184,7 +184,7 @@ pub(crate) fn check_optional_url(item: &Option<Option<String>>) -> Result<(), Le
pub(crate) async fn build_federated_instances( pub(crate) async fn build_federated_instances(
pool: &DbPool, pool: &DbPool,
) -> Result<Option<FederatedInstances>, LemmyError> { ) -> Result<Option<FederatedInstances>, LemmyError> {
if Settings::get().federation.enabled { if Settings::get().federation.unwrap_or_default().enabled {
let distinct_communities = blocking(pool, move |conn| { let distinct_communities = blocking(pool, move |conn| {
Community::distinct_federated_communities(conn) Community::distinct_federated_communities(conn)
}) })
@ -199,7 +199,9 @@ pub(crate) async fn build_federated_instances(
.collect::<Result<Vec<String>, LemmyError>>()?; .collect::<Result<Vec<String>, LemmyError>>()?;
linked.extend_from_slice(&allowed); linked.extend_from_slice(&allowed);
linked.retain(|a| !blocked.contains(a) && !a.eq("") && !a.eq(&Settings::get().hostname)); linked.retain(|a| {
!blocked.contains(a) && !a.eq("") && !a.eq(&Settings::get().hostname.unwrap_or_default())
});
// Sort and remove dupes // Sort and remove dupes
linked.sort_unstable(); linked.sort_unstable();

View file

@ -121,7 +121,7 @@ impl Perform for Login {
// Return the jwt // Return the jwt
Ok(LoginResponse { Ok(LoginResponse {
jwt: Claims::jwt(user.id, Settings::get().hostname)?, jwt: Claims::jwt(user.id, Settings::get().hostname.unwrap_or_default())?,
}) })
} }
} }
@ -161,7 +161,7 @@ impl Perform for Register {
.await??; .await??;
// If its not the admin, check the captcha // If its not the admin, check the captcha
if !no_admins && Settings::get().captcha.enabled { if !no_admins && Settings::get().captcha.unwrap_or_default().enabled {
let check = context let check = context
.chat_server() .chat_server()
.send(CheckCaptcha { .send(CheckCaptcha {
@ -303,7 +303,10 @@ impl Perform for Register {
// Return the jwt // Return the jwt
Ok(LoginResponse { Ok(LoginResponse {
jwt: Claims::jwt(inserted_user.id, Settings::get().hostname)?, jwt: Claims::jwt(
inserted_user.id,
Settings::get().hostname.unwrap_or_default(),
)?,
}) })
} }
} }
@ -317,7 +320,7 @@ impl Perform for GetCaptcha {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>, _websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> { ) -> Result<Self::Response, LemmyError> {
let captcha_settings = Settings::get().captcha; let captcha_settings = Settings::get().captcha.unwrap_or_default();
if !captcha_settings.enabled { if !captcha_settings.enabled {
return Ok(GetCaptchaResponse { ok: None }); return Ok(GetCaptchaResponse { ok: None });
@ -476,7 +479,10 @@ impl Perform for SaveUserSettings {
// Return the jwt // Return the jwt
Ok(LoginResponse { Ok(LoginResponse {
jwt: Claims::jwt(updated_user.id, Settings::get().hostname)?, jwt: Claims::jwt(
updated_user.id,
Settings::get().hostname.unwrap_or_default(),
)?,
}) })
} }
} }
@ -1012,7 +1018,10 @@ impl Perform for PasswordChange {
// Return the jwt // Return the jwt
Ok(LoginResponse { Ok(LoginResponse {
jwt: Claims::jwt(updated_user.id, Settings::get().hostname)?, jwt: Claims::jwt(
updated_user.id,
Settings::get().hostname.unwrap_or_default(),
)?,
}) })
} }
} }

View file

@ -88,7 +88,7 @@ where
.await? .await?
.iter() .iter()
.unique() .unique()
.filter(|inbox| inbox.host_str() != Some(&Settings::get().hostname)) .filter(|inbox| inbox.host_str() != Some(&Settings::get().hostname.unwrap_or_default()))
.filter(|inbox| check_is_apub_id_valid(inbox).is_ok()) .filter(|inbox| check_is_apub_id_valid(inbox).is_ok())
.map(|inbox| inbox.to_owned()) .map(|inbox| inbox.to_owned())
.collect(); .collect();
@ -215,7 +215,7 @@ where
Kind: Serialize, Kind: Serialize,
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static, <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
{ {
if !Settings::get().federation.enabled || inboxes.is_empty() { if !Settings::get().federation.unwrap_or_default().enabled || inboxes.is_empty() {
return Ok(()); return Ok(());
} }

View file

@ -167,7 +167,7 @@ where
let id = activity.id_unchecked().context(location_info!())?; let id = activity.id_unchecked().context(location_info!())?;
let activity_domain = id.domain().context(location_info!())?; let activity_domain = id.domain().context(location_info!())?;
if activity_domain == Settings::get().hostname { if activity_domain == Settings::get().hostname.unwrap_or_default() {
return Err( return Err(
anyhow!( anyhow!(
"Error: received activity which was sent by local instance: {:?}", "Error: received activity which was sent by local instance: {:?}",

View file

@ -64,7 +64,7 @@ fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> {
let domain = apub_id.domain().context(location_info!())?.to_string(); let domain = apub_id.domain().context(location_info!())?.to_string();
let local_instance = settings.get_hostname_without_port()?; let local_instance = settings.get_hostname_without_port()?;
if !settings.federation.enabled { if !settings.federation.unwrap_or_default().enabled {
return if domain == local_instance { return if domain == local_instance {
Ok(()) Ok(())
} else { } else {

View file

@ -189,7 +189,7 @@ where
let domain = object_id.domain().context(location_info!())?; let domain = object_id.domain().context(location_info!())?;
// if its a local object, return it directly from the database // if its a local object, return it directly from the database
if Settings::get().hostname == domain { if Settings::get().hostname.unwrap_or_default() == domain {
let object = blocking(context.pool(), move |conn| { let object = blocking(context.pool(), move |conn| {
To::read_from_apub_id(conn, &object_id.into()) To::read_from_apub_id(conn, &object_id.into())
}) })

View file

@ -99,7 +99,7 @@ impl FromApub for User_ {
) -> Result<User_, LemmyError> { ) -> Result<User_, LemmyError> {
let user_id = person.id_unchecked().context(location_info!())?.to_owned(); let user_id = person.id_unchecked().context(location_info!())?.to_owned();
let domain = user_id.domain().context(location_info!())?; let domain = user_id.domain().context(location_info!())?;
if domain == Settings::get().hostname { if domain == Settings::get().hostname.unwrap_or_default() {
let user = blocking(context.pool(), move |conn| { let user = blocking(context.pool(), move |conn| {
User_::read_from_apub_id(conn, &user_id.into()) User_::read_from_apub_id(conn, &user_id.into())
}) })

View file

@ -23,8 +23,11 @@ static APUB_JSON_CONTENT_TYPE_LONG: &str =
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""; "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
pub fn config(cfg: &mut web::ServiceConfig) { pub fn config(cfg: &mut web::ServiceConfig) {
if Settings::get().federation.enabled { if Settings::get().federation.unwrap_or_default().enabled {
println!("federation enabled, host is {}", Settings::get().hostname); println!(
"federation enabled, host is {}",
Settings::get().hostname.unwrap_or_default()
);
let digest_verifier = VerifyDigest::new(Sha256::new()); let digest_verifier = VerifyDigest::new(Sha256::new());
let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE)) let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))

View file

@ -163,7 +163,7 @@ fn get_feed_user(
) -> Result<ChannelBuilder, LemmyError> { ) -> Result<ChannelBuilder, LemmyError> {
let site_view = SiteView::read(&conn)?; let site_view = SiteView::read(&conn)?;
let user = User_::find_by_username(&conn, &user_name)?; let user = User_::find_by_username(&conn, &user_name)?;
let user_url = user.get_profile_url(&Settings::get().hostname); let user_url = user.get_profile_url(&Settings::get().hostname.unwrap_or_default());
let posts = PostQueryBuilder::create(&conn) let posts = PostQueryBuilder::create(&conn)
.listing_type(&ListingType::All) .listing_type(&ListingType::All)

View file

@ -54,8 +54,10 @@ async fn upload(
return Ok(HttpResponse::Unauthorized().finish()); return Ok(HttpResponse::Unauthorized().finish());
}; };
let mut client_req = let mut client_req = client.request_from(
client.request_from(format!("{}/image", Settings::get().pictrs_url), req.head()); format!("{}/image", Settings::get().pictrs_url.unwrap_or_default()),
req.head(),
);
if let Some(addr) = req.head().peer_addr { if let Some(addr) = req.head().peer_addr {
client_req = client_req.header("X-Forwarded-For", addr.to_string()) client_req = client_req.header("X-Forwarded-For", addr.to_string())
@ -78,14 +80,18 @@ async fn full_res(
// If there are no query params, the URL is original // If there are no query params, the URL is original
let url = if params.format.is_none() && params.thumbnail.is_none() { let url = if params.format.is_none() && params.thumbnail.is_none() {
format!("{}/image/original/{}", Settings::get().pictrs_url, name,) format!(
"{}/image/original/{}",
Settings::get().pictrs_url.unwrap_or_default(),
name,
)
} else { } else {
// Use jpg as a default when none is given // Use jpg as a default when none is given
let format = params.format.unwrap_or_else(|| "jpg".to_string()); let format = params.format.unwrap_or_else(|| "jpg".to_string());
let mut url = format!( let mut url = format!(
"{}/image/process.{}?src={}", "{}/image/process.{}?src={}",
Settings::get().pictrs_url, Settings::get().pictrs_url.unwrap_or_default(),
format, format,
name, name,
); );
@ -134,7 +140,7 @@ async fn delete(
let url = format!( let url = format!(
"{}/image/delete/{}/{}", "{}/image/delete/{}/{}",
Settings::get().pictrs_url, Settings::get().pictrs_url.unwrap_or_default(),
&token, &token,
&file &file
); );

View file

@ -31,7 +31,7 @@ async fn node_info(context: web::Data<LemmyContext>) -> Result<HttpResponse, Err
.await? .await?
.map_err(|_| ErrorBadRequest(LemmyError::from(anyhow!("not_found"))))?; .map_err(|_| ErrorBadRequest(LemmyError::from(anyhow!("not_found"))))?;
let protocols = if Settings::get().federation.enabled { let protocols = if Settings::get().federation.unwrap_or_default().enabled {
vec!["activitypub".to_string()] vec!["activitypub".to_string()]
} else { } else {
vec![] vec![]

View file

@ -18,7 +18,7 @@ struct Params {
} }
pub fn config(cfg: &mut web::ServiceConfig) { pub fn config(cfg: &mut web::ServiceConfig) {
if Settings::get().federation.enabled { if Settings::get().federation.unwrap_or_default().enabled {
cfg.route( cfg.route(
".well-known/webfinger", ".well-known/webfinger",
web::get().to(get_webfinger_response), web::get().to(get_webfinger_response),

View file

@ -152,7 +152,7 @@ pub fn send_email_to_user(user: User_, subject_text: &str, body_text: &str, comm
let subject = &format!( let subject = &format!(
"{} - {} {}", "{} - {} {}",
subject_text, subject_text,
Settings::get().hostname, Settings::get().hostname.unwrap_or_default(),
user.name, user.name,
); );
let html = &format!( let html = &format!(

View file

@ -9,7 +9,6 @@ path = "src/lib.rs"
[dependencies] [dependencies]
regex = "1.4.3" regex = "1.4.3"
config = { version = "0.10.1", default-features = false, features = ["hjson"] }
chrono = { version = "0.4.19", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] }
lettre = "0.10.0-alpha.5" lettre = "0.10.0-alpha.5"
log = "0.4.14" log = "0.4.14"
@ -34,3 +33,5 @@ futures = "0.3.12"
diesel = "1.4.5" diesel = "1.4.5"
http = "0.2.3" http = "0.2.3"
jsonwebtoken = "7.2.0" jsonwebtoken = "7.2.0"
deser-hjson = "0.1.12"
merge = "0.1.0"

View file

@ -18,7 +18,7 @@ impl Claims {
}; };
decode::<Claims>( decode::<Claims>(
&jwt, &jwt,
&DecodingKey::from_secret(Settings::get().jwt_secret.as_ref()), &DecodingKey::from_secret(Settings::get().jwt_secret.unwrap_or_default().as_ref()),
&v, &v,
) )
} }
@ -31,7 +31,7 @@ impl Claims {
encode( encode(
&Header::default(), &Header::default(),
&my_claims, &my_claims,
&EncodingKey::from_secret(Settings::get().jwt_secret.as_ref()), &EncodingKey::from_secret(Settings::get().jwt_secret.unwrap_or_default().as_ref()),
) )
} }
} }

View file

@ -20,7 +20,7 @@ pub fn send_email(
html: &str, html: &str,
) -> Result<(), String> { ) -> Result<(), String> {
let email_config = Settings::get().email.ok_or("no_email_setup")?; let email_config = Settings::get().email.ok_or("no_email_setup")?;
let domain = Settings::get().hostname; let domain = Settings::get().hostname.unwrap_or_default();
let (smtp_server, smtp_port) = { let (smtp_server, smtp_port) = {
let email_and_port = email_config.smtp_server.split(':').collect::<Vec<&str>>(); let email_and_port = email_config.smtp_server.split(':').collect::<Vec<&str>>();

View file

@ -83,12 +83,12 @@ impl actix_web::error::ResponseError for LemmyError {
lazy_static! { lazy_static! {
pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!( pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
"^group:([a-z0-9_]{{3, 20}})@{}$", "^group:([a-z0-9_]{{3, 20}})@{}$",
Settings::get().hostname Settings::get().hostname.unwrap_or_default()
)) ))
.unwrap(); .unwrap();
pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!( pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
"^acct:([a-z0-9_]{{3, 20}})@{}$", "^acct:([a-z0-9_]{{3, 20}})@{}$",
Settings::get().hostname Settings::get().hostname.unwrap_or_default()
)) ))
.unwrap(); .unwrap();
} }

View file

@ -70,7 +70,7 @@ impl RateLimited {
{ {
// Does not need to be blocking because the RwLock in settings never held across await points, // Does not need to be blocking because the RwLock in settings never held across await points,
// and the operation here locks only long enough to clone // and the operation here locks only long enough to clone
let rate_limit: RateLimitConfig = Settings::get().rate_limit; let rate_limit: RateLimitConfig = Settings::get().rate_limit.unwrap_or_default();
// before // before
{ {

View file

@ -58,7 +58,11 @@ pub(crate) async fn fetch_iframely(
client: &Client, client: &Client,
url: &str, url: &str,
) -> Result<IframelyResponse, LemmyError> { ) -> Result<IframelyResponse, LemmyError> {
let fetch_url = format!("{}/oembed?url={}", Settings::get().iframely_url, url); let fetch_url = format!(
"{}/oembed?url={}",
Settings::get().iframely_url.unwrap_or_default(),
url
);
let response = retry(|| client.get(&fetch_url).send()).await?; let response = retry(|| client.get(&fetch_url).send()).await?;
@ -89,7 +93,7 @@ pub(crate) async fn fetch_pictrs(
let fetch_url = format!( let fetch_url = format!(
"{}/image/download?url={}", "{}/image/download?url={}",
Settings::get().pictrs_url, Settings::get().pictrs_url.unwrap_or_default(),
utf8_percent_encode(image_url, NON_ALPHANUMERIC) // TODO this might not be needed utf8_percent_encode(image_url, NON_ALPHANUMERIC) // TODO this might not be needed
); );

View file

@ -1,27 +1,53 @@
use crate::location_info; use crate::{location_info, LemmyError};
use anyhow::Context; use anyhow::Context;
use config::{Config, ConfigError, Environment, File}; use deser_hjson::from_str;
use merge::Merge;
use serde::Deserialize; use serde::Deserialize;
use std::{env, fs, io::Error, net::IpAddr, sync::RwLock}; use std::{
env,
fs,
io::Error,
net::{IpAddr, Ipv4Addr},
sync::RwLock,
};
static CONFIG_FILE_DEFAULTS: &str = "config/defaults.hjson";
static CONFIG_FILE: &str = "config/config.hjson"; static CONFIG_FILE: &str = "config/config.hjson";
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone, Merge)]
pub struct Settings { pub struct Settings {
pub setup: Option<Setup>, pub setup: Option<Setup>,
pub database: DatabaseConfig, pub database: Option<DatabaseConfig>,
pub hostname: String, pub hostname: Option<String>,
pub bind: IpAddr, pub bind: Option<IpAddr>,
pub port: u16, pub port: Option<u16>,
pub tls_enabled: bool, pub tls_enabled: Option<bool>,
pub jwt_secret: String, pub jwt_secret: Option<String>,
pub pictrs_url: String, pub pictrs_url: Option<String>,
pub iframely_url: String, pub iframely_url: Option<String>,
pub rate_limit: RateLimitConfig, pub rate_limit: Option<RateLimitConfig>,
pub email: Option<EmailConfig>, pub email: Option<EmailConfig>,
pub federation: FederationConfig, pub federation: Option<FederationConfig>,
pub captcha: CaptchaConfig, pub captcha: Option<CaptchaConfig>,
}
impl Default for Settings {
fn default() -> Self {
Self {
database: Some(DatabaseConfig::default()),
rate_limit: Some(RateLimitConfig::default()),
federation: Some(FederationConfig::default()),
captcha: Some(CaptchaConfig::default()),
email: None,
setup: None,
hostname: None,
bind: Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))),
port: Some(8536),
tls_enabled: Some(true),
jwt_secret: Some("changeme".into()),
pictrs_url: Some("http://pictrs:8080".into()),
iframely_url: Some("http://iframely".into()),
}
}
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
@ -44,6 +70,21 @@ pub struct RateLimitConfig {
pub image_per_second: i32, pub image_per_second: i32,
} }
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
message: 180,
message_per_second: 60,
post: 6,
post_per_second: 600,
register: 3,
register_per_second: 3600,
image: 6,
image_per_second: 3600,
}
}
}
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct EmailConfig { pub struct EmailConfig {
pub smtp_server: String, pub smtp_server: String,
@ -56,7 +97,16 @@ pub struct EmailConfig {
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct CaptchaConfig { pub struct CaptchaConfig {
pub enabled: bool, pub enabled: bool,
pub difficulty: String, // easy, medium, or hard pub difficulty: String,
}
impl Default for CaptchaConfig {
fn default() -> Self {
Self {
enabled: true,
difficulty: "medium".into(),
}
}
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
@ -69,6 +119,19 @@ pub struct DatabaseConfig {
pub pool_size: u32, pub pool_size: u32,
} }
impl Default for DatabaseConfig {
fn default() -> Self {
Self {
user: "lemmy".into(),
password: "password".into(),
host: "localhost".into(),
port: 5432,
database: "lemmy".into(),
pool_size: 5,
}
}
}
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct FederationConfig { pub struct FederationConfig {
pub enabled: bool, pub enabled: bool,
@ -76,6 +139,16 @@ pub struct FederationConfig {
pub blocked_instances: String, pub blocked_instances: String,
} }
impl Default for FederationConfig {
fn default() -> Self {
Self {
enabled: false,
allowed_instances: "".into(),
blocked_instances: "".into(),
}
}
}
lazy_static! { lazy_static! {
static ref SETTINGS: RwLock<Settings> = RwLock::new(match Settings::init() { static ref SETTINGS: RwLock<Settings> = RwLock::new(match Settings::init() {
Ok(c) => c, Ok(c) => c,
@ -91,21 +164,14 @@ impl Settings {
/// ///
/// Note: The env var `LEMMY_DATABASE_URL` is parsed in /// Note: The env var `LEMMY_DATABASE_URL` is parsed in
/// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()` /// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
fn init() -> Result<Self, ConfigError> { fn init() -> Result<Self, LemmyError> {
let mut s = Config::new(); // Read the config file
let mut custom_config = from_str::<Settings>(&Self::read_config_file()?)?;
s.merge(File::with_name(&Self::get_config_defaults_location()))?; // Merge with default
custom_config.merge(Settings::default());
s.merge(File::with_name(&Self::get_config_location()).required(false))?; Ok(custom_config)
// Add in settings from the environment (with a prefix of LEMMY)
// Eg.. `LEMMY_DEBUG=1 ./target/app` would set the `debug` key
// Note: we need to use double underscore here, because otherwise variables containing
// underscore cant be set from environmnet.
// https://github.com/mehcode/config-rs/issues/73
s.merge(Environment::with_prefix("LEMMY").separator("__"))?;
s.try_into()
} }
/// Returns the config as a struct. /// Returns the config as a struct.
@ -114,20 +180,13 @@ impl Settings {
} }
pub fn get_database_url(&self) -> String { pub fn get_database_url(&self) -> String {
let conf = self.database.to_owned().unwrap_or_default();
format!( format!(
"postgres://{}:{}@{}:{}/{}", "postgres://{}:{}@{}:{}/{}",
self.database.user, conf.user, conf.password, conf.host, conf.port, conf.database,
self.database.password,
self.database.host,
self.database.port,
self.database.database
) )
} }
pub fn get_config_defaults_location() -> String {
env::var("LEMMY_CONFIG_DEFAULTS_LOCATION").unwrap_or_else(|_| CONFIG_FILE_DEFAULTS.to_string())
}
pub fn get_config_location() -> String { pub fn get_config_location() -> String {
env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE.to_string()) env::var("LEMMY_CONFIG_LOCATION").unwrap_or_else(|_| CONFIG_FILE.to_string())
} }
@ -139,6 +198,8 @@ impl Settings {
pub fn get_allowed_instances(&self) -> Vec<String> { pub fn get_allowed_instances(&self) -> Vec<String> {
let mut allowed_instances: Vec<String> = self let mut allowed_instances: Vec<String> = self
.federation .federation
.to_owned()
.unwrap_or_default()
.allowed_instances .allowed_instances
.split(',') .split(',')
.map(|d| d.trim().to_string()) .map(|d| d.trim().to_string())
@ -146,13 +207,14 @@ impl Settings {
// The defaults.hjson config always returns a [""] // The defaults.hjson config always returns a [""]
allowed_instances.retain(|d| !d.eq("")); allowed_instances.retain(|d| !d.eq(""));
allowed_instances allowed_instances
} }
pub fn get_blocked_instances(&self) -> Vec<String> { pub fn get_blocked_instances(&self) -> Vec<String> {
let mut blocked_instances: Vec<String> = self let mut blocked_instances: Vec<String> = self
.federation .federation
.to_owned()
.unwrap_or_default()
.blocked_instances .blocked_instances
.split(',') .split(',')
.map(|d| d.trim().to_string()) .map(|d| d.trim().to_string())
@ -160,23 +222,30 @@ impl Settings {
// The defaults.hjson config always returns a [""] // The defaults.hjson config always returns a [""]
blocked_instances.retain(|d| !d.eq("")); blocked_instances.retain(|d| !d.eq(""));
blocked_instances blocked_instances
} }
/// Returns either "http" or "https", depending on tls_enabled setting /// Returns either "http" or "https", depending on tls_enabled setting
pub fn get_protocol_string(&self) -> &'static str { pub fn get_protocol_string(&self) -> &'static str {
if self.tls_enabled { if let Some(tls_enabled) = self.tls_enabled {
if tls_enabled {
"https" "https"
} else { } else {
"http" "http"
} }
} else {
"http"
}
} }
/// Returns something like `http://localhost` or `https://lemmy.ml`, /// Returns something like `http://localhost` or `https://lemmy.ml`,
/// with the correct protocol and hostname. /// with the correct protocol and hostname.
pub fn get_protocol_and_hostname(&self) -> String { pub fn get_protocol_and_hostname(&self) -> String {
format!("{}://{}", self.get_protocol_string(), self.hostname) format!(
"{}://{}",
self.get_protocol_string(),
self.hostname.to_owned().unwrap_or_default()
)
} }
/// When running the federation test setup in `api_tests/` or `docker/federation`, the `hostname` /// When running the federation test setup in `api_tests/` or `docker/federation`, the `hostname`
@ -186,6 +255,8 @@ impl Settings {
Ok( Ok(
self self
.hostname .hostname
.to_owned()
.unwrap_or_default()
.split(':') .split(':')
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.first() .first()

View file

@ -85,7 +85,10 @@ pub struct MentionData {
impl MentionData { impl MentionData {
pub fn is_local(&self) -> bool { pub fn is_local(&self) -> bool {
Settings::get().hostname.eq(&self.domain) Settings::get()
.hostname
.unwrap_or_default()
.eq(&self.domain)
} }
pub fn full_name(&self) -> String { pub fn full_name(&self) -> String {
format!("@{}@{}", &self.name, &self.domain) format!("@{}@{}", &self.name, &self.domain)

View file

@ -29,6 +29,10 @@
password: "password" password: "password"
# host where postgres is running # host where postgres is running
host: "postgres" host: "postgres"
# port where postgres can be accessed
port: 5432
# maximum number of active sql connections
pool_size: 5
} }
# # optional: email sending configuration # # optional: email sending configuration
# email: { # email: {

View file

@ -37,7 +37,7 @@ async fn main() -> Result<(), LemmyError> {
}; };
let manager = ConnectionManager::<PgConnection>::new(&db_url); let manager = ConnectionManager::<PgConnection>::new(&db_url);
let pool = Pool::builder() let pool = Pool::builder()
.max_size(settings.database.pool_size) .max_size(settings.database.unwrap_or_default().pool_size)
.build(manager) .build(manager)
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); .unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
@ -61,7 +61,8 @@ async fn main() -> Result<(), LemmyError> {
println!( println!(
"Starting http server at {}:{}", "Starting http server at {}:{}",
settings.bind, settings.port settings.bind.unwrap(),
settings.port.unwrap_or_default()
); );
let activity_queue = create_activity_queue(); let activity_queue = create_activity_queue();
@ -94,7 +95,7 @@ async fn main() -> Result<(), LemmyError> {
.configure(nodeinfo::config) .configure(nodeinfo::config)
.configure(webfinger::config) .configure(webfinger::config)
}) })
.bind((settings.bind, settings.port))? .bind((settings.bind.unwrap(), settings.port.unwrap_or_default()))?
.run() .run()
.await?; .await?;

View file

@ -58,7 +58,7 @@ fn create_context() -> LemmyContext {
}; };
let manager = ConnectionManager::<PgConnection>::new(&db_url); let manager = ConnectionManager::<PgConnection>::new(&db_url);
let pool = Pool::builder() let pool = Pool::builder()
.max_size(settings.database.pool_size) .max_size(settings.database.unwrap_or_default().pool_size)
.build(manager) .build(manager)
.unwrap(); .unwrap();
embedded_migrations::run(&pool.get().unwrap()).unwrap(); embedded_migrations::run(&pool.get().unwrap()).unwrap();