Compare commits

..

No commits in common. "27073138aea8b4282a2a45b7ecf231c40beeb639" and "b910e346eacd4591f3d9da2a098de0e0d09ccce6" have entirely different histories.

4 changed files with 8 additions and 34 deletions

View file

@ -1,5 +1,5 @@
use apb::{ActorMut, BaseMut, ObjectMut, PublicKeyMut};
use axum::{extract::{Query, State}, http::HeaderMap, response::{IntoResponse, Redirect, Response}, Form, Json};
use axum::{extract::{Query, State}, http::HeaderMap, response::{IntoResponse, Redirect, Response}, Json};
use reqwest::Method;
use crate::{errors::UpubError, server::{auth::{AuthIdentity, Identity}, fetcher::Fetcher, Context}, url};
@ -44,12 +44,12 @@ pub struct FetchPath {
id: String,
}
pub async fn proxy_get(
pub async fn debug(
State(ctx): State<Context>,
Query(query): Query<FetchPath>,
AuthIdentity(auth): AuthIdentity,
) -> crate::Result<Json<serde_json::Value>> {
// only local users can request fetches
// only local users can request debug fetches
if !ctx.cfg().security.allow_public_debugger && !matches!(auth, Identity::Local(_)) {
return Err(UpubError::unauthorized());
}
@ -60,31 +60,7 @@ pub async fn proxy_get(
None,
&ctx.base(),
&ctx.app().private_key,
&format!("{}+proxy", ctx.domain()),
)
.await?
.json::<serde_json::Value>()
.await?
))
}
pub async fn proxy_form(
State(ctx): State<Context>,
AuthIdentity(auth): AuthIdentity,
Form(query): Form<FetchPath>,
) -> crate::Result<Json<serde_json::Value>> {
// only local users can request fetches
if !ctx.cfg().security.allow_public_debugger && !matches!(auth, Identity::Local(_)) {
return Err(UpubError::unauthorized());
}
Ok(Json(
Context::request(
Method::GET,
&query.id,
None,
&ctx.base(),
&ctx.app().private_key,
&format!("{}+proxy", ctx.domain()),
&format!("{}|devtools", ctx.domain()),
)
.await?
.json::<serde_json::Value>()

View file

@ -25,8 +25,7 @@ impl ActivityPubRouter for Router<crate::server::Context> {
// core server inbox/outbox, maybe for feeds? TODO do we need these?
.route("/", get(ap::application::view))
// fetch route, to debug and retreive remote objects
.route("/proxy", get(ap::application::proxy_get))
.route("/proxy", post(ap::application::proxy_form))
.route("/dbg", get(ap::application::debug))
// TODO shared inboxes and instance stream will come later, just use users *boxes for now
.route("/inbox", post(ap::inbox::post))
.route("/inbox", get(ap::inbox::get))

View file

@ -77,7 +77,6 @@ pub async fn view(
.set_endpoints(Node::object(
serde_json::Value::new_object()
.set_shared_inbox(Some(&url!(ctx, "/inbox")))
.set_proxy_url(Some(&url!(ctx, "/proxy")))
));
if !auth.is(&uid) && !cfg.show_followers_count {

View file

@ -1,4 +1,4 @@
use apb::{Node, Base, Object, Document};
use apb::{Node, Link, Base, Object, Document};
use sea_orm::{sea_query::Expr, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, Set};
use crate::{errors::UpubError, model, server::Context};
@ -86,7 +86,7 @@ impl Normalizer for super::Context {
document_type: Set(o.as_document().map_or(apb::DocumentType::Document, |x| x.document_type().unwrap_or(apb::DocumentType::Page))),
name: Set(o.name().map(|x| x.to_string())),
media_type: Set(o.media_type().unwrap_or("link").to_string()),
created: Set(o.published().unwrap_or_else(chrono::Utc::now)),
created: Set(o.published().unwrap_or_else(|| chrono::Utc::now())),
},
};
model::attachment::Entity::insert(attachment_model)
@ -114,7 +114,7 @@ impl Normalizer for super::Context {
document_type: Set(img.as_document().map_or(apb::DocumentType::Document, |x| x.document_type().unwrap_or(apb::DocumentType::Page))),
name: Set(img.name().map(|x| x.to_string())),
media_type: Set(img.media_type().unwrap_or(media_type.as_deref().unwrap_or("link")).to_string()),
created: Set(img.published().unwrap_or_else(chrono::Utc::now)),
created: Set(img.published().unwrap_or_else(|| chrono::Utc::now())),
};
model::attachment::Entity::insert(attachment_model)
.exec(self.db())