Rename constants

This commit is contained in:
silverpill 2022-10-01 16:56:57 +00:00
parent 5862f49015
commit feca43dea7
5 changed files with 19 additions and 18 deletions

View file

@ -1,5 +1,6 @@
// https://www.w3.org/TR/activitypub/#server-to-server-interactions
pub const ACTIVITY_CONTENT_TYPE: &str = r#"application/ld+json; profile="https://www.w3.org/ns/activitystreams""#;
pub const AP_MEDIA_TYPE: &str = r#"application/ld+json; profile="https://www.w3.org/ns/activitystreams""#;
pub const AS_MEDIA_TYPE: &str = "application/activity+json";
pub const AP_CONTEXT: &str = "https://www.w3.org/ns/activitystreams";
pub const AP_PUBLIC: &str = "https://www.w3.org/ns/activitystreams#Public";

View file

@ -10,7 +10,7 @@ use crate::http_signatures::create::{create_http_signature, SignatureError};
use crate::models::users::types::User;
use crate::utils::crypto::deserialize_private_key;
use super::actors::types::Actor;
use super::constants::{ACTIVITY_CONTENT_TYPE, ACTOR_KEY_SUFFIX};
use super::constants::{AP_MEDIA_TYPE, ACTOR_KEY_SUFFIX};
use super::identifiers::local_actor_id;
#[derive(thiserror::Error, Debug)]
@ -52,7 +52,7 @@ async fn send_activity(
.header("Date", headers.date)
.header("Digest", headers.digest.unwrap())
.header("Signature", headers.signature)
.header(reqwest::header::CONTENT_TYPE, ACTIVITY_CONTENT_TYPE)
.header(reqwest::header::CONTENT_TYPE, AP_MEDIA_TYPE)
.header(reqwest::header::USER_AGENT, instance.agent())
.body(activity_json.to_owned());

View file

@ -6,7 +6,7 @@ use serde_json::Value;
use crate::activitypub::activity::Object;
use crate::activitypub::actors::types::{Actor, ActorAddress};
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
use crate::activitypub::constants::AP_MEDIA_TYPE;
use crate::config::Instance;
use crate::http_signatures::create::{create_http_signature, SignatureError};
use crate::utils::files::save_file;
@ -72,7 +72,7 @@ async fn send_request(
};
let data = request_builder
.header(reqwest::header::ACCEPT, ACTIVITY_CONTENT_TYPE)
.header(reqwest::header::ACCEPT, AP_MEDIA_TYPE)
.send().await?
.error_for_status()?
.text().await?;

View file

@ -22,7 +22,7 @@ use super::collections::{
OrderedCollection,
OrderedCollectionPage,
};
use super::constants::ACTIVITY_CONTENT_TYPE;
use super::constants::{AP_MEDIA_TYPE, AS_MEDIA_TYPE};
use super::identifiers::{
local_actor_followers,
local_actor_following,
@ -33,8 +33,8 @@ use super::receiver::receive_activity;
fn is_activitypub_request(headers: &HeaderMap) -> bool {
const CONTENT_TYPES: [&str; 4] = [
ACTIVITY_CONTENT_TYPE,
"application/activity+json",
AP_MEDIA_TYPE,
AS_MEDIA_TYPE,
"application/ld+json",
"application/json",
];
@ -67,7 +67,7 @@ async fn actor_view(
let actor = get_local_actor(&user, &config.instance_url())
.map_err(|_| HttpError::InternalError)?;
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(actor);
Ok(response)
}
@ -122,7 +122,7 @@ async fn outbox(
None,
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(collection);
return Ok(response);
};
@ -156,7 +156,7 @@ async fn outbox(
activities,
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(collection_page);
Ok(response)
}
@ -184,7 +184,7 @@ async fn followers_collection(
Some(user.profile.follower_count),
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(collection);
Ok(response)
}
@ -212,7 +212,7 @@ async fn following_collection(
Some(user.profile.following_count),
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(collection);
Ok(response)
}
@ -240,7 +240,7 @@ async fn subscribers_collection(
Some(user.profile.subscriber_count),
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(collection);
Ok(response)
}
@ -262,7 +262,7 @@ async fn instance_actor_view(
let actor = get_instance_actor(&config.instance())
.map_err(|_| HttpError::InternalError)?;
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(actor);
Ok(response)
}
@ -324,7 +324,7 @@ pub async fn object_view(
&post,
);
let response = HttpResponse::Ok()
.content_type(ACTIVITY_CONTENT_TYPE)
.content_type(AP_MEDIA_TYPE)
.json(object);
Ok(response)
}

View file

@ -2,7 +2,7 @@ use actix_web::{get, web, HttpResponse};
use regex::Regex;
use tokio_postgres::GenericClient;
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
use crate::activitypub::constants::AP_MEDIA_TYPE;
use crate::activitypub::identifiers::{
local_actor_id,
local_instance_actor_id,
@ -50,7 +50,7 @@ async fn get_user_info(
};
let link = Link {
rel: "self".to_string(),
link_type: Some(ACTIVITY_CONTENT_TYPE.to_string()),
link_type: Some(AP_MEDIA_TYPE.to_string()),
href: Some(actor_url),
};
let jrd = JsonResourceDescriptor {