Add actor collections enum

This commit is contained in:
silverpill 2022-07-15 19:36:21 +00:00
parent 75e4bfaaf7
commit 34ecf56ccd
3 changed files with 25 additions and 2 deletions

View file

@ -13,6 +13,7 @@ use crate::models::users::types::User;
use crate::utils::crypto::{deserialize_private_key, get_public_key_pem};
use crate::utils::files::get_file_url;
use super::constants::{ACTOR_KEY_SUFFIX, AP_CONTEXT};
use super::identifiers::LocalActorCollection;
use super::views::{
get_actor_url,
get_inbox_url,
@ -339,8 +340,8 @@ pub fn get_instance_actor(
instance: &Instance,
) -> Result<Actor, ActorKeyError> {
let actor_id = instance.actor_id();
let actor_inbox = format!("{}/inbox", actor_id);
let actor_outbox = format!("{}/outbox", actor_id);
let actor_inbox = LocalActorCollection::Inbox.of(&actor_id);
let actor_outbox = LocalActorCollection::Outbox.of(&actor_id);
let public_key_pem = get_public_key_pem(&instance.actor_key)?;
let public_key = PublicKey {
id: instance.actor_key_id(),

View file

@ -0,0 +1,21 @@
#[allow(dead_code)]
pub enum LocalActorCollection {
Inbox,
Outbox,
Followers,
Following,
Subscribers,
}
impl LocalActorCollection {
pub fn of(&self, actor_id: &str) -> String {
let name = match self {
Self::Inbox => "inbox",
Self::Outbox => "outbox",
Self::Followers => "followers",
Self::Following => "following",
Self::Subscribers => "subscribers",
};
format!("{}/{}", actor_id, name)
}
}

View file

@ -6,6 +6,7 @@ pub mod constants;
mod deliverer;
pub mod fetcher;
pub mod handlers;
mod identifiers;
mod receiver;
pub mod views;
mod vocabulary;