add stub ActivityStreams inbox endpoint & worker
This commit is contained in:
parent
6e81a7198b
commit
5b985b0059
5 changed files with 63 additions and 1 deletions
|
@ -26,6 +26,7 @@ pub enum Error {
|
||||||
BadToken(jsonwebtoken::errors::Error),
|
BadToken(jsonwebtoken::errors::Error),
|
||||||
BadCredentials,
|
BadCredentials,
|
||||||
BadBearcap,
|
BadBearcap,
|
||||||
|
BadRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn utc_now() -> NaiveDateTime {
|
pub fn utc_now() -> NaiveDateTime {
|
||||||
|
@ -48,6 +49,7 @@ impl ResponseError for Error {
|
||||||
Error::BadToken(_) => StatusCode::UNAUTHORIZED,
|
Error::BadToken(_) => StatusCode::UNAUTHORIZED,
|
||||||
Error::BadCredentials => StatusCode::UNAUTHORIZED,
|
Error::BadCredentials => StatusCode::UNAUTHORIZED,
|
||||||
Error::BadBearcap => StatusCode::UNPROCESSABLE_ENTITY,
|
Error::BadBearcap => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
Error::BadRequest => StatusCode::BAD_REQUEST,
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +70,7 @@ impl fmt::Display for Error {
|
||||||
Error::BadToken(jwt_error) => jwt_error.fmt(f),
|
Error::BadToken(jwt_error) => jwt_error.fmt(f),
|
||||||
Error::BadCredentials => write!(f, "Invalid user name or password"),
|
Error::BadCredentials => write!(f, "Invalid user name or password"),
|
||||||
Error::BadBearcap => write!(f, "Invalid bearcap URL"),
|
Error::BadBearcap => write!(f, "Invalid bearcap URL"),
|
||||||
|
Error::BadRequest => write!(f, "Bad request"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/job/inbox.rs
Normal file
35
src/job/inbox.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use super::Job;
|
||||||
|
use crate::core::*;
|
||||||
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct InboxWorker {
|
||||||
|
raw: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InboxWorker {
|
||||||
|
pub fn new(raw: String) -> InboxWorker {
|
||||||
|
InboxWorker { raw }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Job for InboxWorker {
|
||||||
|
async fn perform(&self, state: &AppState) -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"inbox"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for InboxWorker {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "ActivityPub ingress: {}", &self.raw)
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,8 @@ use tokio::time::sleep;
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
use crate::state::{AppState, State};
|
use crate::state::{AppState, State};
|
||||||
|
|
||||||
|
pub mod inbox;
|
||||||
|
|
||||||
const MAX_RETRIES: u32 = 3;
|
const MAX_RETRIES: u32 = 3;
|
||||||
const ERROR_DELAY: Duration = Duration::from_secs(5 * 60);
|
const ERROR_DELAY: Duration = Duration::from_secs(5 * 60);
|
||||||
|
|
||||||
|
|
20
src/route/inbox.rs
Normal file
20
src/route/inbox.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::ap::processor::InboxWorker;
|
||||||
|
use actix_web::{post, web, HttpResponse, HttpRequest};
|
||||||
|
|
||||||
|
use crate::core::*;
|
||||||
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
#[post("")]
|
||||||
|
async fn post_inbox(body: String, request: HttpRequest, state: AppState) -> Result<HttpResponse> {
|
||||||
|
let content_type = request.headers().get("Content-Type").ok_or(Error::BadRequest)?.to_str()?;
|
||||||
|
if content_type != "application/activity+json" {
|
||||||
|
return Ok(HttpResponse::BadRequest().finish());
|
||||||
|
}
|
||||||
|
|
||||||
|
state.sched.schedule(InboxWorker::new(body));
|
||||||
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||||
|
cfg.service(post_inbox);
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
pub mod inbox;
|
||||||
|
|
||||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(web::scope("/api").configure(api::configure));
|
cfg.service(web::scope("/api").configure(api::configure))
|
||||||
|
.service(web::scope("/inbox").configure(inbox::configure));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue