mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
This commit is contained in:
parent
ab9b60e86d
commit
3bfa8ab4ff
3 changed files with 12 additions and 8 deletions
|
@ -1,10 +1,9 @@
|
|||
use crate::{
|
||||
http::{create_apub_response, create_apub_tombstone_response},
|
||||
http::{create_apub_response, create_apub_tombstone_response, err_object_not_local},
|
||||
objects::comment::ApubComment,
|
||||
};
|
||||
use activitypub_federation::traits::ApubObject;
|
||||
use actix_web::{web, web::Path, HttpResponse};
|
||||
use diesel::result::Error::NotFound;
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
@ -24,7 +23,7 @@ pub(crate) async fn get_apub_comment(
|
|||
let id = CommentId(info.comment_id.parse::<i32>()?);
|
||||
let comment: ApubComment = Comment::read(context.pool(), id).await?.into();
|
||||
if !comment.local {
|
||||
return Err(NotFound.into());
|
||||
return Err(err_object_not_local());
|
||||
}
|
||||
|
||||
if !comment.deleted && !comment.removed {
|
||||
|
|
|
@ -100,6 +100,10 @@ fn create_apub_tombstone_response<T: Into<Url>>(id: T) -> HttpResponse {
|
|||
.json(WithContext::new(tombstone, CONTEXT.deref().clone()))
|
||||
}
|
||||
|
||||
fn err_object_not_local() -> LemmyError {
|
||||
LemmyError::from_message("Object not local, fetch it from original instance")
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ActivityQuery {
|
||||
type_: String,
|
||||
|
@ -123,8 +127,10 @@ pub(crate) async fn get_activity(
|
|||
let activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?;
|
||||
|
||||
let sensitive = activity.sensitive.unwrap_or(true);
|
||||
if !activity.local || sensitive {
|
||||
Ok(HttpResponse::NotFound().finish())
|
||||
if !activity.local {
|
||||
return Err(err_object_not_local());
|
||||
} else if sensitive {
|
||||
Ok(HttpResponse::Forbidden().finish())
|
||||
} else {
|
||||
Ok(create_json_apub_response(activity.data))
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use crate::{
|
||||
http::{create_apub_response, create_apub_tombstone_response},
|
||||
http::{create_apub_response, create_apub_tombstone_response, err_object_not_local},
|
||||
objects::post::ApubPost,
|
||||
};
|
||||
use activitypub_federation::traits::ApubObject;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use diesel::result::Error::NotFound;
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
@ -24,7 +23,7 @@ pub(crate) async fn get_apub_post(
|
|||
let id = PostId(info.post_id.parse::<i32>()?);
|
||||
let post: ApubPost = Post::read(context.pool(), id).await?.into();
|
||||
if !post.local {
|
||||
return Err(NotFound.into());
|
||||
return Err(err_object_not_local());
|
||||
}
|
||||
|
||||
if !post.deleted && !post.removed {
|
||||
|
|
Loading…
Reference in a new issue