Skip to content

Commit

Permalink
rename type
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Dec 2, 2023
1 parent 373c5c7 commit 8560ee0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kitsune-consts = { path = "../crates/kitsune-consts" }
kitsune-core = { path = "../crates/kitsune-core" }
kitsune-db = { path = "../crates/kitsune-db" }
kitsune-embed = { path = "../crates/kitsune-embed" }
kitsune-federation = { path = "../crates/kitsune-federation" }
kitsune-federation-filter = { path = "../crates/kitsune-federation-filter" }
kitsune-http-signatures = { path = "../crates/kitsune-http-signatures" }
kitsune-job-runner = { path = "../kitsune-job-runner" }
Expand Down
4 changes: 2 additions & 2 deletions kitsune/src/http/extractor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ mod auth;
mod json;
mod signed_activity;

pub struct FormOrJson<T>(pub T);
pub struct AgnosticForm<T>(pub T);

#[async_trait]
impl<S, T> FromRequest<S, Body> for FormOrJson<T>
impl<S, T> FromRequest<S, Body> for AgnosticForm<T>
where
S: Send + Sync,
T: DeserializeOwned + Send + 'static,
Expand Down
4 changes: 2 additions & 2 deletions kitsune/src/http/handler/mastodon/api/v1/accounts/follow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::Result,
http::extractor::{AuthExtractor, FormOrJson, MastodonAuthExtractor},
http::extractor::{AgnosticForm, AuthExtractor, MastodonAuthExtractor},
};
use axum::{
debug_handler,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub async fn post(
State(mastodon_mapper): State<MastodonMapper>,
AuthExtractor(user_data): MastodonAuthExtractor,
Path(id): Path<Uuid>,
follow_body: Option<FormOrJson<FollowBody>>,
follow_body: Option<AgnosticForm<FollowBody>>,
) -> Result<Json<Relationship>> {
if user_data.account.id == id {
return Err(ApiError::BadRequest.into());
Expand Down
4 changes: 2 additions & 2 deletions kitsune/src/http/handler/mastodon/api/v1/apps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::state::Zustand;
use crate::{
error::Result,
http::extractor::FormOrJson,
http::extractor::AgnosticForm,
oauth2::{CreateApp, OAuth2Service},
};
use axum::{extract::State, routing, Json, Router};
Expand All @@ -25,7 +25,7 @@ pub struct AppForm {
)]
async fn post(
State(oauth2): State<OAuth2Service>,
FormOrJson(form): FormOrJson<AppForm>,
AgnosticForm(form): AgnosticForm<AppForm>,
) -> Result<Json<App>> {
let create_app = CreateApp::builder()
.name(form.client_name)
Expand Down
4 changes: 2 additions & 2 deletions kitsune/src/http/handler/mastodon/api/v1/media.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
error::{Error, Result},
http::{
extractor::{AuthExtractor, FormOrJson, MastodonAuthExtractor},
extractor::{AgnosticForm, AuthExtractor, MastodonAuthExtractor},
util::buffer_multipart_to_tempfile,
},
state::Zustand,
Expand Down Expand Up @@ -108,7 +108,7 @@ pub async fn put(
State(mastodon_mapper): State<MastodonMapper>,
AuthExtractor(user_data): MastodonAuthExtractor,
Path(attachment_id): Path<Uuid>,
FormOrJson(form): FormOrJson<UpdateAttachment>,
AgnosticForm(form): AgnosticForm<UpdateAttachment>,
) -> Result<Json<MediaAttachment>> {
let update = Update::builder()
.account_id(user_data.account.id)
Expand Down
6 changes: 3 additions & 3 deletions kitsune/src/http/handler/mastodon/api/v1/statuses/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::Result,
http::extractor::{AuthExtractor, FormOrJson, MastodonAuthExtractor},
http::extractor::{AgnosticForm, AuthExtractor, MastodonAuthExtractor},
state::Zustand,
};
use axum::{
Expand Down Expand Up @@ -124,7 +124,7 @@ async fn post(
State(mastodon_mapper): State<MastodonMapper>,
State(post_service): State<PostService>,
AuthExtractor(user_data): MastodonAuthExtractor,
FormOrJson(form): FormOrJson<CreateForm>,
AgnosticForm(form): AgnosticForm<CreateForm>,
) -> Result<Json<Status>> {
let create_post = CreatePost::builder()
.author_id(user_data.account.id)
Expand Down Expand Up @@ -159,7 +159,7 @@ async fn put(
State(post): State<PostService>,
AuthExtractor(user_data): MastodonAuthExtractor,
Path(id): Path<Uuid>,
FormOrJson(form): FormOrJson<UpdateForm>,
AgnosticForm(form): AgnosticForm<UpdateForm>,
) -> Result<Json<Status>> {
let update_post = UpdatePost::builder()
.account_id(user_data.account.id)
Expand Down
4 changes: 2 additions & 2 deletions kitsune/src/http/handler/mastodon/api/v1/statuses/reblog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::Result,
http::extractor::{AuthExtractor, FormOrJson, MastodonAuthExtractor},
http::extractor::{AgnosticForm, AuthExtractor, MastodonAuthExtractor},
};
use axum::{
debug_handler,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub async fn post(
State(post): State<PostService>,
AuthExtractor(user_data): MastodonAuthExtractor,
Path(id): Path<Uuid>,
FormOrJson(body): FormOrJson<RepostBody>,
AgnosticForm(body): AgnosticForm<RepostBody>,
) -> Result<Json<Status>> {
let repost_post = RepostPost::builder()
.account_id(user_data.account.id)
Expand Down
17 changes: 11 additions & 6 deletions kitsune/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use axum_extra::extract::cookie;
use kitsune_core::event::PostEventEmitter;
use kitsune_db::PgPool;
use kitsune_embed::Client as EmbedClient;
use kitsune_federation::any::{AnyDeliverer, AnyFetcher};
use kitsune_federation_filter::FederationFilter;
use kitsune_service::{
account::AccountService, attachment::AttachmentService, captcha::CaptchaService,
custom_emoji::CustomEmojiService, instance::InstanceService, job::JobService,
mailing::MailingService, notification::NotificationService, post::PostService,
search::SearchService, timeline::TimelineService, url::UrlService, user::UserService,
attachment::AttachmentService, captcha::CaptchaService, custom_emoji::CustomEmojiService,
instance::InstanceService, job::JobService, mailing::MailingService,
notification::NotificationService, timeline::TimelineService, url::UrlService,
user::UserService,
};
use std::{ops::Deref, sync::Arc};

Expand All @@ -18,6 +19,11 @@ use kitsune_mastodon::MastodonMapper;
#[cfg(feature = "oidc")]
use kitsune_oidc::OidcService;

pub type AccountService =
kitsune_service::account::AccountService<Vec<AnyFetcher>, Vec<AnyDeliverer>>;
pub type PostService = kitsune_service::post::PostService<Vec<AnyFetcher>, Vec<AnyDeliverer>>;
pub type SearchService = kitsune_service::search::SearchService<Vec<AnyFetcher>>;

#[macro_export]
macro_rules! impl_from_ref {
($source:path; [ $($target:path => $extract_impl:expr),+ ]) => {
Expand All @@ -35,7 +41,7 @@ macro_rules! impl_from_ref {
impl_from_ref! {
Zustand;
[
PgPool => |input: &Zustand| input.db_pool().clone()
PgPool => |input: &Zustand| input.db_pool.clone()
]
}

Expand Down Expand Up @@ -72,7 +78,6 @@ impl_from_ref! {
]
}

#[derive(Clone)]
pub struct SessionConfig {
pub cookie_key: cookie::Key,
pub flash_config: axum_flash::Config,
Expand Down

0 comments on commit 8560ee0

Please sign in to comment.