mirror of
https://github.com/nullishamy/ferri.git
synced 2025-06-28 00:54:17 +00:00
feat: more fixes; finish account api types for now; add some more useful fields to it
This commit is contained in:
parent
76fb8838c2
commit
62931ee20b
10 changed files with 168 additions and 65 deletions
|
@ -45,6 +45,7 @@ pub async fn home(
|
|||
u.username, u.display_name, u.actor_id, p.created_at, p.boosted_post_id
|
||||
FROM post p
|
||||
INNER JOIN user u on p.user_id = u.id
|
||||
ORDER BY datetime(p.created_at) DESC
|
||||
"#
|
||||
)
|
||||
.fetch_all(&mut **db)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use main::ap::http::HttpClient;
|
||||
use rocket::{State, get, response::status};
|
||||
use rocket_db_pools::Connection;
|
||||
use main::ap;
|
||||
|
@ -8,7 +7,7 @@ use uuid::Uuid;
|
|||
|
||||
use crate::{
|
||||
Db,
|
||||
types::{self, activity, content, webfinger},
|
||||
types::{self, webfinger},
|
||||
};
|
||||
|
||||
#[get("/finger/<account>")]
|
||||
|
@ -86,44 +85,17 @@ pub async fn resolve_user(acct: &str, host: &str) -> types::Person {
|
|||
}
|
||||
|
||||
#[get("/test")]
|
||||
pub async fn test(http: &State<HttpClient>, outbound: &State<OutboundQueue>) -> &'static str {
|
||||
pub async fn test(
|
||||
outbound: &State<OutboundQueue>,
|
||||
mut db: Connection<Db>
|
||||
) -> &'static str {
|
||||
use main::types_rewrite::{ObjectUuid, fetch, api};
|
||||
outbound.0.send(ap::QueueMessage::Heartbeat);
|
||||
|
||||
let user = resolve_user("amy@fedi.amy.mov", "fedi.amy.mov").await;
|
||||
|
||||
let post = activity::CreateActivity {
|
||||
id: "https://ferri.amy.mov/activities/amy/20".to_string(),
|
||||
ty: "Create".to_string(),
|
||||
actor: "https://ferri.amy.mov/users/amy".to_string(),
|
||||
object: content::Post {
|
||||
context: "https://www.w3.org/ns/activitystreams".to_string(),
|
||||
id: "https://ferri.amy.mov/users/amy/posts/20".to_string(),
|
||||
ty: "Note".to_string(),
|
||||
content: "My first post".to_string(),
|
||||
ts: "2025-04-10T10:48:11Z".to_string(),
|
||||
to: vec!["https://ferri.amy.mov/users/amy/followers".to_string()],
|
||||
cc: vec!["https://www.w3.org/ns/activitystreams#Public".to_string()],
|
||||
attributed_to: None
|
||||
},
|
||||
ts: "2025-04-10T10:48:11Z".to_string(),
|
||||
to: vec!["https://ferri.amy.mov/users/amy/followers".to_string()],
|
||||
cc: vec![],
|
||||
};
|
||||
|
||||
let key_id = "https://ferri.amy.mov/users/amy#main-key";
|
||||
let follow = http
|
||||
.post(user.inbox)
|
||||
.json(&post)
|
||||
.sign(key_id)
|
||||
.activity()
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
dbg!(follow);
|
||||
let id = ObjectUuid("9b9d497b-2731-435f-a929-e609ca69dac9".to_string());
|
||||
let user= dbg!(fetch::user_by_id(id, &mut **db).await.unwrap());
|
||||
let apu: api::Account = user.into();
|
||||
dbg!(apu);
|
||||
|
||||
"Hello, world!"
|
||||
}
|
||||
|
|
|
@ -50,19 +50,34 @@ async fn create_user(
|
|||
let host = url.host_str().unwrap();
|
||||
info!("creating user '{}'@'{}' ({:#?})", user.preferred_username, host, user);
|
||||
|
||||
let username = format!("{}@{}", user.preferred_username, host);
|
||||
let (acct, remote) = if host != "ferri.amy.mov" {
|
||||
(format!("{}@{}", user.preferred_username, host), true)
|
||||
} else {
|
||||
(user.preferred_username.clone(), false)
|
||||
};
|
||||
|
||||
let url = format!("https://ferri.amy.mov/{}", acct);
|
||||
|
||||
let uuid = Uuid::new_v4().to_string();
|
||||
// FIXME: Pull from user
|
||||
let ts = main::ap::new_ts();
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO user (id, username, actor_id, display_name)
|
||||
VALUES (?1, ?2, ?3, ?4)
|
||||
INSERT INTO user (
|
||||
id, acct, url, remote, username,
|
||||
actor_id, display_name, created_at
|
||||
)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)
|
||||
ON CONFLICT(actor_id) DO NOTHING;
|
||||
"#,
|
||||
uuid,
|
||||
username,
|
||||
acct,
|
||||
url,
|
||||
remote,
|
||||
user.preferred_username,
|
||||
actor,
|
||||
user.name
|
||||
user.name,
|
||||
ts
|
||||
)
|
||||
.execute(conn)
|
||||
.await
|
||||
|
|
|
@ -8,12 +8,12 @@ use rocket::{
|
|||
};
|
||||
use rocket_db_pools::Connection;
|
||||
|
||||
#[get("/oauth/authorize?<client_id>&<scope>&<redirect_uri>&<_response_type>")]
|
||||
#[get("/oauth/authorize?<client_id>&<scope>&<redirect_uri>&<response_type>")]
|
||||
pub async fn authorize(
|
||||
client_id: &str,
|
||||
scope: &str,
|
||||
redirect_uri: &str,
|
||||
_response_type: &str,
|
||||
response_type: &str,
|
||||
mut db: Connection<Db>,
|
||||
) -> Redirect {
|
||||
// For now, we will always authorize the request and assign it to an admin user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue