Make post and profile page redirections work in Mastodon

This commit is contained in:
silverpill 2022-12-27 20:26:42 +00:00
parent 672564bdad
commit e7b318c761
3 changed files with 23 additions and 10 deletions

15
CHANGELOG.md Normal file
View file

@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Changed
- Changed text on Ethereum page.
### Fixed
- Fixed post and profile page redirections.

View file

@ -32,7 +32,7 @@ use super::identifiers::{
};
use super::receiver::receive_activity;
fn is_activitypub_request(headers: &HeaderMap) -> bool {
pub fn is_activitypub_request(headers: &HeaderMap) -> bool {
const CONTENT_TYPES: [&str; 4] = [
AP_MEDIA_TYPE,
AS_MEDIA_TYPE,

View file

@ -12,8 +12,8 @@ use actix_web::{
use uuid::Uuid;
use crate::activitypub::{
constants::{AP_MEDIA_TYPE, AS_MEDIA_TYPE},
identifiers::{local_actor_id, local_object_id},
views::is_activitypub_request,
};
use crate::config::Config;
use crate::database::{get_database_client, DbPool};
@ -59,10 +59,9 @@ async fn profile_page_redirect_view(
pub fn profile_page_redirect() -> Resource {
web::resource("/profile/{profile_id}")
.guard(
guard::Any(guard::Header("Accept", AP_MEDIA_TYPE))
.or(guard::Header("Accept", AS_MEDIA_TYPE))
)
.guard(guard::fn_guard(|ctx| {
is_activitypub_request(ctx.head().headers())
}))
.route(web::get().to(profile_page_redirect_view))
}
@ -82,9 +81,8 @@ async fn post_page_redirect_view(
pub fn post_page_redirect() -> Resource {
web::resource("/post/{object_id}")
.guard(
guard::Any(guard::Header("Accept", AP_MEDIA_TYPE))
.or(guard::Header("Accept", AS_MEDIA_TYPE))
)
.guard(guard::fn_guard(|ctx| {
is_activitypub_request(ctx.head().headers())
}))
.route(web::get().to(post_page_redirect_view))
}