From a07d7ce34a20d412a7d22a518e749b78fc59b33d Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 18 Mar 2023 13:37:46 +0000 Subject: [PATCH] Make webclient-to-object redirects work for remote profiles and posts --- CHANGELOG.md | 4 ++++ src/web_client/views.rs | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e31e1ed..18e2b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `fep-e232` feature flag (disabled by default). +### Fixed + +- Make webclient-to-object redirects work for remote profiles and posts. + ## [1.17.0] - 2023-03-15 ### Added diff --git a/src/web_client/views.rs b/src/web_client/views.rs index 9860b2b..af0b9ea 100644 --- a/src/web_client/views.rs +++ b/src/web_client/views.rs @@ -14,12 +14,14 @@ use uuid::Uuid; use mitra_config::Config; use crate::activitypub::{ - identifiers::{local_actor_id, local_object_id}, views::is_activitypub_request, }; use crate::database::{get_database_client, DbPool}; use crate::errors::HttpError; -use crate::models::users::queries::get_user_by_id; +use crate::models::{ + posts::queries::get_post_by_id, + profiles::queries::get_profile_by_id, +}; pub fn static_service(web_client_dir: &Path) -> Files { Files::new("/", web_client_dir) @@ -48,11 +50,8 @@ async fn profile_page_redirect_view( profile_id: web::Path, ) -> Result { let db_client = &**get_database_client(&db_pool).await?; - let user = get_user_by_id(db_client, &profile_id).await?; - let actor_id = local_actor_id( - &config.instance_url(), - &user.profile.username, - ); + let profile = get_profile_by_id(db_client, &profile_id).await?; + let actor_id = profile.actor_id(&config.instance_url()); let response = HttpResponse::Found() .append_header(("Location", actor_id)) .finish(); @@ -69,12 +68,12 @@ pub fn profile_page_redirect() -> Resource { async fn post_page_redirect_view( config: web::Data, - internal_object_id: web::Path, + db_pool: web::Data, + post_id: web::Path, ) -> Result { - let object_id = local_object_id( - &config.instance_url(), - &internal_object_id, - ); + let db_client = &**get_database_client(&db_pool).await?; + let post = get_post_by_id(db_client, &post_id).await?; + let object_id = post.object_id(&config.instance_url()); let response = HttpResponse::Found() .append_header(("Location", object_id)) .finish();