Skip to content

Commit

Permalink
kitsune server progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Nov 26, 2023
1 parent 8088217 commit 62a3970
Show file tree
Hide file tree
Showing 46 changed files with 105 additions and 118 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ kitsune-messaging = { path = "../kitsune-messaging" }
serde = { version = "1.0.193", features = ["derive"] }
speedy-uuid = { path = "../../lib/speedy-uuid", features = ["diesel"] }
typed-builder = "0.18.0"

[features]
default = []
mastodon-api = []
9 changes: 8 additions & 1 deletion kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ kitsune-blocking = { path = "../crates/kitsune-blocking" }
kitsune-cache = { path = "../crates/kitsune-cache" }
kitsune-captcha = { path = "../crates/kitsune-captcha" }
kitsune-config = { path = "../crates/kitsune-config" }
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-http-signatures = { path = "../crates/kitsune-http-signatures" }
kitsune-job-runner = { path = "../kitsune-job-runner" }
kitsune-jobs = { path = "../crates/kitsune-jobs" }
kitsune-language = { path = "../crates/kitsune-language" }
kitsune-observability = { path = "../crates/kitsune-observability" }
kitsune-search = { path = "../crates/kitsune-search" }
kitsune-service = { path = "../crates/kitsune-service" }
kitsune-storage = { path = "../crates/kitsune-storage" }
kitsune-type = { path = "../crates/kitsune-type" }
kitsune-util = { path = "../crates/kitsune-util" }
metrics = "0.21.1"
mimalloc = "0.1.39"
mime = "0.3.17"
Expand Down Expand Up @@ -96,6 +100,9 @@ async-graphql = { version = "6.0.11", default-features = false, features = [
], optional = true }
async-graphql-axum = { version = "6.0.11", optional = true }

# "mastodon-api" feature
kitsune-mastodon = { path = "../crates/kitsune-mastodon", optional = true }

# "oidc" feature
kitsune-oidc = { path = "../crates/kitsune-oidc", optional = true }

Expand All @@ -114,6 +121,6 @@ graphql-api = [
"dep:async-graphql-axum",
"speedy-uuid/async-graphql",
]
mastodon-api = ["kitsune-core/mastodon-api"]
mastodon-api = ["dep:kitsune-mastodon"]
meilisearch = ["kitsune-search/meilisearch"]
oidc = ["dep:kitsune-oidc"]
24 changes: 9 additions & 15 deletions kitsune/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
response::{IntoResponse, Response},
};
use http::StatusCode;
use kitsune_core::error::{ApiError, Error as CoreError};
use kitsune_service::error::{Error as ServiceError, PostError};
use std::str::ParseBoolError;
use thiserror::Error;

