diff options
Diffstat (limited to 'server')
65 files changed, 3915 insertions, 1302 deletions
diff --git a/server/Cargo.lock b/server/Cargo.lock index c54419e1..62438593 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -63,7 +63,7 @@ dependencies = [ "futures-util", "log", "once_cell", - "parking_lot", + "parking_lot 0.10.2", "pin-project", "smallvec", "tokio", @@ -269,7 +269,7 @@ dependencies = [ "lazy_static", "log", "num_cpus", - "parking_lot", + "parking_lot 0.10.2", "threadpool", ] @@ -398,6 +398,12 @@ dependencies = [ ] [[package]] +name = "adler" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10" + +[[package]] name = "adler32" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -506,7 +512,7 @@ dependencies = [ "addr2line", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.3.7", "object", "rustc-demangle", ] @@ -680,9 +686,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.55" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1be3409f94d7bdceeb5f5fac551039d9b3f00e25da7a74fc4d33400a0d96368" +checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe" [[package]] name = "cfg-if" @@ -692,9 +698,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +checksum = "f0fee792e164f78f5fe0c296cc2eb3688a2ca2b70cdff33040922d298203f0c4" dependencies = [ "num-integer", "num-traits 0.2.12", @@ -727,6 +733,15 @@ dependencies = [ ] [[package]] +name = "cloudabi" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" +dependencies = [ + "bitflags", +] + +[[package]] name = "comrak" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1120,14 +1135,14 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42" +checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" dependencies = [ "cfg-if", "crc32fast", "libc", - "miniz_oxide", + "miniz_oxide 0.4.0", ] [[package]] @@ -1385,12 +1400,6 @@ dependencies = [ ] [[package]] -name = "htmlescape" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163" - -[[package]] name = "http" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1471,6 +1480,12 @@ dependencies = [ ] [[package]] +name = "instant" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69da7ce1490173c2bf4d26bc8be429aaeeaf4cce6c4b970b7949651fa17655fe" + +[[package]] name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1508,18 +1523,18 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "js-sys" -version = "0.3.40" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177" +checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916" dependencies = [ "wasm-bindgen", ] [[package]] name = "jsonwebtoken" -version = "7.1.2" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f325ae57ddcf609f02d891486ce740f5bbd0cc3e93f9bffaacdf6594b21404" +checksum = "afabcc15e437a6484fc4f12d0fd63068fe457bf93f1c148d3d9649c60b103f32" dependencies = [ "base64 0.12.3", "pem", @@ -1552,6 +1567,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] +name = "lemmy_db" +version = "0.1.0" +dependencies = [ + "bcrypt", + "chrono", + "diesel", + "log", + "serde 1.0.114", + "serde_json", + "sha2", + "strum", + "strum_macros", +] + +[[package]] name = "lemmy_server" version = "0.0.1" dependencies = [ @@ -1568,27 +1598,23 @@ dependencies = [ "base64 0.12.3", "bcrypt", "chrono", - "comrak", - "config", "diesel", "diesel_migrations", "dotenv", "env_logger", "failure", "futures", - "htmlescape", "http", "http-signature-normalization-actix", "itertools", "jsonwebtoken", "lazy_static", - "lettre", - "lettre_email", + "lemmy_db", + "lemmy_utils", "log", "openssl", "percent-encoding", "rand 0.7.3", - "regex", "rss", "serde 1.0.114", "serde_json", @@ -1601,6 +1627,26 @@ dependencies = [ ] [[package]] +name = "lemmy_utils" +version = "0.1.0" +dependencies = [ + "chrono", + "comrak", + "config", + "itertools", + "lazy_static", + "lettre", + "lettre_email", + "log", + "openssl", + "rand 0.7.3", + "regex", + "serde 1.0.114", + "serde_json", + "url", +] + +[[package]] name = "lettre" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1677,6 +1723,15 @@ dependencies = [ ] [[package]] +name = "lock_api" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de302ce1fe7482db13738fbaf2e21cfb06a986b89c0bf38d88abf16681aada4e" +dependencies = [ + "scopeguard", +] + +[[package]] name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1782,6 +1837,15 @@ dependencies = [ ] [[package]] +name = "miniz_oxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +dependencies = [ + "adler", +] + +[[package]] name = "mio" version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1985,8 +2049,19 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ - "lock_api", - "parking_lot_core", + "lock_api 0.3.4", + "parking_lot_core 0.7.2", +] + +[[package]] +name = "parking_lot" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" +dependencies = [ + "instant", + "lock_api 0.4.0", + "parking_lot_core 0.8.0", ] [[package]] @@ -1996,7 +2071,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", - "cloudabi", + "cloudabi 0.0.3", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" +dependencies = [ + "cfg-if", + "cloudabi 0.1.0", + "instant", "libc", "redox_syscall", "smallvec", @@ -2164,12 +2254,12 @@ dependencies = [ [[package]] name = "r2d2" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1497e40855348e4a8a40767d8e55174bce1e445a3ac9254ad44ad468ee0485af" +checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" dependencies = [ "log", - "parking_lot", + "parking_lot 0.11.0", "scheduled-thread-pool", ] @@ -2306,7 +2396,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" dependencies = [ - "cloudabi", + "cloudabi 0.0.3", "fuchsia-cprng", "libc", "rand_core 0.4.2", @@ -2462,11 +2552,11 @@ dependencies = [ [[package]] name = "scheduled-thread-pool" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0988d7fdf88d5e5fcf5923a0f1e8ab345f3e98ab4bc6bc45a2d5ff7f7458fbf6" +checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" dependencies = [ - "parking_lot", + "parking_lot 0.11.0", ] [[package]] @@ -2570,9 +2660,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.55" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" dependencies = [ "indexmap", "itoa", @@ -3106,9 +3196,9 @@ checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" [[package]] name = "unicode-width" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -3222,9 +3312,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.63" +version = "0.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2dc4aa152834bc334f506c1a06b866416a8b6697d5c9f75b9a689c8486def0" +checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3232,9 +3322,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.63" +version = "0.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded84f06e0ed21499f6184df0e0cb3494727b0c5da89534e0fcc55c51d812101" +checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df" dependencies = [ "bumpalo", "lazy_static", @@ -3247,9 +3337,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.63" +version = "0.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "838e423688dac18d73e31edce74ddfac468e37b1506ad163ffaf0a46f703ffe3" +checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3257,9 +3347,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.63" +version = "0.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3156052d8ec77142051a533cdd686cba889537b213f948cd1d20869926e68e92" +checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75" dependencies = [ "proc-macro2", "quote", @@ -3270,15 +3360,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.63" +version = "0.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9ba19973a58daf4db6f352eda73dc0e289493cd29fb2632eb172085b6521acd" +checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae" [[package]] name = "web-sys" -version = "0.3.40" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17" +checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/server/Cargo.toml b/server/Cargo.toml index 8daf72c4..a5e5a583 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,14 +1,21 @@ [package] name = "lemmy_server" version = "0.0.1" -authors = ["Dessalines <tyhou13@gmx.com>"] edition = "2018" [profile.release] lto = true +[workspace] +members = [ + "lemmy_utils", + "lemmy_db" +] + [dependencies] -diesel = { version = "1.4.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] } +lemmy_utils = { path = "./lemmy_utils" } +lemmy_db = { path = "./lemmy_db" } +diesel = "1.4.4" diesel_migrations = "1.4.0" dotenv = "0.15.0" activitystreams = "0.6.2" @@ -31,16 +38,10 @@ rand = "0.7.3" strum = "0.18.0" strum_macros = "0.18.0" jsonwebtoken = "7.0.1" -regex = "1.3.5" lazy_static = "1.3.0" -lettre = "0.9.3" -lettre_email = "0.9.4" rss = "1.9.0" -htmlescape = "0.3.1" url = { version = "2.1.1", features = ["serde"] } -config = {version = "0.10.1", default-features = false, features = ["hjson"] } percent-encoding = "2.1.0" -comrak = "0.7" openssl = "0.10" http = "0.2.1" http-signature-normalization-actix = { version = "0.4.0-alpha.0", default-features = false, features = ["sha-2"] } diff --git a/server/db-init.sh b/server/db-init.sh index a2ad77b5..ccecb7de 100755 --- a/server/db-init.sh +++ b/server/db-init.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +set -e # Default configurations username=lemmy diff --git a/server/diesel.toml b/server/diesel.toml index 92267c82..1644558f 100644 --- a/server/diesel.toml +++ b/server/diesel.toml @@ -2,4 +2,4 @@ # see diesel.rs/guides/configuring-diesel-cli [print_schema] -file = "src/schema.rs" +file = "lemmy_db/src/schema.rs" diff --git a/server/lemmy_db/Cargo.toml b/server/lemmy_db/Cargo.toml new file mode 100644 index 00000000..d94cf5fc --- /dev/null +++ b/server/lemmy_db/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "lemmy_db" +version = "0.1.0" +edition = "2018" + +[dependencies] +diesel = { version = "1.4.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] } +chrono = { version = "0.4.7", features = ["serde"] } +serde = { version = "1.0.105", features = ["derive"] } +serde_json = { version = "1.0.52", features = ["preserve_order"]} +strum = "0.18.0" +strum_macros = "0.18.0" +log = "0.4.0" +sha2 = "0.9" +bcrypt = "0.8.0"
\ No newline at end of file diff --git a/server/src/db/activity.rs b/server/lemmy_db/src/activity.rs index 8c2b0c74..83f85ca1 100644 --- a/server/src/db/activity.rs +++ b/server/lemmy_db/src/activity.rs @@ -1,9 +1,12 @@ -use crate::{blocking, db::Crud, schema::activity, DbPool, LemmyError}; +use crate::{schema::activity, Crud}; use diesel::{dsl::*, result::Error, *}; use log::debug; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::fmt::Debug; +use std::{ + fmt::Debug, + io::{Error as IoError, ErrorKind}, +}; #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[table_name = "activity"] @@ -55,46 +58,43 @@ impl Crud<ActivityForm> for Activity { } } -pub async fn insert_activity<T>( - user_id: i32, - data: T, - local: bool, - pool: &DbPool, -) -> Result<(), LemmyError> -where - T: Serialize + Debug + Send + 'static, -{ - blocking(pool, move |conn| { - do_insert_activity(conn, user_id, &data, local) - }) - .await??; - Ok(()) -} - -fn do_insert_activity<T>( +pub fn do_insert_activity<T>( conn: &PgConnection, user_id: i32, data: &T, local: bool, -) -> Result<(), LemmyError> +) -> Result<Activity, IoError> where T: Serialize + Debug, { + debug!("inserting activity for user {}, data {:?}", user_id, &data); let activity_form = ActivityForm { user_id, data: serde_json::to_value(&data)?, |