Generate XsdAnyUri rather than String, remove XsdString

This commit is contained in:
asonix 2020-06-03 12:37:36 -05:00
parent 12660a6243
commit d5cf29f237
13 changed files with 170 additions and 150 deletions

178
Cargo.lock generated
View file

@ -9,7 +9,7 @@ dependencies = [
"activitystreams-derive",
"chrono",
"mime",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"thiserror",
"url",
@ -32,17 +32,17 @@ version = "0.1.0"
source = "git+https://git.asonix.dog/asonix/activitystreams-ext#e5c97f4ea9f60e49bc7ff27fb0fb515d3190fd25"
dependencies = [
"activitystreams-new",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
]
[[package]]
name = "activitystreams-new"
version = "0.1.0"
source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#2cb0ee89d1a2c827d3a78c08342e36bbf53f52d9"
source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#d37714ff57820fb80b2c0799153a1a8d56699ecb"
dependencies = [
"activitystreams",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"typed-builder",
]
@ -122,7 +122,7 @@ dependencies = [
"pin-project",
"rand",
"regex",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"serde_urlencoded",
"sha-1",
@ -150,7 +150,7 @@ dependencies = [
"http",
"log",
"regex",
"serde 1.0.110",
"serde 1.0.111",
]
[[package]]
@ -296,7 +296,7 @@ dependencies = [
"pin-project",
"regex",
"rustls",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"serde_urlencoded",
"socket2",
@ -324,7 +324,7 @@ checksum = "abb66d471f2af5a9ea7b48ea4456f117c56cd1b2348e52ae8d3bc95cddeebf4c"
dependencies = [
"actix-http",
"actix-web",
"serde 1.0.110",
"serde 1.0.111",
"serde_derive",
"thiserror",
]
@ -409,18 +409,18 @@ dependencies = [
[[package]]
name = "async-mutex"
version = "1.0.1"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2158da821e7ba10beee4c01ad1d8f7f49a30675f8761106dd7d569284024d40"
checksum = "7685ce9f0bbc046731a469dd6e17361b0403aa79e6e15c9492e15f3118dfe196"
dependencies = [
"event-listener",
]
[[package]]
name = "async-trait"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26c4f3195085c36ea8d24d32b2f828d23296a9370a28aa39d111f6f16bef9f3b"
checksum = "0eb7f9ad01405feb3c1dac82463038945cf88eea4569acaf3ad662233496dd96"
dependencies = [
"proc-macro2",
"quote",
@ -469,7 +469,7 @@ dependencies = [
"percent-encoding",
"rand",
"rustls",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"serde_urlencoded",
]
@ -498,7 +498,7 @@ dependencies = [
"log",
"num_cpus",
"rand",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"thiserror",
"tokio",
@ -517,7 +517,7 @@ dependencies = [
"chrono",
"futures",
"log",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"thiserror",
"tokio",
@ -610,9 +610,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.3.0"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "byte-tools"
@ -667,7 +667,7 @@ checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
dependencies = [
"num-integer",
"num-traits 0.2.11",
"serde 1.0.110",
"serde 1.0.111",
"time 0.1.43",
]
@ -704,7 +704,7 @@ dependencies = [
"lazy_static",
"nom",
"rust-ini",
"serde 1.0.110",
"serde 1.0.111",
"serde-hjson",
"serde_json",
"toml",
@ -733,9 +733,9 @@ dependencies = [
[[package]]
name = "copyless"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff9c56c9fb2a49c05ef0e431485a22400af20d33226dc0764d891d09e724127"
checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
[[package]]
name = "crc32fast"
@ -748,9 +748,9 @@ dependencies = [
[[package]]
name = "crossbeam-queue"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
checksum = "ab6bffe714b6bb07e42f201352c34f51fefd355ace793f9e638ebd52d23f98d2"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -787,7 +787,7 @@ dependencies = [
"config",
"crossbeam-queue",
"num_cpus",
"serde 1.0.110",
"serde 1.0.111",
"tokio",
]
@ -802,7 +802,7 @@ dependencies = [
"deadpool",
"futures",
"log",
"serde 1.0.110",
"serde 1.0.111",
"tokio",
"tokio-postgres",
]
@ -887,9 +887,9 @@ dependencies = [
[[package]]
name = "event-listener"
version = "1.0.1"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0173b36d730a966f1e1aa2a811cc41619aaf50df92df434fdbad0504d39a973d"
checksum = "043d21a617dda31c36aed31a38f4ebb643a6fa55c2963fd9f0cc1c831e5095d7"
[[package]]
name = "failure"
@ -1248,9 +1248,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "1.3.2"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292"
checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe"
dependencies = [
"autocfg 1.0.0",
]
@ -1293,9 +1293,9 @@ checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
[[package]]
name = "js-sys"
version = "0.3.39"
version = "0.3.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7"
checksum = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177"
dependencies = [
"wasm-bindgen",
]
@ -1340,9 +1340,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.70"
version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
[[package]]
name = "libm"
@ -1386,9 +1386,9 @@ dependencies = [
[[package]]
name = "lru"
version = "0.4.4"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348b828e43d7d1d7a247a6ece0c041d95fb0e34d5496bb4c308428face25df6b"
checksum = "0609345ddee5badacf857d4f547e0e5a2e987db77085c24cd887f73573a04237"
dependencies = [
"hashbrown",
]
@ -1423,7 +1423,7 @@ dependencies = [
"log",
"phf",
"phf_codegen",
"serde 1.0.110",
"serde 1.0.111",
"serde_derive",
"serde_json",
"string_cache",
@ -1583,7 +1583,7 @@ dependencies = [
"num-iter",
"num-traits 0.2.11",
"rand",
"serde 1.0.110",
"serde 1.0.111",
"smallvec",
"zeroize",
]
@ -1767,9 +1767,9 @@ dependencies = [
[[package]]
name = "pin-project-lite"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7505eeebd78492e0f6108f7171c4948dbb120ee8119d9d77d0afa5469bef67f"
checksum = "9df32da11d84f3a7d70205549562966279adb900e080fad3dccd8e64afccf0ad"
[[package]]
name = "pin-utils"
@ -1805,7 +1805,7 @@ dependencies = [
"chrono",
"fallible-iterator",
"postgres-protocol",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"uuid",
]
@ -1860,9 +1860,9 @@ dependencies = [
[[package]]
name = "proc-macro-hack"
version = "0.5.15"
version = "0.5.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63"
checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
[[package]]
name = "proc-macro-nested"
@ -1872,9 +1872,9 @@ checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694"
[[package]]
name = "proc-macro2"
version = "1.0.17"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
dependencies = [
"unicode-xid",
]
@ -1953,9 +1953,9 @@ checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
[[package]]
name = "regex"
version = "1.3.7"
version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
dependencies = [
"aho-corasick",
"memchr",
@ -1965,9 +1965,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.17"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
[[package]]
name = "relay"
@ -2002,7 +2002,7 @@ dependencies = [
"rsa-magic-public-key",
"rsa-pem",
"ructe",
"serde 1.0.110",
"serde 1.0.111",
"serde_json",
"sha2",
"structopt",
@ -2025,9 +2025,9 @@ dependencies = [
[[package]]
name = "ring"
version = "0.16.13"
version = "0.16.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196"
checksum = "06b3fefa4f12272808f809a0af618501fdaba41a58963c5fb72238ab0be09603"
dependencies = [
"cc",
"libc",
@ -2052,7 +2052,7 @@ dependencies = [
"num-iter",
"num-traits 0.2.11",
"rand",
"subtle 2.2.2",
"subtle 2.2.3",
"zeroize",
]
@ -2150,9 +2150,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "scopeguard"
@ -2193,9 +2193,9 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.110"
version = "1.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c"
checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d"
dependencies = [
"serde_derive",
]
@ -2215,9 +2215,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.110"
version = "1.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984"
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
dependencies = [
"proc-macro2",
"quote",
@ -2232,7 +2232,7 @@ checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2"
dependencies = [
"itoa",
"ryu",
"serde 1.0.110",
"serde 1.0.111",
]
[[package]]
@ -2252,7 +2252,7 @@ checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97"
dependencies = [
"dtoa",
"itoa",
"serde 1.0.110",
"serde 1.0.111",
"url",
]
@ -2276,9 +2276,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "sha2"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
dependencies = [
"block-buffer",
"digest",
@ -2366,7 +2366,7 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde 1.0.110",
"serde 1.0.111",
"serde_derive",
"syn",
]
@ -2380,7 +2380,7 @@ dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde 1.0.110",
"serde 1.0.111",
"serde_derive",
"serde_json",
"sha1",
@ -2403,7 +2403,7 @@ dependencies = [
"new_debug_unreachable",
"phf_shared",
"precomputed-hash",
"serde 1.0.110",
"serde 1.0.111",
]
[[package]]
@ -2466,15 +2466,15 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
[[package]]
name = "subtle"
version = "2.2.2"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941"
checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1"
[[package]]
name = "syn"
version = "1.0.23"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269"
checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2"
dependencies = [
"proc-macro2",
"quote",
@ -2714,7 +2714,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
dependencies = [
"serde 1.0.110",
"serde 1.0.111",
]
[[package]]
@ -2849,7 +2849,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
dependencies = [
"rand",
"serde 1.0.110",
"serde 1.0.111",
]
[[package]]
@ -2860,9 +2860,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasi"
@ -2872,9 +2872,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551"
checksum = "4c2dc4aa152834bc334f506c1a06b866416a8b6697d5c9f75b9a689c8486def0"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@ -2882,9 +2882,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94"
checksum = "ded84f06e0ed21499f6184df0e0cb3494727b0c5da89534e0fcc55c51d812101"
dependencies = [
"bumpalo",
"lazy_static",
@ -2897,9 +2897,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776"
checksum = "838e423688dac18d73e31edce74ddfac468e37b1506ad163ffaf0a46f703ffe3"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2907,9 +2907,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a"
checksum = "3156052d8ec77142051a533cdd686cba889537b213f948cd1d20869926e68e92"
dependencies = [
"proc-macro2",
"quote",
@ -2920,15 +2920,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad"
checksum = "c9ba19973a58daf4db6f352eda73dc0e289493cd29fb2632eb172085b6521acd"
[[package]]
name = "web-sys"
version = "0.3.39"
version = "0.3.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642"
checksum = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -2936,9 +2936,9 @@ dependencies = [
[[package]]
name = "webpki"
version = "0.21.2"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef"
checksum = "ab146130f5f790d45f82aeeb09e55a256573373ec64409fc19a6fb82fb1032ae"
dependencies = [
"ring",
"untrusted",
@ -3035,9 +3035,9 @@ dependencies = [
[[package]]
name = "yaml-rust"
version = "0.4.3"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d"
checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d"
dependencies = [
"linked-hash-map 0.5.3",
]

View file

@ -1,4 +1,5 @@
use crate::{data::ActorCache, error::MyError, middleware::MyVerify, requests::Requests};
use activitystreams_new::primitives::XsdAnyUri;
use config::Environment;
use http_signature_normalization_actix::prelude::{VerifyDigest, VerifySignature};
use sha2::{Digest, Sha256};
@ -6,7 +7,7 @@ use std::net::IpAddr;
use uuid::Uuid;
#[derive(Clone, Debug, serde::Deserialize)]
pub struct Config {
pub struct ParsedConfig {
hostname: String,
addr: IpAddr,
port: u16,
@ -20,6 +21,21 @@ pub struct Config {
max_connections: usize,
}
#[derive(Clone, Debug)]
pub struct Config {
hostname: String,
addr: IpAddr,
port: u16,
debug: bool,
whitelist_mode: bool,
validate_signatures: bool,
database_url: String,
pretty_log: bool,
publish_blocks: bool,
max_connections: usize,
base_uri: XsdAnyUri,
}
pub enum UrlKind {
Activity,
Actor,
@ -49,7 +65,24 @@ impl Config {
.set_default("max_connections", 2)?
.merge(Environment::new())?;
Ok(config.try_into()?)
let config: ParsedConfig = config.try_into()?;
let scheme = if config.https { "https" } else { "http" };
let base_uri = format!("{}://{}", scheme, config.hostname).parse()?;
Ok(Config {
hostname: config.hostname,
addr: config.addr,
port: config.port,
debug: config.debug,
whitelist_mode: config.whitelist_mode,
validate_signatures: config.validate_signatures,
database_url: config.database_url,
pretty_log: config.pretty_log,
publish_blocks: config.publish_blocks,
max_connections: config.max_connections,
base_uri,
})
}
pub fn pretty_log(&self) -> bool {
@ -124,22 +157,26 @@ impl Config {
"https://git.asonix.dog/asonix/ap-relay".to_owned()
}
pub fn generate_url(&self, kind: UrlKind) -> String {
let scheme = if self.https { "https" } else { "http" };
pub fn generate_url(&self, kind: UrlKind) -> XsdAnyUri {
let mut uri = self.base_uri.clone();
let url = uri.as_url_mut();
match kind {
UrlKind::Activity => {
format!("{}://{}/activity/{}", scheme, self.hostname, Uuid::new_v4())
UrlKind::Activity => url.set_path(&format!("activity/{}", Uuid::new_v4())),
UrlKind::Actor => url.set_path("actor"),
UrlKind::Followers => url.set_path("followers"),
UrlKind::Following => url.set_path("following"),
UrlKind::Inbox => url.set_path("inbox"),
UrlKind::Index => (),
UrlKind::MainKey => {
url.set_path("actor");
url.set_fragment(Some("main-key"));
}
UrlKind::Actor => format!("{}://{}/actor", scheme, self.hostname),
UrlKind::Followers => format!("{}://{}/followers", scheme, self.hostname),
UrlKind::Following => format!("{}://{}/following", scheme, self.hostname),
UrlKind::Inbox => format!("{}://{}/inbox", scheme, self.hostname),
UrlKind::Index => format!("{}://{}/", scheme, self.hostname),
UrlKind::MainKey => format!("{}://{}/actor#main-key", scheme, self.hostname),
UrlKind::Media(uuid) => format!("{}://{}/media/{}", scheme, self.hostname, uuid),
UrlKind::NodeInfo => format!("{}://{}/nodeinfo/2.0.json", scheme, self.hostname),
UrlKind::Outbox => format!("{}://{}/outbox", scheme, self.hostname),
}
UrlKind::Media(uuid) => url.set_path(&format!("media/{}", uuid)),
UrlKind::NodeInfo => url.set_path("nodeinfo/2.0.json"),
UrlKind::Outbox => url.set_path("outbox"),
};
uri
}
}

View file

@ -38,7 +38,7 @@ impl State {
pub fn requests(&self) -> Requests {
Requests::new(
self.config.generate_url(UrlKind::MainKey),
self.config.generate_url(UrlKind::MainKey).to_string(),
self.private_key.clone(),
format!(
"Actix Web 3.0.0-alpha.1 ({}/{}; +{})",

View file

@ -23,7 +23,7 @@ impl Announce {
}
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
let activity_id: XsdAnyUri = state.config.generate_url(UrlKind::Activity).parse()?;
let activity_id = state.config.generate_url(UrlKind::Activity);
let announce = generate_announce(&state.config, &activity_id, &self.object_id)?;
let inboxes = get_inboxes(&state.state, &self.actor, &self.object_id).await?;
@ -42,10 +42,7 @@ fn generate_announce(
activity_id: &XsdAnyUri,
object_id: &XsdAnyUri,
) -> Result<AsAnnounce, MyError> {
let announce = AsAnnounce::new(
config.generate_url(UrlKind::Actor).parse::<XsdAnyUri>()?,
object_id.clone(),
);
let announce = AsAnnounce::new(config.generate_url(UrlKind::Actor), object_id.clone());
prepare_activity(
announce,

View file

@ -33,7 +33,7 @@ impl Follow {
if !self.is_listener {
state.db.add_listener(self.actor.inbox.clone()).await?;
}
let my_id: XsdAnyUri = state.config.generate_url(UrlKind::Actor).parse()?;
let my_id = state.config.generate_url(UrlKind::Actor);
// if following relay directly, not just following 'public', followback
if self.input.object_is(&my_id) && !state.actors.is_following(&self.actor.id).await {

View file

@ -57,7 +57,7 @@ fn generate_undo_follow(
) -> Result<AsUndo, MyError> {
let mut follow = AsFollow::new(my_id.clone(), actor_id.clone());
follow.set_id(config.generate_url(UrlKind::Activity).parse()?);
follow.set_id(config.generate_url(UrlKind::Activity));
let undo = AsUndo::new(my_id.clone(), follow.into_any_base()?);

View file

@ -3,7 +3,6 @@ use crate::{
data::Actor,
jobs::{apub::generate_undo_follow, Deliver, JobState},
};
use activitystreams_new::primitives::XsdAnyUri;
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
@ -16,7 +15,7 @@ impl Reject {
state.db.remove_listener(self.0.inbox.clone()).await?;
}
let my_id: XsdAnyUri = state.config.generate_url(UrlKind::Actor).parse()?;
let my_id = state.config.generate_url(UrlKind::Actor);
let undo = generate_undo_follow(&state.config, &self.0.id, &my_id)?;
state.job_server.queue(Deliver::new(self.0.inbox, undo)?)?;

View file

@ -4,7 +4,6 @@ use crate::{
data::Actor,
jobs::{apub::generate_undo_follow, Deliver, JobState},
};
use activitystreams_new::primitives::XsdAnyUri;
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
@ -27,7 +26,7 @@ impl Undo {
}
if was_following {
let my_id: XsdAnyUri = state.config.generate_url(UrlKind::Actor).parse()?;
let my_id = state.config.generate_url(UrlKind::Actor);
let undo = generate_undo_follow(&state.config, &self.actor.id, &my_id)?;
state
.job_server

View file

@ -48,11 +48,11 @@ impl QueryInstance {
if let Some(mut contact) = instance.contact {
let uuid = if let Some(uuid) = state.media.get_uuid(&contact.avatar).await? {
contact.avatar = state.config.generate_url(UrlKind::Media(uuid)).parse()?;
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
uuid
} else {
let uuid = state.media.store_url(&contact.avatar).await?;
contact.avatar = state.config.generate_url(UrlKind::Media(uuid)).parse()?;
contact.avatar = state.config.generate_url(UrlKind::Media(uuid));
uuid
};

View file

@ -36,9 +36,9 @@ impl Resolver for RelayResolver {
return Ok(None);
}
let mut wf = Webfinger::new(&config.generate_resource());
wf.add_alias(&config.generate_url(UrlKind::Actor))
.add_activitypub(&config.generate_url(UrlKind::Actor))
let mut wf = Webfinger::new(config.generate_resource().as_str());
wf.add_alias(config.generate_url(UrlKind::Actor).as_str())
.add_activitypub(config.generate_url(UrlKind::Actor).as_str())
.add_magic_public_key(&state.public_key.as_magic_public_key());
Ok(Some(wf))

View file

@ -10,7 +10,6 @@ use activitystreams_new::{
actor::{ApActor, Application, Endpoints},
context,
prelude::*,
primitives::{XsdAnyUri, XsdString},
security,
};
use actix_web::{web, Responder};
@ -21,39 +20,28 @@ pub async fn route(
config: web::Data<Config>,
) -> Result<impl Responder, MyError> {
let mut application = Ext1::new(
ApActor::new(
config.generate_url(UrlKind::Inbox).parse()?,
Application::new(),
),
ApActor::new(config.generate_url(UrlKind::Inbox), Application::new()),
PublicKey {
public_key: PublicKeyInner {
id: config.generate_url(UrlKind::MainKey).parse()?,
owner: config.generate_url(UrlKind::Actor).parse()?,
id: config.generate_url(UrlKind::MainKey),
owner: config.generate_url(UrlKind::Actor),
public_key_pem: state.public_key.to_pem_pkcs8()?,
},
},
);
application
.set_id(config.generate_url(UrlKind::Actor).parse()?)
.set_summary(XsdString::from("AodeRelay bot"))
.set_name(XsdString::from("AodeRelay"))
.set_url(config.generate_url(UrlKind::Actor).parse::<XsdAnyUri>()?)
.set_id(config.generate_url(UrlKind::Actor))
.set_summary("AodeRelay bot".to_owned())
.set_name("AodeRelay".to_owned())
.set_url(config.generate_url(UrlKind::Actor))
.set_many_contexts(vec![context(), security()])
.set_preferred_username("relay".into())
.set_outbox(config.generate_url(UrlKind::Outbox).parse()?)
.set_followers(
config
.generate_url(UrlKind::Followers)
.parse::<XsdAnyUri>()?,
)
.set_following(
config
.generate_url(UrlKind::Following)
.parse::<XsdAnyUri>()?,
)
.set_outbox(config.generate_url(UrlKind::Outbox))
.set_followers(config.generate_url(UrlKind::Followers))
.set_following(config.generate_url(UrlKind::Following))
.set_endpoints(Endpoints {
shared_inbox: Some(config.generate_url(UrlKind::Inbox).parse::<XsdAnyUri>()?),
shared_inbox: Some(config.generate_url(UrlKind::Inbox)),
..Default::default()
});

View file

@ -115,7 +115,7 @@ async fn handle_accept(config: &Config, input: AcceptedActivities) -> Result<(),
));
};
if !follow.actor_is(&config.generate_url(UrlKind::Actor).parse()?) {
if !follow.actor_is(&config.generate_url(UrlKind::Actor)) {
return Err(MyError::WrongActor(id_string(
follow.actor().as_single_id(),
)?));
@ -139,7 +139,7 @@ async fn handle_reject(
));
};
if !follow.actor_is(&config.generate_url(UrlKind::Actor).parse()?) {
if !follow.actor_is(&config.generate_url(UrlKind::Actor)) {
return Err(MyError::WrongActor(id_string(
follow.actor().as_single_id(),
)?));
@ -170,7 +170,7 @@ async fn handle_undo(
}
}
let my_id: XsdAnyUri = config.generate_url(UrlKind::Actor).parse()?;
let my_id: XsdAnyUri = config.generate_url(UrlKind::Actor);
if !undone_object.object_is(&my_id) && !undone_object.object_is(&public()) {
return Err(MyError::WrongActor(id_string(
@ -220,7 +220,7 @@ async fn handle_follow(
actor: Actor,
is_listener: bool,
) -> Result<(), MyError> {
let my_id: XsdAnyUri = config.generate_url(UrlKind::Actor).parse()?;
let my_id: XsdAnyUri = config.generate_url(UrlKind::Actor);
if !input.object_is(&my_id) && !input.object_is(&public()) {
return Err(MyError::WrongActor(id_string(

View file

@ -9,7 +9,7 @@ pub async fn well_known(config: web::Data<Config>) -> impl Responder {
web::Json(Links {
links: vec![Link {
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(),
href: Some(config.generate_url(UrlKind::NodeInfo)),
href: Some(config.generate_url(UrlKind::NodeInfo).to_string()),
template: None,
kind: None,
}],