Add redirection views for /profile/{id} and /post/{id} paths

This commit is contained in:
silverpill 2022-10-27 22:12:54 +00:00
parent 367e3f37c7
commit 2e7403ef14
2 changed files with 38 additions and 1 deletions

View file

@ -15,7 +15,7 @@ use crate::errors::HttpError;
use crate::frontend::{get_post_page_url, get_profile_page_url}; use crate::frontend::{get_post_page_url, get_profile_page_url};
use crate::models::posts::helpers::{add_related_posts, can_view_post}; use crate::models::posts::helpers::{add_related_posts, can_view_post};
use crate::models::posts::queries::{get_post_by_id, get_posts_by_author}; use crate::models::posts::queries::{get_post_by_id, get_posts_by_author};
use crate::models::users::queries::get_user_by_name; use crate::models::users::queries::{get_user_by_id, get_user_by_name};
use super::actors::types::{get_local_actor, get_instance_actor}; use super::actors::types::{get_local_actor, get_instance_actor};
use super::builders::create_note::{build_note, build_create_note}; use super::builders::create_note::{build_note, build_create_note};
use super::collections::{ use super::collections::{
@ -27,8 +27,10 @@ use super::constants::{AP_MEDIA_TYPE, AS_MEDIA_TYPE};
use super::identifiers::{ use super::identifiers::{
local_actor_followers, local_actor_followers,
local_actor_following, local_actor_following,
local_actor_id,
local_actor_subscribers, local_actor_subscribers,
local_actor_outbox, local_actor_outbox,
local_object_id,
}; };
use super::receiver::receive_activity; use super::receiver::receive_activity;
@ -318,6 +320,39 @@ pub async fn object_view(
Ok(response) Ok(response)
} }
#[get("/profile/{profile_id}")]
pub async fn frontend_profile_redirect(
config: web::Data<Config>,
db_pool: web::Data<Pool>,
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 response = HttpResponse::Found()
.append_header(("Location", actor_id))
.finish();
return Ok(response);
}
#[get("/post/{object_id}")]
pub async fn frontend_post_redirect(
config: web::Data<Config>,
internal_object_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let object_id = local_object_id(
&config.instance_url(),
&internal_object_id,
);
let response = HttpResponse::Found()
.append_header(("Location", object_id))
.finish();
return Ok(response);
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use actix_web::http::{ use actix_web::http::{

View file

@ -153,6 +153,8 @@ async fn main() -> std::io::Result<()> {
.service(activitypub::actor_scope()) .service(activitypub::actor_scope())
.service(activitypub::instance_actor_scope()) .service(activitypub::instance_actor_scope())
.service(activitypub::object_view) .service(activitypub::object_view)
.service(activitypub::frontend_profile_redirect)
.service(activitypub::frontend_post_redirect)
.service(atom::get_atom_feed) .service(atom::get_atom_feed)
.service(nodeinfo::get_nodeinfo) .service(nodeinfo::get_nodeinfo)
.service(nodeinfo::get_nodeinfo_2_0); .service(nodeinfo::get_nodeinfo_2_0);