From 4a99a3dc40d1898859b856cb219dfd302b39314e Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 26 Mar 2024 00:49:07 +0100 Subject: [PATCH] chore: small improvements and fixed some warns --- src/fetcher.rs | 5 +++-- src/main.rs | 6 +++--- src/model/mod.rs | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/fetcher.rs b/src/fetcher.rs index 74f0bb3a..89ee01d2 100644 --- a/src/fetcher.rs +++ b/src/fetcher.rs @@ -1,3 +1,4 @@ +use openssl::pkey::{PKey, Private}; use reqwest::header::USER_AGENT; use sea_orm::{DatabaseConnection, EntityTrait, IntoActiveModel}; @@ -18,13 +19,13 @@ pub enum FetchError { pub struct Fetcher { db: DatabaseConnection, - key: String, // TODO store pre-parsed + _key: PKey, // TODO store pre-parsed domain: String, // TODO merge directly with Context so we don't need to copy this } impl Fetcher { pub fn new(db: DatabaseConnection, domain: String, key: String) -> Self { - Fetcher { db, domain, key } + Fetcher { db, domain, _key: PKey::private_key_from_pem(key.as_bytes()).unwrap() } } pub async fn user(&self, id: &str) -> Result { diff --git a/src/main.rs b/src/main.rs index 66041112..1f03e1c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,17 +112,17 @@ async fn fetch(db: &sea_orm::DatabaseConnection, uri: &str, save: bool) -> reqwe match obj.base_type() { Some(BaseType::Object(ObjectType::Actor(_))) => { model::user::Entity::insert( - model::user::Model::new(obj).unwrap().into_active_model() + model::user::Model::new(&obj).unwrap().into_active_model() ).exec(db).await.unwrap(); }, Some(BaseType::Object(ObjectType::Activity(_))) => { model::activity::Entity::insert( - model::activity::Model::new(obj).unwrap().into_active_model() + model::activity::Model::new(&obj).unwrap().into_active_model() ).exec(db).await.unwrap(); }, Some(BaseType::Object(ObjectType::Note)) => { model::object::Entity::insert( - model::object::Model::new(obj).unwrap().into_active_model() + model::object::Model::new(&obj).unwrap().into_active_model() ).exec(db).await.unwrap(); }, Some(BaseType::Object(t)) => tracing::warn!("not implemented: {:?}", t), diff --git a/src/model/mod.rs b/src/model/mod.rs index 1fd88ec1..7236d17e 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -18,6 +18,13 @@ pub mod faker; #[error("missing required field: '{0}'")] pub struct FieldError(pub &'static str); +impl From for axum::http::StatusCode { + fn from(value: FieldError) -> Self { + tracing::error!("bad request: {value}"); + axum::http::StatusCode::BAD_REQUEST + } +} + #[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, sea_orm::FromJsonQueryResult)] pub struct Audience(pub Vec);