Add webclient redirection rule for /@username routes

This commit is contained in:
silverpill 2023-03-18 13:29:03 +00:00
parent a07d7ce34a
commit f27b2e13eb
3 changed files with 26 additions and 1 deletions

View file

@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed ### Fixed
- Make webclient-to-object redirects work for remote profiles and posts. - Make webclient-to-object redirects work for remote profiles and posts.
- Added webclient redirection rule for `/@username` routes.
## [1.17.0] - 2023-03-15 ## [1.17.0] - 2023-03-15

View file

@ -175,6 +175,7 @@ async fn main() -> std::io::Result<()> {
.service(nodeinfo::get_nodeinfo_2_0) .service(nodeinfo::get_nodeinfo_2_0)
.service(nodeinfo::get_nodeinfo_2_1) .service(nodeinfo::get_nodeinfo_2_1)
.service(web_client::profile_page_redirect()) .service(web_client::profile_page_redirect())
.service(web_client::profile_acct_page_redirect())
.service(web_client::post_page_redirect()) .service(web_client::post_page_redirect())
.service( .service(
// Fallback for well-known paths // Fallback for well-known paths

View file

@ -20,7 +20,7 @@ use crate::database::{get_database_client, DbPool};
use crate::errors::HttpError; use crate::errors::HttpError;
use crate::models::{ use crate::models::{
posts::queries::get_post_by_id, posts::queries::get_post_by_id,
profiles::queries::get_profile_by_id, profiles::queries::{get_profile_by_acct, get_profile_by_id},
}; };
pub fn static_service(web_client_dir: &Path) -> Files { pub fn static_service(web_client_dir: &Path) -> Files {
@ -44,6 +44,7 @@ pub fn static_service(web_client_dir: &Path) -> Files {
})) }))
} }
// DEPRECATED
async fn profile_page_redirect_view( async fn profile_page_redirect_view(
config: web::Data<Config>, config: web::Data<Config>,
db_pool: web::Data<DbPool>, db_pool: web::Data<DbPool>,
@ -66,6 +67,28 @@ pub fn profile_page_redirect() -> Resource {
.route(web::get().to(profile_page_redirect_view)) .route(web::get().to(profile_page_redirect_view))
} }
async fn profile_acct_page_redirect_view(
config: web::Data<Config>,
db_pool: web::Data<DbPool>,
acct: web::Path<String>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let profile = get_profile_by_acct(db_client, &acct).await?;
let actor_id = profile.actor_id(&config.instance_url());
let response = HttpResponse::Found()
.append_header(("Location", actor_id))
.finish();
Ok(response)
}
pub fn profile_acct_page_redirect() -> Resource {
web::resource("/@{acct}")
.guard(guard::fn_guard(|ctx| {
is_activitypub_request(ctx.head().headers())
}))
.route(web::get().to(profile_acct_page_redirect_view))
}
async fn post_page_redirect_view( async fn post_page_redirect_view(
config: web::Data<Config>, config: web::Data<Config>,
db_pool: web::Data<DbPool>, db_pool: web::Data<DbPool>,