mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-28 22:41:06 +00:00
extract common routing code into private "_guts()" functions
This commit is contained in:
parent
8e6b1ab86e
commit
a0aef50674
2 changed files with 36 additions and 24 deletions
|
@ -36,39 +36,39 @@ msgstr ""
|
||||||
msgid "{0}'s avatar"
|
msgid "{0}'s avatar"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:84
|
# src/routes/blogs.rs:96
|
||||||
msgid "To create a new blog, you need to be logged in"
|
msgid "To create a new blog, you need to be logged in"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:126
|
# src/routes/blogs.rs:138
|
||||||
msgid "A blog with the same name already exists."
|
msgid "A blog with the same name already exists."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:161
|
# src/routes/blogs.rs:173
|
||||||
msgid "Your blog was successfully created!"
|
msgid "Your blog was successfully created!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:183
|
# src/routes/blogs.rs:195
|
||||||
msgid "Your blog was deleted."
|
msgid "Your blog was deleted."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:190
|
# src/routes/blogs.rs:202
|
||||||
msgid "You are not allowed to delete this blog."
|
msgid "You are not allowed to delete this blog."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:238
|
# src/routes/blogs.rs:250
|
||||||
msgid "You are not allowed to edit this blog."
|
msgid "You are not allowed to edit this blog."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:283
|
# src/routes/blogs.rs:295
|
||||||
msgid "You can't use this media as a blog icon."
|
msgid "You can't use this media as a blog icon."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:301
|
# src/routes/blogs.rs:313
|
||||||
msgid "You can't use this media as a blog banner."
|
msgid "You can't use this media as a blog banner."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# src/routes/blogs.rs:334
|
# src/routes/blogs.rs:346
|
||||||
msgid "Your blog information have been updated."
|
msgid "Your blog information have been updated."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -19,21 +19,9 @@ use plume_models::{
|
||||||
use routes::{errors::ErrorPage, Page, RespondOrRedirect};
|
use routes::{errors::ErrorPage, Page, RespondOrRedirect};
|
||||||
use template_utils::{IntoContext, Ructe};
|
use template_utils::{IntoContext, Ructe};
|
||||||
|
|
||||||
#[get("/<custom_domain>?<page>", rank = 2)]
|
fn detail_guts(blog: Blog, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
||||||
pub fn custom_details(
|
|
||||||
custom_domain: String,
|
|
||||||
page: Option<Page>,
|
|
||||||
rockets: PlumeRocket,
|
|
||||||
) -> Result<Ructe, ErrorPage> {
|
|
||||||
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
|
||||||
details(blog.fqn, page, rockets)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/~/<name>?<page>", rank = 2)]
|
|
||||||
pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
|
||||||
let page = page.unwrap_or_default();
|
let page = page.unwrap_or_default();
|
||||||
let conn = &*rockets.conn;
|
let conn = &*rockets.conn;
|
||||||
let blog = Blog::find_by_fqn(&rockets, &name)?;
|
|
||||||
let posts = Post::blog_page(conn, &blog, page.limits())?;
|
let posts = Post::blog_page(conn, &blog, page.limits())?;
|
||||||
let articles_count = Post::count_for_blog(conn, &blog)?;
|
let articles_count = Post::count_for_blog(conn, &blog)?;
|
||||||
let authors = &blog.list_authors(conn)?;
|
let authors = &blog.list_authors(conn)?;
|
||||||
|
@ -48,6 +36,30 @@ pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/<custom_domain>?<page>", rank = 2)]
|
||||||
|
pub fn custom_details(
|
||||||
|
custom_domain: String,
|
||||||
|
page: Option<Page>,
|
||||||
|
rockets: PlumeRocket,
|
||||||
|
) -> Result<Ructe, ErrorPage> {
|
||||||
|
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain))?;
|
||||||
|
detail_guts(blog, page, rockets)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/~/<name>?<page>", rank = 2)]
|
||||||
|
pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
||||||
|
let blog = Blog::find_by_fqn(&rockets, &name)?;
|
||||||
|
detail_guts(blog, page, rockets)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn activity_detail_guts(
|
||||||
|
blog: Blog,
|
||||||
|
rockets: PlumeRocket,
|
||||||
|
_ap: ApRequest,
|
||||||
|
) -> Option<ActivityStream<CustomGroup>> {
|
||||||
|
Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/<custom_domain>", rank = 1)]
|
#[get("/<custom_domain>", rank = 1)]
|
||||||
pub fn custom_activity_details(
|
pub fn custom_activity_details(
|
||||||
custom_domain: String,
|
custom_domain: String,
|
||||||
|
@ -55,7 +67,7 @@ pub fn custom_activity_details(
|
||||||
_ap: ApRequest,
|
_ap: ApRequest,
|
||||||
) -> Option<ActivityStream<CustomGroup>> {
|
) -> Option<ActivityStream<CustomGroup>> {
|
||||||
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain)).ok()?;
|
let blog = Blog::find_by_host(&rockets, Host::new(custom_domain)).ok()?;
|
||||||
activity_details(blog.fqn, rockets, _ap)
|
activity_detail_guts(blog, rockets, _ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<name>", rank = 1)]
|
#[get("/~/<name>", rank = 1)]
|
||||||
|
@ -65,7 +77,7 @@ pub fn activity_details(
|
||||||
_ap: ApRequest,
|
_ap: ApRequest,
|
||||||
) -> Option<ActivityStream<CustomGroup>> {
|
) -> Option<ActivityStream<CustomGroup>> {
|
||||||
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
||||||
Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?))
|
activity_detail_guts(blog, rockets, _ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/blogs/new")]
|
#[get("/blogs/new")]
|
||||||
|
|
Loading…
Reference in a new issue