mirror of
https://github.com/nullishamy/ferri.git
synced 2025-06-28 17:14:18 +00:00
feat: logging; fixes; error handloing
This commit is contained in:
parent
9c7c2858cc
commit
3719fae102
18 changed files with 228 additions and 106 deletions
|
@ -1,17 +1,17 @@
|
|||
use crate::timeline::TimelineStatus;
|
||||
use chrono::Local;
|
||||
use main::ap::{self, http::HttpClient};
|
||||
use rocket::{
|
||||
FromForm, State,
|
||||
form::Form,
|
||||
post,
|
||||
get,
|
||||
serde::{Deserialize, Serialize, json::Json},
|
||||
};
|
||||
use rocket_db_pools::Connection;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api::user::CredentialAcount;
|
||||
use crate::{AuthenticatedUser, Db, types::content};
|
||||
use crate::{AuthenticatedUser, Db};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, FromForm)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
|
@ -19,17 +19,36 @@ pub struct Status {
|
|||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, FromForm)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct StatusContext {
|
||||
ancestors: Vec<Status>,
|
||||
descendants: Vec<Status>
|
||||
}
|
||||
|
||||
#[get("/statuses/<status>/context")]
|
||||
pub async fn status_context(
|
||||
status: &str,
|
||||
user: AuthenticatedUser,
|
||||
mut db: Connection<Db>
|
||||
) -> Json<StatusContext> {
|
||||
Json(StatusContext {
|
||||
ancestors: vec![],
|
||||
descendants: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
async fn create_status(
|
||||
user: AuthenticatedUser,
|
||||
mut db: Connection<Db>,
|
||||
http: &HttpClient,
|
||||
status: &Status,
|
||||
) -> TimelineStatus {
|
||||
let user = ap::User::from_id(&user.username, &mut **db).await;
|
||||
let user = ap::User::from_id(&user.id, &mut **db).await.unwrap();
|
||||
let outbox = ap::Outbox::for_user(user.clone(), http);
|
||||
|
||||
let post_id = ap::new_id();
|
||||
let now = ap::new_ts();
|
||||
let now = ap::now();
|
||||
|
||||
let post = ap::Post::from_parts(post_id, status.status.clone(), user.clone())
|
||||
.to(format!("{}/followers", user.uri()))
|
||||
|
@ -55,6 +74,7 @@ async fn create_status(
|
|||
ty: ap::ActivityType::Create,
|
||||
object: post.clone().to_ap(),
|
||||
to: vec![format!("{}/followers", user.uri())],
|
||||
published: now,
|
||||
cc: vec!["https://www.w3.org/ns/activitystreams#Public".to_string()],
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -37,7 +37,6 @@ pub async fn home(
|
|||
limit: i64,
|
||||
user: AuthenticatedUser,
|
||||
) -> Json<Vec<TimelineStatus>> {
|
||||
dbg!(user);
|
||||
let posts = sqlx::query!(
|
||||
r#"
|
||||
SELECT p.id as "post_id", u.id as "user_id", p.content, p.uri as "post_uri",
|
||||
|
|
|
@ -5,6 +5,7 @@ use rocket::{
|
|||
};
|
||||
use rocket_db_pools::Connection;
|
||||
use uuid::Uuid;
|
||||
use rocket::response::status::NotFound;
|
||||
|
||||
use crate::timeline::{TimelineAccount, TimelineStatus};
|
||||
use crate::{AuthenticatedUser, Db, http::HttpClient};
|
||||
|
@ -62,9 +63,12 @@ pub async fn new_follow(
|
|||
http: &State<HttpClient>,
|
||||
uuid: &str,
|
||||
user: AuthenticatedUser,
|
||||
) {
|
||||
) -> Result<(), NotFound<String>> {
|
||||
let follower = ap::User::from_actor_id(&user.actor_id, &mut **db).await;
|
||||
let followed = ap::User::from_id(uuid, &mut **db).await;
|
||||
|
||||
let followed = ap::User::from_id(uuid, &mut **db)
|
||||
.await
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
|
||||
let outbox = ap::Outbox::for_user(follower.clone(), http.inner());
|
||||
|
||||
|
@ -83,6 +87,8 @@ pub async fn new_follow(
|
|||
|
||||
req.save(&mut **db).await;
|
||||
outbox.post(req).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/accounts/<uuid>")]
|
||||
|
@ -90,10 +96,12 @@ pub async fn account(
|
|||
mut db: Connection<Db>,
|
||||
uuid: &str,
|
||||
user: AuthenticatedUser,
|
||||
) -> Json<TimelineAccount> {
|
||||
let user = ap::User::from_id(uuid, &mut **db).await;
|
||||
) -> Result<Json<TimelineAccount>, NotFound<String>> {
|
||||
let user = ap::User::from_id(uuid, &mut **db)
|
||||
.await
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
let user_uri = format!("https://ferri.amy.mov/users/{}", user.username());
|
||||
Json(CredentialAcount {
|
||||
Ok(Json(CredentialAcount {
|
||||
id: user.id().to_string(),
|
||||
username: user.username().to_string(),
|
||||
acct: user.username().to_string(),
|
||||
|
@ -112,7 +120,7 @@ pub async fn account(
|
|||
following_count: 1,
|
||||
statuses_count: 1,
|
||||
last_status_at: "2025-04-10T22:14:34Z".to_string(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
#[get("/accounts/<uuid>/statuses?<limit>")]
|
||||
|
@ -121,8 +129,10 @@ pub async fn statuses(
|
|||
uuid: &str,
|
||||
limit: Option<i64>,
|
||||
user: AuthenticatedUser,
|
||||
) -> Json<Vec<TimelineStatus>> {
|
||||
let user = ap::User::from_id(uuid, &mut **db).await;
|
||||
) -> Result<Json<Vec<TimelineStatus>>, NotFound<String>> {
|
||||
let user = ap::User::from_id(uuid, &mut **db)
|
||||
.await
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
|
||||
let uid = user.id();
|
||||
let posts = sqlx::query!(
|
||||
|
@ -181,5 +191,5 @@ pub async fn statuses(
|
|||
});
|
||||
}
|
||||
|
||||
Json(out)
|
||||
Ok(Json(out))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue