-use crate::{
- api::PerformApub,
- fetcher::search::{search_query_to_object_id, SearchableObjects},
-};
+use crate::fetcher::search::{search_query_to_object_id, SearchableObjects};
use activitypub_federation::config::Data;
+use actix_web::web::{Json, Query};
use diesel::NotFound;
use lemmy_api_common::{
context::LemmyContext,
use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool};
use lemmy_db_views::structs::{CommentView, PostView};
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
-use lemmy_utils::error::LemmyError;
-
-#[async_trait::async_trait]
-impl PerformApub for ResolveObject {
- type Response = ResolveObjectResponse;
+use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType};
- #[tracing::instrument(skip(context))]
- async fn perform(
- &self,
- context: &Data<LemmyContext>,
- ) -> Result<ResolveObjectResponse, LemmyError> {
- let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
- let person_id = local_user_view.person.id;
- check_private_instance(&Some(local_user_view), &local_site)?;
+#[tracing::instrument(skip(context))]
+pub async fn resolve_object(
+ data: Query<ResolveObject>,
+ context: Data<LemmyContext>,
+) -> Result<Json<ResolveObjectResponse>, LemmyError> {
+ let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
+ let person_id = local_user_view.person.id;
+ check_private_instance(&Some(local_user_view), &local_site)?;
- let res = search_query_to_object_id(&self.q, context)
- .await
- .map_err(|e| e.with_message("couldnt_find_object"))?;
- convert_response(res, person_id, context.pool())
- .await
- .map_err(|e| e.with_message("couldnt_find_object"))
- }
+ let res = search_query_to_object_id(&data.q, &context)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntFindObject)?;
+ convert_response(res, person_id, &mut context.pool())
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntFindObject)
}
async fn convert_response(
object: SearchableObjects,
user_id: PersonId,
- pool: &DbPool,
-) -> Result<ResolveObjectResponse, LemmyError> {
+ pool: &mut DbPool<'_>,
+) -> Result<Json<ResolveObjectResponse>, LemmyError> {
use SearchableObjects::*;
let removed_or_deleted;
let mut res = ResolveObjectResponse::default();
if removed_or_deleted {
return Err(NotFound {}.into());
}
- Ok(res)
+ Ok(Json(res))
}