Make webclient-to-object redirects work for remote profiles and posts

This commit is contained in:
silverpill 2023-03-18 13:37:46 +00:00
parent f037a4d58c
commit a07d7ce34a
2 changed files with 15 additions and 12 deletions

View file

@ -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

View file

@ -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<Uuid>,
) -> Result<HttpResponse, HttpError> {
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<Config>,
internal_object_id: web::Path<Uuid>,
db_pool: web::Data<DbPool>,
post_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
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();