Server: redirect profile id to handle, impl UrlFor
This commit is contained in:
parent
abb9f79464
commit
2e9b671269
14
src/main.rs
14
src/main.rs
|
@ -214,6 +214,19 @@ impl std::str::FromStr for SecretKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Urls;
|
||||||
|
impl hyaenidae_profiles::UrlFor for Urls {
|
||||||
|
fn profile(&self, profile: &hyaenidae_profiles::store::Profile) -> String {
|
||||||
|
format!("/profiles/id/{}", profile.id())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn icon(&self, file: &hyaenidae_profiles::store::File) -> String {
|
||||||
|
file.pictrs_key()
|
||||||
|
.map(|key| images::largest_icon(key, images::ImageType::Png))
|
||||||
|
.unwrap_or("/404".to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct State {
|
struct State {
|
||||||
profiles: Arc<hyaenidae_profiles::State>,
|
profiles: Arc<hyaenidae_profiles::State>,
|
||||||
|
@ -249,6 +262,7 @@ impl State {
|
||||||
images.clone(),
|
images.clone(),
|
||||||
apub.clone(),
|
apub.clone(),
|
||||||
spawn.clone(),
|
spawn.clone(),
|
||||||
|
Urls,
|
||||||
arbiter,
|
arbiter,
|
||||||
db.clone(),
|
db.clone(),
|
||||||
)?,
|
)?,
|
||||||
|
|
|
@ -497,32 +497,10 @@ impl From<SubmissionPage> for crate::pagination::PageSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn id_view(
|
async fn id_view(id: web::Path<Uuid>, state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||||
loader: ActixLoader,
|
|
||||||
req: HttpRequest,
|
|
||||||
user: Option<User>,
|
|
||||||
self_profile: Option<UserProfile>,
|
|
||||||
id: web::Path<Uuid>,
|
|
||||||
page: Option<web::Query<SubmissionPage>>,
|
|
||||||
nav_state: NavState,
|
|
||||||
state: web::Data<State>,
|
|
||||||
) -> Result<HttpResponse, Error> {
|
|
||||||
let profile = profile_from_id(id.into_inner(), &state).await?;
|
let profile = profile_from_id(id.into_inner(), &state).await?;
|
||||||
if profile.is_suspended() {
|
|
||||||
return Ok(crate::to_404());
|
|
||||||
}
|
|
||||||
|
|
||||||
do_public_view(
|
Ok(crate::redirect(&profile.view_path()))
|
||||||
loader,
|
|
||||||
req.uri().path(),
|
|
||||||
user,
|
|
||||||
self_profile.map(|p| p.into_inner()),
|
|
||||||
profile,
|
|
||||||
page.map(|q| q.into_inner()),
|
|
||||||
nav_state,
|
|
||||||
&state,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_view(
|
async fn handle_view(
|
||||||
|
|
Loading…
Reference in a new issue