You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
988 B
Rust

use actix_web::http::header::{ACCEPT, CONTENT_TYPE};
use actix_web::{post, web, HttpRequest, HttpResponse};
use crate::core::*;
use crate::job::inbox::InboxWorker;
use crate::state::AppState;
#[post("")]
async fn post_inbox(body: String, request: HttpRequest, state: AppState) -> Result<HttpResponse> {
const CONTENT_TYPES: &[&str] = &[
"application/activity+json",
"application/ld+json",
"application/json",
];
let content_type = request
.headers()
.get(CONTENT_TYPE)
.ok_or(Error::BadRequest)?
.to_str()?;
if CONTENT_TYPES.iter().all(|&typ| typ != content_type) {
return Ok(HttpResponse::UnsupportedMediaType()
.append_header((ACCEPT, "application/activity+json, application/ld+json"))
.finish());
}
state.sched.schedule(InboxWorker::new(body));
Ok(HttpResponse::Accepted().finish())
}
pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service(post_inbox);
}