fix: redirect after fetching if id is different
for example, pleroma servers objects under /notice/abcd... but the object id itself is different, under /objects/<uuid>. when fetching pleroma redirects, but we get unreliable behavior. redirect so that we can force clients to use the proper id
This commit is contained in:
parent
a3cf7a17e8
commit
95f9d05875
2 changed files with 12 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
use axum::http::StatusCode;
|
||||
use axum::{http::StatusCode, response::Redirect};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum UpubError {
|
||||
|
@ -22,6 +22,11 @@ pub enum UpubError {
|
|||
|
||||
#[error("invalid base64 string: {0}")]
|
||||
Base64(#[from] base64::DecodeError),
|
||||
|
||||
// TODO this isn't really an error but i need to redirect from some routes so this allows me to
|
||||
// keep the type hints on the return type, still what the hell!!!!
|
||||
#[error("redirecting to {0}")]
|
||||
Redirect(String),
|
||||
}
|
||||
|
||||
impl UpubError {
|
||||
|
@ -66,6 +71,7 @@ impl axum::response::IntoResponse for UpubError {
|
|||
fn into_response(self) -> axum::response::Response {
|
||||
let descr = self.to_string();
|
||||
match self {
|
||||
UpubError::Redirect(to) => Redirect::to(&to).into_response(),
|
||||
UpubError::Status(status) => (status, descr).into_response(),
|
||||
UpubError::Database(_) => (StatusCode::SERVICE_UNAVAILABLE, descr).into_response(),
|
||||
UpubError::Reqwest(x) =>
|
||||
|
|
|
@ -20,7 +20,11 @@ pub async fn view(
|
|||
ctx.oid(id.clone())
|
||||
};
|
||||
if auth.is_local() && query.fetch && !ctx.is_local(&oid) {
|
||||
ctx.fetch_object(&oid).await?;
|
||||
let obj = ctx.fetch_object(&oid).await?;
|
||||
// some implementations serve statuses on different urls than their AP id
|
||||
if obj.id != oid {
|
||||
return Err(UpubError::Redirect(crate::url!(ctx, "/objects/{}", ctx.id(&obj.id))));
|
||||
}
|
||||
}
|
||||
|
||||
let item = model::addressing::Entity::find_addressed()
|
||||
|
|
Loading…
Reference in a new issue