move custom_ route functions into a custom namespace
this way, we can actually use the url! macro
This commit is contained in:
parent
7139119b8f
commit
f635dcf6c3
@ -200,10 +200,10 @@ Then try to restart Plume
|
|||||||
.mount(
|
.mount(
|
||||||
"/custom_domains/",
|
"/custom_domains/",
|
||||||
routes![
|
routes![
|
||||||
routes::blogs::custom_details,
|
routes::blogs::custom::details,
|
||||||
routes::posts::custom_details,
|
routes::posts::custom::details,
|
||||||
routes::blogs::custom_activity_details,
|
routes::blogs::custom::activity_details,
|
||||||
routes::search::custom_search,
|
routes::search::custom::search,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount(
|
.mount(
|
||||||
|
@ -41,16 +41,6 @@ fn detail_guts(
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<custom_domain>?<page>", rank = 2)]
|
|
||||||
pub fn custom_details(
|
|
||||||
custom_domain: String,
|
|
||||||
page: Option<Page>,
|
|
||||||
rockets: PlumeRocket,
|
|
||||||
) -> Result<RespondOrRedirect, ErrorPage> {
|
|
||||||
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
|
||||||
detail_guts(blog, page, rockets)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/~/<name>?<page>", rank = 2)]
|
#[get("/~/<name>?<page>", rank = 2)]
|
||||||
pub fn details(
|
pub fn details(
|
||||||
name: String,
|
name: String,
|
||||||
@ -74,7 +64,7 @@ pub fn details(
|
|||||||
Ok(Redirect::to(format!("https://{}/", custom_domain)).into())
|
Ok(Redirect::to(format!("https://{}/", custom_domain)).into())
|
||||||
}
|
}
|
||||||
// we need this match arm, or the match won't compile
|
// we need this match arm, or the match won't compile
|
||||||
(None, _) => panic!("This code path should have already been handled!"),
|
(None, _) => unreachable!("This code path should have already been handled!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,16 +76,6 @@ pub fn activity_detail_guts(
|
|||||||
Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?))
|
Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<custom_domain>", rank = 1)]
|
|
||||||
pub fn custom_activity_details(
|
|
||||||
custom_domain: String,
|
|
||||||
rockets: PlumeRocket,
|
|
||||||
_ap: ApRequest,
|
|
||||||
) -> Option<ActivityStream<CustomGroup>> {
|
|
||||||
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain)).ok()?;
|
|
||||||
activity_detail_guts(blog, rockets, _ap)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/~/<name>", rank = 1)]
|
#[get("/~/<name>", rank = 1)]
|
||||||
pub fn activity_details(
|
pub fn activity_details(
|
||||||
name: String,
|
name: String,
|
||||||
@ -115,6 +95,32 @@ pub fn new(rockets: PlumeRocket, _user: User) -> Ructe {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod custom {
|
||||||
|
use plume_common::activity_pub::{ActivityStream, ApRequest};
|
||||||
|
use plume_models::{blogs::Blog, blogs::CustomGroup, blogs::Host, PlumeRocket};
|
||||||
|
use routes::{errors::ErrorPage, Page, RespondOrRedirect};
|
||||||
|
|
||||||
|
#[get("/<custom_domain>?<page>", rank = 2)]
|
||||||
|
pub fn details(
|
||||||
|
custom_domain: String,
|
||||||
|
page: Option<Page>,
|
||||||
|
rockets: PlumeRocket,
|
||||||
|
) -> Result<RespondOrRedirect, ErrorPage> {
|
||||||
|
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
||||||
|
super::detail_guts(blog, page, rockets)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/<custom_domain>", rank = 1)]
|
||||||
|
pub fn activity_details(
|
||||||
|
custom_domain: String,
|
||||||
|
rockets: PlumeRocket,
|
||||||
|
_ap: ApRequest,
|
||||||
|
) -> Option<ActivityStream<CustomGroup>> {
|
||||||
|
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain)).ok()?;
|
||||||
|
super::activity_detail_guts(blog, rockets, _ap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/blogs/new", rank = 2)]
|
#[get("/blogs/new", rank = 2)]
|
||||||
pub fn new_auth(i18n: I18n) -> Flash<Redirect> {
|
pub fn new_auth(i18n: I18n) -> Flash<Redirect> {
|
||||||
utils::requires_login(
|
utils::requires_login(
|
||||||
|
@ -83,33 +83,6 @@ fn detail_guts(
|
|||||||
)).into())
|
)).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/custom_domains/<custom_domain>/<slug>?<responding_to>", rank = 4)]
|
|
||||||
pub fn custom_details(
|
|
||||||
custom_domain: String,
|
|
||||||
slug: String,
|
|
||||||
responding_to: Option<i32>,
|
|
||||||
rockets: PlumeRocket,
|
|
||||||
) -> Result<RespondOrRedirect, ErrorPage> {
|
|
||||||
let conn = &*rockets.conn;
|
|
||||||
let user = rockets.user.clone();
|
|
||||||
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
|
||||||
let post = Post::find_by_slug(&*conn, &slug, blog.id)?;
|
|
||||||
if !(post.published
|
|
||||||
|| post
|
|
||||||
.get_authors(&*conn)?
|
|
||||||
.into_iter()
|
|
||||||
.any(|a| a.id == user.clone().map(|u| u.id).unwrap_or(0)))
|
|
||||||
{
|
|
||||||
return Ok(render!(errors::not_authorized(
|
|
||||||
&rockets.to_context(),
|
|
||||||
i18n!(rockets.intl.catalog, "This post isn't published yet.")
|
|
||||||
))
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
detail_guts(&blog, &post, responding_to, &rockets)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>?<responding_to>", rank = 4)]
|
#[get("/~/<blog>/<slug>?<responding_to>", rank = 4)]
|
||||||
pub fn details(
|
pub fn details(
|
||||||
blog: String,
|
blog: String,
|
||||||
@ -155,6 +128,39 @@ pub fn details(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod custom {
|
||||||
|
use plume_models::{blogs::Blog, blogs::Host, posts::Post, PlumeRocket};
|
||||||
|
use routes::{errors::ErrorPage, RespondOrRedirect};
|
||||||
|
use template_utils::{IntoContext, Ructe};
|
||||||
|
|
||||||
|
#[get("/custom_domains/<custom_domain>/<slug>?<responding_to>", rank = 4)]
|
||||||
|
pub fn details(
|
||||||
|
custom_domain: String,
|
||||||
|
slug: String,
|
||||||
|
responding_to: Option<i32>,
|
||||||
|
rockets: PlumeRocket,
|
||||||
|
) -> Result<RespondOrRedirect, ErrorPage> {
|
||||||
|
let conn = &*rockets.conn;
|
||||||
|
let user = rockets.user.clone();
|
||||||
|
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
||||||
|
let post = Post::find_by_slug(&*conn, &slug, blog.id)?;
|
||||||
|
if !(post.published
|
||||||
|
|| post
|
||||||
|
.get_authors(&*conn)?
|
||||||
|
.into_iter()
|
||||||
|
.any(|a| a.id == user.clone().map(|u| u.id).unwrap_or(0)))
|
||||||
|
{
|
||||||
|
return Ok(render!(errors::not_authorized(
|
||||||
|
&rockets.to_context(),
|
||||||
|
i18n!(rockets.intl.catalog, "This post isn't published yet.")
|
||||||
|
))
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
super::detail_guts(&blog, &post, responding_to, &rockets)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/~/<blog>/<slug>", rank = 3)]
|
#[get("/~/<blog>/<slug>", rank = 3)]
|
||||||
pub fn activity_details(
|
pub fn activity_details(
|
||||||
blog: String,
|
blog: String,
|
||||||
|
@ -88,11 +88,17 @@ pub fn search(query: Option<Form<SearchQuery>>, rockets: PlumeRocket) -> Ructe {
|
|||||||
search_guts(query, rockets)
|
search_guts(query, rockets)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<_custom_domain>/search?<query..>")]
|
pub mod custom {
|
||||||
pub fn custom_search(
|
use plume_models::PlumeRocket;
|
||||||
|
use rocket::request::Form;
|
||||||
|
use template_utils::Ructe;
|
||||||
|
|
||||||
|
#[get("/<_custom_domain>/search?<query..>")]
|
||||||
|
pub fn search(
|
||||||
_custom_domain: String,
|
_custom_domain: String,
|
||||||
query: Option<Form<SearchQuery>>,
|
query: Option<Form<super::SearchQuery>>,
|
||||||
rockets: PlumeRocket,
|
rockets: PlumeRocket,
|
||||||
) -> Ructe {
|
) -> Ructe {
|
||||||
search_guts(query, rockets)
|
super::search_guts(query, rockets)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user