mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-10 19:11:47 +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::{
|
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,
|
objects::comment::ApubComment,
|
||||||
};
|
};
|
||||||
use activitypub_federation::traits::ApubObject;
|
use activitypub_federation::traits::ApubObject;
|
||||||
use actix_web::{web, web::Path, HttpResponse};
|
use actix_web::{web, web::Path, HttpResponse};
|
||||||
use diesel::result::Error::NotFound;
|
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
|
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
|
||||||
use lemmy_utils::error::LemmyError;
|
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 id = CommentId(info.comment_id.parse::<i32>()?);
|
||||||
let comment: ApubComment = Comment::read(context.pool(), id).await?.into();
|
let comment: ApubComment = Comment::read(context.pool(), id).await?.into();
|
||||||
if !comment.local {
|
if !comment.local {
|
||||||
return Err(NotFound.into());
|
return Err(err_object_not_local());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !comment.deleted && !comment.removed {
|
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()))
|
.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)]
|
#[derive(Deserialize)]
|
||||||
pub struct ActivityQuery {
|
pub struct ActivityQuery {
|
||||||
type_: String,
|
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 activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?;
|
||||||
|
|
||||||
let sensitive = activity.sensitive.unwrap_or(true);
|
let sensitive = activity.sensitive.unwrap_or(true);
|
||||||
if !activity.local || sensitive {
|
if !activity.local {
|
||||||
Ok(HttpResponse::NotFound().finish())
|
return Err(err_object_not_local());
|
||||||
|
} else if sensitive {
|
||||||
|
Ok(HttpResponse::Forbidden().finish())
|
||||||
} else {
|
} else {
|
||||||
Ok(create_json_apub_response(activity.data))
|
Ok(create_json_apub_response(activity.data))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::{
|
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,
|
objects::post::ApubPost,
|
||||||
};
|
};
|
||||||
use activitypub_federation::traits::ApubObject;
|
use activitypub_federation::traits::ApubObject;
|
||||||
use actix_web::{web, HttpResponse};
|
use actix_web::{web, HttpResponse};
|
||||||
use diesel::result::Error::NotFound;
|
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
|
use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
|
||||||
use lemmy_utils::error::LemmyError;
|
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 id = PostId(info.post_id.parse::<i32>()?);
|
||||||
let post: ApubPost = Post::read(context.pool(), id).await?.into();
|
let post: ApubPost = Post::read(context.pool(), id).await?.into();
|
||||||
if !post.local {
|
if !post.local {
|
||||||
return Err(NotFound.into());
|
return Err(err_object_not_local());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !post.deleted && !post.removed {
|
if !post.deleted && !post.removed {
|
||||||
|
|
Loading…
Reference in a new issue