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)]
|
||||
struct State {
|
||||
profiles: Arc<hyaenidae_profiles::State>,
|
||||
|
@ -249,6 +262,7 @@ impl State {
|
|||
images.clone(),
|
||||
apub.clone(),
|
||||
spawn.clone(),
|
||||
Urls,
|
||||
arbiter,
|
||||
db.clone(),
|
||||
)?,
|
||||
|
|
|
@ -497,32 +497,10 @@ impl From<SubmissionPage> for crate::pagination::PageSource {
|
|||
}
|
||||
}
|
||||
|
||||
async fn id_view(
|
||||
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> {
|
||||
async fn id_view(id: web::Path<Uuid>, state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||
let profile = profile_from_id(id.into_inner(), &state).await?;
|
||||
if profile.is_suspended() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
||||
do_public_view(
|
||||
loader,
|
||||
req.uri().path(),
|
||||
user,
|
||||
self_profile.map(|p| p.into_inner()),
|
||||
profile,
|
||||
page.map(|q| q.into_inner()),
|
||||
nav_state,
|
||||
&state,
|
||||
)
|
||||
.await
|
||||
Ok(crate::redirect(&profile.view_path()))
|
||||
}
|
||||
|
||||
async fn handle_view(
|
||||
|
|
Loading…
Reference in a new issue