Add custom_details and custom_activity_details as first routes
how this works: we use find_by_host() to find the Host in question, the defer to the existing function! Caveat: Currently, we, in that function, we do another lookup DB lookup for the Blog, even thou we already know it. It might be wise, to have both of those another wrapper here?!
This commit is contained in:
parent
0645f7e253
commit
468e663344
@ -195,6 +195,23 @@ impl Blog {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_by_host(c: &PlumeRocket, host: Host) -> Result<Blog> {
|
||||
let from_db = blogs::table
|
||||
.filter(blogs::custom_domain.eq(host))
|
||||
.limit(1)
|
||||
.load::<Blog>(&*c.conn)?
|
||||
.into_iter()
|
||||
.next();
|
||||
if let Some(from_db) = from_db {
|
||||
Ok(from_db)
|
||||
} else {
|
||||
// we should never get here, because
|
||||
// a) load::<Blog>()? should return early if it fails
|
||||
// b) this function is only called after a Request::guard::<Host>()
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
||||
.links
|
||||
|
@ -36,39 +36,39 @@ msgstr ""
|
||||
msgid "{0}'s avatar"
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:64
|
||||
# src/routes/blogs.rs:84
|
||||
msgid "To create a new blog, you need to be logged in"
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:106
|
||||
# src/routes/blogs.rs:126
|
||||
msgid "A blog with the same name already exists."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:141
|
||||
# src/routes/blogs.rs:161
|
||||
msgid "Your blog was successfully created!"
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:163
|
||||
# src/routes/blogs.rs:183
|
||||
msgid "Your blog was deleted."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:170
|
||||
# src/routes/blogs.rs:190
|
||||
msgid "You are not allowed to delete this blog."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:218
|
||||
# src/routes/blogs.rs:238
|
||||
msgid "You are not allowed to edit this blog."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:263
|
||||
# src/routes/blogs.rs:283
|
||||
msgid "You can't use this media as a blog icon."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:281
|
||||
# src/routes/blogs.rs:301
|
||||
msgid "You can't use this media as a blog banner."
|
||||
msgstr ""
|
||||
|
||||
# src/routes/blogs.rs:314
|
||||
# src/routes/blogs.rs:334
|
||||
msgid "Your blog information have been updated."
|
||||
msgstr ""
|
||||
|
||||
|
@ -197,6 +197,13 @@ Then try to restart Plume
|
||||
});
|
||||
|
||||
let rocket = rocket::custom(CONFIG.rocket.clone().unwrap())
|
||||
.mount(
|
||||
"/custom_domains/",
|
||||
routes![
|
||||
routes::blogs::custom_details,
|
||||
routes::blogs::custom_activity_details,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
|
@ -19,6 +19,16 @@ use plume_models::{
|
||||
use routes::{errors::ErrorPage, Page, RespondOrRedirect};
|
||||
use template_utils::{IntoContext, Ructe};
|
||||
|
||||
#[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))?;
|
||||
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();
|
||||
@ -38,6 +48,16 @@ pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result
|
||||
)))
|
||||
}
|
||||
|
||||
#[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_details(blog.fqn, rockets, _ap)
|
||||
}
|
||||
|
||||
#[get("/~/<name>", rank = 1)]
|
||||
pub fn activity_details(
|
||||
name: String,
|
||||
|
Loading…
Reference in New Issue
Block a user