From 95daa94a97541b77af703a42bc1e47ac3ec7155e Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 30 Mar 2023 20:27:17 +0000 Subject: [PATCH] Move contents of database and models modules to mitra-models crate --- Cargo.lock | 34 +++++++--- Cargo.toml | 16 ++--- mitra-cli/Cargo.toml | 1 + mitra-cli/src/cli.rs | 16 ++--- mitra-cli/src/main.rs | 4 +- mitra-models/Cargo.toml | 45 +++++++++++++ .../migrations}/V0001__create_tables.sql | 0 ...V0002__actor_profile__add_extra_fields.sql | 0 .../V0003__post__add_in_reply_to.sql | 0 .../V0004__post__add_reply_count.sql | 0 .../V0005__media_attachment__add_ipfs_cid.sql | 0 .../migrations}/V0006__oauth_token.sql | 0 .../V0007__post__add_object_id.sql | 0 .../migrations}/V0008__notification.sql | 0 .../migrations}/V0009__post_reaction.sql | 0 .../migrations}/V0010__timeline_marker.sql | 0 .../migrations}/V0011__mention.sql | 0 .../V0012__post__add_visibility.sql | 0 .../V0013__post__add_repost_fields.sql | 0 .../migrations}/V0014__post_tag.sql | 0 .../V0015__post_reaction__add_activity_id.sql | 0 ..._user_account__nullable_wallet_address.sql | 0 ..._profile__increase_display_name_length.sql | 0 .../V0018__relationship__add_id.sql | 0 ...9__relationship__add_relationship_type.sql | 0 .../migrations}/V0020__subscription.sql | 0 ...__user_account__nullable_password_hash.sql | 0 .../V0022__actor_profile__add_actor_id.sql | 0 ...23__actor_profile__add_identity_proofs.sql | 0 .../V0024__post__add_updated_at.sql | 0 .../V0025__actor_profile__add_updated_at.sql | 0 ...26__actor_profile__add_payment_options.sql | 0 .../migrations}/V0027__post_link.sql | 0 ...__actor_profile__clear_payment_options.sql | 0 .../V0029__subscription__add_chain_id.sql | 0 .../migrations}/V0030__invoice.sql | 0 ..._subscription__sender_address_nullable.sql | 0 ...2__actor_profile__add_subscriber_count.sql | 0 .../V0033__invoice__add_amount.sql | 0 .../V0034__actor_profile__add_hostname.sql | 0 .../migrations}/V0035__background_job.sql | 0 ...V0036__follow_request__add_activity_id.sql | 0 ...__actor_profile__add_unreachable_since.sql | 0 .../V0038__actor_profile__image_json.sql | 0 .../migrations}/V0039__emoji.sql | 0 ...V0040__media_attachment__add_file_size.sql | 0 .../V0041__user_account__user_role.sql | 0 .../migrations}/V0042__oauth_application.sql | 0 .../V0043__oauth_authorization.sql | 0 ...r_invite_code__add_note_and_created_at.sql | 0 .../migrations}/V0045__profile_emoji.sql | 0 .../V0046__actor_profile__add_emoji.sql | 0 .../migrations}/V0047__internal_property.sql | 0 ...or_profile__identity_proof_type_number.sql | 0 ...ofile__add_manually_approves_followers.sql | 0 .../V0050__actor_profile__add_aliases.sql | 0 .../migrations}/schema.sql | 0 .../src}/attachments/mod.rs | 0 .../src}/attachments/queries.rs | 11 ++-- .../src}/attachments/types.rs | 0 .../src}/background_jobs/mod.rs | 0 .../src}/background_jobs/queries.rs | 0 .../src}/background_jobs/types.rs | 0 {src/models => mitra-models/src}/cleanup.rs | 0 .../src}/database/int_enum.rs | 0 .../src}/database/json_macro.rs | 0 {src => mitra-models/src}/database/migrate.rs | 0 {src => mitra-models/src}/database/mod.rs | 2 +- .../src}/database/query_macro.rs | 0 .../src}/database/test_utils.rs | 0 .../src}/emojis/helpers.rs | 1 + .../models => mitra-models/src}/emojis/mod.rs | 0 .../src}/emojis/queries.rs | 9 ++- .../src}/emojis/types.rs | 4 +- .../src}/instances/mod.rs | 0 .../src}/instances/queries.rs | 0 .../src}/invoices/mod.rs | 0 .../src}/invoices/queries.rs | 13 ++-- .../src}/invoices/types.rs | 0 src/models/mod.rs => mitra-models/src/lib.rs | 1 + .../src}/markers/mod.rs | 0 .../src}/markers/queries.rs | 0 .../src}/markers/types.rs | 0 .../src}/notifications/mod.rs | 0 .../src}/notifications/queries.rs | 7 +- .../src}/notifications/types.rs | 10 ++- {src/models => mitra-models/src}/oauth/mod.rs | 0 .../src}/oauth/queries.rs | 13 ++-- .../src}/oauth/types.rs | 0 .../src}/posts/helpers.rs | 25 ++++---- {src/models => mitra-models/src}/posts/mod.rs | 0 .../src}/posts/queries.rs | 59 +++++++++-------- .../src}/posts/types.rs | 10 ++- .../src}/profiles/helpers.rs | 1 + .../src}/profiles/mod.rs | 0 .../src}/profiles/queries.rs | 37 ++++++----- .../src}/profiles/types.rs | 10 +-- .../src}/properties/mod.rs | 0 .../src}/properties/queries.rs | 0 .../src}/reactions/mod.rs | 0 .../src}/reactions/queries.rs | 11 ++-- .../src}/reactions/types.rs | 0 .../src}/relationships/mod.rs | 0 .../src}/relationships/queries.rs | 21 +++--- .../src}/relationships/types.rs | 12 ++-- .../src}/subscriptions/mod.rs | 0 .../src}/subscriptions/queries.rs | 29 +++++---- .../src}/subscriptions/types.rs | 6 +- {src/models => mitra-models/src}/tags/mod.rs | 0 .../src}/tags/queries.rs | 0 {src/models => mitra-models/src}/users/mod.rs | 0 .../src}/users/queries.rs | 9 +-- .../src}/users/types.rs | 6 +- .../src}/users/utils.rs | 0 src/activitypub/actors/attachments.rs | 15 +++-- src/activitypub/actors/helpers.rs | 22 +++---- src/activitypub/actors/types.rs | 23 +++---- src/activitypub/authentication.rs | 11 ++-- src/activitypub/builders/accept_follow.rs | 8 +-- src/activitypub/builders/add_person.rs | 8 +-- src/activitypub/builders/announce.rs | 16 ++--- src/activitypub/builders/create_note.rs | 20 +++--- src/activitypub/builders/delete_note.rs | 15 +++-- src/activitypub/builders/delete_person.rs | 14 ++-- src/activitypub/builders/follow.rs | 8 +-- src/activitypub/builders/like.rs | 12 ++-- src/activitypub/builders/move_person.rs | 10 +-- src/activitypub/builders/remove_person.rs | 9 +-- src/activitypub/builders/undo_announce.rs | 12 ++-- src/activitypub/builders/undo_follow.rs | 9 +-- src/activitypub/builders/undo_like.rs | 13 ++-- src/activitypub/builders/update_person.rs | 14 ++-- src/activitypub/deliverer.rs | 17 ++--- src/activitypub/fetcher/helpers.rs | 24 +++---- src/activitypub/handlers/accept.rs | 19 +++--- src/activitypub/handlers/add.rs | 12 ++-- src/activitypub/handlers/announce.rs | 16 ++--- src/activitypub/handlers/create.rs | 34 +++++----- src/activitypub/handlers/delete.rs | 19 +++--- src/activitypub/handlers/follow.rs | 16 ++--- src/activitypub/handlers/like.rs | 9 +-- src/activitypub/handlers/move.rs | 23 +++---- src/activitypub/handlers/reject.rs | 19 +++--- src/activitypub/handlers/remove.rs | 17 ++--- src/activitypub/handlers/undo.rs | 19 +++--- src/activitypub/handlers/update.rs | 19 +++--- src/activitypub/identifiers.rs | 5 +- src/activitypub/queues.rs | 18 +++--- src/activitypub/receiver.rs | 2 +- src/activitypub/views.rs | 8 +-- src/atom/feeds.rs | 8 +-- src/atom/views.rs | 8 +-- src/errors.rs | 2 +- src/ethereum/contracts.rs | 2 +- src/ethereum/errors.rs | 3 +- src/ethereum/nft.rs | 9 +-- src/ethereum/subscriptions.rs | 33 +++++----- src/ethereum/sync.rs | 11 ++-- src/ipfs/posts.rs | 2 +- src/job_queue/periodic_tasks.rs | 34 +++++----- src/job_queue/scheduler.rs | 2 +- src/lib.rs | 2 - src/main.rs | 4 +- src/mastodon_api/accounts/helpers.rs | 35 +++++----- src/mastodon_api/accounts/types.rs | 32 +++++----- src/mastodon_api/accounts/views.rs | 64 +++++++++---------- src/mastodon_api/apps/views.rs | 11 ++-- src/mastodon_api/custom_emojis/types.rs | 3 +- src/mastodon_api/custom_emojis/views.rs | 7 +- src/mastodon_api/directory/views.rs | 6 +- src/mastodon_api/errors.rs | 3 +- src/mastodon_api/instance/views.rs | 11 ++-- src/mastodon_api/markers/types.rs | 3 +- src/mastodon_api/markers/views.rs | 14 ++-- src/mastodon_api/media/types.rs | 5 +- src/mastodon_api/media/views.rs | 6 +- src/mastodon_api/notifications/types.rs | 3 +- src/mastodon_api/notifications/views.rs | 6 +- src/mastodon_api/oauth/auth.rs | 7 +- src/mastodon_api/oauth/views.rs | 23 +++---- src/mastodon_api/search/helpers.rs | 38 +++++------ src/mastodon_api/search/views.rs | 2 +- src/mastodon_api/settings/helpers.rs | 38 +++++------ src/mastodon_api/settings/views.rs | 12 ++-- src/mastodon_api/statuses/helpers.rs | 6 +- .../statuses/microsyntax/emojis.rs | 5 +- .../statuses/microsyntax/links.rs | 7 +- .../statuses/microsyntax/mentions.rs | 9 +-- src/mastodon_api/statuses/types.rs | 11 ++-- src/mastodon_api/statuses/views.rs | 52 +++++++-------- src/mastodon_api/subscriptions/types.rs | 3 +- src/mastodon_api/subscriptions/views.rs | 38 +++++------ src/mastodon_api/timelines/views.rs | 14 ++-- src/media.rs | 2 +- src/monero/helpers.rs | 9 +-- src/monero/subscriptions.rs | 9 +-- src/monero/wallet.rs | 3 +- src/nodeinfo/helpers.rs | 5 +- src/nodeinfo/views.rs | 2 +- src/validators/profiles.rs | 10 +-- src/web_client/views.rs | 10 +-- src/webfinger/types.rs | 5 +- src/webfinger/views.rs | 17 +++-- 203 files changed, 882 insertions(+), 742 deletions(-) create mode 100644 mitra-models/Cargo.toml rename {migrations => mitra-models/migrations}/V0001__create_tables.sql (100%) rename {migrations => mitra-models/migrations}/V0002__actor_profile__add_extra_fields.sql (100%) rename {migrations => mitra-models/migrations}/V0003__post__add_in_reply_to.sql (100%) rename {migrations => mitra-models/migrations}/V0004__post__add_reply_count.sql (100%) rename {migrations => mitra-models/migrations}/V0005__media_attachment__add_ipfs_cid.sql (100%) rename {migrations => mitra-models/migrations}/V0006__oauth_token.sql (100%) rename {migrations => mitra-models/migrations}/V0007__post__add_object_id.sql (100%) rename {migrations => mitra-models/migrations}/V0008__notification.sql (100%) rename {migrations => mitra-models/migrations}/V0009__post_reaction.sql (100%) rename {migrations => mitra-models/migrations}/V0010__timeline_marker.sql (100%) rename {migrations => mitra-models/migrations}/V0011__mention.sql (100%) rename {migrations => mitra-models/migrations}/V0012__post__add_visibility.sql (100%) rename {migrations => mitra-models/migrations}/V0013__post__add_repost_fields.sql (100%) rename {migrations => mitra-models/migrations}/V0014__post_tag.sql (100%) rename {migrations => mitra-models/migrations}/V0015__post_reaction__add_activity_id.sql (100%) rename {migrations => mitra-models/migrations}/V0016__user_account__nullable_wallet_address.sql (100%) rename {migrations => mitra-models/migrations}/V0017__actor_profile__increase_display_name_length.sql (100%) rename {migrations => mitra-models/migrations}/V0018__relationship__add_id.sql (100%) rename {migrations => mitra-models/migrations}/V0019__relationship__add_relationship_type.sql (100%) rename {migrations => mitra-models/migrations}/V0020__subscription.sql (100%) rename {migrations => mitra-models/migrations}/V0021__user_account__nullable_password_hash.sql (100%) rename {migrations => mitra-models/migrations}/V0022__actor_profile__add_actor_id.sql (100%) rename {migrations => mitra-models/migrations}/V0023__actor_profile__add_identity_proofs.sql (100%) rename {migrations => mitra-models/migrations}/V0024__post__add_updated_at.sql (100%) rename {migrations => mitra-models/migrations}/V0025__actor_profile__add_updated_at.sql (100%) rename {migrations => mitra-models/migrations}/V0026__actor_profile__add_payment_options.sql (100%) rename {migrations => mitra-models/migrations}/V0027__post_link.sql (100%) rename {migrations => mitra-models/migrations}/V0028__actor_profile__clear_payment_options.sql (100%) rename {migrations => mitra-models/migrations}/V0029__subscription__add_chain_id.sql (100%) rename {migrations => mitra-models/migrations}/V0030__invoice.sql (100%) rename {migrations => mitra-models/migrations}/V0031__subscription__sender_address_nullable.sql (100%) rename {migrations => mitra-models/migrations}/V0032__actor_profile__add_subscriber_count.sql (100%) rename {migrations => mitra-models/migrations}/V0033__invoice__add_amount.sql (100%) rename {migrations => mitra-models/migrations}/V0034__actor_profile__add_hostname.sql (100%) rename {migrations => mitra-models/migrations}/V0035__background_job.sql (100%) rename {migrations => mitra-models/migrations}/V0036__follow_request__add_activity_id.sql (100%) rename {migrations => mitra-models/migrations}/V0037__actor_profile__add_unreachable_since.sql (100%) rename {migrations => mitra-models/migrations}/V0038__actor_profile__image_json.sql (100%) rename {migrations => mitra-models/migrations}/V0039__emoji.sql (100%) rename {migrations => mitra-models/migrations}/V0040__media_attachment__add_file_size.sql (100%) rename {migrations => mitra-models/migrations}/V0041__user_account__user_role.sql (100%) rename {migrations => mitra-models/migrations}/V0042__oauth_application.sql (100%) rename {migrations => mitra-models/migrations}/V0043__oauth_authorization.sql (100%) rename {migrations => mitra-models/migrations}/V0044__user_invite_code__add_note_and_created_at.sql (100%) rename {migrations => mitra-models/migrations}/V0045__profile_emoji.sql (100%) rename {migrations => mitra-models/migrations}/V0046__actor_profile__add_emoji.sql (100%) rename {migrations => mitra-models/migrations}/V0047__internal_property.sql (100%) rename {migrations => mitra-models/migrations}/V0048__actor_profile__identity_proof_type_number.sql (100%) rename {migrations => mitra-models/migrations}/V0049__actor_profile__add_manually_approves_followers.sql (100%) rename {migrations => mitra-models/migrations}/V0050__actor_profile__add_aliases.sql (100%) rename {migrations => mitra-models/migrations}/schema.sql (100%) rename {src/models => mitra-models/src}/attachments/mod.rs (100%) rename {src/models => mitra-models/src}/attachments/queries.rs (96%) rename {src/models => mitra-models/src}/attachments/types.rs (100%) rename {src/models => mitra-models/src}/background_jobs/mod.rs (100%) rename {src/models => mitra-models/src}/background_jobs/queries.rs (100%) rename {src/models => mitra-models/src}/background_jobs/types.rs (100%) rename {src/models => mitra-models/src}/cleanup.rs (100%) rename {src => mitra-models/src}/database/int_enum.rs (100%) rename {src => mitra-models/src}/database/json_macro.rs (100%) rename {src => mitra-models/src}/database/migrate.rs (100%) rename {src => mitra-models/src}/database/mod.rs (98%) rename {src => mitra-models/src}/database/query_macro.rs (100%) rename {src => mitra-models/src}/database/test_utils.rs (100%) rename {src/models => mitra-models/src}/emojis/helpers.rs (99%) rename {src/models => mitra-models/src}/emojis/mod.rs (100%) rename {src/models => mitra-models/src}/emojis/queries.rs (97%) rename {src/models => mitra-models/src}/emojis/types.rs (87%) rename {src/models => mitra-models/src}/instances/mod.rs (100%) rename {src/models => mitra-models/src}/instances/queries.rs (100%) rename {src/models => mitra-models/src}/invoices/mod.rs (100%) rename {src/models => mitra-models/src}/invoices/queries.rs (95%) rename {src/models => mitra-models/src}/invoices/types.rs (100%) rename src/models/mod.rs => mitra-models/src/lib.rs (94%) rename {src/models => mitra-models/src}/markers/mod.rs (100%) rename {src/models => mitra-models/src}/markers/queries.rs (100%) rename {src/models => mitra-models/src}/markers/types.rs (100%) rename {src/models => mitra-models/src}/notifications/mod.rs (100%) rename {src/models => mitra-models/src}/notifications/queries.rs (97%) rename {src/models => mitra-models/src}/notifications/types.rs (95%) rename {src/models => mitra-models/src}/oauth/mod.rs (100%) rename {src/models => mitra-models/src}/oauth/queries.rs (97%) rename {src/models => mitra-models/src}/oauth/types.rs (100%) rename {src/models => mitra-models/src}/posts/helpers.rs (95%) rename {src/models => mitra-models/src}/posts/mod.rs (100%) rename {src/models => mitra-models/src}/posts/queries.rs (98%) rename {src/models => mitra-models/src}/posts/types.rs (97%) rename {src/models => mitra-models/src}/profiles/helpers.rs (99%) rename {src/models => mitra-models/src}/profiles/mod.rs (100%) rename {src/models => mitra-models/src}/profiles/queries.rs (98%) rename {src/models => mitra-models/src}/profiles/types.rs (98%) rename {src/models => mitra-models/src}/properties/mod.rs (100%) rename {src/models => mitra-models/src}/properties/queries.rs (100%) rename {src/models => mitra-models/src}/reactions/mod.rs (100%) rename {src/models => mitra-models/src}/reactions/queries.rs (95%) rename {src/models => mitra-models/src}/reactions/types.rs (100%) rename {src/models => mitra-models/src}/relationships/mod.rs (100%) rename {src/models => mitra-models/src}/relationships/queries.rs (98%) rename {src/models => mitra-models/src}/relationships/types.rs (95%) rename {src/models => mitra-models/src}/subscriptions/mod.rs (100%) rename {src/models => mitra-models/src}/subscriptions/queries.rs (93%) rename {src/models => mitra-models/src}/subscriptions/types.rs (92%) rename {src/models => mitra-models/src}/tags/mod.rs (100%) rename {src/models => mitra-models/src}/tags/queries.rs (100%) rename {src/models => mitra-models/src}/users/mod.rs (100%) rename {src/models => mitra-models/src}/users/queries.rs (98%) rename {src/models => mitra-models/src}/users/types.rs (96%) rename {src/models => mitra-models/src}/users/utils.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 1b78f03..2fad7e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1832,22 +1832,16 @@ dependencies = [ "base64", "blake2", "chrono", - "deadpool", - "deadpool-postgres", "ed25519", "ed25519-dalek", "env_logger", "hex", "log", "mitra-config", + "mitra-models", "mitra-utils", "monero-rpc", "num_cpus", - "postgres-protocol", - "postgres-types", - "postgres_query", - "postgres_query_macro", - "refinery", "regex", "reqwest", "rsa", @@ -1859,7 +1853,6 @@ dependencies = [ "siwe", "thiserror", "tokio", - "tokio-postgres", "url 2.2.2", "uuid", "web3", @@ -1874,6 +1867,7 @@ dependencies = [ "log", "mitra", "mitra-config", + "mitra-models", "mitra-utils", "tokio", "uuid", @@ -1894,6 +1888,30 @@ dependencies = [ "url 2.2.2", ] +[[package]] +name = "mitra-models" +version = "1.19.0" +dependencies = [ + "chrono", + "deadpool", + "deadpool-postgres", + "hex", + "log", + "mitra-utils", + "postgres-protocol", + "postgres-types", + "postgres_query", + "postgres_query_macro", + "refinery", + "serde", + "serde_json", + "serial_test", + "thiserror", + "tokio", + "tokio-postgres", + "uuid", +] + [[package]] name = "mitra-utils" version = "1.19.0" diff --git a/Cargo.toml b/Cargo.toml index f86d3b8..08ed909 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,17 +14,20 @@ members = [ ".", "mitra-cli", "mitra-config", + "mitra-models", "mitra-utils", ] default-members = [ ".", "mitra-cli", "mitra-config", + "mitra-models", "mitra-utils", ] [dependencies] mitra-config = { path = "mitra-config" } +mitra-models = { path = "mitra-models" } mitra-utils = { path = "mitra-utils" } # Used to handle incoming HTTP requests @@ -38,9 +41,6 @@ anyhow = "1.0.58" base64 = "0.13.0" # Used for working with dates chrono = { version = "0.4.23", default-features = false, features = ["std", "serde"] } -# Used for pooling database connections -deadpool = "0.9.2" -deadpool-postgres = { version = "0.10.2", default-features = false } # Used to work with hexadecimal strings hex = { version = "0.4.3", features = ["serde"] } # Used for logging @@ -56,8 +56,6 @@ monero-rpc = "0.3.2" num_cpus = "1.13.0" # Used for working with regular expressions regex = "1.6.0" -# Used for managing database migrations -refinery = { version = "0.8.4", features = ["tokio-postgres"] } # Used for making async HTTP requests reqwest = { version = "0.11.13", features = ["json", "multipart", "socks"] } # Used for working with RSA keys @@ -75,13 +73,6 @@ siwe = "0.4.0" thiserror = "1.0.37" # Async runtime tokio = { version = "1.20.4", features = ["macros"] } -# Used for working with Postgresql database -tokio-postgres = { version = "0.7.6", features = ["with-chrono-0_4", "with-uuid-1", "with-serde_json-1"] } -postgres-types = { version = "0.2.3", features = ["derive", "with-chrono-0_4", "with-uuid-1", "with-serde_json-1"] } -postgres-protocol = "0.6.4" -# Used to construct PostgreSQL queries -postgres_query = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" } -postgres_query_macro = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" } # Used to work with URLs url = "2.2.2" # Used to work with UUIDs @@ -91,6 +82,7 @@ web3 = { version = "0.18.0", default-features = false, features = ["http", "http [dev-dependencies] mitra-config = { path = "mitra-config", features = ["test-utils"] } +mitra-models = { path = "mitra-models", features = ["test-utils"] } mitra-utils = { path = "mitra-utils", features = ["test-utils"] } serial_test = "0.7.0" diff --git a/mitra-cli/Cargo.toml b/mitra-cli/Cargo.toml index 45509d5..5847e76 100644 --- a/mitra-cli/Cargo.toml +++ b/mitra-cli/Cargo.toml @@ -11,6 +11,7 @@ path = "src/main.rs" [dependencies] mitra-config = { path = "../mitra-config" } +mitra-models = { path = "../mitra-models" } mitra-utils = { path = "../mitra-utils" } mitra = { path = ".." } diff --git a/mitra-cli/src/cli.rs b/mitra-cli/src/cli.rs index 5a63bfc..5ccdbd8 100644 --- a/mitra-cli/src/cli.rs +++ b/mitra-cli/src/cli.rs @@ -8,7 +8,6 @@ use mitra::activitypub::{ builders::delete_person::prepare_delete_person, fetcher::fetchers::fetch_actor, }; -use mitra::database::DatabaseClient; use mitra::ethereum::{ signatures::generate_ecdsa_key, sync::save_current_block_number, @@ -19,9 +18,16 @@ use mitra::media::{ remove_media, MediaStorage, }; -use mitra::models::{ +use mitra::monero::{ + helpers::check_expired_invoice, + wallet::create_monero_wallet, +}; +use mitra::validators::emojis::EMOJI_LOCAL_MAX_SIZE; +use mitra_config::Config; +use mitra_models::{ attachments::queries::delete_unused_attachments, cleanup::find_orphaned_files, + database::DatabaseClient, emojis::helpers::get_emoji_by_name, emojis::queries::{ create_emoji, @@ -48,12 +54,6 @@ use mitra::models::{ }, users::types::Role, }; -use mitra::monero::{ - helpers::check_expired_invoice, - wallet::create_monero_wallet, -}; -use mitra::validators::emojis::EMOJI_LOCAL_MAX_SIZE; -use mitra_config::Config; use mitra_utils::{ crypto_rsa::{ generate_rsa_key, diff --git a/mitra-cli/src/main.rs b/mitra-cli/src/main.rs index df48ab9..30c2221 100644 --- a/mitra-cli/src/main.rs +++ b/mitra-cli/src/main.rs @@ -1,9 +1,9 @@ use clap::Parser; -use mitra::database::create_database_client; -use mitra::database::migrate::apply_migrations; use mitra::logger::configure_logger; use mitra_config::parse_config; +use mitra_models::database::create_database_client; +use mitra_models::database::migrate::apply_migrations; mod cli; use cli::{Opts, SubCommand}; diff --git a/mitra-models/Cargo.toml b/mitra-models/Cargo.toml new file mode 100644 index 0000000..0aed989 --- /dev/null +++ b/mitra-models/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "mitra-models" +version = "1.19.0" +license = "AGPL-3.0" +edition = "2021" +rust-version = "1.56" + +[dependencies] +mitra-utils = { path = "../mitra-utils" } + +# Used for working with dates +chrono = { version = "0.4.23", default-features = false, features = ["std", "serde"] } +# Used for pooling database connections +deadpool = "0.9.2" +deadpool-postgres = { version = "0.10.2", default-features = false } +# Used to work with hexadecimal strings +hex = { version = "0.4.3", features = ["serde"] } +# Used for logging +log = "0.4.14" +# Used for managing database migrations +refinery = { version = "0.8.4", features = ["tokio-postgres"] } +# Used for serialization/deserialization +serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0.89" +# Used for creating error types +thiserror = "1.0.37" +# Async runtime +tokio = { version = "1.20.4", features = [] } +# Used for working with Postgresql database +tokio-postgres = { version = "0.7.6", features = ["with-chrono-0_4", "with-uuid-1", "with-serde_json-1"] } +postgres-types = { version = "0.2.3", features = ["derive", "with-chrono-0_4", "with-uuid-1", "with-serde_json-1"] } +postgres-protocol = "0.6.4" +# Used to construct PostgreSQL queries +postgres_query = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" } +postgres_query_macro = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" } +# Used to work with UUIDs +uuid = { version = "1.1.2", features = ["serde", "v4"] } + +[dev-dependencies] +mitra-utils = { path = "../mitra-utils", features = ["test-utils"] } + +serial_test = "0.7.0" + +[features] +test-utils = [] diff --git a/migrations/V0001__create_tables.sql b/mitra-models/migrations/V0001__create_tables.sql similarity index 100% rename from migrations/V0001__create_tables.sql rename to mitra-models/migrations/V0001__create_tables.sql diff --git a/migrations/V0002__actor_profile__add_extra_fields.sql b/mitra-models/migrations/V0002__actor_profile__add_extra_fields.sql similarity index 100% rename from migrations/V0002__actor_profile__add_extra_fields.sql rename to mitra-models/migrations/V0002__actor_profile__add_extra_fields.sql diff --git a/migrations/V0003__post__add_in_reply_to.sql b/mitra-models/migrations/V0003__post__add_in_reply_to.sql similarity index 100% rename from migrations/V0003__post__add_in_reply_to.sql rename to mitra-models/migrations/V0003__post__add_in_reply_to.sql diff --git a/migrations/V0004__post__add_reply_count.sql b/mitra-models/migrations/V0004__post__add_reply_count.sql similarity index 100% rename from migrations/V0004__post__add_reply_count.sql rename to mitra-models/migrations/V0004__post__add_reply_count.sql diff --git a/migrations/V0005__media_attachment__add_ipfs_cid.sql b/mitra-models/migrations/V0005__media_attachment__add_ipfs_cid.sql similarity index 100% rename from migrations/V0005__media_attachment__add_ipfs_cid.sql rename to mitra-models/migrations/V0005__media_attachment__add_ipfs_cid.sql diff --git a/migrations/V0006__oauth_token.sql b/mitra-models/migrations/V0006__oauth_token.sql similarity index 100% rename from migrations/V0006__oauth_token.sql rename to mitra-models/migrations/V0006__oauth_token.sql diff --git a/migrations/V0007__post__add_object_id.sql b/mitra-models/migrations/V0007__post__add_object_id.sql similarity index 100% rename from migrations/V0007__post__add_object_id.sql rename to mitra-models/migrations/V0007__post__add_object_id.sql diff --git a/migrations/V0008__notification.sql b/mitra-models/migrations/V0008__notification.sql similarity index 100% rename from migrations/V0008__notification.sql rename to mitra-models/migrations/V0008__notification.sql diff --git a/migrations/V0009__post_reaction.sql b/mitra-models/migrations/V0009__post_reaction.sql similarity index 100% rename from migrations/V0009__post_reaction.sql rename to mitra-models/migrations/V0009__post_reaction.sql diff --git a/migrations/V0010__timeline_marker.sql b/mitra-models/migrations/V0010__timeline_marker.sql similarity index 100% rename from migrations/V0010__timeline_marker.sql rename to mitra-models/migrations/V0010__timeline_marker.sql diff --git a/migrations/V0011__mention.sql b/mitra-models/migrations/V0011__mention.sql similarity index 100% rename from migrations/V0011__mention.sql rename to mitra-models/migrations/V0011__mention.sql diff --git a/migrations/V0012__post__add_visibility.sql b/mitra-models/migrations/V0012__post__add_visibility.sql similarity index 100% rename from migrations/V0012__post__add_visibility.sql rename to mitra-models/migrations/V0012__post__add_visibility.sql diff --git a/migrations/V0013__post__add_repost_fields.sql b/mitra-models/migrations/V0013__post__add_repost_fields.sql similarity index 100% rename from migrations/V0013__post__add_repost_fields.sql rename to mitra-models/migrations/V0013__post__add_repost_fields.sql diff --git a/migrations/V0014__post_tag.sql b/mitra-models/migrations/V0014__post_tag.sql similarity index 100% rename from migrations/V0014__post_tag.sql rename to mitra-models/migrations/V0014__post_tag.sql diff --git a/migrations/V0015__post_reaction__add_activity_id.sql b/mitra-models/migrations/V0015__post_reaction__add_activity_id.sql similarity index 100% rename from migrations/V0015__post_reaction__add_activity_id.sql rename to mitra-models/migrations/V0015__post_reaction__add_activity_id.sql diff --git a/migrations/V0016__user_account__nullable_wallet_address.sql b/mitra-models/migrations/V0016__user_account__nullable_wallet_address.sql similarity index 100% rename from migrations/V0016__user_account__nullable_wallet_address.sql rename to mitra-models/migrations/V0016__user_account__nullable_wallet_address.sql diff --git a/migrations/V0017__actor_profile__increase_display_name_length.sql b/mitra-models/migrations/V0017__actor_profile__increase_display_name_length.sql similarity index 100% rename from migrations/V0017__actor_profile__increase_display_name_length.sql rename to mitra-models/migrations/V0017__actor_profile__increase_display_name_length.sql diff --git a/migrations/V0018__relationship__add_id.sql b/mitra-models/migrations/V0018__relationship__add_id.sql similarity index 100% rename from migrations/V0018__relationship__add_id.sql rename to mitra-models/migrations/V0018__relationship__add_id.sql diff --git a/migrations/V0019__relationship__add_relationship_type.sql b/mitra-models/migrations/V0019__relationship__add_relationship_type.sql similarity index 100% rename from migrations/V0019__relationship__add_relationship_type.sql rename to mitra-models/migrations/V0019__relationship__add_relationship_type.sql diff --git a/migrations/V0020__subscription.sql b/mitra-models/migrations/V0020__subscription.sql similarity index 100% rename from migrations/V0020__subscription.sql rename to mitra-models/migrations/V0020__subscription.sql diff --git a/migrations/V0021__user_account__nullable_password_hash.sql b/mitra-models/migrations/V0021__user_account__nullable_password_hash.sql similarity index 100% rename from migrations/V0021__user_account__nullable_password_hash.sql rename to mitra-models/migrations/V0021__user_account__nullable_password_hash.sql diff --git a/migrations/V0022__actor_profile__add_actor_id.sql b/mitra-models/migrations/V0022__actor_profile__add_actor_id.sql similarity index 100% rename from migrations/V0022__actor_profile__add_actor_id.sql rename to mitra-models/migrations/V0022__actor_profile__add_actor_id.sql diff --git a/migrations/V0023__actor_profile__add_identity_proofs.sql b/mitra-models/migrations/V0023__actor_profile__add_identity_proofs.sql similarity index 100% rename from migrations/V0023__actor_profile__add_identity_proofs.sql rename to mitra-models/migrations/V0023__actor_profile__add_identity_proofs.sql diff --git a/migrations/V0024__post__add_updated_at.sql b/mitra-models/migrations/V0024__post__add_updated_at.sql similarity index 100% rename from migrations/V0024__post__add_updated_at.sql rename to mitra-models/migrations/V0024__post__add_updated_at.sql diff --git a/migrations/V0025__actor_profile__add_updated_at.sql b/mitra-models/migrations/V0025__actor_profile__add_updated_at.sql similarity index 100% rename from migrations/V0025__actor_profile__add_updated_at.sql rename to mitra-models/migrations/V0025__actor_profile__add_updated_at.sql diff --git a/migrations/V0026__actor_profile__add_payment_options.sql b/mitra-models/migrations/V0026__actor_profile__add_payment_options.sql similarity index 100% rename from migrations/V0026__actor_profile__add_payment_options.sql rename to mitra-models/migrations/V0026__actor_profile__add_payment_options.sql diff --git a/migrations/V0027__post_link.sql b/mitra-models/migrations/V0027__post_link.sql similarity index 100% rename from migrations/V0027__post_link.sql rename to mitra-models/migrations/V0027__post_link.sql diff --git a/migrations/V0028__actor_profile__clear_payment_options.sql b/mitra-models/migrations/V0028__actor_profile__clear_payment_options.sql similarity index 100% rename from migrations/V0028__actor_profile__clear_payment_options.sql rename to mitra-models/migrations/V0028__actor_profile__clear_payment_options.sql diff --git a/migrations/V0029__subscription__add_chain_id.sql b/mitra-models/migrations/V0029__subscription__add_chain_id.sql similarity index 100% rename from migrations/V0029__subscription__add_chain_id.sql rename to mitra-models/migrations/V0029__subscription__add_chain_id.sql diff --git a/migrations/V0030__invoice.sql b/mitra-models/migrations/V0030__invoice.sql similarity index 100% rename from migrations/V0030__invoice.sql rename to mitra-models/migrations/V0030__invoice.sql diff --git a/migrations/V0031__subscription__sender_address_nullable.sql b/mitra-models/migrations/V0031__subscription__sender_address_nullable.sql similarity index 100% rename from migrations/V0031__subscription__sender_address_nullable.sql rename to mitra-models/migrations/V0031__subscription__sender_address_nullable.sql diff --git a/migrations/V0032__actor_profile__add_subscriber_count.sql b/mitra-models/migrations/V0032__actor_profile__add_subscriber_count.sql similarity index 100% rename from migrations/V0032__actor_profile__add_subscriber_count.sql rename to mitra-models/migrations/V0032__actor_profile__add_subscriber_count.sql diff --git a/migrations/V0033__invoice__add_amount.sql b/mitra-models/migrations/V0033__invoice__add_amount.sql similarity index 100% rename from migrations/V0033__invoice__add_amount.sql rename to mitra-models/migrations/V0033__invoice__add_amount.sql diff --git a/migrations/V0034__actor_profile__add_hostname.sql b/mitra-models/migrations/V0034__actor_profile__add_hostname.sql similarity index 100% rename from migrations/V0034__actor_profile__add_hostname.sql rename to mitra-models/migrations/V0034__actor_profile__add_hostname.sql diff --git a/migrations/V0035__background_job.sql b/mitra-models/migrations/V0035__background_job.sql similarity index 100% rename from migrations/V0035__background_job.sql rename to mitra-models/migrations/V0035__background_job.sql diff --git a/migrations/V0036__follow_request__add_activity_id.sql b/mitra-models/migrations/V0036__follow_request__add_activity_id.sql similarity index 100% rename from migrations/V0036__follow_request__add_activity_id.sql rename to mitra-models/migrations/V0036__follow_request__add_activity_id.sql diff --git a/migrations/V0037__actor_profile__add_unreachable_since.sql b/mitra-models/migrations/V0037__actor_profile__add_unreachable_since.sql similarity index 100% rename from migrations/V0037__actor_profile__add_unreachable_since.sql rename to mitra-models/migrations/V0037__actor_profile__add_unreachable_since.sql diff --git a/migrations/V0038__actor_profile__image_json.sql b/mitra-models/migrations/V0038__actor_profile__image_json.sql similarity index 100% rename from migrations/V0038__actor_profile__image_json.sql rename to mitra-models/migrations/V0038__actor_profile__image_json.sql diff --git a/migrations/V0039__emoji.sql b/mitra-models/migrations/V0039__emoji.sql similarity index 100% rename from migrations/V0039__emoji.sql rename to mitra-models/migrations/V0039__emoji.sql diff --git a/migrations/V0040__media_attachment__add_file_size.sql b/mitra-models/migrations/V0040__media_attachment__add_file_size.sql similarity index 100% rename from migrations/V0040__media_attachment__add_file_size.sql rename to mitra-models/migrations/V0040__media_attachment__add_file_size.sql diff --git a/migrations/V0041__user_account__user_role.sql b/mitra-models/migrations/V0041__user_account__user_role.sql similarity index 100% rename from migrations/V0041__user_account__user_role.sql rename to mitra-models/migrations/V0041__user_account__user_role.sql diff --git a/migrations/V0042__oauth_application.sql b/mitra-models/migrations/V0042__oauth_application.sql similarity index 100% rename from migrations/V0042__oauth_application.sql rename to mitra-models/migrations/V0042__oauth_application.sql diff --git a/migrations/V0043__oauth_authorization.sql b/mitra-models/migrations/V0043__oauth_authorization.sql similarity index 100% rename from migrations/V0043__oauth_authorization.sql rename to mitra-models/migrations/V0043__oauth_authorization.sql diff --git a/migrations/V0044__user_invite_code__add_note_and_created_at.sql b/mitra-models/migrations/V0044__user_invite_code__add_note_and_created_at.sql similarity index 100% rename from migrations/V0044__user_invite_code__add_note_and_created_at.sql rename to mitra-models/migrations/V0044__user_invite_code__add_note_and_created_at.sql diff --git a/migrations/V0045__profile_emoji.sql b/mitra-models/migrations/V0045__profile_emoji.sql similarity index 100% rename from migrations/V0045__profile_emoji.sql rename to mitra-models/migrations/V0045__profile_emoji.sql diff --git a/migrations/V0046__actor_profile__add_emoji.sql b/mitra-models/migrations/V0046__actor_profile__add_emoji.sql similarity index 100% rename from migrations/V0046__actor_profile__add_emoji.sql rename to mitra-models/migrations/V0046__actor_profile__add_emoji.sql diff --git a/migrations/V0047__internal_property.sql b/mitra-models/migrations/V0047__internal_property.sql similarity index 100% rename from migrations/V0047__internal_property.sql rename to mitra-models/migrations/V0047__internal_property.sql diff --git a/migrations/V0048__actor_profile__identity_proof_type_number.sql b/mitra-models/migrations/V0048__actor_profile__identity_proof_type_number.sql similarity index 100% rename from migrations/V0048__actor_profile__identity_proof_type_number.sql rename to mitra-models/migrations/V0048__actor_profile__identity_proof_type_number.sql diff --git a/migrations/V0049__actor_profile__add_manually_approves_followers.sql b/mitra-models/migrations/V0049__actor_profile__add_manually_approves_followers.sql similarity index 100% rename from migrations/V0049__actor_profile__add_manually_approves_followers.sql rename to mitra-models/migrations/V0049__actor_profile__add_manually_approves_followers.sql diff --git a/migrations/V0050__actor_profile__add_aliases.sql b/mitra-models/migrations/V0050__actor_profile__add_aliases.sql similarity index 100% rename from migrations/V0050__actor_profile__add_aliases.sql rename to mitra-models/migrations/V0050__actor_profile__add_aliases.sql diff --git a/migrations/schema.sql b/mitra-models/migrations/schema.sql similarity index 100% rename from migrations/schema.sql rename to mitra-models/migrations/schema.sql diff --git a/src/models/attachments/mod.rs b/mitra-models/src/attachments/mod.rs similarity index 100% rename from src/models/attachments/mod.rs rename to mitra-models/src/attachments/mod.rs diff --git a/src/models/attachments/queries.rs b/mitra-models/src/attachments/queries.rs similarity index 96% rename from src/models/attachments/queries.rs rename to mitra-models/src/attachments/queries.rs index 586ba99..6acb8d9 100644 --- a/src/models/attachments/queries.rs +++ b/mitra-models/src/attachments/queries.rs @@ -3,12 +3,13 @@ use uuid::Uuid; use mitra_utils::id::generate_ulid; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::cleanup::{ +use crate::cleanup::{ find_orphaned_files, find_orphaned_ipfs_objects, DeletionQueue, }; +use crate::database::{DatabaseClient, DatabaseError}; + use super::types::DbMediaAttachment; pub async fn create_attachment( @@ -97,9 +98,9 @@ pub async fn delete_unused_attachments( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::{ - profiles::types::ProfileCreateData, - profiles::queries::create_profile, + use crate::profiles::{ + queries::create_profile, + types::ProfileCreateData, }; use super::*; diff --git a/src/models/attachments/types.rs b/mitra-models/src/attachments/types.rs similarity index 100% rename from src/models/attachments/types.rs rename to mitra-models/src/attachments/types.rs diff --git a/src/models/background_jobs/mod.rs b/mitra-models/src/background_jobs/mod.rs similarity index 100% rename from src/models/background_jobs/mod.rs rename to mitra-models/src/background_jobs/mod.rs diff --git a/src/models/background_jobs/queries.rs b/mitra-models/src/background_jobs/queries.rs similarity index 100% rename from src/models/background_jobs/queries.rs rename to mitra-models/src/background_jobs/queries.rs diff --git a/src/models/background_jobs/types.rs b/mitra-models/src/background_jobs/types.rs similarity index 100% rename from src/models/background_jobs/types.rs rename to mitra-models/src/background_jobs/types.rs diff --git a/src/models/cleanup.rs b/mitra-models/src/cleanup.rs similarity index 100% rename from src/models/cleanup.rs rename to mitra-models/src/cleanup.rs diff --git a/src/database/int_enum.rs b/mitra-models/src/database/int_enum.rs similarity index 100% rename from src/database/int_enum.rs rename to mitra-models/src/database/int_enum.rs diff --git a/src/database/json_macro.rs b/mitra-models/src/database/json_macro.rs similarity index 100% rename from src/database/json_macro.rs rename to mitra-models/src/database/json_macro.rs diff --git a/src/database/migrate.rs b/mitra-models/src/database/migrate.rs similarity index 100% rename from src/database/migrate.rs rename to mitra-models/src/database/migrate.rs diff --git a/src/database/mod.rs b/mitra-models/src/database/mod.rs similarity index 98% rename from src/database/mod.rs rename to mitra-models/src/database/mod.rs index a75d48f..4f956fe 100644 --- a/src/database/mod.rs +++ b/mitra-models/src/database/mod.rs @@ -6,7 +6,7 @@ pub mod json_macro; pub mod migrate; pub mod query_macro; -#[cfg(test)] +#[cfg(feature = "test-utils")] pub mod test_utils; pub type DbPool = deadpool_postgres::Pool; diff --git a/src/database/query_macro.rs b/mitra-models/src/database/query_macro.rs similarity index 100% rename from src/database/query_macro.rs rename to mitra-models/src/database/query_macro.rs diff --git a/src/database/test_utils.rs b/mitra-models/src/database/test_utils.rs similarity index 100% rename from src/database/test_utils.rs rename to mitra-models/src/database/test_utils.rs diff --git a/src/models/emojis/helpers.rs b/mitra-models/src/emojis/helpers.rs similarity index 99% rename from src/models/emojis/helpers.rs rename to mitra-models/src/emojis/helpers.rs index 82480cf..8dfd277 100644 --- a/src/models/emojis/helpers.rs +++ b/mitra-models/src/emojis/helpers.rs @@ -1,4 +1,5 @@ use crate::database::{DatabaseClient, DatabaseError}; + use super::types::DbEmoji; use super::queries::{ get_local_emoji_by_name, diff --git a/src/models/emojis/mod.rs b/mitra-models/src/emojis/mod.rs similarity index 100% rename from src/models/emojis/mod.rs rename to mitra-models/src/emojis/mod.rs diff --git a/src/models/emojis/queries.rs b/mitra-models/src/emojis/queries.rs similarity index 97% rename from src/models/emojis/queries.rs rename to mitra-models/src/emojis/queries.rs index b2330eb..3e2694a 100644 --- a/src/models/emojis/queries.rs +++ b/mitra-models/src/emojis/queries.rs @@ -3,16 +3,15 @@ use uuid::Uuid; use mitra_utils::id::generate_ulid; +use crate::cleanup::{find_orphaned_files, DeletionQueue}; use crate::database::{ catch_unique_violation, DatabaseClient, DatabaseError, }; -use crate::models::{ - cleanup::{find_orphaned_files, DeletionQueue}, - instances::queries::create_instance, - profiles::queries::update_emoji_caches, -}; +use crate::instances::queries::create_instance; +use crate::profiles::queries::update_emoji_caches; + use super::types::{DbEmoji, EmojiImage}; pub async fn create_emoji( diff --git a/src/models/emojis/types.rs b/mitra-models/src/emojis/types.rs similarity index 87% rename from src/models/emojis/types.rs rename to mitra-models/src/emojis/types.rs index 98bb822..0b4b4fd 100644 --- a/src/models/emojis/types.rs +++ b/mitra-models/src/emojis/types.rs @@ -9,7 +9,7 @@ use crate::database::json_macro::{json_from_sql, json_to_sql}; fn default_emoji_file_size() -> usize { 250 * 1000 } #[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] pub struct EmojiImage { pub file_name: String, #[serde(default = "default_emoji_file_size")] @@ -21,7 +21,7 @@ json_from_sql!(EmojiImage); json_to_sql!(EmojiImage); #[derive(Clone, Deserialize, FromSql)] -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] #[postgres(name = "emoji")] pub struct DbEmoji { pub id: Uuid, diff --git a/src/models/instances/mod.rs b/mitra-models/src/instances/mod.rs similarity index 100% rename from src/models/instances/mod.rs rename to mitra-models/src/instances/mod.rs diff --git a/src/models/instances/queries.rs b/mitra-models/src/instances/queries.rs similarity index 100% rename from src/models/instances/queries.rs rename to mitra-models/src/instances/queries.rs diff --git a/src/models/invoices/mod.rs b/mitra-models/src/invoices/mod.rs similarity index 100% rename from src/models/invoices/mod.rs rename to mitra-models/src/invoices/mod.rs diff --git a/src/models/invoices/queries.rs b/mitra-models/src/invoices/queries.rs similarity index 95% rename from src/models/invoices/queries.rs rename to mitra-models/src/invoices/queries.rs index eb05d67..25a1885 100644 --- a/src/models/invoices/queries.rs +++ b/mitra-models/src/invoices/queries.rs @@ -10,6 +10,7 @@ use crate::database::{ DatabaseClient, DatabaseError, }; + use super::types::{DbChainId, DbInvoice, InvoiceStatus}; pub async fn create_invoice( @@ -120,11 +121,13 @@ pub async fn set_invoice_status( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::{ - profiles::queries::create_profile, - profiles::types::ProfileCreateData, - users::queries::create_user, - users::types::UserCreateData, + use crate::profiles::{ + queries::create_profile, + types::ProfileCreateData, + }; + use crate::users::{ + queries::create_user, + types::UserCreateData, }; use super::*; diff --git a/src/models/invoices/types.rs b/mitra-models/src/invoices/types.rs similarity index 100% rename from src/models/invoices/types.rs rename to mitra-models/src/invoices/types.rs diff --git a/src/models/mod.rs b/mitra-models/src/lib.rs similarity index 94% rename from src/models/mod.rs rename to mitra-models/src/lib.rs index bb60be7..38fbdc3 100644 --- a/src/models/mod.rs +++ b/mitra-models/src/lib.rs @@ -1,5 +1,6 @@ pub mod attachments; pub mod background_jobs; +pub mod database; pub mod cleanup; pub mod emojis; pub mod instances; diff --git a/src/models/markers/mod.rs b/mitra-models/src/markers/mod.rs similarity index 100% rename from src/models/markers/mod.rs rename to mitra-models/src/markers/mod.rs diff --git a/src/models/markers/queries.rs b/mitra-models/src/markers/queries.rs similarity index 100% rename from src/models/markers/queries.rs rename to mitra-models/src/markers/queries.rs diff --git a/src/models/markers/types.rs b/mitra-models/src/markers/types.rs similarity index 100% rename from src/models/markers/types.rs rename to mitra-models/src/markers/types.rs diff --git a/src/models/notifications/mod.rs b/mitra-models/src/notifications/mod.rs similarity index 100% rename from src/models/notifications/mod.rs rename to mitra-models/src/notifications/mod.rs diff --git a/src/models/notifications/queries.rs b/mitra-models/src/notifications/queries.rs similarity index 97% rename from src/models/notifications/queries.rs rename to mitra-models/src/notifications/queries.rs index 103b0b5..7e6f21f 100644 --- a/src/models/notifications/queries.rs +++ b/mitra-models/src/notifications/queries.rs @@ -1,9 +1,9 @@ use uuid::Uuid; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::helpers::{add_related_posts, add_user_actions}, - posts::queries::{ +use crate::posts::{ + helpers::{add_related_posts, add_user_actions}, + queries::{ RELATED_ATTACHMENTS, RELATED_EMOJIS, RELATED_LINKS, @@ -11,6 +11,7 @@ use crate::models::{ RELATED_TAGS, }, }; + use super::types::{EventType, Notification}; async fn create_notification( diff --git a/src/models/notifications/types.rs b/mitra-models/src/notifications/types.rs similarity index 95% rename from src/models/notifications/types.rs rename to mitra-models/src/notifications/types.rs index 708613a..585df00 100644 --- a/src/models/notifications/types.rs +++ b/mitra-models/src/notifications/types.rs @@ -3,17 +3,15 @@ use postgres_types::FromSql; use tokio_postgres::Row; use uuid::Uuid; +use crate::attachments::types::DbMediaAttachment; use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseError, DatabaseTypeError, }; -use crate::models::{ - attachments::types::DbMediaAttachment, - emojis::types::DbEmoji, - posts::types::{DbPost, Post}, - profiles::types::DbActorProfile, -}; +use crate::emojis::types::DbEmoji; +use crate::posts::types::{DbPost, Post}; +use crate::profiles::types::DbActorProfile; #[derive(Debug)] pub enum EventType { diff --git a/src/models/oauth/mod.rs b/mitra-models/src/oauth/mod.rs similarity index 100% rename from src/models/oauth/mod.rs rename to mitra-models/src/oauth/mod.rs diff --git a/src/models/oauth/queries.rs b/mitra-models/src/oauth/queries.rs similarity index 97% rename from src/models/oauth/queries.rs rename to mitra-models/src/oauth/queries.rs index b50ceb5..de39801 100644 --- a/src/models/oauth/queries.rs +++ b/mitra-models/src/oauth/queries.rs @@ -6,10 +6,9 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::{ - profiles::types::DbActorProfile, - users::types::{DbUser, User}, -}; +use crate::profiles::types::DbActorProfile; +use crate::users::types::{DbUser, User}; + use super::types::{DbOauthApp, DbOauthAppData}; pub async fn create_oauth_app( @@ -200,8 +199,10 @@ pub async fn get_user_by_oauth_token( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::users::queries::create_user; - use crate::models::users::types::UserCreateData; + use crate::users::{ + queries::create_user, + types::UserCreateData, + }; use super::*; #[tokio::test] diff --git a/src/models/oauth/types.rs b/mitra-models/src/oauth/types.rs similarity index 100% rename from src/models/oauth/types.rs rename to mitra-models/src/oauth/types.rs diff --git a/src/models/posts/helpers.rs b/mitra-models/src/posts/helpers.rs similarity index 95% rename from src/models/posts/helpers.rs rename to mitra-models/src/posts/helpers.rs index f4a87d1..02716e8 100644 --- a/src/models/posts/helpers.rs +++ b/mitra-models/src/posts/helpers.rs @@ -1,12 +1,13 @@ use uuid::Uuid; use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - reactions::queries::find_favourited_by_user, - relationships::queries::has_relationship, - relationships::types::RelationshipType, - users::types::{Permission, User}, +use crate::reactions::queries::find_favourited_by_user; +use crate::relationships::{ + queries::has_relationship, + types::RelationshipType, }; +use crate::users::types::{Permission, User}; + use super::queries::{ get_post_by_id, get_related_posts, @@ -145,12 +146,14 @@ mod tests { use serial_test::serial; use tokio_postgres::Client; use crate::database::test_utils::create_test_database; - use crate::models::{ - posts::queries::create_post, - posts::types::PostCreateData, - relationships::queries::{follow, subscribe}, - users::queries::create_user, - users::types::{Role, User, UserCreateData}, + use crate::posts::{ + queries::create_post, + types::PostCreateData, + }; + use crate::relationships::queries::{follow, subscribe}; + use crate::users::{ + queries::create_user, + types::{Role, User, UserCreateData}, }; use super::*; diff --git a/src/models/posts/mod.rs b/mitra-models/src/posts/mod.rs similarity index 100% rename from src/models/posts/mod.rs rename to mitra-models/src/posts/mod.rs diff --git a/src/models/posts/queries.rs b/mitra-models/src/posts/queries.rs similarity index 98% rename from src/models/posts/queries.rs rename to mitra-models/src/posts/queries.rs index 652dc50..4546c08 100644 --- a/src/models/posts/queries.rs +++ b/mitra-models/src/posts/queries.rs @@ -3,30 +3,33 @@ use uuid::Uuid; use mitra_utils::id::generate_ulid; +use crate::attachments::{ + queries::set_attachment_ipfs_cid, + types::DbMediaAttachment, +}; +use crate::cleanup::{ + find_orphaned_files, + find_orphaned_ipfs_objects, + DeletionQueue, +}; use crate::database::{ catch_unique_violation, query_macro::query, DatabaseClient, DatabaseError, }; -use crate::models::{ - attachments::queries::set_attachment_ipfs_cid, - attachments::types::DbMediaAttachment, - cleanup::{ - find_orphaned_files, - find_orphaned_ipfs_objects, - DeletionQueue, - }, - emojis::types::DbEmoji, - notifications::queries::{ - create_mention_notification, - create_reply_notification, - create_repost_notification, - }, - profiles::queries::update_post_count, - profiles::types::DbActorProfile, - relationships::types::RelationshipType, +use crate::emojis::types::DbEmoji; +use crate::notifications::queries::{ + create_mention_notification, + create_reply_notification, + create_repost_notification, }; +use crate::profiles::{ + queries::update_post_count, + types::DbActorProfile, +}; +use crate::relationships::types::RelationshipType; + use super::types::{ DbPost, Post, @@ -1308,16 +1311,18 @@ mod tests { use chrono::Duration; use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::{ - profiles::queries::create_profile, - profiles::types::ProfileCreateData, - relationships::queries::{ - follow, - hide_reposts, - subscribe, - }, - users::queries::create_user, - users::types::UserCreateData, + use crate::profiles::{ + queries::create_profile, + types::ProfileCreateData, + }; + use crate::relationships::queries::{ + follow, + hide_reposts, + subscribe, + }; + use crate::users::{ + queries::create_user, + types::UserCreateData, }; use super::*; diff --git a/src/models/posts/types.rs b/mitra-models/src/posts/types.rs similarity index 97% rename from src/models/posts/types.rs rename to mitra-models/src/posts/types.rs index 8a960d5..09b7902 100644 --- a/src/models/posts/types.rs +++ b/mitra-models/src/posts/types.rs @@ -3,16 +3,14 @@ use postgres_types::FromSql; use tokio_postgres::Row; use uuid::Uuid; +use crate::attachments::types::DbMediaAttachment; use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseError, DatabaseTypeError, }; -use crate::models::{ - attachments::types::DbMediaAttachment, - emojis::types::DbEmoji, - profiles::types::DbActorProfile, -}; +use crate::emojis::types::DbEmoji; +use crate::profiles::types::DbActorProfile; #[derive(Clone, Debug, PartialEq)] pub enum Visibility { @@ -182,7 +180,7 @@ impl Post { } } -#[cfg(test)] +#[cfg(feature = "test-utils")] impl Default for Post { fn default() -> Self { Self { diff --git a/src/models/profiles/helpers.rs b/mitra-models/src/profiles/helpers.rs similarity index 99% rename from src/models/profiles/helpers.rs rename to mitra-models/src/profiles/helpers.rs index b695ac4..9273d5f 100644 --- a/src/models/profiles/helpers.rs +++ b/mitra-models/src/profiles/helpers.rs @@ -1,4 +1,5 @@ use crate::database::{DatabaseClient, DatabaseError}; + use super::queries::search_profiles_by_did_only; use super::types::DbActorProfile; diff --git a/src/models/profiles/mod.rs b/mitra-models/src/profiles/mod.rs similarity index 100% rename from src/models/profiles/mod.rs rename to mitra-models/src/profiles/mod.rs diff --git a/src/models/profiles/queries.rs b/mitra-models/src/profiles/queries.rs similarity index 98% rename from src/models/profiles/queries.rs rename to mitra-models/src/profiles/queries.rs index 9fca33c..5672fdb 100644 --- a/src/models/profiles/queries.rs +++ b/mitra-models/src/profiles/queries.rs @@ -8,22 +8,21 @@ use mitra_utils::{ id::generate_ulid, }; +use crate::cleanup::{ + find_orphaned_files, + find_orphaned_ipfs_objects, + DeletionQueue, +}; use crate::database::{ catch_unique_violation, query_macro::query, DatabaseClient, DatabaseError, }; -use crate::models::{ - cleanup::{ - find_orphaned_files, - find_orphaned_ipfs_objects, - DeletionQueue, - }, - emojis::types::DbEmoji, - instances::queries::create_instance, - relationships::types::RelationshipType, -}; +use crate::emojis::types::DbEmoji; +use crate::instances::queries::create_instance; +use crate::relationships::types::RelationshipType; + use super::types::{ Aliases, DbActorProfile, @@ -829,19 +828,23 @@ pub async fn find_empty_profiles( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::{ - emojis::queries::create_emoji, - emojis::types::EmojiImage, - profiles::queries::create_profile, - profiles::types::{ + use crate::emojis::{ + queries::create_emoji, + types::EmojiImage, + }; + use crate::profiles::{ + queries::create_profile, + types::{ DbActor, ExtraField, IdentityProof, IdentityProofType, ProfileCreateData, }, - users::queries::create_user, - users::types::UserCreateData, + }; + use crate::users::{ + queries::create_user, + types::UserCreateData, }; use super::*; diff --git a/src/models/profiles/types.rs b/mitra-models/src/profiles/types.rs similarity index 98% rename from src/models/profiles/types.rs rename to mitra-models/src/profiles/types.rs index d093933..11e5ea6 100644 --- a/src/models/profiles/types.rs +++ b/mitra-models/src/profiles/types.rs @@ -17,7 +17,7 @@ use crate::database::{ json_macro::{json_from_sql, json_to_sql}, DatabaseTypeError, }; -use crate::models::emojis::types::DbEmoji; +use crate::emojis::types::DbEmoji; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ProfileImage { @@ -334,7 +334,7 @@ impl ProfileEmojis { json_from_sql!(ProfileEmojis); #[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] #[serde(rename_all = "camelCase")] pub struct DbActorPublicKey { pub id: String, @@ -343,7 +343,7 @@ pub struct DbActorPublicKey { } #[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] #[serde(rename_all = "camelCase")] pub struct DbActor { #[serde(rename = "type")] @@ -422,7 +422,7 @@ impl DbActorProfile { } } -#[cfg(test)] +#[cfg(feature = "test-utils")] impl Default for DbActorProfile { fn default() -> Self { let now = Utc::now(); @@ -455,7 +455,7 @@ impl Default for DbActorProfile { } } -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] pub struct ProfileCreateData { pub username: String, pub hostname: Option, diff --git a/src/models/properties/mod.rs b/mitra-models/src/properties/mod.rs similarity index 100% rename from src/models/properties/mod.rs rename to mitra-models/src/properties/mod.rs diff --git a/src/models/properties/queries.rs b/mitra-models/src/properties/queries.rs similarity index 100% rename from src/models/properties/queries.rs rename to mitra-models/src/properties/queries.rs diff --git a/src/models/reactions/mod.rs b/mitra-models/src/reactions/mod.rs similarity index 100% rename from src/models/reactions/mod.rs rename to mitra-models/src/reactions/mod.rs diff --git a/src/models/reactions/queries.rs b/mitra-models/src/reactions/queries.rs similarity index 95% rename from src/models/reactions/queries.rs rename to mitra-models/src/reactions/queries.rs index ff21ecf..864b506 100644 --- a/src/models/reactions/queries.rs +++ b/mitra-models/src/reactions/queries.rs @@ -7,13 +7,12 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::{ - notifications::queries::create_reaction_notification, - posts::queries::{ - update_reaction_count, - get_post_author, - }, +use crate::notifications::queries::create_reaction_notification; +use crate::posts::queries::{ + update_reaction_count, + get_post_author, }; + use super::types::DbReaction; pub async fn create_reaction( diff --git a/src/models/reactions/types.rs b/mitra-models/src/reactions/types.rs similarity index 100% rename from src/models/reactions/types.rs rename to mitra-models/src/reactions/types.rs diff --git a/src/models/relationships/mod.rs b/mitra-models/src/relationships/mod.rs similarity index 100% rename from src/models/relationships/mod.rs rename to mitra-models/src/relationships/mod.rs diff --git a/src/models/relationships/queries.rs b/mitra-models/src/relationships/queries.rs similarity index 98% rename from src/models/relationships/queries.rs rename to mitra-models/src/relationships/queries.rs index a15e688..15fdd2f 100644 --- a/src/models/relationships/queries.rs +++ b/mitra-models/src/relationships/queries.rs @@ -7,15 +7,16 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::{ - notifications::queries::create_follow_notification, - profiles::queries::{ +use crate::notifications::queries::create_follow_notification; +use crate::profiles::{ + queries::{ update_follower_count, update_following_count, update_subscriber_count, }, - profiles::types::DbActorProfile, + types::DbActorProfile, }; + use super::types::{ DbFollowRequest, DbRelationship, @@ -561,11 +562,13 @@ mod tests { test_utils::create_test_database, DatabaseError, }; - use crate::models::{ - profiles::queries::create_profile, - profiles::types::{DbActor, ProfileCreateData}, - users::queries::create_user, - users::types::UserCreateData, + use crate::profiles::{ + queries::create_profile, + types::{DbActor, ProfileCreateData}, + }; + use crate::users::{ + queries::create_user, + types::UserCreateData, }; use super::*; diff --git a/src/models/relationships/types.rs b/mitra-models/src/relationships/types.rs similarity index 95% rename from src/models/relationships/types.rs rename to mitra-models/src/relationships/types.rs index 499a426..029a3dd 100644 --- a/src/models/relationships/types.rs +++ b/mitra-models/src/relationships/types.rs @@ -2,12 +2,14 @@ use postgres_types::FromSql; use tokio_postgres::Row; use uuid::Uuid; -use crate::database::{ - int_enum::{int_enum_from_sql, int_enum_to_sql}, - DatabaseError, - DatabaseTypeError, +use crate::{ + database::{ + int_enum::{int_enum_from_sql, int_enum_to_sql}, + DatabaseError, + DatabaseTypeError, + }, + profiles::types::DbActorProfile, }; -use crate::models::profiles::types::DbActorProfile; #[derive(Debug)] pub enum RelationshipType { diff --git a/src/models/subscriptions/mod.rs b/mitra-models/src/subscriptions/mod.rs similarity index 100% rename from src/models/subscriptions/mod.rs rename to mitra-models/src/subscriptions/mod.rs diff --git a/src/models/subscriptions/queries.rs b/mitra-models/src/subscriptions/queries.rs similarity index 93% rename from src/models/subscriptions/queries.rs rename to mitra-models/src/subscriptions/queries.rs index e5be337..7c3a626 100644 --- a/src/models/subscriptions/queries.rs +++ b/mitra-models/src/subscriptions/queries.rs @@ -8,12 +8,13 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::{ - invoices::types::DbChainId, - profiles::types::PaymentType, - relationships::queries::{subscribe, subscribe_opt}, - relationships::types::RelationshipType, +use crate::invoices::types::DbChainId; +use crate::profiles::types::PaymentType; +use crate::relationships::{ + queries::{subscribe, subscribe_opt}, + types::RelationshipType, }; + use super::types::{DbSubscription, Subscription}; pub async fn create_subscription( @@ -195,13 +196,17 @@ pub async fn reset_subscriptions( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::{ - profiles::queries::create_profile, - profiles::types::ProfileCreateData, - relationships::queries::has_relationship, - relationships::types::RelationshipType, - users::queries::create_user, - users::types::UserCreateData, + use crate::profiles::{ + queries::create_profile, + types::ProfileCreateData, + }; + use crate::relationships::{ + queries::has_relationship, + types::RelationshipType, + }; + use crate::users::{ + queries::create_user, + types::UserCreateData, }; use super::*; diff --git a/src/models/subscriptions/types.rs b/mitra-models/src/subscriptions/types.rs similarity index 92% rename from src/models/subscriptions/types.rs rename to mitra-models/src/subscriptions/types.rs index d95e642..75719fb 100644 --- a/src/models/subscriptions/types.rs +++ b/mitra-models/src/subscriptions/types.rs @@ -4,10 +4,8 @@ use tokio_postgres::Row; use uuid::Uuid; use crate::database::DatabaseError; -use crate::models::{ - invoices::types::DbChainId, - profiles::types::DbActorProfile, -}; +use crate::invoices::types::DbChainId; +use crate::profiles::types::DbActorProfile; #[derive(FromSql)] #[postgres(name = "subscription")] diff --git a/src/models/tags/mod.rs b/mitra-models/src/tags/mod.rs similarity index 100% rename from src/models/tags/mod.rs rename to mitra-models/src/tags/mod.rs diff --git a/src/models/tags/queries.rs b/mitra-models/src/tags/queries.rs similarity index 100% rename from src/models/tags/queries.rs rename to mitra-models/src/tags/queries.rs diff --git a/src/models/users/mod.rs b/mitra-models/src/users/mod.rs similarity index 100% rename from src/models/users/mod.rs rename to mitra-models/src/users/mod.rs diff --git a/src/models/users/queries.rs b/mitra-models/src/users/queries.rs similarity index 98% rename from src/models/users/queries.rs rename to mitra-models/src/users/queries.rs index b7e7ad2..e5f1ad1 100644 --- a/src/models/users/queries.rs +++ b/mitra-models/src/users/queries.rs @@ -11,10 +11,11 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::models::{ - profiles::queries::create_profile, - profiles::types::{DbActorProfile, ProfileCreateData}, +use crate::profiles::{ + queries::create_profile, + types::{DbActorProfile, ProfileCreateData}, }; + use super::types::{ DbInviteCode, DbUser, @@ -309,7 +310,7 @@ pub async fn get_user_count( mod tests { use serial_test::serial; use crate::database::test_utils::create_test_database; - use crate::models::users::types::Role; + use crate::users::types::Role; use super::*; #[tokio::test] diff --git a/src/models/users/types.rs b/mitra-models/src/users/types.rs similarity index 96% rename from src/models/users/types.rs rename to mitra-models/src/users/types.rs index df7c7cf..06d8bb2 100644 --- a/src/models/users/types.rs +++ b/mitra-models/src/users/types.rs @@ -11,7 +11,7 @@ use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseTypeError, }; -use crate::models::profiles::types::DbActorProfile; +use crate::profiles::types::DbActorProfile; #[allow(dead_code)] #[derive(FromSql)] @@ -115,7 +115,7 @@ pub struct DbUser { // Represents local user #[derive(Clone)] -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] pub struct User { pub id: Uuid, pub wallet_address: Option, // login address @@ -160,7 +160,7 @@ impl User { } } -#[cfg_attr(test, derive(Default))] +#[cfg_attr(feature = "test-utils", derive(Default))] pub struct UserCreateData { pub username: String, pub password_hash: Option, diff --git a/src/models/users/utils.rs b/mitra-models/src/users/utils.rs similarity index 100% rename from src/models/users/utils.rs rename to mitra-models/src/users/utils.rs diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index fa67ee6..488dec2 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -1,3 +1,10 @@ +use mitra_models::profiles::types::{ + ExtraField, + IdentityProof, + IdentityProofType, + PaymentLink, + PaymentOption, +}; use mitra_utils::did::Did; use crate::activitypub::vocabulary::{ @@ -18,14 +25,8 @@ use crate::json_signatures::proofs::{ PROOF_TYPE_ID_EIP191, PROOF_TYPE_ID_MINISIGN, }; -use crate::models::profiles::types::{ - ExtraField, - IdentityProof, - IdentityProofType, - PaymentLink, - PaymentOption, -}; use crate::web_client::urls::get_subscription_page_url; + use super::types::ActorAttachment; pub fn attach_identity_proof( diff --git a/src/activitypub/actors/helpers.rs b/src/activitypub/actors/helpers.rs index d430a42..41a93ba 100644 --- a/src/activitypub/actors/helpers.rs +++ b/src/activitypub/actors/helpers.rs @@ -3,17 +3,8 @@ use std::path::Path; use uuid::Uuid; use mitra_config::Instance; - -use crate::activitypub::{ - actors::types::Actor, - fetcher::fetchers::fetch_file, - handlers::create::handle_emoji, - receiver::{parse_array, HandlerError}, - vocabulary::{EMOJI, HASHTAG}, -}; -use crate::database::DatabaseClient; -use crate::media::MediaStorage; -use crate::models::{ +use mitra_models::{ + database::DatabaseClient, profiles::queries::{create_profile, update_profile}, profiles::types::{ DbActorProfile, @@ -22,6 +13,15 @@ use crate::models::{ ProfileUpdateData, }, }; + +use crate::activitypub::{ + actors::types::Actor, + fetcher::fetchers::fetch_file, + handlers::create::handle_emoji, + receiver::{parse_array, HandlerError}, + vocabulary::{EMOJI, HASHTAG}, +}; +use crate::media::MediaStorage; use crate::validators::{ posts::EMOJIS_MAX_NUM, profiles::{clean_profile_create_data, clean_profile_update_data}, diff --git a/src/activitypub/actors/types.rs b/src/activitypub/actors/types.rs index 57750cc..493a843 100644 --- a/src/activitypub/actors/types.rs +++ b/src/activitypub/actors/types.rs @@ -9,6 +9,16 @@ use serde::{ use serde_json::{json, Value}; use mitra_config::Instance; +use mitra_models::{ + profiles::types::{ + DbActor, + DbActorPublicKey, + ExtraField, + IdentityProof, + PaymentOption, + }, + users::types::User, +}; use mitra_utils::{ crypto_rsa::{deserialize_private_key, get_public_key_pem}, urls::get_hostname, @@ -34,17 +44,8 @@ use crate::activitypub::{ }; use crate::errors::ValidationError; use crate::media::get_file_url; -use crate::models::{ - profiles::types::{ - DbActor, - DbActorPublicKey, - ExtraField, - IdentityProof, - PaymentOption, - }, - users::types::User, -}; use crate::webfinger::types::ActorAddress; + use super::attachments::{ attach_extra_field, attach_identity_proof, @@ -418,11 +419,11 @@ pub fn get_instance_actor( #[cfg(test)] mod tests { + use mitra_models::profiles::types::DbActorProfile; 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"; diff --git a/src/activitypub/authentication.rs b/src/activitypub/authentication.rs index 73cf0ad..b0cfb43 100644 --- a/src/activitypub/authentication.rs +++ b/src/activitypub/authentication.rs @@ -2,12 +2,16 @@ use actix_web::HttpRequest; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + profiles::queries::get_profile_by_remote_actor_id, + profiles::types::DbActorProfile, +}; use mitra_utils::{ crypto_rsa::deserialize_public_key, did::Did, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::http_signatures::verify::{ parse_http_signature, verify_http_signature, @@ -25,10 +29,7 @@ use crate::json_signatures::{ }, }; use crate::media::MediaStorage; -use crate::models::{ - profiles::queries::get_profile_by_remote_actor_id, - profiles::types::DbActorProfile, -}; + use super::fetcher::helpers::get_or_import_profile_by_actor_id; use super::receiver::HandlerError; diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index bb0607f..0d1d090 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -1,6 +1,10 @@ use serde::Serialize; use mitra_config::Instance; +use mitra_models::{ + profiles::types::{DbActor, DbActorProfile}, + users::types::User, +}; use mitra_utils::id::generate_ulid; use crate::activitypub::{ @@ -9,10 +13,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::ACCEPT, }; -use crate::models::{ - profiles::types::{DbActor, DbActorProfile}, - users::types::User, -}; #[derive(Serialize)] struct AcceptFollow { diff --git a/src/activitypub/builders/add_person.rs b/src/activitypub/builders/add_person.rs index 9bab743..87e3daa 100644 --- a/src/activitypub/builders/add_person.rs +++ b/src/activitypub/builders/add_person.rs @@ -1,6 +1,10 @@ use serde::Serialize; use mitra_config::Instance; +use mitra_models::{ + profiles::types::DbActor, + users::types::User, +}; use mitra_utils::id::generate_ulid; use crate::activitypub::{ @@ -9,10 +13,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::{ADD, REMOVE}, }; -use crate::models::{ - profiles::types::DbActor, - users::types::User, -}; #[derive(Serialize)] struct AddOrRemovePerson { diff --git a/src/activitypub/builders/announce.rs b/src/activitypub/builders/announce.rs index db011c0..4ffed60 100644 --- a/src/activitypub/builders/announce.rs +++ b/src/activitypub/builders/announce.rs @@ -2,6 +2,13 @@ use chrono::{DateTime, Utc}; use serde::Serialize; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::types::Post, + profiles::types::DbActor, + relationships::queries::get_followers, + users::types::User, +}; use crate::activitypub::{ constants::AP_PUBLIC, @@ -16,13 +23,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::ANNOUNCE, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::types::Post, - profiles::types::DbActor, - relationships::queries::get_followers, - users::types::User, -}; #[derive(Serialize)] struct Announce { @@ -113,7 +113,7 @@ pub async fn prepare_announce( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActorProfile; + use mitra_models::profiles::types::DbActorProfile; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/create_note.rs b/src/activitypub/builders/create_note.rs index 87b0605..16f2a73 100644 --- a/src/activitypub/builders/create_note.rs +++ b/src/activitypub/builders/create_note.rs @@ -2,6 +2,15 @@ use chrono::{DateTime, Utc}; use serde::Serialize; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + emojis::types::DbEmoji, + posts::queries::get_post_author, + posts::types::{Post, Visibility}, + profiles::types::DbActor, + relationships::queries::{get_followers, get_subscribers}, + users::types::User, +}; use crate::activitypub::{ constants::{AP_MEDIA_TYPE, AP_PUBLIC}, @@ -27,16 +36,7 @@ use crate::activitypub::{ }, vocabulary::*, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::media::get_file_url; -use crate::models::{ - emojis::types::DbEmoji, - posts::queries::get_post_author, - posts::types::{Post, Visibility}, - profiles::types::DbActor, - relationships::queries::{get_followers, get_subscribers}, - users::types::User, -}; use crate::webfinger::types::ActorAddress; #[allow(dead_code)] @@ -309,7 +309,7 @@ pub async fn prepare_create_note( #[cfg(test)] mod tests { use serde_json::json; - use crate::models::profiles::types::DbActorProfile; + use mitra_models::profiles::types::DbActorProfile; use super::*; const INSTANCE_HOSTNAME: &str = "example.com"; diff --git a/src/activitypub/builders/delete_note.rs b/src/activitypub/builders/delete_note.rs index 27da0cb..1598085 100644 --- a/src/activitypub/builders/delete_note.rs +++ b/src/activitypub/builders/delete_note.rs @@ -1,6 +1,12 @@ use serde::Serialize; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::helpers::add_related_posts, + posts::types::Post, + users::types::User, +}; use crate::activitypub::{ deliverer::OutgoingActivity, @@ -8,12 +14,7 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::{DELETE, NOTE, TOMBSTONE}, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::helpers::add_related_posts, - posts::types::Post, - users::types::User, -}; + use super::create_note::{ build_note, get_note_recipients, @@ -101,11 +102,11 @@ pub async fn prepare_delete_note( #[cfg(test)] mod tests { + use mitra_models::profiles::types::DbActorProfile; use crate::activitypub::{ constants::AP_PUBLIC, identifiers::local_actor_followers, }; - use crate::models::profiles::types::DbActorProfile; use super::*; const INSTANCE_HOSTNAME: &str = "example.com"; diff --git a/src/activitypub/builders/delete_person.rs b/src/activitypub/builders/delete_person.rs index 1dab9ad..b9e1e44 100644 --- a/src/activitypub/builders/delete_person.rs +++ b/src/activitypub/builders/delete_person.rs @@ -2,6 +2,12 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + profiles::types::DbActor, + relationships::queries::{get_followers, get_following}, + users::types::User, +}; use crate::activitypub::{ constants::AP_PUBLIC, @@ -10,12 +16,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::DELETE, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - profiles::types::DbActor, - relationships::queries::{get_followers, get_following}, - users::types::User, -}; #[derive(Serialize)] struct DeletePerson { @@ -80,7 +80,7 @@ pub async fn prepare_delete_person( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActorProfile; + use mitra_models::profiles::types::DbActorProfile; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/follow.rs b/src/activitypub/builders/follow.rs index 9426cde..4ddf7dc 100644 --- a/src/activitypub/builders/follow.rs +++ b/src/activitypub/builders/follow.rs @@ -2,6 +2,10 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + profiles::types::{DbActor, DbActorProfile}, + users::types::User, +}; use crate::activitypub::{ deliverer::OutgoingActivity, @@ -9,10 +13,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::FOLLOW, }; -use crate::models::{ - profiles::types::{DbActor, DbActorProfile}, - users::types::User, -}; #[derive(Serialize)] pub(super) struct Follow { diff --git a/src/activitypub/builders/like.rs b/src/activitypub/builders/like.rs index 13189d5..979426b 100644 --- a/src/activitypub/builders/like.rs +++ b/src/activitypub/builders/like.rs @@ -2,6 +2,12 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::types::{Post, Visibility}, + profiles::types::{DbActor, DbActorProfile}, + users::types::User, +}; use crate::activitypub::{ constants::AP_PUBLIC, @@ -15,12 +21,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::LIKE, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::types::{Post, Visibility}, - profiles::types::{DbActor, DbActorProfile}, - users::types::User, -}; #[derive(Serialize)] struct Like { diff --git a/src/activitypub/builders/move_person.rs b/src/activitypub/builders/move_person.rs index 934fce2..46ce87d 100644 --- a/src/activitypub/builders/move_person.rs +++ b/src/activitypub/builders/move_person.rs @@ -2,6 +2,10 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + profiles::types::DbActor, + users::types::User, +}; use mitra_utils::id::generate_ulid; use crate::activitypub::{ @@ -10,10 +14,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::MOVE, }; -use crate::models::{ - profiles::types::DbActor, - users::types::User, -}; #[derive(Serialize)] pub struct MovePerson { @@ -81,7 +81,7 @@ pub fn prepare_move_person( #[cfg(test)] mod tests { use mitra_utils::id::generate_ulid; - use crate::models::profiles::types::DbActorProfile; + use mitra_models::profiles::types::DbActorProfile; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/remove_person.rs b/src/activitypub/builders/remove_person.rs index 141eadb..1a4aca9 100644 --- a/src/activitypub/builders/remove_person.rs +++ b/src/activitypub/builders/remove_person.rs @@ -1,13 +1,14 @@ use mitra_config::Instance; +use mitra_models::{ + profiles::types::DbActor, + users::types::User, +}; use crate::activitypub::{ deliverer::OutgoingActivity, identifiers::LocalActorCollection, }; -use crate::models::{ - profiles::types::DbActor, - users::types::User, -}; + use super::add_person::prepare_update_collection; pub fn prepare_remove_person( diff --git a/src/activitypub/builders/undo_announce.rs b/src/activitypub/builders/undo_announce.rs index d5d48c1..c786381 100644 --- a/src/activitypub/builders/undo_announce.rs +++ b/src/activitypub/builders/undo_announce.rs @@ -2,6 +2,12 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::types::Post, + profiles::types::DbActorProfile, + users::types::User, +}; use crate::activitypub::{ constants::AP_PUBLIC, @@ -10,12 +16,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::UNDO, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::types::Post, - profiles::types::DbActorProfile, - users::types::User, -}; use super::announce::get_announce_recipients; #[derive(Serialize)] diff --git a/src/activitypub/builders/undo_follow.rs b/src/activitypub/builders/undo_follow.rs index 0206cc2..28c2195 100644 --- a/src/activitypub/builders/undo_follow.rs +++ b/src/activitypub/builders/undo_follow.rs @@ -2,6 +2,10 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + profiles::types::{DbActor, DbActorProfile}, + users::types::User, +}; use crate::activitypub::{ deliverer::OutgoingActivity, @@ -9,10 +13,7 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::{FOLLOW, UNDO}, }; -use crate::models::{ - profiles::types::{DbActor, DbActorProfile}, - users::types::User, -}; + use super::follow::Follow; #[derive(Serialize)] diff --git a/src/activitypub/builders/undo_like.rs b/src/activitypub/builders/undo_like.rs index 213a7ed..1aed9c5 100644 --- a/src/activitypub/builders/undo_like.rs +++ b/src/activitypub/builders/undo_like.rs @@ -2,6 +2,12 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::types::{Post, Visibility}, + profiles::types::DbActorProfile, + users::types::User, +}; use crate::activitypub::{ deliverer::OutgoingActivity, @@ -9,12 +15,7 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::UNDO, }; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ - posts::types::{Post, Visibility}, - profiles::types::DbActorProfile, - users::types::User, -}; + use super::like::{ get_like_audience, get_like_recipients, diff --git a/src/activitypub/builders/update_person.rs b/src/activitypub/builders/update_person.rs index e9050be..bfa9b52 100644 --- a/src/activitypub/builders/update_person.rs +++ b/src/activitypub/builders/update_person.rs @@ -2,6 +2,12 @@ use serde::Serialize; use uuid::Uuid; use mitra_config::Instance; +use mitra_models::{ + database::{DatabaseClient, DatabaseError, DatabaseTypeError}, + profiles::types::DbActor, + relationships::queries::get_followers, + users::types::User, +}; use mitra_utils::id::generate_ulid; use crate::activitypub::{ @@ -12,12 +18,6 @@ use crate::activitypub::{ types::{build_default_context, Context}, vocabulary::UPDATE, }; -use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError}; -use crate::models::{ - profiles::types::DbActor, - relationships::queries::get_followers, - users::types::User, -}; #[derive(Serialize)] pub struct UpdatePerson { @@ -94,11 +94,11 @@ pub async fn prepare_update_person( #[cfg(test)] mod tests { + use mitra_models::profiles::types::DbActorProfile; 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"; diff --git a/src/activitypub/deliverer.rs b/src/activitypub/deliverer.rs index 60647d7..9a0b357 100644 --- a/src/activitypub/deliverer.rs +++ b/src/activitypub/deliverer.rs @@ -7,15 +7,19 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use mitra_config::Instance; +use mitra_models::{ + database::{ + DatabaseClient, + DatabaseError, + }, + profiles::types::DbActor, + users::types::User, +}; use mitra_utils::{ crypto_rsa::deserialize_private_key, urls::get_hostname, }; -use crate::database::{ - DatabaseClient, - DatabaseError, -}; use crate::http_signatures::create::{ create_http_signature, HttpSignatureError, @@ -25,10 +29,7 @@ use crate::json_signatures::create::{ sign_object, JsonSignatureError, }; -use crate::models::{ - profiles::types::DbActor, - users::types::User, -}; + use super::{ constants::AP_MEDIA_TYPE, http_client::build_federation_client, diff --git a/src/activitypub/fetcher/helpers.rs b/src/activitypub/fetcher/helpers.rs index 179624d..111271b 100644 --- a/src/activitypub/fetcher/helpers.rs +++ b/src/activitypub/fetcher/helpers.rs @@ -1,18 +1,8 @@ use std::collections::HashMap; use mitra_config::Instance; - -use crate::activitypub::{ - actors::helpers::{create_remote_profile, update_remote_profile}, - handlers::create::{get_object_links, handle_note}, - identifiers::parse_local_object_id, - receiver::HandlerError, - types::Object, -}; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::errors::ValidationError; -use crate::media::MediaStorage; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, posts::helpers::get_local_post_by_id, posts::queries::get_post_by_remote_object_id, posts::types::Post, @@ -22,6 +12,16 @@ use crate::models::{ }, profiles::types::DbActorProfile, }; + +use crate::activitypub::{ + actors::helpers::{create_remote_profile, update_remote_profile}, + handlers::create::{get_object_links, handle_note}, + identifiers::parse_local_object_id, + receiver::HandlerError, + types::Object, +}; +use crate::errors::ValidationError; +use crate::media::MediaStorage; use crate::webfinger::types::ActorAddress; use super::fetchers::{ fetch_actor, diff --git a/src/activitypub/handlers/accept.rs b/src/activitypub/handlers/accept.rs index 3e3fce0..ebc880f 100644 --- a/src/activitypub/handlers/accept.rs +++ b/src/activitypub/handlers/accept.rs @@ -2,15 +2,8 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; - -use crate::activitypub::{ - identifiers::parse_local_object_id, - receiver::deserialize_into_object_id, - vocabulary::FOLLOW, -}; -use crate::database::DatabaseClient; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ + database::DatabaseClient, profiles::queries::get_profile_by_remote_actor_id, relationships::queries::{ follow_request_accepted, @@ -18,6 +11,14 @@ use crate::models::{ }, relationships::types::FollowRequestStatus, }; + +use crate::activitypub::{ + identifiers::parse_local_object_id, + receiver::deserialize_into_object_id, + vocabulary::FOLLOW, +}; +use crate::errors::ValidationError; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/add.rs b/src/activitypub/handlers/add.rs index 8339405..a8abb0d 100644 --- a/src/activitypub/handlers/add.rs +++ b/src/activitypub/handlers/add.rs @@ -2,18 +2,18 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::DatabaseClient, + profiles::queries::get_profile_by_remote_actor_id, + relationships::queries::subscribe_opt, + users::queries::get_user_by_name, +}; use crate::activitypub::{ identifiers::parse_local_actor_id, vocabulary::PERSON, }; -use crate::database::DatabaseClient; use crate::errors::ValidationError; -use crate::models::{ - profiles::queries::get_profile_by_remote_actor_id, - relationships::queries::subscribe_opt, - users::queries::get_user_by_name, -}; use super::{HandlerError, HandlerResult}; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/announce.rs b/src/activitypub/handlers/announce.rs index b6725f5..2677b99 100644 --- a/src/activitypub/handlers/announce.rs +++ b/src/activitypub/handlers/announce.rs @@ -2,6 +2,14 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::queries::{ + create_post, + get_post_by_remote_object_id, + }, + posts::types::PostCreateData, +}; use crate::activitypub::{ fetcher::helpers::{get_or_import_profile_by_actor_id, import_post}, @@ -9,16 +17,8 @@ use crate::activitypub::{ receiver::deserialize_into_object_id, vocabulary::{CREATE, DELETE, DISLIKE, LIKE, NOTE, UNDO, UPDATE}, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - posts::queries::{ - create_post, - get_post_by_remote_object_id, - }, - posts::types::PostCreateData, -}; use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/create.rs b/src/activitypub/handlers/create.rs index a2eff62..f7d1022 100644 --- a/src/activitypub/handlers/create.rs +++ b/src/activitypub/handlers/create.rs @@ -5,6 +5,22 @@ use serde_json::{Value as JsonValue}; use uuid::Uuid; use mitra_config::{Config, Instance}; +use mitra_models::{ + attachments::queries::create_attachment, + database::{DatabaseClient, DatabaseError}, + emojis::queries::{ + create_emoji, + get_emoji_by_remote_object_id, + update_emoji, + }, + emojis::types::{DbEmoji, EmojiImage}, + posts::{ + queries::create_post, + types::{Post, PostCreateData, Visibility}, + }, + profiles::types::DbActorProfile, + users::queries::get_user_by_name, +}; use mitra_utils::{ html::clean_html, urls::get_hostname, @@ -24,24 +40,8 @@ use crate::activitypub::{ types::{Attachment, EmojiTag, Link, LinkTag, Object, Tag}, vocabulary::*, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - attachments::queries::create_attachment, - emojis::queries::{ - create_emoji, - get_emoji_by_remote_object_id, - update_emoji, - }, - emojis::types::{DbEmoji, EmojiImage}, - posts::{ - queries::create_post, - types::{Post, PostCreateData, Visibility}, - }, - profiles::types::DbActorProfile, - users::queries::get_user_by_name, -}; use crate::validators::{ emojis::{ validate_emoji_name, @@ -666,11 +666,11 @@ pub async fn handle_create( #[cfg(test)] mod tests { use serde_json::json; + use mitra_models::profiles::types::DbActor; use crate::activitypub::{ types::Object, vocabulary::NOTE, }; - use crate::models::profiles::types::DbActor; use super::*; #[test] diff --git a/src/activitypub/handlers/delete.rs b/src/activitypub/handlers/delete.rs index 2e70681..3dd0966 100644 --- a/src/activitypub/handlers/delete.rs +++ b/src/activitypub/handlers/delete.rs @@ -2,15 +2,8 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; - -use crate::activitypub::{ - receiver::deserialize_into_object_id, - vocabulary::{NOTE, PERSON}, -}; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::errors::ValidationError; -use crate::media::remove_media; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, posts::queries::{ delete_post, get_post_by_remote_object_id, @@ -20,6 +13,14 @@ use crate::models::{ get_profile_by_remote_actor_id, }, }; + +use crate::activitypub::{ + receiver::deserialize_into_object_id, + vocabulary::{NOTE, PERSON}, +}; +use crate::errors::ValidationError; +use crate::media::remove_media; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/follow.rs b/src/activitypub/handlers/follow.rs index e8198d7..91b2081 100644 --- a/src/activitypub/handlers/follow.rs +++ b/src/activitypub/handlers/follow.rs @@ -2,6 +2,14 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + relationships::queries::{ + create_remote_follow_request_opt, + follow_request_accepted, + }, + users::queries::get_user_by_name, +}; use crate::activitypub::{ builders::accept_follow::prepare_accept_follow, @@ -10,16 +18,8 @@ use crate::activitypub::{ receiver::deserialize_into_object_id, vocabulary::PERSON, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - relationships::queries::{ - create_remote_follow_request_opt, - follow_request_accepted, - }, - users::queries::get_user_by_name, -}; use super::{HandlerError, HandlerResult}; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/like.rs b/src/activitypub/handlers/like.rs index af6955a..5764cc9 100644 --- a/src/activitypub/handlers/like.rs +++ b/src/activitypub/handlers/like.rs @@ -2,6 +2,10 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + reactions::queries::create_reaction, +}; use crate::activitypub::{ fetcher::helpers::{ @@ -11,12 +15,9 @@ use crate::activitypub::{ receiver::deserialize_into_object_id, vocabulary::NOTE, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - reactions::queries::create_reaction, -}; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/move.rs b/src/activitypub/handlers/move.rs index 544104a..bbdb90f 100644 --- a/src/activitypub/handlers/move.rs +++ b/src/activitypub/handlers/move.rs @@ -2,6 +2,17 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + notifications::queries::create_move_notification, + profiles::helpers::find_aliases, + relationships::queries::{ + create_follow_request, + get_followers, + unfollow, + }, + users::queries::{get_user_by_id, get_user_by_name}, +}; use crate::activitypub::{ builders::{ @@ -12,19 +23,9 @@ use crate::activitypub::{ identifiers::{parse_local_actor_id, profile_actor_id}, vocabulary::PERSON, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - notifications::queries::create_move_notification, - profiles::helpers::find_aliases, - relationships::queries::{ - create_follow_request, - get_followers, - unfollow, - }, - users::queries::{get_user_by_id, get_user_by_name}, -}; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/reject.rs b/src/activitypub/handlers/reject.rs index 1ac2b92..b9eb2ca 100644 --- a/src/activitypub/handlers/reject.rs +++ b/src/activitypub/handlers/reject.rs @@ -2,15 +2,8 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; - -use crate::activitypub::{ - identifiers::parse_local_object_id, - receiver::deserialize_into_object_id, - vocabulary::FOLLOW, -}; -use crate::database::DatabaseClient; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ + database::DatabaseClient, profiles::queries::get_profile_by_remote_actor_id, relationships::queries::{ follow_request_rejected, @@ -18,6 +11,14 @@ use crate::models::{ }, relationships::types::FollowRequestStatus, }; + +use crate::activitypub::{ + identifiers::parse_local_object_id, + receiver::deserialize_into_object_id, + vocabulary::FOLLOW, +}; +use crate::errors::ValidationError; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/remove.rs b/src/activitypub/handlers/remove.rs index 065a576..1ec7dea 100644 --- a/src/activitypub/handlers/remove.rs +++ b/src/activitypub/handlers/remove.rs @@ -2,14 +2,8 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; - -use crate::activitypub::{ - identifiers::parse_local_actor_id, - vocabulary::PERSON, -}; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, notifications::queries::{ create_subscription_expiration_notification, }, @@ -17,6 +11,13 @@ use crate::models::{ relationships::queries::unsubscribe, users::queries::get_user_by_name, }; + +use crate::activitypub::{ + identifiers::parse_local_actor_id, + vocabulary::PERSON, +}; +use crate::errors::ValidationError; + use super::{HandlerError, HandlerResult}; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/undo.rs b/src/activitypub/handlers/undo.rs index 772f6ad..2bf298c 100644 --- a/src/activitypub/handlers/undo.rs +++ b/src/activitypub/handlers/undo.rs @@ -2,15 +2,8 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; - -use crate::activitypub::{ - identifiers::parse_local_actor_id, - receiver::{deserialize_into_object_id, find_object_id}, - vocabulary::{ANNOUNCE, FOLLOW, LIKE}, -}; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, posts::queries::{ delete_post, get_post_by_remote_object_id, @@ -28,6 +21,14 @@ use crate::models::{ unfollow, }, }; + +use crate::activitypub::{ + identifiers::parse_local_actor_id, + receiver::{deserialize_into_object_id, find_object_id}, + vocabulary::{ANNOUNCE, FOLLOW, LIKE}, +}; +use crate::errors::ValidationError; + use super::HandlerResult; #[derive(Deserialize)] diff --git a/src/activitypub/handlers/update.rs b/src/activitypub/handlers/update.rs index 88e606f..03d48d7 100644 --- a/src/activitypub/handlers/update.rs +++ b/src/activitypub/handlers/update.rs @@ -5,6 +5,15 @@ use serde::Deserialize; use serde_json::Value; use mitra_config::Config; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::queries::{ + get_post_by_remote_object_id, + update_post, + }, + posts::types::PostUpdateData, + profiles::queries::get_profile_by_remote_actor_id, +}; use crate::activitypub::{ actors::{ @@ -21,17 +30,9 @@ use crate::activitypub::{ types::Object, vocabulary::{NOTE, PERSON}, }; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::media::MediaStorage; -use crate::models::{ - posts::queries::{ - get_post_by_remote_object_id, - update_post, - }, - posts::types::PostUpdateData, - profiles::queries::get_profile_by_remote_actor_id, -}; + use super::HandlerResult; async fn handle_update_note( diff --git a/src/activitypub/identifiers.rs b/src/activitypub/identifiers.rs index f6d0259..5b650a9 100644 --- a/src/activitypub/identifiers.rs +++ b/src/activitypub/identifiers.rs @@ -1,12 +1,13 @@ use regex::Regex; use uuid::Uuid; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ posts::types::Post, profiles::types::DbActorProfile, }; +use crate::errors::ValidationError; + const ACTOR_KEY_SUFFIX: &str = "#main-key"; pub enum LocalActorCollection { diff --git a/src/activitypub/queues.rs b/src/activitypub/queues.rs index 3b54001..68fdabb 100644 --- a/src/activitypub/queues.rs +++ b/src/activitypub/queues.rs @@ -4,24 +4,24 @@ use serde_json::Value; use uuid::Uuid; use mitra_config::Config; - -use crate::database::{ - get_database_client, - DatabaseClient, - DatabaseError, - DatabaseTypeError, - DbPool, -}; -use crate::models::{ +use mitra_models::{ background_jobs::queries::{ enqueue_job, get_job_batch, delete_job_from_queue, }, background_jobs::types::JobType, + database::{ + get_database_client, + DatabaseClient, + DatabaseError, + DatabaseTypeError, + DbPool, + }, profiles::queries::set_reachability_status, users::queries::get_user_by_id, }; + use super::deliverer::{OutgoingActivity, Recipient}; use super::fetcher::fetchers::FetchError; use super::receiver::{handle_activity, HandlerError}; diff --git a/src/activitypub/receiver.rs b/src/activitypub/receiver.rs index 54d7eca..10aa26e 100644 --- a/src/activitypub/receiver.rs +++ b/src/activitypub/receiver.rs @@ -8,8 +8,8 @@ use serde::{ use serde_json::Value; use mitra_config::Config; +use mitra_models::database::{DatabaseClient, DatabaseError}; -use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::{ ConversionError, HttpError, diff --git a/src/activitypub/views.rs b/src/activitypub/views.rs index 4496787..66b1204 100644 --- a/src/activitypub/views.rs +++ b/src/activitypub/views.rs @@ -15,15 +15,15 @@ use tokio::sync::Mutex; use uuid::Uuid; use mitra_config::Config; - -use crate::database::{get_database_client, DbPool}; -use crate::errors::HttpError; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, emojis::queries::get_local_emoji_by_name, posts::helpers::{add_related_posts, can_view_post}, posts::queries::{get_post_by_id, get_posts_by_author}, users::queries::get_user_by_name, }; + +use crate::errors::HttpError; use crate::web_client::urls::{ get_post_page_url, get_profile_page_url, diff --git a/src/atom/feeds.rs b/src/atom/feeds.rs index e50ef60..7104350 100644 --- a/src/atom/feeds.rs +++ b/src/atom/feeds.rs @@ -1,14 +1,14 @@ use mitra_config::Instance; +use mitra_models::{ + posts::types::Post, + profiles::types::DbActorProfile, +}; 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::models::{ - posts::types::Post, - profiles::types::DbActorProfile, -}; use crate::webfinger::types::ActorAddress; const ENTRY_TITLE_MAX_LENGTH: usize = 75; diff --git a/src/atom/views.rs b/src/atom/views.rs index 4afa970..e6238b8 100644 --- a/src/atom/views.rs +++ b/src/atom/views.rs @@ -1,13 +1,13 @@ use actix_web::{web, HttpResponse, Scope}; use mitra_config::Config; - -use crate::database::{get_database_client, DbPool}; -use crate::errors::HttpError; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, posts::queries::get_posts_by_author, users::queries::get_user_by_name, }; + +use crate::errors::HttpError; use super::feeds::make_feed; const FEED_SIZE: u16 = 10; diff --git a/src/errors.rs b/src/errors.rs index 9dab473..6f9f2b4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -6,7 +6,7 @@ use actix_web::{ }; use serde::Serialize; -use crate::database::DatabaseError; +use mitra_models::database::DatabaseError; #[derive(thiserror::Error, Debug)] #[error("conversion error")] diff --git a/src/ethereum/contracts.rs b/src/ethereum/contracts.rs index 4651c35..3885a27 100644 --- a/src/ethereum/contracts.rs +++ b/src/ethereum/contracts.rs @@ -9,8 +9,8 @@ use web3::{ }; use mitra_config::EthereumConfig; +use mitra_models::database::DatabaseClient; -use crate::database::DatabaseClient; use super::api::connect; use super::errors::EthereumError; use super::sync::{ diff --git a/src/ethereum/errors.rs b/src/ethereum/errors.rs index 815fc3a..c494f36 100644 --- a/src/ethereum/errors.rs +++ b/src/ethereum/errors.rs @@ -1,4 +1,5 @@ -use crate::database::DatabaseError; +use mitra_models::database::DatabaseError; + use super::contracts::ArtifactError; use super::signatures::SignatureError; use super::utils::AddressError; diff --git a/src/ethereum/nft.rs b/src/ethereum/nft.rs index 9e98a4d..4607b48 100644 --- a/src/ethereum/nft.rs +++ b/src/ethereum/nft.rs @@ -11,10 +11,8 @@ use web3::{ }; use mitra_config::EthereumConfig; - -use crate::database::{get_database_client, DatabaseError, DbPool}; -use crate::ipfs::utils::parse_ipfs_url; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, posts::queries::{ get_post_by_ipfs_cid, get_token_waitlist, @@ -26,6 +24,9 @@ use crate::models::{ set_internal_property, }, }; + +use crate::ipfs::utils::parse_ipfs_url; + use super::errors::EthereumError; use super::signatures::{sign_contract_call, CallArgs, SignatureData}; use super::sync::SyncState; diff --git a/src/ethereum/subscriptions.rs b/src/ethereum/subscriptions.rs index 9b70597..43930ee 100644 --- a/src/ethereum/subscriptions.rs +++ b/src/ethereum/subscriptions.rs @@ -10,23 +10,13 @@ use web3::{ }; use mitra_config::{EthereumConfig, Instance}; -use mitra_utils::currencies::Currency; - -use crate::activitypub::{ - builders::{ - add_person::prepare_add_person, - remove_person::prepare_remove_person, +use mitra_models::{ + database::{ + get_database_client, + DatabaseClient, + DatabaseError, + DbPool, }, - identifiers::LocalActorCollection, -}; -use crate::database::{ - get_database_client, - DatabaseClient, - DatabaseError, - DbPool, -}; -use crate::errors::ConversionError; -use crate::models::{ notifications::queries::{ create_subscription_notification, create_subscription_expiration_notification, @@ -49,6 +39,17 @@ use crate::models::{ }, users::types::User, }; +use mitra_utils::currencies::Currency; + +use crate::activitypub::{ + builders::{ + add_person::prepare_add_person, + remove_person::prepare_remove_person, + }, + identifiers::LocalActorCollection, +}; +use crate::errors::ConversionError; + use super::contracts::ContractSet; use super::errors::EthereumError; use super::signatures::{ diff --git a/src/ethereum/sync.rs b/src/ethereum/sync.rs index 298d602..dc05578 100644 --- a/src/ethereum/sync.rs +++ b/src/ethereum/sync.rs @@ -3,11 +3,14 @@ use std::path::Path; use web3::{api::Web3, transports::Http, types::Address}; -use crate::database::DatabaseClient; -use crate::models::properties::queries::{ - get_internal_property, - set_internal_property, +use mitra_models::{ + database::DatabaseClient, + properties::queries::{ + get_internal_property, + set_internal_property, + }, }; + use super::errors::EthereumError; const BLOCK_NUMBER_FILE_NAME: &str = "current_block"; diff --git a/src/ipfs/posts.rs b/src/ipfs/posts.rs index e21a311..0e85dec 100644 --- a/src/ipfs/posts.rs +++ b/src/ipfs/posts.rs @@ -55,7 +55,7 @@ impl PostMetadata { #[cfg(test)] mod tests { - use crate::models::posts::types::Post; + use mitra_models::posts::types::Post; use super::*; #[test] diff --git a/src/job_queue/periodic_tasks.rs b/src/job_queue/periodic_tasks.rs index eeaeb4a..9d1e98e 100644 --- a/src/job_queue/periodic_tasks.rs +++ b/src/job_queue/periodic_tasks.rs @@ -3,23 +3,8 @@ use std::time::Duration; use anyhow::Error; use mitra_config::Config; -use mitra_utils::datetime::days_before_now; - -use crate::activitypub::queues::{ - process_queued_incoming_activities, - process_queued_outgoing_activities, -}; -use crate::database::{get_database_client, DbPool}; -use crate::ethereum::{ - contracts::Blockchain, - subscriptions::{ - check_ethereum_subscriptions, - update_expired_subscriptions, - }, -}; -use crate::media::remove_media; -use crate::monero::subscriptions::check_monero_subscriptions; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, emojis::queries::{ delete_emoji, find_unused_remote_emojis, @@ -31,6 +16,21 @@ use crate::models::{ get_profile_by_id, }, }; +use mitra_utils::datetime::days_before_now; + +use crate::activitypub::queues::{ + process_queued_incoming_activities, + process_queued_outgoing_activities, +}; +use crate::ethereum::{ + contracts::Blockchain, + subscriptions::{ + check_ethereum_subscriptions, + update_expired_subscriptions, + }, +}; +use crate::media::remove_media; +use crate::monero::subscriptions::check_monero_subscriptions; #[cfg(feature = "ethereum-extras")] use crate::ethereum::nft::process_nft_events; diff --git a/src/job_queue/scheduler.rs b/src/job_queue/scheduler.rs index 36732a7..f9ecd35 100644 --- a/src/job_queue/scheduler.rs +++ b/src/job_queue/scheduler.rs @@ -4,8 +4,8 @@ use std::time::Duration; use chrono::{DateTime, Utc}; use mitra_config::Config; +use mitra_models::database::DbPool; -use crate::database::DbPool; use crate::ethereum::contracts::Blockchain; use super::periodic_tasks::*; diff --git a/src/lib.rs b/src/lib.rs index 055c3f2..1b3ec4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ pub mod activitypub; pub mod atom; -pub mod database; mod errors; pub mod ethereum; pub mod http; @@ -12,7 +11,6 @@ mod json_signatures; pub mod logger; pub mod mastodon_api; pub mod media; -pub mod models; pub mod monero; pub mod nodeinfo; pub mod validators; diff --git a/src/main.rs b/src/main.rs index 6661f25..821eef0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,6 @@ use tokio::sync::Mutex; use mitra::activitypub::views as activitypub; use mitra::atom::views::atom_scope; -use mitra::database::{get_database_client, create_pool}; -use mitra::database::migrate::apply_migrations; use mitra::ethereum::contracts::get_contracts; use mitra::http::{ create_auth_error_handler, @@ -40,6 +38,8 @@ use mitra::nodeinfo::views as nodeinfo; use mitra::webfinger::views as webfinger; use mitra::web_client::views as web_client; use mitra_config::{parse_config, Environment, MITRA_VERSION}; +use mitra_models::database::{get_database_client, create_pool}; +use mitra_models::database::migrate::apply_migrations; #[actix_web::main] async fn main() -> std::io::Result<()> { diff --git a/src/mastodon_api/accounts/helpers.rs b/src/mastodon_api/accounts/helpers.rs index 219f766..8938b02 100644 --- a/src/mastodon_api/accounts/helpers.rs +++ b/src/mastodon_api/accounts/helpers.rs @@ -1,10 +1,8 @@ use uuid::Uuid; use mitra_config::Instance; - -use crate::activitypub::builders::follow::prepare_follow; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, profiles::types::DbActorProfile, relationships::queries::{ create_follow_request, @@ -14,6 +12,9 @@ use crate::models::{ relationships::types::RelationshipType, users::types::User, }; + +use crate::activitypub::builders::follow::prepare_follow; + use super::types::RelationshipMap; pub async fn follow_or_create_request( @@ -97,19 +98,21 @@ pub async fn get_relationship( #[cfg(test)] mod tests { use serial_test::serial; - use crate::database::test_utils::create_test_database; - use crate::models::relationships::queries::{ - create_follow_request, - follow, - follow_request_accepted, - hide_reposts, - show_reposts, - subscribe, - unfollow, - unsubscribe, + use mitra_models::{ + database::test_utils::create_test_database, + relationships::queries::{ + create_follow_request, + follow, + follow_request_accepted, + hide_reposts, + show_reposts, + subscribe, + unfollow, + unsubscribe, + }, + users::queries::create_user, + users::types::{User, UserCreateData}, }; - use crate::models::users::queries::create_user; - use crate::models::users::types::{User, UserCreateData}; use super::*; async fn create_users(db_client: &mut impl DatabaseClient) diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index d7b4ba8..93a1572 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -4,6 +4,21 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; +use mitra_models::{ + profiles::types::{ + DbActorProfile, + ExtraField, + PaymentOption, + ProfileImage, + ProfileUpdateData, + }, + subscriptions::types::Subscription, + users::types::{ + Role, + Permission, + User, + }, +}; use mitra_utils::{ did::Did, markdown::markdown_basic_to_html, @@ -21,21 +36,6 @@ use crate::mastodon_api::{ uploads::{save_b64_file, UploadError}, }; use crate::media::get_file_url; -use crate::models::{ - profiles::types::{ - DbActorProfile, - ExtraField, - PaymentOption, - ProfileImage, - ProfileUpdateData, - }, - subscriptions::types::Subscription, - users::types::{ - Role, - Permission, - User, - }, -}; use crate::validators::{ profiles::validate_username, users::validate_local_username, @@ -545,7 +545,7 @@ impl ApiSubscription { #[cfg(test)] mod tests { - use crate::models::profiles::types::ProfileImage; + use mitra_models::profiles::types::ProfileImage; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index d9aa09a..f97d6ae 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -12,6 +12,38 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use uuid::Uuid; use mitra_config::{Config, DefaultRole, RegistrationType}; +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, + posts::queries::get_posts_by_author, + profiles::helpers::find_aliases, + profiles::queries::{ + get_profile_by_acct, + get_profile_by_id, + search_profiles_by_did, + update_profile, + }, + profiles::types::{ + IdentityProof, + IdentityProofType, + ProfileUpdateData, + }, + relationships::queries::{ + get_followers_paginated, + get_following_paginated, + hide_replies, + hide_reposts, + show_replies, + show_reposts, + unfollow, + }, + subscriptions::queries::get_incoming_subscriptions, + users::queries::{ + create_user, + get_user_by_did, + is_valid_invite_code, + }, + users::types::{Role, UserCreateData}, +}; use mitra_utils::{ caip2::ChainId, canonicalization::canonicalize_object, @@ -36,7 +68,6 @@ use crate::activitypub::{ }, identifiers::local_actor_id, }; -use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::ValidationError; use crate::ethereum::{ contracts::ContractSet, @@ -68,37 +99,6 @@ use crate::mastodon_api::{ statuses::helpers::build_status_list, statuses::types::Status, }; -use crate::models::{ - posts::queries::get_posts_by_author, - profiles::helpers::find_aliases, - profiles::queries::{ - get_profile_by_acct, - get_profile_by_id, - search_profiles_by_did, - update_profile, - }, - profiles::types::{ - IdentityProof, - IdentityProofType, - ProfileUpdateData, - }, - relationships::queries::{ - get_followers_paginated, - get_following_paginated, - hide_replies, - hide_reposts, - show_replies, - show_reposts, - unfollow, - }, - subscriptions::queries::get_incoming_subscriptions, - users::queries::{ - create_user, - get_user_by_did, - is_valid_invite_code, - }, - users::types::{Role, UserCreateData}, -}; use crate::validators::profiles::clean_profile_update_data; use super::helpers::{follow_or_create_request, get_relationship}; use super::types::{ diff --git a/src/mastodon_api/apps/views.rs b/src/mastodon_api/apps/views.rs index b77a16a..4f27573 100644 --- a/src/mastodon_api/apps/views.rs +++ b/src/mastodon_api/apps/views.rs @@ -7,15 +7,16 @@ use actix_web::{ }; use uuid::Uuid; -use crate::database::{get_database_client, DbPool}; +use mitra_models::{ + database::{get_database_client, DbPool}, + oauth::queries::create_oauth_app, + oauth::types::DbOauthAppData, +}; + use crate::mastodon_api::{ errors::MastodonError, oauth::utils::generate_access_token, }; -use crate::models::{ - oauth::queries::create_oauth_app, - oauth::types::DbOauthAppData, -}; use super::types::{OauthApp, CreateAppRequest}; /// https://docs.joinmastodon.org/methods/apps/ diff --git a/src/mastodon_api/custom_emojis/types.rs b/src/mastodon_api/custom_emojis/types.rs index 3b9478b..d268ce1 100644 --- a/src/mastodon_api/custom_emojis/types.rs +++ b/src/mastodon_api/custom_emojis/types.rs @@ -1,7 +1,8 @@ use serde::Serialize; +use mitra_models::emojis::types::DbEmoji; + use crate::media::get_file_url; -use crate::models::emojis::types::DbEmoji; /// https://docs.joinmastodon.org/entities/CustomEmoji/ #[derive(Serialize)] diff --git a/src/mastodon_api/custom_emojis/views.rs b/src/mastodon_api/custom_emojis/views.rs index 38b5162..8109f50 100644 --- a/src/mastodon_api/custom_emojis/views.rs +++ b/src/mastodon_api/custom_emojis/views.rs @@ -6,10 +6,13 @@ use actix_web::{ Scope, }; -use crate::database::{get_database_client, DbPool}; +use mitra_models::{ + database::{get_database_client, DbPool}, + emojis::queries::get_local_emojis, +}; + use crate::http::get_request_base_url; use crate::mastodon_api::errors::MastodonError; -use crate::models::emojis::queries::get_local_emojis; use super::types::CustomEmoji; /// https://docs.joinmastodon.org/methods/custom_emojis/ diff --git a/src/mastodon_api/directory/views.rs b/src/mastodon_api/directory/views.rs index 0678166..4534f41 100644 --- a/src/mastodon_api/directory/views.rs +++ b/src/mastodon_api/directory/views.rs @@ -9,15 +9,17 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::{ + database::{get_database_client, DbPool}, + profiles::queries::get_profiles, +}; -use crate::database::{get_database_client, DbPool}; use crate::http::get_request_base_url; use crate::mastodon_api::{ accounts::types::Account, errors::MastodonError, oauth::auth::get_current_user, }; -use crate::models::profiles::queries::get_profiles; use super::types::DirectoryQueryParams; #[get("")] diff --git a/src/mastodon_api/errors.rs b/src/mastodon_api/errors.rs index 4cec0a6..b19b101 100644 --- a/src/mastodon_api/errors.rs +++ b/src/mastodon_api/errors.rs @@ -6,7 +6,8 @@ use actix_web::{ }; use serde::Serialize; -use crate::database::DatabaseError; +use mitra_models::database::DatabaseError; + use crate::errors::ValidationError; #[derive(thiserror::Error, Debug)] diff --git a/src/mastodon_api/instance/views.rs b/src/mastodon_api/instance/views.rs index 79b801f..230f4b3 100644 --- a/src/mastodon_api/instance/views.rs +++ b/src/mastodon_api/instance/views.rs @@ -1,15 +1,16 @@ use actix_web::{get, web, HttpResponse, Scope}; use mitra_config::Config; - -use crate::database::{get_database_client, DbPool}; -use crate::ethereum::contracts::ContractSet; -use crate::mastodon_api::errors::MastodonError; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, instances::queries::{get_peers, get_peer_count}, posts::queries::get_local_post_count, users::queries::get_user_count, }; + +use crate::ethereum::contracts::ContractSet; +use crate::mastodon_api::errors::MastodonError; + use super::types::InstanceInfo; /// https://docs.joinmastodon.org/methods/instance/#v1 diff --git a/src/mastodon_api/markers/types.rs b/src/mastodon_api/markers/types.rs index 5daff8c..a1cfcf7 100644 --- a/src/mastodon_api/markers/types.rs +++ b/src/mastodon_api/markers/types.rs @@ -1,8 +1,9 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +use mitra_models::markers::types::{DbTimelineMarker, Timeline}; + use crate::errors::ValidationError; -use crate::models::markers::types::{DbTimelineMarker, Timeline}; #[derive(Deserialize)] pub struct MarkerQueryParams { diff --git a/src/mastodon_api/markers/views.rs b/src/mastodon_api/markers/views.rs index 201082d..310c031 100644 --- a/src/mastodon_api/markers/views.rs +++ b/src/mastodon_api/markers/views.rs @@ -1,18 +1,20 @@ use actix_web::{get, post, web, HttpResponse, Scope}; use actix_web_httpauth::extractors::bearer::BearerAuth; -use crate::database::{get_database_client, DbPool}; -use crate::mastodon_api::{ - errors::MastodonError, - oauth::auth::get_current_user, -}; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, markers::queries::{ create_or_update_marker, get_marker_opt, }, markers::types::Timeline, }; + +use crate::mastodon_api::{ + errors::MastodonError, + oauth::auth::get_current_user, +}; + use super::types::{MarkerQueryParams, MarkerCreateData, Markers}; /// https://docs.joinmastodon.org/methods/timelines/markers/ diff --git a/src/mastodon_api/media/types.rs b/src/mastodon_api/media/types.rs index 22ab455..77e6361 100644 --- a/src/mastodon_api/media/types.rs +++ b/src/mastodon_api/media/types.rs @@ -1,12 +1,13 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::media::get_file_url; -use crate::models::attachments::types::{ +use mitra_models::attachments::types::{ AttachmentType, DbMediaAttachment, }; +use crate::media::get_file_url; + #[derive(Deserialize)] pub struct AttachmentCreateData { // base64-encoded file (not comtaible with Mastodon) diff --git a/src/mastodon_api/media/views.rs b/src/mastodon_api/media/views.rs index 5497618..80f57a2 100644 --- a/src/mastodon_api/media/views.rs +++ b/src/mastodon_api/media/views.rs @@ -3,14 +3,16 @@ use actix_web::{post, web, HttpResponse, Scope}; use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::{ + attachments::queries::create_attachment, + database::{get_database_client, DbPool}, +}; -use crate::database::{get_database_client, DbPool}; use crate::mastodon_api::{ errors::MastodonError, oauth::auth::get_current_user, uploads::save_b64_file, }; -use crate::models::attachments::queries::create_attachment; use super::types::{AttachmentCreateData, Attachment}; #[post("")] diff --git a/src/mastodon_api/notifications/types.rs b/src/mastodon_api/notifications/types.rs index cb3b8f2..eb264fc 100644 --- a/src/mastodon_api/notifications/types.rs +++ b/src/mastodon_api/notifications/types.rs @@ -1,12 +1,13 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +use mitra_models::notifications::types::{EventType, Notification}; + use crate::mastodon_api::{ accounts::types::Account, pagination::PageSize, statuses::types::Status, }; -use crate::models::notifications::types::{EventType, Notification}; fn default_page_size() -> PageSize { PageSize::new(20) } diff --git a/src/mastodon_api/notifications/views.rs b/src/mastodon_api/notifications/views.rs index f368c2d..b4e3de0 100644 --- a/src/mastodon_api/notifications/views.rs +++ b/src/mastodon_api/notifications/views.rs @@ -9,15 +9,17 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::{ + database::{get_database_client, DbPool}, + notifications::queries::get_notifications, +}; -use crate::database::{get_database_client, DbPool}; use crate::http::get_request_base_url; use crate::mastodon_api::{ errors::MastodonError, oauth::auth::get_current_user, pagination::get_paginated_response, }; -use crate::models::notifications::queries::get_notifications; use super::types::{ApiNotification, NotificationQueryParams}; #[get("")] diff --git a/src/mastodon_api/oauth/auth.rs b/src/mastodon_api/oauth/auth.rs index f3ff24b..5b6f8c8 100644 --- a/src/mastodon_api/oauth/auth.rs +++ b/src/mastodon_api/oauth/auth.rs @@ -1,10 +1,11 @@ -use crate::database::{DatabaseClient, DatabaseError}; -use crate::mastodon_api::errors::MastodonError; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, oauth::queries::get_user_by_oauth_token, users::types::User, }; +use crate::mastodon_api::errors::MastodonError; + pub async fn get_current_user( db_client: &impl DatabaseClient, token: &str, diff --git a/src/mastodon_api/oauth/views.rs b/src/mastodon_api/oauth/views.rs index 5363f58..db55820 100644 --- a/src/mastodon_api/oauth/views.rs +++ b/src/mastodon_api/oauth/views.rs @@ -10,17 +10,8 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use chrono::{Duration, Utc}; use mitra_config::Config; -use mitra_utils::passwords::verify_password; - -use crate::database::{get_database_client, DatabaseError, DbPool}; -use crate::errors::ValidationError; -use crate::ethereum::{ - eip4361::verify_eip4361_signature, - utils::validate_ethereum_address, -}; -use crate::http::FormOrJson; -use crate::mastodon_api::errors::MastodonError; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, oauth::queries::{ create_oauth_authorization, delete_oauth_token, @@ -33,6 +24,16 @@ use crate::models::{ get_user_by_login_address, }, }; +use mitra_utils::passwords::verify_password; + +use crate::errors::ValidationError; +use crate::ethereum::{ + eip4361::verify_eip4361_signature, + utils::validate_ethereum_address, +}; +use crate::http::FormOrJson; +use crate::mastodon_api::errors::MastodonError; + use super::auth::get_current_user; use super::types::{ AuthorizationRequest, diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index a078360..65a7c33 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -4,25 +4,8 @@ use regex::Regex; use url::Url; use mitra_config::Config; -use mitra_utils::{ - currencies::Currency, - did::Did, -}; - -use crate::activitypub::{ - fetcher::helpers::{ - get_or_import_profile_by_actor_id, - import_post, - import_profile_by_actor_address, - }, - identifiers::{parse_local_actor_id, parse_local_object_id}, - HandlerError, -}; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::errors::ValidationError; -use crate::ethereum::utils::validate_ethereum_address; -use crate::media::MediaStorage; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, posts::{ helpers::{can_view_post, get_local_post_by_id}, types::Post, @@ -39,6 +22,23 @@ use crate::models::{ types::User, }, }; +use mitra_utils::{ + currencies::Currency, + did::Did, +}; + +use crate::activitypub::{ + fetcher::helpers::{ + get_or_import_profile_by_actor_id, + import_post, + import_profile_by_actor_address, + }, + identifiers::{parse_local_actor_id, parse_local_object_id}, + HandlerError, +}; +use crate::errors::ValidationError; +use crate::ethereum::utils::validate_ethereum_address; +use crate::media::MediaStorage; use crate::webfinger::types::ActorAddress; const SEARCH_FETCHER_TIMEOUT: u64 = 5; diff --git a/src/mastodon_api/search/views.rs b/src/mastodon_api/search/views.rs index 9d3e836..24606fe 100644 --- a/src/mastodon_api/search/views.rs +++ b/src/mastodon_api/search/views.rs @@ -9,8 +9,8 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::database::{get_database_client, DbPool}; -use crate::database::{get_database_client, DbPool}; use crate::http::get_request_base_url; use crate::mastodon_api::{ accounts::types::Account, diff --git a/src/mastodon_api/settings/helpers.rs b/src/mastodon_api/settings/helpers.rs index 6b203fb..c9a6345 100644 --- a/src/mastodon_api/settings/helpers.rs +++ b/src/mastodon_api/settings/helpers.rs @@ -1,25 +1,13 @@ use uuid::Uuid; use mitra_config::Config; - -use crate::activitypub::{ - builders::{ - move_person::prepare_move_person, - undo_follow::prepare_undo_follow, +use mitra_models::{ + database::{ + get_database_client, + DatabaseClient, + DatabaseError, + DbPool, }, - fetcher::helpers::get_or_import_profile_by_actor_address, - HandlerError, -}; -use crate::database::{ - get_database_client, - DatabaseClient, - DatabaseError, - DbPool, -}; -use crate::errors::ValidationError; -use crate::mastodon_api::accounts::helpers::follow_or_create_request; -use crate::media::MediaStorage; -use crate::models::{ profiles::types::DbActorProfile, relationships::queries::{ follow, @@ -29,6 +17,18 @@ use crate::models::{ }, users::types::User, }; + +use crate::activitypub::{ + builders::{ + move_person::prepare_move_person, + undo_follow::prepare_undo_follow, + }, + fetcher::helpers::get_or_import_profile_by_actor_address, + HandlerError, +}; +use crate::errors::ValidationError; +use crate::mastodon_api::accounts::helpers::follow_or_create_request; +use crate::media::MediaStorage; use crate::webfinger::types::ActorAddress; fn export_profiles_to_csv( @@ -199,7 +199,7 @@ pub async fn move_followers_task( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActor; + use mitra_models::profiles::types::DbActor; use super::*; #[test] diff --git a/src/mastodon_api/settings/views.rs b/src/mastodon_api/settings/views.rs index 51f66f6..4e62d63 100644 --- a/src/mastodon_api/settings/views.rs +++ b/src/mastodon_api/settings/views.rs @@ -9,10 +9,15 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, + profiles::helpers::find_aliases, + profiles::queries::get_profile_by_remote_actor_id, + users::queries::set_user_password, +}; use mitra_utils::passwords::hash_password; use crate::activitypub::identifiers::profile_actor_id; -use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::ValidationError; use crate::http::get_request_base_url; use crate::mastodon_api::{ @@ -20,11 +25,6 @@ use crate::mastodon_api::{ errors::MastodonError, oauth::auth::get_current_user, }; -use crate::models::{ - profiles::helpers::find_aliases, - profiles::queries::get_profile_by_remote_actor_id, - users::queries::set_user_password, -}; use super::helpers::{ export_followers, export_follows, diff --git a/src/mastodon_api/statuses/helpers.rs b/src/mastodon_api/statuses/helpers.rs index 2089c87..e37b6fb 100644 --- a/src/mastodon_api/statuses/helpers.rs +++ b/src/mastodon_api/statuses/helpers.rs @@ -1,9 +1,8 @@ use uuid::Uuid; use mitra_config::Instance; - -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, emojis::types::DbEmoji, posts::{ helpers::{add_related_posts, add_user_actions}, @@ -11,6 +10,7 @@ use crate::models::{ }, users::types::User, }; + use super::microsyntax::{ emojis::find_emojis, hashtags::{find_hashtags, replace_hashtags}, diff --git a/src/mastodon_api/statuses/microsyntax/emojis.rs b/src/mastodon_api/statuses/microsyntax/emojis.rs index aee723c..91b1147 100644 --- a/src/mastodon_api/statuses/microsyntax/emojis.rs +++ b/src/mastodon_api/statuses/microsyntax/emojis.rs @@ -2,11 +2,12 @@ use std::collections::HashMap; use regex::Regex; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, emojis::queries::get_local_emojis_by_names, emojis::types::DbEmoji, }; + use super::links::is_inside_code_block; // See also: EMOJI_NAME_RE in validators::emojis diff --git a/src/mastodon_api/statuses/microsyntax/links.rs b/src/mastodon_api/statuses/microsyntax/links.rs index 704cc25..e8e5a72 100644 --- a/src/mastodon_api/statuses/microsyntax/links.rs +++ b/src/mastodon_api/statuses/microsyntax/links.rs @@ -2,9 +2,12 @@ use std::collections::HashMap; use regex::{Captures, Match, Regex}; +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, + posts::types::{Post, Visibility}, +}; + use crate::activitypub::fetcher::helpers::get_post_by_object_id; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::posts::types::{Post, Visibility}; // MediaWiki-like syntax: [[url|text]] const OBJECT_LINK_SEARCH_RE: &str = r"(?m)\[\[(?P[^\s\|]+)(\|(?P.+?))?\]\]"; diff --git a/src/mastodon_api/statuses/microsyntax/mentions.rs b/src/mastodon_api/statuses/microsyntax/mentions.rs index b8e9eda..4a2114d 100644 --- a/src/mastodon_api/statuses/microsyntax/mentions.rs +++ b/src/mastodon_api/statuses/microsyntax/mentions.rs @@ -2,12 +2,13 @@ use std::collections::HashMap; use regex::{Captures, Regex}; -use crate::activitypub::identifiers::profile_actor_url; -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, profiles::queries::get_profiles_by_accts, profiles::types::DbActorProfile, }; + +use crate::activitypub::identifiers::profile_actor_url; use crate::webfinger::types::ActorAddress; use super::links::is_inside_code_block; @@ -105,7 +106,7 @@ pub fn replace_mentions( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActor; + use mitra_models::profiles::types::DbActor; use super::*; const INSTANCE_HOSTNAME: &str = "server1.com"; diff --git a/src/mastodon_api/statuses/types.rs b/src/mastodon_api/statuses/types.rs index 64db3b7..946b94b 100644 --- a/src/mastodon_api/statuses/types.rs +++ b/src/mastodon_api/statuses/types.rs @@ -2,6 +2,12 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; +use mitra_models::{ + emojis::types::DbEmoji, + posts::types::{Post, Visibility}, + profiles::types::DbActorProfile, +}; + use crate::activitypub::identifiers::{ local_tag_collection, post_object_id, @@ -12,11 +18,6 @@ use crate::mastodon_api::{ custom_emojis::types::CustomEmoji, media::types::Attachment, }; -use crate::models::{ - emojis::types::DbEmoji, - posts::types::{Post, Visibility}, - profiles::types::DbActorProfile, -}; /// https://docs.joinmastodon.org/entities/mention/ #[derive(Serialize)] diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index 375b445..11ed12b 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -13,32 +13,8 @@ use chrono::Utc; use uuid::Uuid; use mitra_config::Config; -use mitra_utils::markdown::markdown_lite_to_html; - -use crate::activitypub::{ - builders::{ - announce::prepare_announce, - create_note::prepare_create_note, - delete_note::prepare_delete_note, - like::prepare_like, - undo_announce::prepare_undo_announce, - undo_like::prepare_undo_like, - }, - identifiers::local_object_id, -}; -use crate::database::{get_database_client, DatabaseError, DbPool}; -use crate::errors::ValidationError; -use crate::http::{get_request_base_url, FormOrJson}; -use crate::ipfs::{ - store as ipfs_store, - posts::PostMetadata, -}; -use crate::mastodon_api::{ - errors::MastodonError, - oauth::auth::get_current_user, -}; -use crate::media::remove_media; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, posts::helpers::{can_create_post, can_view_post}, posts::queries::{ create_post, @@ -55,6 +31,30 @@ use crate::models::{ }, relationships::queries::get_subscribers, }; +use mitra_utils::markdown::markdown_lite_to_html; + +use crate::activitypub::{ + builders::{ + announce::prepare_announce, + create_note::prepare_create_note, + delete_note::prepare_delete_note, + like::prepare_like, + undo_announce::prepare_undo_announce, + undo_like::prepare_undo_like, + }, + identifiers::local_object_id, +}; +use crate::errors::ValidationError; +use crate::http::{get_request_base_url, FormOrJson}; +use crate::ipfs::{ + store as ipfs_store, + posts::PostMetadata, +}; +use crate::mastodon_api::{ + errors::MastodonError, + oauth::auth::get_current_user, +}; +use crate::media::remove_media; use crate::validators::posts::{ clean_content, ATTACHMENTS_MAX_NUM, diff --git a/src/mastodon_api/subscriptions/types.rs b/src/mastodon_api/subscriptions/types.rs index 9a8dcb1..265c5ce 100644 --- a/src/mastodon_api/subscriptions/types.rs +++ b/src/mastodon_api/subscriptions/types.rs @@ -2,10 +2,11 @@ use chrono::{DateTime, Duration, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::models::{ +use mitra_models::{ invoices::types::{DbInvoice, InvoiceStatus}, profiles::types::PaymentOption, }; + use crate::monero::subscriptions::MONERO_INVOICE_TIMEOUT; #[derive(Deserialize)] diff --git a/src/mastodon_api/subscriptions/views.rs b/src/mastodon_api/subscriptions/views.rs index dd7b510..a6d0b78 100644 --- a/src/mastodon_api/subscriptions/views.rs +++ b/src/mastodon_api/subscriptions/views.rs @@ -10,25 +10,8 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use uuid::Uuid; use mitra_config::Config; -use mitra_utils::currencies::Currency; - -use crate::activitypub::builders::update_person::prepare_update_person; -use crate::database::{get_database_client, DbPool}; -use crate::errors::ValidationError; -use crate::ethereum::{ - contracts::ContractSet, - subscriptions::{ - create_subscription_signature, - is_registered_recipient, - }, -}; -use crate::http::get_request_base_url; -use crate::mastodon_api::{ - accounts::types::Account, - errors::MastodonError, - oauth::auth::get_current_user, -}; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DbPool}, invoices::queries::{create_invoice, get_invoice_by_id}, profiles::queries::{ get_profile_by_id, @@ -44,6 +27,23 @@ use crate::models::{ users::queries::get_user_by_id, users::types::Permission, }; +use mitra_utils::currencies::Currency; + +use crate::activitypub::builders::update_person::prepare_update_person; +use crate::errors::ValidationError; +use crate::ethereum::{ + contracts::ContractSet, + subscriptions::{ + create_subscription_signature, + is_registered_recipient, + }, +}; +use crate::http::get_request_base_url; +use crate::mastodon_api::{ + accounts::types::Account, + errors::MastodonError, + oauth::auth::get_current_user, +}; use crate::monero::{ helpers::validate_monero_address, wallet::create_monero_address, diff --git a/src/mastodon_api/timelines/views.rs b/src/mastodon_api/timelines/views.rs index be2f695..3d7e6ea 100644 --- a/src/mastodon_api/timelines/views.rs +++ b/src/mastodon_api/timelines/views.rs @@ -9,19 +9,21 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use mitra_config::Config; +use mitra_models::{ + database::{get_database_client, DbPool}, + posts::queries::{ + get_home_timeline, + get_local_timeline, + get_posts_by_tag, + }, +}; -use crate::database::{get_database_client, DbPool}; use crate::http::get_request_base_url; use crate::mastodon_api::{ errors::MastodonError, oauth::auth::get_current_user, statuses::helpers::build_status_list, }; -use crate::models::posts::queries::{ - get_home_timeline, - get_local_timeline, - get_posts_by_tag, -}; use super::types::TimelineQueryParams; #[get("/home")] diff --git a/src/media.rs b/src/media.rs index c1cc463..def64e3 100644 --- a/src/media.rs +++ b/src/media.rs @@ -5,10 +5,10 @@ use std::path::{Path, PathBuf}; use sha2::{Digest, Sha256}; use mitra_config::Config; +use mitra_models::cleanup::DeletionQueue; use mitra_utils::files::{get_media_type_extension, write_file}; use crate::ipfs::store as ipfs_store; -use crate::models::cleanup::DeletionQueue; pub const SUPPORTED_MEDIA_TYPES: [&str; 11] = [ "audio/mpeg", diff --git a/src/monero/helpers.rs b/src/monero/helpers.rs index a4744fb..35d8d7c 100644 --- a/src/monero/helpers.rs +++ b/src/monero/helpers.rs @@ -5,16 +5,17 @@ use monero_rpc::monero::Address; use uuid::Uuid; use mitra_config::MoneroConfig; - -use crate::database::DatabaseClient; -use crate::errors::ValidationError; -use crate::models::{ +use mitra_models::{ + database::DatabaseClient, invoices::queries::{ get_invoice_by_id, set_invoice_status, }, invoices::types::InvoiceStatus, }; + +use crate::errors::ValidationError; + use super::wallet::{ open_monero_wallet, MoneroError, diff --git a/src/monero/subscriptions.rs b/src/monero/subscriptions.rs index 9b80c44..2712f6d 100644 --- a/src/monero/subscriptions.rs +++ b/src/monero/subscriptions.rs @@ -5,10 +5,8 @@ use monero_rpc::TransferType; use monero_rpc::monero::{Address, Amount}; use mitra_config::{Instance, MoneroConfig}; - -use crate::database::{get_database_client, DatabaseError, DbPool}; -use crate::ethereum::subscriptions::send_subscription_notifications; -use crate::models::{ +use mitra_models::{ + database::{get_database_client, DatabaseError, DbPool}, invoices::queries::{ get_invoice_by_address, get_invoices_by_status, @@ -24,6 +22,9 @@ use crate::models::{ }, users::queries::get_user_by_id, }; + +use crate::ethereum::subscriptions::send_subscription_notifications; + use super::wallet::{ get_single_item, get_subaddress_balance, diff --git a/src/monero/wallet.rs b/src/monero/wallet.rs index 9649018..2f6c9a6 100644 --- a/src/monero/wallet.rs +++ b/src/monero/wallet.rs @@ -14,8 +14,7 @@ use monero_rpc::monero::{ }; use mitra_config::MoneroConfig; - -use crate::database::DatabaseError; +use mitra_models::database::DatabaseError; #[derive(thiserror::Error, Debug)] pub enum MoneroError { diff --git a/src/nodeinfo/helpers.rs b/src/nodeinfo/helpers.rs index 074eceb..aca2c04 100644 --- a/src/nodeinfo/helpers.rs +++ b/src/nodeinfo/helpers.rs @@ -1,8 +1,9 @@ -use crate::database::{DatabaseClient, DatabaseError}; -use crate::models::{ +use mitra_models::{ + database::{DatabaseClient, DatabaseError}, posts::queries::get_local_post_count, users::queries::get_user_count, }; + use super::types::{Usage, Users}; pub async fn get_usage(db_client: &impl DatabaseClient) diff --git a/src/nodeinfo/views.rs b/src/nodeinfo/views.rs index a468e4f..3f6bd27 100644 --- a/src/nodeinfo/views.rs +++ b/src/nodeinfo/views.rs @@ -3,8 +3,8 @@ use actix_web::{get, web, HttpResponse}; use mitra_config::Config; +use mitra_models::database::{get_database_client, DbPool}; -use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; use crate::webfinger::types::{ Link, diff --git a/src/validators/profiles.rs b/src/validators/profiles.rs index ebfda99..6c7fb7c 100644 --- a/src/validators/profiles.rs +++ b/src/validators/profiles.rs @@ -1,13 +1,13 @@ use regex::Regex; -use mitra_utils::html::{clean_html, clean_html_strict}; - -use crate::errors::ValidationError; -use crate::models::profiles::types::{ +use mitra_models::profiles::types::{ ExtraField, ProfileCreateData, ProfileUpdateData, }; +use mitra_utils::html::{clean_html, clean_html_strict}; + +use crate::errors::ValidationError; const USERNAME_RE: &str = r"^[a-zA-Z0-9_\.-]+$"; const DISPLAY_NAME_MAX_LENGTH: usize = 200; @@ -129,7 +129,7 @@ pub fn clean_profile_update_data( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActor; + use mitra_models::profiles::types::DbActor; use super::*; #[test] diff --git a/src/web_client/views.rs b/src/web_client/views.rs index 69a8fd0..4d7b7c8 100644 --- a/src/web_client/views.rs +++ b/src/web_client/views.rs @@ -12,17 +12,17 @@ use actix_web::{ use uuid::Uuid; use mitra_config::Config; +use mitra_models::{ + database::{get_database_client, DbPool}, + posts::queries::get_post_by_id, + profiles::queries::{get_profile_by_acct, get_profile_by_id}, +}; use crate::activitypub::{ identifiers::{post_object_id, profile_actor_id}, views::is_activitypub_request, }; -use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::models::{ - posts::queries::get_post_by_id, - profiles::queries::{get_profile_by_acct, get_profile_by_id}, -}; pub fn static_service(web_client_dir: &Path) -> Files { Files::new("/", web_client_dir) diff --git a/src/webfinger/types.rs b/src/webfinger/types.rs index db48010..c17c2a8 100644 --- a/src/webfinger/types.rs +++ b/src/webfinger/types.rs @@ -8,8 +8,9 @@ use std::{ use regex::Regex; use serde::{Serialize, Deserialize}; +use mitra_models::profiles::types::DbActorProfile; + use crate::errors::ValidationError; -use crate::models::profiles::types::DbActorProfile; // See also: USERNAME_RE in validators::profiles const ACTOR_ADDRESS_RE: &str = r"^(?P[\w\.-]+)@(?P[\w\.-]+)$"; @@ -104,7 +105,7 @@ pub struct JsonResourceDescriptor { #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActor; + use mitra_models::profiles::types::DbActor; use super::*; #[test] diff --git a/src/webfinger/views.rs b/src/webfinger/views.rs index 833b597..aeb4a79 100644 --- a/src/webfinger/views.rs +++ b/src/webfinger/views.rs @@ -1,6 +1,10 @@ use actix_web::{get, web, HttpResponse}; use mitra_config::{Config, Instance}; +use mitra_models::{ + database::{get_database_client, DatabaseClient, DbPool}, + users::queries::is_registered_user, +}; use crate::activitypub::{ constants::AP_MEDIA_TYPE, @@ -10,9 +14,8 @@ use crate::activitypub::{ parse_local_actor_id, }, }; -use crate::database::{get_database_client, DatabaseClient, DbPool}; use crate::errors::{HttpError, ValidationError}; -use crate::models::users::queries::is_registered_user; + use super::types::{ ActorAddress, Link, @@ -98,10 +101,12 @@ pub async fn webfinger_view( #[cfg(test)] mod tests { use serial_test::serial; - use crate::database::test_utils::create_test_database; - use crate::models::users::{ - queries::create_user, - types::UserCreateData, + use mitra_models::{ + database::test_utils::create_test_database, + users::{ + queries::create_user, + types::UserCreateData, + }, }; use super::*;