fix(cli): traits come from core again

This commit is contained in:
əlemi 2024-06-06 02:21:01 +02:00
parent acb9a9add5
commit bbcc46d0ee
Signed by: alemi
GPG key ID: A4895B84D311642C
7 changed files with 12 additions and 15 deletions

View file

@ -13,7 +13,6 @@ readme = "README.md"
[dependencies] [dependencies]
apb = { path = "../../apb/" } apb = { path = "../../apb/" }
upub = { path = "../core" } upub = { path = "../core" }
upub-processor = { path = "../processor/" }
tracing = "0.1" tracing = "0.1"
serde_json = "1" serde_json = "1"
sha256 = "1.5" sha256 = "1.5"

View file

@ -1,5 +1,5 @@
use sea_orm::EntityTrait; use sea_orm::EntityTrait;
use upub_processor::{fetch::{Fetchable, PullError}, normalize::{AP, Normalizer}}; use upub::traits::{fetch::{Fetchable, PullError}, Normalizer};
pub async fn fetch(ctx: upub::Context, uri: String, save: bool) -> Result<(), PullError> { pub async fn fetch(ctx: upub::Context, uri: String, save: bool) -> Result<(), PullError> {
use apb::Base; use apb::Base;
@ -15,7 +15,7 @@ pub async fn fetch(ctx: upub::Context, uri: String, save: bool) -> Result<(), Pu
match obj.base_type() { match obj.base_type() {
Ok(apb::BaseType::Object(apb::ObjectType::Actor(_))) => { Ok(apb::BaseType::Object(apb::ObjectType::Actor(_))) => {
upub::model::actor::Entity::insert( upub::model::actor::Entity::insert(
AP::actor_q(&obj).unwrap() upub::AP::actor_q(&obj).unwrap()
).exec(ctx.db()).await.unwrap(); ).exec(ctx.db()).await.unwrap();
}, },
Ok(apb::BaseType::Object(apb::ObjectType::Activity(_))) => { Ok(apb::BaseType::Object(apb::ObjectType::Activity(_))) => {

View file

@ -1,6 +1,6 @@
use sea_orm::EntityTrait; use sea_orm::EntityTrait;
pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -> upub::Result<()> { pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -> Result<(), sea_orm::DbErr> {
use futures::TryStreamExt; use futures::TryStreamExt;
let db = ctx.db(); let db = ctx.db();

View file

@ -93,12 +93,12 @@ pub enum CliCommand {
} }
} }
pub async fn run(ctx: upub::Context, command: CliCommand) -> upub::Result<()> { pub async fn run(ctx: upub::Context, command: CliCommand) -> Result<(), Box<dyn std::error::Error>> {
match command { match command {
CliCommand::Faker { count } => CliCommand::Faker { count } =>
Ok(faker(ctx, count as i64).await?), Ok(faker(ctx, count as i64).await?),
CliCommand::Fetch { uri, save } => CliCommand::Fetch { uri, save } =>
Ok(fetch(ctx, uri, save).await.map_err(|_e| upub::Error::internal_server_error())?), Ok(fetch(ctx, uri, save).await?),
CliCommand::Relay { actor, accept } => CliCommand::Relay { actor, accept } =>
Ok(relay(ctx, actor, accept).await?), Ok(relay(ctx, actor, accept).await?),
CliCommand::Fix { likes, shares, replies } => CliCommand::Fix { likes, shares, replies } =>

View file

@ -1,4 +1,4 @@
use upub::server::admin::Administrable; use upub::traits::Administrable;
pub async fn register( pub async fn register(
ctx: upub::Context, ctx: upub::Context,
@ -8,7 +8,7 @@ pub async fn register(
summary: Option<String>, summary: Option<String>,
avatar_url: Option<String>, avatar_url: Option<String>,
banner_url: Option<String>, banner_url: Option<String>,
) -> upub::Result<()> { ) -> Result<(), sea_orm::DbErr> {
ctx.register_user( ctx.register_user(
username.clone(), username.clone(),
password, password,

View file

@ -1,8 +1,7 @@
use sea_orm::{ActiveValue::{Set, NotSet}, ColumnTrait, EntityTrait, QueryFilter, QueryOrder}; use sea_orm::{ActiveValue::{Set, NotSet}, ColumnTrait, EntityTrait, QueryFilter, QueryOrder};
use upub::traits::Addresser;
use upub_processor::address::Addresser; pub async fn relay(ctx: upub::Context, actor: String, accept: bool) -> Result<(), sea_orm::DbErr> {
pub async fn relay(ctx: upub::Context, actor: String, accept: bool) -> upub::Result<()> {
let aid = ctx.aid(&uuid::Uuid::new_v4().to_string()); let aid = ctx.aid(&uuid::Uuid::new_v4().to_string());
let mut activity_model = upub::model::activity::ActiveModel { let mut activity_model = upub::model::activity::ActiveModel {

View file

@ -1,9 +1,8 @@
use futures::TryStreamExt; use futures::TryStreamExt;
use sea_orm::{ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter}; use sea_orm::{ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter};
use upub::traits::Fetcher;
use upub_processor::{fetch::Fetcher, normalize::AP}; pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::DbErr> {
pub async fn update_users(ctx: upub::Context, days: i64) -> upub::Result<()> {
let mut count = 0; let mut count = 0;
let mut insertions = Vec::new(); let mut insertions = Vec::new();
@ -19,7 +18,7 @@ pub async fn update_users(ctx: upub::Context, days: i64) -> upub::Result<()> {
match ctx.pull(&user.id).await.map(|x| x.actor()) { match ctx.pull(&user.id).await.map(|x| x.actor()) {
Err(e) => tracing::warn!("could not update user {}: {e}", user.id), Err(e) => tracing::warn!("could not update user {}: {e}", user.id),
Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id), Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id),
Ok(Ok(doc)) => match AP::actor_q(&doc) { Ok(Ok(doc)) => match upub::AP::actor_q(&doc) {
Ok(mut u) => { Ok(mut u) => {
u.internal = Set(user.internal); u.internal = Set(user.internal);
u.updated = Set(chrono::Utc::now()); u.updated = Set(chrono::Utc::now());