Expand All @@ -20,9 +20,6 @@ pub enum Error {
#[error(transparent)]
Cache(#[from] kitsune_cache::Error),

#[error(transparent)]
Core(#[from] CoreError),

#[error(transparent)]
Database(#[from] diesel::result::Error),

Expand Down Expand Up @@ -54,6 +51,9 @@ pub enum Error {
#[error("Password mismatch")]
PasswordMismatch,

#[error(transparent)]
Service(#[from] ServiceError),

#[error(transparent)]
SimdJson(#[from] simd_json::Error),

Expand Down Expand Up @@ -88,12 +88,6 @@ pub enum OAuth2Error {
Web(#[from] oxide_auth_axum::WebError),
}

impl From<ApiError> for Error {
fn from(value: ApiError) -> Self {
Self::Core(value.into())
}
}

impl<E> From<kitsune_db::PoolError<E>> for Error
where
E: Into<Error>,
Expand All @@ -118,19 +112,19 @@ impl IntoResponse for Error {
Self::Database(diesel::result::Error::NotFound) => {
StatusCode::NOT_FOUND.into_response()
}
Self::Core(CoreError::Validate(report)) => {
Self::Service(ServiceError::Validate(report)) => {
(StatusCode::BAD_REQUEST, Json(report)).into_response()
}
err @ Self::Core(CoreError::Api(ApiError::NotFound)) => {
err @ Self::Service(ServiceError::NotFound) => {
(StatusCode::NOT_FOUND, err.to_string()).into_response()
}
err @ Self::Core(CoreError::Api(ApiError::BadRequest)) => {
err @ Self::Service(ServiceError::Post(PostError::BadRequest)) => {
(StatusCode::BAD_REQUEST, err.to_string()).into_response()
}
err @ Self::Core(CoreError::Api(ApiError::Unauthorised)) => {
err @ Self::Service(ServiceError::Post(PostError::Unauthorised)) => {
(StatusCode::UNAUTHORIZED, err.to_string()).into_response()
}
err @ Self::Core(CoreError::Api(ApiError::UnsupportedMediaType)) => {
err @ Self::Service(_) => {
(StatusCode::UNSUPPORTED_MEDIA_TYPE, err.to_string()).into_response()
}
error => {
Expand Down
7 changes: 5 additions & 2 deletions kitsune/src/http/extractor/signed_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use const_oid::db::rfc8410::ID_ED_25519;
use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
use http::{request::Parts, StatusCode};
use kitsune_core::{activitypub::fetcher::FetchOptions, error::ApiError};
use kitsune_core::traits::fetcher::AccountFetchOptions;
use kitsune_db::{model::account::Account, schema::accounts, PgPool};
use kitsune_http_signatures::{
ring::signature::{
Expand Down Expand Up @@ -70,7 +70,10 @@ impl FromRequest<Zustand, Body> for SignedActivity {

if !verify_signature(&parts, state.db_pool(), Some(&remote_user)).await? {
// Refetch the user and try again. Maybe they rekeyed
let opts = FetchOptions::builder().refetch(true).url(ap_id).build();
let opts = AccountFetchOptions::builder()
.refetch(true)
.url(ap_id)
.build();
let remote_user = state
.fetcher()
.fetch_actor(opts)
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/mutation/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
oauth2::CreateApp,
};
use async_graphql::{Context, Object, Result};
use kitsune_core::service::user::Register;
use kitsune_service::user::Register;

#[derive(Default)]
pub struct AuthMutation;
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/mutation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::http::graphql::ContextExt;
use async_graphql::{Context, Error, MergedObject, Result, Upload};
use bytes::Bytes;
use futures_util::{Stream, TryStreamExt};
use kitsune_core::service::attachment;
use kitsune_service::attachment;
use kitsune_storage::BoxError;
use mime::Mime;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/mutation/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::http::graphql::{
ContextExt,
};
use async_graphql::{Context, Object, Result};
use kitsune_core::service::post::{CreatePost, DeletePost};
use kitsune_service::post::{CreatePost, DeletePost};
use speedy_uuid::Uuid;

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/mutation/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::handle_upload;
use crate::http::graphql::{types::Account, ContextExt};
use async_graphql::{Context, Error, Object, Result, Upload};
use kitsune_core::service::account::Update;
use kitsune_service::account::Update;

#[derive(Default)]
pub struct UserMutation;
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/query/instance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::http::graphql::{types::Instance, ContextExt};
use async_graphql::{Context, Object, Result};
use kitsune_core::consts::VERSION;
use kitsune_consts::VERSION;
use std::convert::Into;

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/query/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_graphql::{
Context, Object, Result,
};
use futures_util::TryStreamExt;
use kitsune_core::service::timeline::{GetHome, GetPublic};
use kitsune_service::timeline::{GetHome, GetPublic};
use speedy_uuid::Uuid;

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/graphql/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use async_graphql::{
use diesel::{OptionalExtension, QueryDsl};
use diesel_async::RunQueryDsl;
use futures_util::TryStreamExt;
use kitsune_core::service::account::GetPosts;
use kitsune_db::{
model::{
account::Account as DbAccount, media_attachment::MediaAttachment as DbMediaAttachment,
},
schema::media_attachments,
};
use kitsune_service::account::GetPosts;
use scoped_futures::ScopedFutureExt;
use speedy_uuid::Uuid;
use time::OffsetDateTime;
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/handler/confirm_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
extract::{Path, State},
routing, Router,
};
use kitsune_core::service::user::UserService;
use kitsune_service::user::UserService;
use serde::Deserialize;

#[derive(Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion kitsune/src/http/handler/custom_emojis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{error::Result, http::responder::ActivityPubJson, state::Zustand};
use axum::{debug_handler, extract::Path, extract::State, routing, Router};
use kitsune_core::{mapping::IntoObject, service::custom_emoji::CustomEmojiService};
use kitsune_core::mapping::IntoObject;
use kitsune_service::custom_emoji::CustomEmojiService;
use kitsune_type::ap::emoji::Emoji;
use speedy_uuid::Uuid;

Expand Down
6 changes: 2 additions & 4 deletions kitsune/src/http/handler/mastodon/api/v1/custom_emojis.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::{error::Result, http::extractor::MastodonAuthExtractor, state::Zustand};
use axum::{debug_handler, extract::State, routing, Json, Router};
use futures_util::TryStreamExt;
use kitsune_core::{
mapping::MastodonMapper,
service::custom_emoji::{CustomEmojiService, GetEmojiList},
};
use kitsune_mastodon::MastodonMapper;
use kitsune_service::custom_emoji::{CustomEmojiService, GetEmojiList};
use kitsune_type::mastodon::CustomEmoji;

#[debug_handler(state = crate::state::Zustand)]
Expand Down
6 changes: 2 additions & 4 deletions kitsune/src/http/handler/mastodon/api/v1/instance.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::{error::Result, state::Zustand};
use axum::{extract::State, routing, Json, Router};
use kitsune_core::{
consts::VERSION,
service::{instance::InstanceService, url::UrlService},
};
use kitsune_consts::VERSION;
use kitsune_service::{instance::InstanceService, url::UrlService};
use kitsune_type::mastodon::{
instance::{Stats, Urls},
Instance,
Expand Down
8 changes: 3 additions & 5 deletions kitsune/src/http/handler/mastodon/api/v1/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ use axum::{
routing, Json, Router,
};
use futures_util::TryFutureExt;
use kitsune_core::{
error::ApiError,
mapping::MastodonMapper,
service::attachment::{AttachmentService, Update, Upload},
};
use kitsune_core::error::ApiError;
use kitsune_mastodon::MastodonMapper;
use kitsune_service::attachment::{AttachmentService, Update, Upload};
use kitsune_type::mastodon::MediaAttachment;
use serde::Deserialize;
use speedy_uuid::Uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use axum::{debug_handler, extract::State};
use http::StatusCode;
use kitsune_core::service::notification::NotificationService;
use kitsune_service::notification::NotificationService;

#[debug_handler(state = crate::state::Zustand)]
#[utoipa::path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
extract::{Path, State},
};
use http::StatusCode;
use kitsune_core::service::notification::NotificationService;
use kitsune_service::notification::NotificationService;
use speedy_uuid::Uuid;

#[debug_handler(state = crate::state::Zustand)]
Expand Down
12 changes: 5 additions & 7 deletions kitsune/src/http/handler/mastodon/api/v1/notifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ use axum::{
};
use axum_extra::extract::Query;
use futures_util::TryStreamExt;
use kitsune_core::{
error::ApiError,
mapping::MastodonMapper,
service::{
notification::{GetNotifications, NotificationService},
url::UrlService,
},
use kitsune_core::error::ApiError;
use kitsune_mastodon::MastodonMapper;
use kitsune_service::{
notification::{GetNotifications, NotificationService},
url::UrlService,
};
use kitsune_type::mastodon::{notification::NotificationType, Notification};
use serde::Deserialize;
Expand Down
3 changes: 2 additions & 1 deletion kitsune/src/http/handler/mastodon/api/v1/statuses/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use axum::{
Json,
};
use futures_util::TryStreamExt;
use kitsune_core::{mapping::MastodonMapper, service::post::PostService};
use kitsune_mastodon::MastodonMapper;
use kitsune_service::post::PostService;
use kitsune_type::mastodon::status::Context;
use speedy_uuid::Uuid;
use std::collections::VecDeque;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use axum::{
extract::{Path, State},
Json,
};
use kitsune_core::{mapping::MastodonMapper, service::post::PostService};
use kitsune_mastodon::MastodonMapper;
use kitsune_service::post::PostService;
use kitsune_type::mastodon::Status;
use speedy_uuid::Uuid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ use axum::{
};
use axum_extra::extract::Query;
use futures_util::TryStreamExt;
use kitsune_core::{
mapping::MastodonMapper,
service::{
post::{GetAccountsInteractingWithPost, PostService},
url::UrlService,
},
use kitsune_mastodon::MastodonMapper;
use kitsune_service::{
post::{GetAccountsInteractingWithPost, PostService},
url::UrlService,
};
use kitsune_type::mastodon::Account;
use serde::Deserialize;
Expand Down
6 changes: 2 additions & 4 deletions kitsune/src/http/handler/mastodon/api/v1/statuses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use axum::{
routing, Json, Router,
};
use http::StatusCode;
use kitsune_core::{
mapping::MastodonMapper,
service::post::{CreatePost, DeletePost, PostService, UpdatePost},
};
use kitsune_mastodon::MastodonMapper;
use kitsune_service::post::{CreatePost, DeletePost, PostService, UpdatePost};
use kitsune_type::mastodon::{status::Visibility, Status};
use serde::Deserialize;
use speedy_uuid::Uuid;
Expand Down
6 changes: 2 additions & 4 deletions kitsune/src/http/handler/mastodon/api/v1/statuses/reblog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use axum::{
extract::{Path, State},
Json,
};
use kitsune_core::{
mapping::MastodonMapper,
service::post::{PostService, RepostPost},
};
use kitsune_mastodon::MastodonMapper;
use kitsune_service::post::{PostService, RepostPost};
use kitsune_type::mastodon::{status::Visibility, Status};
use serde::Deserialize;
use speedy_uuid::Uuid;
Expand Down
Loading

0 comments on commit 62a3970

Please sign in to comment.