From 79eb929f26a36f8db801a83c0740de6478662407 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 4 Nov 2020 10:54:21 -0500 Subject: [PATCH] add simple mastodon client --- backend/Cargo.lock | 910 +----------------------------------- backend/Cargo.toml | 1 - backend/src/api/mod.rs | 8 + backend/src/main.rs | 2 + backend/src/web/mastodon.rs | 55 +++ backend/src/web/mod.rs | 1 + 6 files changed, 79 insertions(+), 898 deletions(-) create mode 100644 backend/src/web/mastodon.rs diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 28eb022..8ada459 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -156,15 +156,6 @@ dependencies = [ "safemem", ] -[[package]] -name = "base64" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" -dependencies = [ - "byteorder 1.3.4", -] - [[package]] name = "base64" version = "0.11.0" @@ -240,12 +231,6 @@ dependencies = [ "byteorder 0.3.13", ] -[[package]] -name = "bytecount" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b92204551573580e078dc80017f36a213eb77a0450e4ddd8cfa0f3f2d1f0178f" - [[package]] name = "byteorder" version = "0.3.13" @@ -258,36 +243,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder 1.3.4", - "either", - "iovec", -] - -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - -[[package]] -name = "cargo_metadata" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d1b4d380e1bab994591a24c2bdd1b054f64b60bef483a8c598c7c345bc3bbe" -dependencies = [ - "error-chain", - "semver", - "serde", - "serde_derive", - "serde_json", -] - [[package]] name = "cc" version = "1.0.59" @@ -384,16 +339,6 @@ dependencies = [ "time 0.1.44", ] -[[package]] -name = "cookie" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" -dependencies = [ - "time 0.1.44", - "url 1.7.2", -] - [[package]] name = "cookie" version = "0.14.2" @@ -405,24 +350,6 @@ dependencies = [ "version_check 0.9.2", ] -[[package]] -name = "cookie_store" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" -dependencies = [ - "cookie 0.12.0", - "failure", - "idna 0.1.5", - "log 0.4.11", - "publicsuffix", - "serde", - "serde_json", - "time 0.1.44", - "try_from", - "url 1.7.2", -] - [[package]] name = "cookie_store" version = "0.12.0" @@ -439,22 +366,6 @@ dependencies = [ "url 2.1.1", ] -[[package]] -name = "core-foundation" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" - [[package]] name = "crc32fast" version = "1.2.0" @@ -464,54 +375,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-deque" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" -dependencies = [ - "autocfg 1.0.1", - "cfg-if", - "crossbeam-utils", - "lazy_static", - "maybe-uninit", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-queue" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-utils" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg 1.0.1", - "cfg-if", - "lazy_static", -] - [[package]] name = "crypto-mac" version = "0.7.0" @@ -522,12 +385,6 @@ dependencies = [ "subtle 1.0.0", ] -[[package]] -name = "data-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d0e2d24e5ee3b23a01de38eefdcd978907890701f08ffffd4cb457ca4ee8d6" - [[package]] name = "devise" version = "0.2.0" @@ -606,42 +463,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" -[[package]] -name = "dtoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" - -[[package]] -name = "either" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" - -[[package]] -name = "elefren" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba08a959d3824df696d49c2ec023f45851f663c47b57b2de933aab749104cd18" -dependencies = [ - "chrono", - "doc-comment", - "hyper-old-types", - "isolang", - "log 0.4.11", - "reqwest", - "serde", - "serde_derive", - "serde_json", - "serde_qs", - "serde_urlencoded 0.6.1", - "skeptic", - "tap-reader", - "try_from", - "tungstenite", - "url 1.7.2", -] - [[package]] name = "encoding" version = "0.2.33" @@ -706,15 +527,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -[[package]] -name = "encoding_rs" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" -dependencies = [ - "cfg-if", -] - [[package]] name = "error-chain" version = "0.12.4" @@ -775,18 +587,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "flate2" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "766d0e77a2c1502169d4a93ff3b8c15a71fd946cd0126309752104e5f3c46d94" -dependencies = [ - "cfg-if", - "crc32fast", - "libc", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" @@ -859,22 +659,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.1.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" - -[[package]] -name = "futures-cpupool" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" -dependencies = [ - "futures", - "num_cpus", -] - [[package]] name = "futures-io" version = "0.3.5" @@ -922,36 +706,12 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" -[[package]] -name = "glob" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" - [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "h2" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" -dependencies = [ - "byteorder 1.3.4", - "bytes 0.4.12", - "fnv", - "futures", - "http 0.1.21", - "indexmap", - "log 0.4.11", - "slab", - "string", - "tokio-io", -] - [[package]] name = "hashbrown" version = "0.9.0" @@ -993,40 +753,6 @@ dependencies = [ "digest", ] -[[package]] -name = "http" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" -dependencies = [ - "bytes 0.4.12", - "fnv", - "itoa", -] - -[[package]] -name = "http" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" -dependencies = [ - "bytes 0.5.6", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" -dependencies = [ - "bytes 0.4.12", - "futures", - "http 0.1.21", - "tokio-buf", -] - [[package]] name = "httparse" version = "1.3.4" @@ -1048,70 +774,10 @@ dependencies = [ "time 0.1.44", "traitobject", "typeable", - "unicase 1.4.2", + "unicase", "url 1.7.2", ] -[[package]] -name = "hyper" -version = "0.12.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" -dependencies = [ - "bytes 0.4.12", - "futures", - "futures-cpupool", - "h2", - "http 0.1.21", - "http-body", - "httparse", - "iovec", - "itoa", - "log 0.4.11", - "net2", - "rustc_version", - "time 0.1.44", - "tokio", - "tokio-buf", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-threadpool", - "tokio-timer", - "want", -] - -[[package]] -name = "hyper-old-types" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6896be51ecf3966c0fa14ff2da3233dbb9aef57ccea1be1afe55f105f4d4c9c4" -dependencies = [ - "base64 0.9.3", - "bytes 0.4.12", - "httparse", - "language-tags", - "log 0.4.11", - "mime 0.3.16", - "percent-encoding 1.0.1", - "time 0.1.44", - "unicase 2.6.0", -] - -[[package]] -name = "hyper-tls" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" -dependencies = [ - "bytes 0.4.12", - "futures", - "hyper 0.12.35", - "native-tls", - "tokio-io", -] - [[package]] name = "idna" version = "0.1.5" @@ -1170,15 +836,6 @@ dependencies = [ "libc", ] -[[package]] -name = "input_buffer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" -dependencies = [ - "bytes 0.5.6", -] - [[package]] name = "instant" version = "0.1.6" @@ -1194,17 +851,6 @@ dependencies = [ "libc", ] -[[package]] -name = "isolang" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265ef164908329e47e753c769b14cbb27434abf0c41984dca201484022f09ce5" -dependencies = [ - "phf", - "phf_codegen", - "serde", -] - [[package]] name = "itoa" version = "0.4.6" @@ -1310,15 +956,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "lock_api" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] - [[package]] name = "lock_api" version = "0.4.1" @@ -1361,27 +998,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" -[[package]] -name = "memoffset" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" -dependencies = [ - "autocfg 1.0.1", -] - [[package]] name = "mi" version = "1.0.0" @@ -1389,7 +1011,6 @@ dependencies = [ "chrono", "color-eyre", "diesel", - "elefren", "futures-io", "hex", "jsonfeed", @@ -1430,16 +1051,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime 0.3.16", - "unicase 2.6.0", -] - [[package]] name = "miniz_oxide" version = "0.4.1" @@ -1492,24 +1103,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "native-tls" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" -dependencies = [ - "lazy_static", - "libc", - "log 0.4.11", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "net2" version = "0.2.35" @@ -1600,12 +1193,6 @@ dependencies = [ "openssl-sys", ] -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - [[package]] name = "openssl-sys" version = "0.9.58" @@ -1625,17 +1212,6 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a1250cdd103eef6bd542b5ae82989f931fc00a41a27f60377338241594410f3" -[[package]] -name = "parking_lot" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" -dependencies = [ - "lock_api 0.3.4", - "parking_lot_core 0.6.2", - "rustc_version", -] - [[package]] name = "parking_lot" version = "0.11.0" @@ -1643,23 +1219,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" dependencies = [ "instant", - "lock_api 0.4.1", - "parking_lot_core 0.8.0", -] - -[[package]] -name = "parking_lot_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" -dependencies = [ - "cfg-if", - "cloudabi 0.0.3", - "libc", - "redox_syscall", - "rustc_version", - "smallvec 0.6.13", - "winapi 0.3.9", + "lock_api", + "parking_lot_core", ] [[package]] @@ -1673,7 +1234,7 @@ dependencies = [ "instant", "libc", "redox_syscall", - "smallvec 1.4.2", + "smallvec", "winapi 0.3.9", ] @@ -1727,44 +1288,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "phf" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" -dependencies = [ - "phf_shared", - "rand 0.6.5", -] - -[[package]] -name = "phf_shared" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" -dependencies = [ - "siphasher", -] - [[package]] name = "pkg-config" version = "0.3.18" @@ -1835,7 +1358,7 @@ dependencies = [ "fnv", "lazy_static", "libc", - "parking_lot 0.11.0", + "parking_lot", "procfs", "regex", "thiserror", @@ -1854,15 +1377,6 @@ dependencies = [ "url 2.1.1", ] -[[package]] -name = "pulldown-cmark" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15" -dependencies = [ - "bitflags", -] - [[package]] name = "qstring" version = "0.7.2" @@ -1897,7 +1411,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" dependencies = [ "log 0.4.11", - "parking_lot 0.11.0", + "parking_lot", "scheduled-thread-pool", ] @@ -2114,49 +1628,6 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "reqwest" -version = "0.9.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" -dependencies = [ - "base64 0.10.1", - "bytes 0.4.12", - "cookie 0.12.0", - "cookie_store 0.7.0", - "encoding_rs", - "flate2", - "futures", - "http 0.1.21", - "hyper 0.12.35", - "hyper-tls", - "log 0.4.11", - "mime 0.3.16", - "mime_guess", - "native-tls", - "serde", - "serde_json", - "serde_urlencoded 0.5.5", - "time 0.1.44", - "tokio", - "tokio-executor", - "tokio-io", - "tokio-threadpool", - "tokio-timer", - "url 1.7.2", - "uuid", - "winreg", -] - [[package]] name = "ring" version = "0.16.15" @@ -2206,7 +1677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb852e6da168fb948a8f2b798ba2e2f0e4fc860eae0efa9cf2bf0f5466bb0425" dependencies = [ "devise", - "glob 0.3.0", + "glob", "indexmap", "quote 0.6.13", "rocket_http", @@ -2251,11 +1722,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aff5a5480175f2f553a876b251e9350c74196128806d176da3a51c82aab5428" dependencies = [ "cookie 0.11.3", - "hyper 0.10.16", + "hyper", "indexmap", "pear", "percent-encoding 1.0.1", - "smallvec 1.4.2", + "smallvec", "state", "time 0.1.44", "unicode-xid 0.1.0", @@ -2351,23 +1822,13 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi 0.3.9", -] - [[package]] name = "scheduled-thread-pool" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" dependencies = [ - "parking_lot 0.11.0", + "parking_lot", ] [[package]] @@ -2386,29 +1847,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2416,7 +1854,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ "semver-parser", - "serde", ] [[package]] @@ -2456,42 +1893,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_qs" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35965fa1d2413717053d67c2df1f5c3e1763fbf77200ea7e767523707bd5a0af" -dependencies = [ - "data-encoding", - "error-chain", - "percent-encoding 1.0.1", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" -dependencies = [ - "dtoa", - "itoa", - "serde", - "url 1.7.2", -] - -[[package]] -name = "serde_urlencoded" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" -dependencies = [ - "dtoa", - "itoa", - "serde", - "url 2.1.1", -] - [[package]] name = "serde_urlencoded" version = "0.7.0" @@ -2504,18 +1905,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha-1" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" -dependencies = [ - "block-buffer", - "digest", - "fake-simd", - "opaque-debug", -] - [[package]] name = "sha1" version = "0.6.0" @@ -2543,43 +1932,12 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" - -[[package]] -name = "skeptic" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6fb8ed853fdc19ce09752d63f3a2e5b5158aeb261520cd75eb618bd60305165" -dependencies = [ - "bytecount", - "cargo_metadata", - "error-chain", - "glob 0.2.11", - "pulldown-cmark", - "serde_json", - "tempdir", - "walkdir", -] - [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -[[package]] -name = "smallvec" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" -dependencies = [ - "maybe-uninit", -] - [[package]] name = "smallvec" version = "1.4.2" @@ -2667,15 +2025,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "string" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" -dependencies = [ - "bytes 0.4.12", -] - [[package]] name = "subtle" version = "1.0.0" @@ -2722,36 +2071,6 @@ dependencies = [ "unicode-xid 0.2.1", ] -[[package]] -name = "tap-reader" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f13fc301d415a8cd4529ba679720c59f07369bcff573618a6e8d5afebefb6f3" - -[[package]] -name = "tempdir" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -dependencies = [ - "rand 0.4.6", - "remove_dir_all", -] - -[[package]] -name = "tempfile" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -dependencies = [ - "cfg-if", - "libc", - "rand 0.7.3", - "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "thiserror" version = "1.0.20" @@ -2836,139 +2155,6 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" -[[package]] -name = "tokio" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" -dependencies = [ - "bytes 0.4.12", - "futures", - "mio", - "num_cpus", - "tokio-current-thread", - "tokio-executor", - "tokio-io", - "tokio-reactor", - "tokio-tcp", - "tokio-threadpool", - "tokio-timer", -] - -[[package]] -name = "tokio-buf" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" -dependencies = [ - "bytes 0.4.12", - "either", - "futures", -] - -[[package]] -name = "tokio-current-thread" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de0e32a83f131e002238d7ccde18211c0a5397f60cbfffcb112868c2e0e20e" -dependencies = [ - "futures", - "tokio-executor", -] - -[[package]] -name = "tokio-executor" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" -dependencies = [ - "crossbeam-utils", - "futures", -] - -[[package]] -name = "tokio-io" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" -dependencies = [ - "bytes 0.4.12", - "futures", - "log 0.4.11", -] - -[[package]] -name = "tokio-reactor" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" -dependencies = [ - "crossbeam-utils", - "futures", - "lazy_static", - "log 0.4.11", - "mio", - "num_cpus", - "parking_lot 0.9.0", - "slab", - "tokio-executor", - "tokio-io", - "tokio-sync", -] - -[[package]] -name = "tokio-sync" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfe50152bc8164fcc456dab7891fa9bf8beaf01c5ee7e1dd43a397c3cf87dee" -dependencies = [ - "fnv", - "futures", -] - -[[package]] -name = "tokio-tcp" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" -dependencies = [ - "bytes 0.4.12", - "futures", - "iovec", - "mio", - "tokio-io", - "tokio-reactor", -] - -[[package]] -name = "tokio-threadpool" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" -dependencies = [ - "crossbeam-deque", - "crossbeam-queue", - "crossbeam-utils", - "futures", - "lazy_static", - "log 0.4.11", - "num_cpus", - "slab", - "tokio-executor", -] - -[[package]] -name = "tokio-timer" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" -dependencies = [ - "crossbeam-utils", - "futures", - "slab", - "tokio-executor", -] - [[package]] name = "toml" version = "0.4.10" @@ -3054,7 +2240,7 @@ dependencies = [ "serde", "serde_json", "sharded-slab", - "smallvec 1.4.2", + "smallvec", "thread_local", "tracing-core", "tracing-log", @@ -3067,41 +2253,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] -name = "try_from" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "tungstenite" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfea31758bf674f990918962e8e5f07071a3161bd7c4138ed23e416e1ac4264e" -dependencies = [ - "base64 0.11.0", - "byteorder 1.3.4", - "bytes 0.5.6", - "http 0.2.1", - "httparse", - "input_buffer", - "log 0.4.11", - "native-tls", - "rand 0.7.3", - "sha-1", - "url 2.1.1", - "utf-8", -] - [[package]] name = "twapi-oauth" version = "0.1.4" @@ -3125,7 +2276,7 @@ dependencies = [ "bytebuffer", "rand 0.7.3", "serde_json", - "serde_urlencoded 0.7.0", + "serde_urlencoded", "twapi-oauth", "ureq", ] @@ -3151,15 +2302,6 @@ dependencies = [ "version_check 0.1.5", ] -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check 0.9.2", -] - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -3215,7 +2357,7 @@ dependencies = [ "base64 0.13.0", "chunked_transfer", "cookie 0.14.2", - "cookie_store 0.12.0", + "cookie_store", "encoding", "log 0.4.11", "once_cell", @@ -3250,12 +2392,6 @@ dependencies = [ "percent-encoding 2.1.0", ] -[[package]] -name = "utf-8" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" - [[package]] name = "uuid" version = "0.7.4" @@ -3295,17 +2431,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" -dependencies = [ - "futures", - "log 0.4.11", - "try-lock", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -3444,15 +2569,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winreg" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 5378ceb..9dc5f28 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -10,7 +10,6 @@ edition = "2018" chrono = { version = "0.4", features = ["serde"] } color-eyre = "0.5" twapi-ureq = "0.1.5" -elefren = "0.22" kankyo = "0.3" log = "0.4" mime = "0.3.0" diff --git a/backend/src/api/mod.rs b/backend/src/api/mod.rs index 50f224d..443f717 100644 --- a/backend/src/api/mod.rs +++ b/backend/src/api/mod.rs @@ -38,6 +38,14 @@ pub fn tweet(body: StringBody, tw: State, tok: paseto::Tok Ok(()) } +#[post("/toot", data = "")] +#[instrument(skip(ma), err)] +pub fn toot(body: StringBody, ma: State, tok: paseto::Token) -> Result { + ma.toot(body.unwrap())?; + + Ok(()) +} + #[derive(Debug)] pub struct StringBody(String); diff --git a/backend/src/main.rs b/backend/src/main.rs index 0ca789d..917aa37 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -44,6 +44,7 @@ fn main() -> Result<()> { .attach(SpaceHelmet::default()) .attach(paseto::ed25519_keypair()) .attach(web::discord_webhook::Client::fairing()) + .attach(web::mastodon::Client::fairing()) .attach(web::pluralkit::Client::fairing()) .attach(web::switchcounter::Client::fairing()) .attach(web::twitter::Client::fairing()) @@ -59,6 +60,7 @@ fn main() -> Result<()> { api::get_members, api::token_info, api::tweet, + api::toot, ], ) .launch(); diff --git a/backend/src/web/mastodon.rs b/backend/src/web/mastodon.rs new file mode 100644 index 0000000..13ba277 --- /dev/null +++ b/backend/src/web/mastodon.rs @@ -0,0 +1,55 @@ +use super::{Error, Result}; +use rocket::fairing::AdHoc; + +pub struct Client { + instance_url: String, + app_id: String, + app_secret: String, + token: String, + account_name: String, +} + +impl Client { + pub fn fairing() -> AdHoc { + AdHoc::on_attach("Mastodon client", |rocket| { + let cfg = rocket.config(); + let table = cfg.get_table("mastodon").unwrap(); + let instance_url = table["instance"].as_str().unwrap().to_string(); + let app_id = table["app_id"].as_str().unwrap().to_string(); + let app_secret = table["app_secret"].as_str().unwrap().to_string(); + let token = table["token"].as_str().unwrap().to_string(); + let account_name = table["account"].as_str().unwrap().to_string(); + + let cli = Client { + instance_url: instance_url, + app_id: app_id, + app_secret: app_secret, + token: token, + account_name: account_name, + }; + + Ok(rocket.manage(cli)) + }) + } + + pub fn account_name(&self) -> String { + self.account_name.clone() + } + + pub fn toot(&self, body: String) -> Result { + let url = &format!("{}/api/v1/statuses", self.instance_url); + + let resp = ureq::post(url) + .set("Authorization", &format!("bearer {}", self.token)) + .send_form(&[("status", body.as_str())]); + + if resp.ok() { + Ok(()) + } else { + Err(match resp.synthetic_error() { + Some(why) => Error::UReq(why.to_string()), + None => Error::HttpStatus(resp.status()), + }) + } + } +} diff --git a/backend/src/web/mod.rs b/backend/src/web/mod.rs index a386d2d..d8472e9 100644 --- a/backend/src/web/mod.rs +++ b/backend/src/web/mod.rs @@ -1,4 +1,5 @@ pub mod discord_webhook; +pub mod mastodon; pub mod pluralkit; pub mod switchcounter; pub mod twitter;