Add CLI command for re-fetching actors
This commit is contained in:
parent
28ccd19c34
commit
f2e61dd9a3
4 changed files with 26 additions and 2 deletions
|
@ -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> {
|
||||
|
|
|
@ -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"))?;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue