From 8b817d50c553cb95c144062907a5cadadcf83169 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 12 Sep 2021 02:14:49 +0900 Subject: [PATCH] Add URI /!/ --- src/main.rs | 1 + src/routes/instance.rs | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8a896b2a..aa227fd4 100755 --- a/src/main.rs +++ b/src/main.rs @@ -129,6 +129,7 @@ Then try to restart Plume. routes::comments::delete, routes::comments::activity_pub, routes::instance::index, + routes::instance::activity_details, routes::instance::admin, routes::instance::admin_mod, routes::instance::admin_instances, diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 648c2960..aa95bc81 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -11,7 +11,7 @@ use validator::{Validate, ValidationErrors}; use crate::inbox; use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect}; use crate::template_utils::{IntoContext, Ructe}; -use plume_common::activity_pub::{broadcast, inbox::FromId}; +use plume_common::activity_pub::{broadcast, inbox::FromId, ActivityStream, ApRequest}; use plume_models::{ admin::*, blocklisted_emails::*, @@ -49,6 +49,36 @@ pub fn index(conn: DbConn, rockets: PlumeRocket) -> Result { ))) } +/// Experimental +/// "!" might be change in the future +/// +/// This exists for communication with Mastodon. +/// Secure mode Mastodon requires HTTP signature for event GET requests. +/// To sign requests, public key of request sender is required. We decided +/// the sender is local instance. +#[get("/!/")] +pub fn activity_details( + public_domain: String, + conn: DbConn, + _ap: ApRequest, +) -> Option> { + if let Ok(instance) = Instance::find_by_domain(&conn, &public_domain) { + if !instance.local { + return None; + } + match instance.to_activity() { + Ok(activity) => Some(ActivityStream::new(activity)), + Err(plume_models::Error::NotFound) => None, + Err(err) => { + tracing::error!("{:?}", err); + panic!(); + } + } + } else { + None + } +} + #[get("/admin")] pub fn admin(_admin: Admin, conn: DbConn, rockets: PlumeRocket) -> Result { let local_inst = Instance::get_local()?;