Move utils to mitra-utils crate

This commit is contained in:
silverpill 2023-02-18 22:25:49 +00:00
parent bcef9bb989
commit 7d3c558ede
77 changed files with 246 additions and 153 deletions

38
Cargo.lock generated
View file

@ -1703,13 +1703,10 @@ dependencies = [
"actix-files",
"actix-web",
"actix-web-httpauth",
"ammonia",
"anyhow",
"base64",
"blake2",
"bs58",
"chrono",
"comrak",
"deadpool",
"deadpool-postgres",
"dotenv",
@ -1718,24 +1715,19 @@ dependencies = [
"env_logger",
"hex",
"log",
"mime-sniffer",
"mime_guess",
"mitra-utils",
"monero-rpc",
"num_cpus",
"pem",
"postgres-protocol",
"postgres-types",
"postgres_query",
"postgres_query_macro",
"rand 0.8.4",
"refinery",
"regex",
"reqwest",
"rsa",
"rust-argon2",
"secp256k1",
"serde",
"serde_jcs",
"serde_json",
"serde_yaml",
"serial_test",
@ -1744,7 +1736,6 @@ dependencies = [
"thiserror",
"tokio",
"tokio-postgres",
"ulid",
"url 2.2.2",
"uuid",
"web3",
@ -1758,10 +1749,37 @@ dependencies = [
"clap",
"log",
"mitra",
"mitra-utils",
"tokio",
"uuid",
]
[[package]]
name = "mitra-utils"
version = "1.13.1"
dependencies = [
"ammonia",
"base64",
"bs58",
"chrono",
"comrak",
"mime-sniffer",
"mime_guess",
"pem",
"rand 0.8.4",
"regex",
"rsa",
"rust-argon2",
"serde",
"serde_jcs",
"serde_json",
"sha2 0.9.9",
"thiserror",
"ulid",
"url 2.2.2",
"uuid",
]
[[package]]
name = "monero"
version = "0.17.2"

View file

@ -12,6 +12,7 @@ default-run = "mitra"
[workspace]
members = [
".",
"mitra-utils",
"mitra-cli",
]
default-members = [
@ -20,23 +21,19 @@ default-members = [
]
[dependencies]
mitra-utils = { path = "mitra-utils" }
# Used to handle incoming HTTP requests
actix-cors = "0.6.2"
actix-files = "0.6.2"
actix-web = "4.1.0"
actix-web-httpauth = "0.8.0"
# Used for HTML sanitization
ammonia = "3.2.0"
# Used for catching errors
anyhow = "1.0.58"
# Used for working with RSA keys, HTTP signatures and file uploads
base64 = "0.13.0"
# Used to decode base58btc
bs58 = "0.4.0"
# Used for working with dates
chrono = { version = "0.4.23", default-features = false, features = ["std", "serde"] }
# Used for parsing markdown
comrak = { version = "0.15.0", default-features = false }
# Used for pooling database connections
deadpool = "0.9.2"
deadpool-postgres = { version = "0.10.2", default-features = false }
@ -51,33 +48,23 @@ env_logger = { version = "0.9.0", default-features = false }
ed25519-dalek = "1.0.1"
ed25519 = "1.5.2"
blake2 = "0.10.5"
# Used to guess media type of a file
mime_guess = "2.0.3"
mime-sniffer = "0.1.2"
# Used to query Monero node
monero-rpc = "0.3.2"
# Used to determine the number of CPUs on the system
num_cpus = "1.13.0"
# Used for working with regular expressions
regex = "1.6.0"
# Used to generate random numbers
rand = "0.8.4"
# Used for managing database migrations
refinery = { version = "0.8.4", features = ["tokio-postgres"] }
# Used for making async HTTP requests
reqwest = { version = "0.11.10", features = ["json", "multipart", "socks"] }
# Used for working with RSA keys
rsa = "0.5.0"
pem = "1.0.2"
# Used for hashing passwords
rust-argon2 = "1.0.0"
# Used for working with ethereum keys
secp256k1 = { version = "0.21.3", features = ["rand", "rand-std"] }
# Used for serialization/deserialization
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.89"
# Used to create JCS representations
serde_jcs = "0.1.0"
# Used to parse config file
serde_yaml = "0.8.17"
# Used to calculate SHA2 hashes
@ -97,15 +84,13 @@ postgres_query = { git = "https://github.com/nolanderc/rust-postgres-query", rev
postgres_query_macro = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" }
# Used to work with URLs
url = "2.2.2"
# Used to generate lexicographically sortable IDs
ulid = { version = "1.0.0", features = ["uuid"] }
# Used to work with UUIDs
uuid = { version = "1.1.2", features = ["serde", "v4"] }
# Used to query ethereum node
web3 = { version = "0.18.0", default-features = false, features = ["http", "http-tls", "signing"] }
[dev-dependencies]
rand = { version = "0.8.4", features = ["small_rng"] }
mitra-utils = { path = "mitra-utils", features = ["test-utils"] }
serial_test = "0.7.0"
[features]

View file

@ -10,6 +10,7 @@ name = "mitractl"
path = "src/main.rs"
[dependencies]
mitra-utils = { path = "../mitra-utils" }
mitra = { path = ".." }
# Used for catching errors

View file

@ -48,7 +48,7 @@ use mitra::monero::{
helpers::check_expired_invoice,
wallet::create_monero_wallet,
};
use mitra::utils::{
use mitra_utils::{
crypto_rsa::{
generate_rsa_key,
serialize_private_key,

48
mitra-utils/Cargo.toml Normal file
View file

@ -0,0 +1,48 @@
[package]
name = "mitra-utils"
version = "1.13.1"
license = "AGPL-3.0"
edition = "2021"
rust-version = "1.56"
[dependencies]
# Used for HTML sanitization
ammonia = "3.2.0"
# Used for working with RSA keys, HTTP signatures and file uploads
base64 = "0.13.0"
# Used to decode base58btc
bs58 = "0.4.0"
# Used for working with dates
chrono = { version = "0.4.23", default-features = false, features = ["std"] }
# Used for parsing markdown
comrak = { version = "0.15.0", default-features = false }
# Used to guess media type of a file
mime_guess = "2.0.3"
mime-sniffer = "0.1.2"
# Used to generate random numbers
rand = "0.8.4"
# Used for working with regular expressions
regex = "1.6.0"
# Used for working with RSA keys
rsa = "0.5.0"
pem = "1.0.2"
# Used for hashing passwords
rust-argon2 = "1.0.0"
# Used for serialization/deserialization
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.89"
# Used to create JCS representations
serde_jcs = "0.1.0"
# Used to calculate SHA2 hashes
sha2 = "0.9.5"
# Used for creating error types
thiserror = "1.0.37"
# Used to generate lexicographically sortable IDs
ulid = { version = "1.0.0", features = ["uuid"] }
# Used to work with URLs
url = "2.2.2"
# Used to work with UUIDs
uuid = "1.1.2"
[features]
test-utils = ["rand/small_rng"]

View file

@ -8,7 +8,7 @@ pub fn generate_rsa_key() -> Result<RsaPrivateKey, rsa::errors::Error> {
RsaPrivateKey::new(&mut rng, bits)
}
#[cfg(test)]
#[cfg(feature = "test-utils")]
pub fn generate_weak_rsa_key() -> Result<RsaPrivateKey, rsa::errors::Error> {
use rand::SeedableRng;
let mut rng = rand::rngs::SmallRng::seed_from_u64(0);

View file

@ -158,7 +158,7 @@ pub fn parse_extra_field(
#[cfg(test)]
mod tests {
use crate::utils::{
use mitra_utils::{
caip2::ChainId,
id::generate_ulid,
};

View file

@ -6,6 +6,11 @@ use serde::{
};
use serde_json::{json, Value};
use mitra_utils::{
crypto_rsa::{deserialize_private_key, get_public_key_pem},
urls::get_hostname,
};
use crate::activitypub::{
constants::{
AP_CONTEXT,
@ -31,10 +36,6 @@ use crate::models::{
},
users::types::User,
};
use crate::utils::{
crypto_rsa::{deserialize_private_key, get_public_key_pem},
urls::get_hostname,
};
use crate::webfinger::types::ActorAddress;
use super::attachments::{
attach_extra_field,
@ -378,11 +379,11 @@ pub fn get_instance_actor(
#[cfg(test)]
mod tests {
use crate::models::profiles::types::DbActorProfile;
use crate::utils::crypto_rsa::{
use mitra_utils::crypto_rsa::{
generate_weak_rsa_key,
serialize_private_key,
};
use crate::models::profiles::types::DbActorProfile;
use super::*;
const INSTANCE_HOSTNAME: &str = "example.com";

View file

@ -1,6 +1,8 @@
use actix_web::HttpRequest;
use serde_json::Value;
use mitra_utils::crypto_rsa::deserialize_public_key;
use crate::config::Config;
use crate::database::{DatabaseClient, DatabaseError};
use crate::http_signatures::verify::{
@ -21,7 +23,6 @@ use crate::models::{
profiles::queries::get_profile_by_remote_actor_id,
profiles::types::DbActorProfile,
};
use crate::utils::crypto_rsa::deserialize_public_key;
use super::fetcher::helpers::get_or_import_profile_by_actor_id;
use super::receiver::HandlerError;

View file

@ -1,5 +1,7 @@
use serde::Serialize;
use mitra_utils::id::generate_ulid;
use crate::activitypub::{
actors::types::Actor,
deliverer::OutgoingActivity,
@ -12,7 +14,6 @@ use crate::models::{
profiles::types::DbActorProfile,
users::types::User,
};
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
struct AcceptFollow {

View file

@ -1,5 +1,7 @@
use serde::Serialize;
use mitra_utils::id::generate_ulid;
use crate::activitypub::{
actors::types::Actor,
deliverer::OutgoingActivity,
@ -9,7 +11,6 @@ use crate::activitypub::{
};
use crate::config::Instance;
use crate::models::users::types::User;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
struct AddOrRemovePerson {

View file

@ -70,7 +70,7 @@ pub fn prepare_follow(
#[cfg(test)]
mod tests {
use crate::utils::id::generate_ulid;
use mitra_utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -112,7 +112,7 @@ pub async fn prepare_like(
#[cfg(test)]
mod tests {
use crate::utils::id::generate_ulid;
use mitra_utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -1,6 +1,8 @@
use serde::Serialize;
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::activitypub::{
actors::types::Actor,
deliverer::OutgoingActivity,
@ -10,7 +12,6 @@ use crate::activitypub::{
};
use crate::config::Instance;
use crate::models::users::types::User;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
pub struct MovePerson {
@ -77,8 +78,8 @@ pub fn prepare_move_person(
#[cfg(test)]
mod tests {
use mitra_utils::id::generate_ulid;
use crate::models::profiles::types::DbActorProfile;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -90,7 +90,7 @@ pub async fn prepare_undo_announce(
#[cfg(test)]
mod tests {
use crate::utils::id::generate_ulid;
use mitra_utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -87,7 +87,7 @@ pub fn prepare_undo_follow(
#[cfg(test)]
mod tests {
use crate::utils::id::generate_ulid;
use mitra_utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -88,8 +88,8 @@ pub async fn prepare_undo_like(
#[cfg(test)]
mod tests {
use mitra_utils::id::generate_ulid;
use crate::activitypub::constants::AP_PUBLIC;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -1,6 +1,8 @@
use serde::Serialize;
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::activitypub::{
actors::types::{get_local_actor, Actor, ActorKeyError},
constants::AP_PUBLIC,
@ -15,7 +17,6 @@ use crate::models::{
relationships::queries::get_followers,
users::types::User,
};
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
pub struct UpdatePerson {
@ -92,11 +93,11 @@ pub async fn prepare_update_person(
#[cfg(test)]
mod tests {
use crate::models::profiles::types::DbActorProfile;
use crate::utils::crypto_rsa::{
use mitra_utils::crypto_rsa::{
generate_weak_rsa_key,
serialize_private_key,
};
use crate::models::profiles::types::DbActorProfile;
use super::*;
const INSTANCE_URL: &str = "https://example.com";

View file

@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::time::sleep;
use mitra_utils::crypto_rsa::deserialize_private_key;
use crate::config::Instance;
use crate::database::{
get_database_client,
@ -28,7 +30,6 @@ use crate::models::{
profiles::queries::set_reachability_status,
users::types::User,
};
use crate::utils::crypto_rsa::deserialize_private_key;
use super::actors::types::Actor;
use super::constants::AP_MEDIA_TYPE;
use super::identifiers::{local_actor_id, local_actor_key_id};

View file

@ -4,6 +4,11 @@ use std::time::Duration;
use reqwest::{Client, Method, Proxy, RequestBuilder};
use serde_json::Value;
use mitra_utils::{
files::sniff_media_type,
urls::guess_protocol,
};
use crate::activitypub::{
actors::types::Actor,
constants::AP_MEDIA_TYPE,
@ -16,10 +21,6 @@ use crate::http_signatures::create::{
HttpSignatureError,
};
use crate::media::{save_file, SUPPORTED_MEDIA_TYPES};
use crate::utils::{
files::sniff_media_type,
urls::guess_protocol,
};
use crate::webfinger::types::{ActorAddress, JsonResourceDescriptor};
const FETCHER_CONNECTION_TIMEOUT: u64 = 30;

View file

@ -4,6 +4,11 @@ use chrono::Utc;
use serde_json::{Value as JsonValue};
use uuid::Uuid;
use mitra_utils::{
html::clean_html,
urls::get_hostname,
};
use crate::activitypub::{
constants::{AP_MEDIA_TYPE, AP_PUBLIC, AS_MEDIA_TYPE},
fetcher::fetchers::{fetch_file, FetchError},
@ -49,10 +54,6 @@ use crate::models::{
profiles::types::DbActorProfile,
users::queries::get_user_by_name,
};
use crate::utils::{
html::clean_html,
urls::get_hostname,
};
use super::HandlerResult;
fn get_object_attributed_to(object: &Object)

View file

@ -116,7 +116,7 @@ pub fn parse_local_object_id(
#[cfg(test)]
mod tests {
use crate::utils::id::generate_ulid;
use mitra_utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.org";

View file

@ -1,13 +1,14 @@
use mitra_utils::{
datetime::get_min_datetime,
html::{clean_html_all, escape_html},
};
use crate::activitypub::identifiers::{local_actor_id, local_object_id};
use crate::config::Instance;
use crate::models::{
posts::types::Post,
profiles::types::DbActorProfile,
};
use crate::utils::{
datetime::get_min_datetime,
html::{clean_html_all, escape_html},
};
const ENTRY_TITLE_MAX_LENGTH: usize = 75;

View file

@ -2,7 +2,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::utils::caip2::{ChainId, ChainIdError};
use mitra_utils::caip2::{ChainId, ChainIdError};
fn default_chain_sync_step() -> u64 { 1000 }

View file

@ -4,7 +4,7 @@ use std::str::FromStr;
use rsa::RsaPrivateKey;
use crate::utils::{
use mitra_utils::{
crypto_rsa::{
deserialize_private_key,
generate_rsa_key,

View file

@ -9,7 +9,7 @@ use serde::{
};
use url::Url;
use crate::utils::urls::normalize_url;
use mitra_utils::urls::normalize_url;
use super::blockchain::BlockchainConfig;
use super::environment::Environment;
@ -188,7 +188,7 @@ impl Instance {
#[cfg(test)]
impl Instance {
pub fn for_test(url: &str) -> Self {
use crate::utils::crypto_rsa::generate_weak_rsa_key;
use mitra_utils::crypto_rsa::generate_weak_rsa_key;
Self {
_url: Url::parse(url).unwrap(),
actor_key: generate_weak_rsa_key().unwrap(),
@ -200,7 +200,7 @@ impl Instance {
#[cfg(test)]
mod tests {
use crate::utils::crypto_rsa::generate_weak_rsa_key;
use mitra_utils::crypto_rsa::generate_weak_rsa_key;
use super::*;
#[test]

View file

@ -36,6 +36,7 @@ pub fn verify_eip191_identity_proof(
#[cfg(test)]
mod tests {
use web3::signing::{Key, SecretKeyRef};
use mitra_utils::currencies::Currency;
use crate::ethereum::{
signatures::{
generate_ecdsa_key,
@ -43,7 +44,6 @@ mod tests {
},
utils::address_to_string,
};
use crate::utils::currencies::Currency;
use super::*;
const ETHEREUM: Currency = Currency::Ethereum;

View file

@ -1,7 +1,6 @@
use std::convert::TryInto;
use chrono::{DateTime, TimeZone, Utc};
use web3::{
api::Web3,
contract::{Contract, Options},
@ -10,6 +9,11 @@ use web3::{
types::{BlockId, BlockNumber, FilterBuilder, U256},
};
use mitra_utils::{
caip2::ChainId,
currencies::Currency,
};
use crate::activitypub::{
builders::{
add_person::prepare_add_person,
@ -48,10 +52,6 @@ use crate::models::{
},
users::types::User,
};
use crate::utils::{
caip2::ChainId,
currencies::Currency,
};
use super::contracts::ContractSet;
use super::errors::EthereumError;
use super::signatures::{

View file

@ -3,7 +3,8 @@ use std::path::{Path, PathBuf};
use web3::{api::Web3, transports::Http, types::Address};
use crate::utils::files::write_file;
use mitra_utils::files::write_file;
use super::errors::EthereumError;
const BLOCK_NUMBER_FILE_NAME: &str = "current_block";

View file

@ -2,7 +2,7 @@ use actix_web::http::Method;
use chrono::Utc;
use rsa::RsaPrivateKey;
use crate::utils::crypto_rsa::{
use mitra_utils::crypto_rsa::{
create_rsa_signature,
get_message_digest,
};
@ -92,7 +92,7 @@ pub fn create_http_signature(
#[cfg(test)]
mod tests {
use crate::utils::crypto_rsa::generate_weak_rsa_key;
use mitra_utils::crypto_rsa::generate_weak_rsa_key;
use super::*;
#[test]

View file

@ -5,7 +5,7 @@ use chrono::{DateTime, Duration, TimeZone, Utc};
use regex::Regex;
use rsa::RsaPublicKey;
use crate::utils::crypto_rsa::verify_rsa_signature;
use mitra_utils::crypto_rsa::verify_rsa_signature;
const SIGNATURE_PARAMETER_RE: &str = r#"^(?P<key>[a-zA-Z]+)="(?P<value>.+)"$"#;
@ -152,8 +152,8 @@ mod tests {
header::{HeaderMap, HeaderName, HeaderValue},
Uri,
};
use mitra_utils::crypto_rsa::generate_weak_rsa_key;
use crate::http_signatures::create::create_http_signature;
use crate::utils::crypto_rsa::generate_weak_rsa_key;
use super::*;
#[test]

View file

@ -1,6 +1,6 @@
use serde::Serialize;
use crate::utils::canonicalization::{
use mitra_utils::canonicalization::{
canonicalize_object,
CanonicalizationError,
};
@ -30,8 +30,8 @@ pub fn create_identity_claim(
#[cfg(test)]
mod tests {
use mitra_utils::currencies::Currency;
use crate::identity::did_pkh::DidPkh;
use crate::utils::currencies::Currency;
use super::*;
#[test]

View file

@ -4,10 +4,11 @@ use std::str::FromStr;
use regex::Regex;
use crate::utils::multibase::{
use mitra_utils::multibase::{
decode_multibase_base58btc,
encode_multibase_base58btc,
};
use super::did::DidParseError;
const DID_KEY_RE: &str = r"did:key:(?P<key>z[a-km-zA-HJ-NP-Z1-9]+)";

View file

@ -4,8 +4,11 @@ use std::str::FromStr;
use regex::Regex;
use crate::utils::caip2::ChainId;
use crate::utils::currencies::Currency;
use mitra_utils::{
caip2::ChainId,
currencies::Currency,
};
use super::did::DidParseError;
// https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#syntax

View file

@ -5,6 +5,8 @@ use anyhow::Error;
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::datetime::days_before_now;
use crate::activitypub::queues::{
process_queued_incoming_activities,
process_queued_outgoing_activities,
@ -28,7 +30,6 @@ use crate::models::{
get_profile_by_id,
},
};
use crate::utils::datetime::days_before_now;
pub async fn nft_monitor(
maybe_blockchain: Option<&mut Blockchain>,

View file

@ -3,6 +3,15 @@ use rsa::RsaPrivateKey;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use mitra_utils::{
canonicalization::{
canonicalize_object,
CanonicalizationError,
},
crypto_rsa::create_rsa_signature,
multibase::encode_multibase_base58btc,
};
use crate::identity::{
did_key::DidKey,
did_pkh::DidPkh,
@ -12,14 +21,6 @@ use crate::identity::{
PROOF_TYPE_JCS_RSA,
},
};
use crate::utils::{
canonicalization::{
canonicalize_object,
CanonicalizationError,
},
crypto_rsa::create_rsa_signature,
multibase::encode_multibase_base58btc,
};
pub(super) const PROOF_KEY: &str = "proof";
pub(super) const PROOF_PURPOSE: &str = "assertionMethod";
@ -133,7 +134,7 @@ pub fn is_object_signed(object: &Value) -> bool {
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::utils::crypto_rsa::generate_weak_rsa_key;
use mitra_utils::crypto_rsa::generate_weak_rsa_key;
use super::*;
#[test]

View file

@ -4,6 +4,15 @@ use rsa::RsaPublicKey;
use serde_json::Value;
use url::Url;
use mitra_utils::{
canonicalization::{
canonicalize_object,
CanonicalizationError,
},
crypto_rsa::verify_rsa_signature,
multibase::{decode_multibase_base58btc, MultibaseError},
};
use crate::ethereum::identity::verify_eip191_signature;
use crate::identity::{
did::Did,
@ -12,14 +21,6 @@ use crate::identity::{
minisign::verify_ed25519_signature,
signatures::SignatureType,
};
use crate::utils::{
canonicalization::{
canonicalize_object,
CanonicalizationError,
},
crypto_rsa::verify_rsa_signature,
multibase::{decode_multibase_base58btc, MultibaseError},
};
use super::create::{
IntegrityProof,
PROOF_KEY,
@ -132,11 +133,11 @@ pub fn verify_ed25519_json_signature(
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::json_signatures::create::sign_object;
use crate::utils::{
use mitra_utils::{
crypto_rsa::generate_weak_rsa_key,
currencies::Currency,
};
use crate::json_signatures::create::sign_object;
use super::*;
#[test]

View file

@ -16,6 +16,5 @@ pub mod media;
pub mod models;
pub mod monero;
pub mod nodeinfo;
pub mod utils;
pub mod webfinger;
pub mod web_client;

View file

@ -4,6 +4,8 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use mitra_utils::markdown::markdown_basic_to_html;
use crate::errors::{HttpError, ValidationError};
use crate::identity::did::Did;
use crate::mastodon_api::{
@ -28,7 +30,6 @@ use crate::models::{
User,
},
};
use crate::utils::markdown::markdown_basic_to_html;
/// https://docs.joinmastodon.org/entities/field/
#[derive(Serialize)]

View file

@ -5,6 +5,18 @@ use actix_web::{
use actix_web_httpauth::extractors::bearer::BearerAuth;
use uuid::Uuid;
use mitra_utils::{
caip2::ChainId,
canonicalization::canonicalize_object,
crypto_rsa::{
generate_rsa_key,
serialize_private_key,
},
currencies::Currency,
id::generate_ulid,
passwords::hash_password,
};
use crate::activitypub::builders::{
undo_follow::prepare_undo_follow,
update_person::{
@ -75,17 +87,6 @@ use crate::models::{
},
users::types::{Role, UserCreateData},
};
use crate::utils::{
caip2::ChainId,
canonicalization::canonicalize_object,
crypto_rsa::{
generate_rsa_key,
serialize_private_key,
},
currencies::Currency,
id::generate_ulid,
passwords::hash_password,
};
use super::helpers::{follow_or_create_request, get_relationship};
use super::types::{
Account,

View file

@ -1,6 +1,8 @@
use serde::Serialize;
use serde_json::{to_value, Value};
use mitra_utils::markdown::markdown_to_html;
use crate::config::{
BlockchainConfig,
Config,
@ -14,7 +16,6 @@ use crate::mastodon_api::{
};
use crate::media::SUPPORTED_MEDIA_TYPES;
use crate::models::posts::validators::ATTACHMENTS_MAX_NUM;
use crate::utils::markdown::markdown_to_html;
#[derive(Serialize)]
struct InstanceStats {

View file

@ -1,6 +1,6 @@
use base64;
use crate::utils::random::generate_random_sequence;
use mitra_utils::random::generate_random_sequence;
pub fn render_authorization_page() -> String {
let page = r#"<!DOCTYPE html>

View file

@ -10,6 +10,8 @@ use actix_web::{
use actix_web_httpauth::extractors::bearer::BearerAuth;
use chrono::{Duration, Utc};
use mitra_utils::passwords::verify_password;
use crate::config::Config;
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::{HttpError, ValidationError};
@ -30,7 +32,6 @@ use crate::models::{
get_user_by_login_address,
},
};
use crate::utils::passwords::verify_password;
use super::auth::get_current_user;
use super::types::{
AuthorizationRequest,

View file

@ -3,6 +3,8 @@ use std::str::FromStr;
use regex::Regex;
use url::Url;
use mitra_utils::currencies::Currency;
use crate::activitypub::{
fetcher::helpers::{
get_or_import_profile_by_actor_id,
@ -34,7 +36,6 @@ use crate::models::{
types::User,
},
};
use crate::utils::currencies::Currency;
use crate::webfinger::types::ActorAddress;
enum SearchQuery {

View file

@ -1,6 +1,8 @@
use actix_web::{get, post, web, HttpResponse, Scope};
use actix_web_httpauth::extractors::bearer::BearerAuth;
use mitra_utils::passwords::hash_password;
use crate::activitypub::{
builders::{
move_person::prepare_move_person,
@ -20,7 +22,6 @@ use crate::models::{
relationships::queries::{follow, unfollow},
users::queries::set_user_password,
};
use crate::utils::passwords::hash_password;
use super::helpers::{
export_followers,
export_follows,

View file

@ -4,6 +4,11 @@ use actix_web_httpauth::extractors::bearer::BearerAuth;
use chrono::Utc;
use uuid::Uuid;
use mitra_utils::{
currencies::Currency,
markdown::markdown_lite_to_html,
};
use crate::activitypub::builders::{
announce::prepare_announce,
create_note::prepare_create_note,
@ -45,10 +50,6 @@ use crate::models::{
},
relationships::queries::get_subscribers,
};
use crate::utils::{
currencies::Currency,
markdown::markdown_lite_to_html,
};
use super::helpers::{
build_status,
build_status_list,

View file

@ -2,6 +2,8 @@ use actix_web::{get, post, web, HttpResponse, Scope};
use actix_web_httpauth::extractors::bearer::BearerAuth;
use uuid::Uuid;
use mitra_utils::currencies::Currency;
use crate::activitypub::builders::update_person::prepare_update_person;
use crate::config::Config;
use crate::database::{get_database_client, DbPool};
@ -37,7 +39,6 @@ use crate::monero::{
helpers::validate_monero_address,
wallet::create_monero_address,
};
use crate::utils::currencies::Currency;
use super::types::{
Invoice,
InvoiceData,

View file

@ -1,8 +1,9 @@
use std::path::Path;
use mitra_utils::files::sniff_media_type;
use crate::errors::HttpError;
use crate::media::{save_file, SUPPORTED_MEDIA_TYPES};
use crate::utils::files::sniff_media_type;
pub const UPLOAD_MAX_SIZE: usize = 1024 * 1024 * 5;

View file

@ -4,7 +4,7 @@ use std::path::Path;
use sha2::{Digest, Sha256};
use crate::utils::files::{get_media_type_extension, write_file};
use mitra_utils::files::{get_media_type_extension, write_file};
pub const SUPPORTED_MEDIA_TYPES: [&str; 8] = [
"audio/mpeg",
@ -61,7 +61,7 @@ pub fn remove_files(files: Vec<String>, from_dir: &Path) -> () {
#[cfg(test)]
mod tests {
use crate::utils::files::sniff_media_type;
use mitra_utils::files::sniff_media_type;
use super::*;
#[test]

View file

@ -1,13 +1,14 @@
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::database::{DatabaseClient, DatabaseError};
use crate::models::cleanup::{
find_orphaned_files,
find_orphaned_ipfs_objects,
DeletionQueue,
};
use crate::utils::id::generate_ulid;
use super::types::DbMediaAttachment;
pub async fn create_attachment(

View file

@ -1,6 +1,8 @@
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::database::{
catch_unique_violation,
DatabaseClient,
@ -10,7 +12,6 @@ use crate::models::{
cleanup::{find_orphaned_files, DeletionQueue},
instances::queries::create_instance,
};
use crate::utils::id::generate_ulid;
use super::types::{DbEmoji, EmojiImage};
pub async fn create_emoji(

View file

@ -1,14 +1,15 @@
use uuid::Uuid;
use mitra_utils::{
caip2::ChainId,
id::generate_ulid,
};
use crate::database::{
catch_unique_violation,
DatabaseClient,
DatabaseError,
};
use crate::utils::{
caip2::ChainId,
id::generate_ulid,
};
use super::types::{DbChainId, DbInvoice, InvoiceStatus};
pub async fn create_invoice(

View file

@ -11,11 +11,12 @@ use postgres_types::{
};
use uuid::Uuid;
use mitra_utils::caip2::ChainId;
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseTypeError,
};
use crate::utils::caip2::ChainId;
#[derive(Debug)]
pub struct DbChainId(ChainId);

View file

@ -1,6 +1,8 @@
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::database::{
catch_unique_violation,
query_macro::query,
@ -25,7 +27,6 @@ use crate::models::{
profiles::types::DbActorProfile,
relationships::types::RelationshipType,
};
use crate::utils::id::generate_ulid;
use super::types::{
DbPost,
Post,

View file

@ -1,5 +1,6 @@
use mitra_utils::html::clean_html_strict;
use crate::errors::ValidationError;
use crate::utils::html::clean_html_strict;
pub const ATTACHMENTS_MAX_NUM: usize = 15;
pub const EMOJIS_MAX_NUM: usize = 20;

View file

@ -1,6 +1,11 @@
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::{
currencies::Currency,
id::generate_ulid,
};
use crate::database::{
catch_unique_violation,
query_macro::query,
@ -17,10 +22,6 @@ use crate::models::{
instances::queries::create_instance,
relationships::types::RelationshipType,
};
use crate::utils::{
currencies::Currency,
id::generate_ulid,
};
use super::types::{
DbActorProfile,
ExtraFields,

View file

@ -11,6 +11,8 @@ use serde::{
};
use uuid::Uuid;
use mitra_utils::caip2::ChainId;
use crate::activitypub::{
actors::types::Actor,
identifiers::local_actor_id,
@ -24,7 +26,6 @@ use crate::identity::{
did::Did,
signatures::{PROOF_TYPE_ID_EIP191, PROOF_TYPE_ID_MINISIGN},
};
use crate::utils::caip2::ChainId;
use crate::webfinger::types::ActorAddress;
use super::validators::{
validate_username,

View file

@ -1,6 +1,8 @@
use regex::Regex;
use mitra_utils::html::{clean_html, clean_html_strict};
use crate::errors::ValidationError;
use crate::utils::html::{clean_html, clean_html_strict};
use super::types::ExtraField;
const USERNAME_RE: &str = r"^[a-zA-Z0-9_\.-]+$";

View file

@ -1,5 +1,7 @@
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::database::{
catch_unique_violation,
DatabaseClient,
@ -12,7 +14,6 @@ use crate::models::{
get_post_author,
},
};
use crate::utils::id::generate_ulid;
use super::types::DbReaction;
pub async fn create_reaction(

View file

@ -1,5 +1,7 @@
use uuid::Uuid;
use mitra_utils::id::generate_ulid;
use crate::database::{
catch_unique_violation,
DatabaseClient,
@ -14,7 +16,6 @@ use crate::models::{
},
profiles::types::DbActorProfile,
};
use crate::utils::id::generate_ulid;
use super::types::{
DbFollowRequest,
DbRelationship,

View file

@ -1,6 +1,8 @@
use chrono::{DateTime, Utc};
use uuid::Uuid;
use mitra_utils::caip2::ChainId;
use crate::database::{
catch_unique_violation,
DatabaseClient,
@ -12,7 +14,6 @@ use crate::models::{
relationships::queries::{subscribe, subscribe_opt},
relationships::types::RelationshipType,
};
use crate::utils::caip2::ChainId;
use super::types::{DbSubscription, Subscription};
pub async fn create_subscription(

View file

@ -1,5 +1,7 @@
use uuid::Uuid;
use mitra_utils::currencies::Currency;
use crate::database::{
catch_unique_violation,
DatabaseClient,
@ -10,7 +12,6 @@ use crate::models::{
profiles::queries::create_profile,
profiles::types::{DbActorProfile, ProfileCreateData},
};
use crate::utils::currencies::Currency;
use super::types::{DbUser, Role, User, UserCreateData};
use super::utils::generate_invite_code;

View file

@ -3,6 +3,8 @@ use postgres_types::FromSql;
use regex::Regex;
use uuid::Uuid;
use mitra_utils::currencies::Currency;
use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseTypeError,
@ -10,7 +12,6 @@ use crate::database::{
use crate::errors::ValidationError;
use crate::identity::did::Did;
use crate::models::profiles::types::DbActorProfile;
use crate::utils::currencies::Currency;
#[derive(PartialEq)]
pub enum Permission {

View file

@ -1,6 +1,6 @@
use hex;
use crate::utils::random::generate_random_sequence;
use mitra_utils::random::generate_random_sequence;
const INVITE_CODE_LENGTH: usize = 32;