Add CLI command for re-fetching actors

This commit is contained in:
silverpill 2022-05-22 00:07:01 +00:00
parent 28ccd19c34
commit f2e61dd9a3
4 changed files with 26 additions and 2 deletions

View file

@ -142,7 +142,7 @@ pub async fn fetch_profile(
fetch_profile_by_actor_id(instance, actor_url, media_dir).await
}
async fn fetch_actor(
pub async fn fetch_actor(
instance: &Instance,
actor_url: &str,
) -> Result<Actor, FetchError> {

View file

@ -25,6 +25,14 @@ pub async fn handle_update_person(
if actor.id != activity.actor {
return Err(ValidationError("actor ID mismatch").into());
};
update_actor(db_client, media_dir, actor).await
}
pub async fn update_actor(
db_client: &impl GenericClient,
media_dir: &Path,
actor: Actor,
) -> Result<(), ImportError> {
let profile = get_profile_by_actor_id(db_client, &actor.id).await?;
let (avatar, banner) = fetch_avatar_and_banner(&actor, media_dir).await
.map_err(|_| ValidationError("failed to fetch image"))?;

View file

@ -4,7 +4,7 @@ mod collections;
pub mod constants;
pub mod deliverer;
pub mod fetcher;
mod inbox;
pub mod inbox;
mod receiver;
pub mod views;
mod vocabulary;

View file

@ -2,6 +2,8 @@ use chrono::{Duration, Utc};
use clap::Parser;
use uuid::Uuid;
use mitra::activitypub::fetcher::fetchers::fetch_actor;
use mitra::activitypub::inbox::update_person::update_actor;
use mitra::config;
use mitra::database::create_database_client;
use mitra::database::migrate::apply_migrations;
@ -31,6 +33,7 @@ enum SubCommand {
GenerateInviteCode(GenerateInviteCode),
ListInviteCodes(ListInviteCodes),
RefetchActor(RefetchActor),
DeleteProfile(DeleteProfile),
DeletePost(DeletePost),
DeleteExtraneousPosts(DeleteExtraneousPosts),
@ -61,6 +64,13 @@ struct GenerateInviteCode;
#[derive(Parser)]
struct ListInviteCodes;
/// Re-fetch actor profile by actor ID
#[derive(Parser)]
struct RefetchActor {
#[clap(short)]
id: String,
}
/// Delete profile
#[derive(Parser)]
struct DeleteProfile {
@ -130,6 +140,12 @@ async fn main() {
println!("{}", code);
};
},
SubCommand::RefetchActor(subopts) => {
let actor_id = subopts.id;
let actor = fetch_actor(&config.instance(), &actor_id).await.unwrap();
update_actor(db_client, &config.media_dir(), actor).await.unwrap();
println!("profile updated");
},
SubCommand::DeleteProfile(subopts) => {
let deletion_queue = delete_profile(db_client, &subopts.id).await.unwrap();
deletion_queue.process(&config).await;