mirror of
https://github.com/nullishamy/ferri.git
synced 2025-06-29 01:24:17 +00:00
refactor: everything
This commit is contained in:
parent
90577e43b0
commit
022e6f9c6d
32 changed files with 1570 additions and 668 deletions
14
ferri-server/src/endpoints/api/apps.rs
Normal file
14
ferri-server/src/endpoints/api/apps.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use rocket::{form::Form, post, serde::json::Json};
|
||||
|
||||
use crate::types::oauth::{App, CredentialApplication};
|
||||
|
||||
#[post("/apps", data = "<app>")]
|
||||
pub async fn new_app(app: Form<App>) -> Json<CredentialApplication> {
|
||||
Json(CredentialApplication {
|
||||
name: app.client_name.clone(),
|
||||
scopes: app.scopes.clone(),
|
||||
redirect_uris: app.redirect_uris.clone(),
|
||||
client_id: format!("id-for-{}", app.client_name),
|
||||
client_secret: format!("secret-for-{}", app.client_name),
|
||||
})
|
||||
}
|
62
ferri-server/src/endpoints/api/instance.rs
Normal file
62
ferri-server/src/endpoints/api/instance.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use rocket::{get, serde::json::Json};
|
||||
|
||||
use crate::types::instance::{Accounts, Configuration, Contact, Instance, MediaAttachments, Polls, Registrations, Statuses, Thumbnail, Translation, Urls};
|
||||
|
||||
#[get("/instance")]
|
||||
pub async fn instance() -> Json<Instance> {
|
||||
Json(Instance {
|
||||
domain: "ferri.amy.mov".to_string(),
|
||||
title: "Ferri".to_string(),
|
||||
version: "0.0.1".to_string(),
|
||||
source_url: "https://forge.amy.mov/amy/ferri".to_string(),
|
||||
description: "ferriverse".to_string(),
|
||||
thumbnail: Thumbnail {
|
||||
url: "".to_string(),
|
||||
},
|
||||
icon: vec![],
|
||||
languages: vec![],
|
||||
configuration: Configuration {
|
||||
urls: Urls {
|
||||
streaming: "".to_string(),
|
||||
about: "".to_string(),
|
||||
privacy_policy: "".to_string(),
|
||||
terms_of_service: "".to_string(),
|
||||
},
|
||||
accounts: Accounts {
|
||||
max_featured_tags: 10,
|
||||
max_pinned_statuses: 10,
|
||||
},
|
||||
statuses: Statuses {
|
||||
max_characters: 1000,
|
||||
max_media_attachments: 5,
|
||||
characters_reserved_per_url: 10,
|
||||
},
|
||||
media_attachments: MediaAttachments {
|
||||
supported_mime_types: vec![],
|
||||
description_limit: 10,
|
||||
image_size_limit: 10,
|
||||
image_matrix_limit: 10,
|
||||
video_size_limit: 10,
|
||||
video_frame_rate_limit: 10,
|
||||
video_matrix_limit: 10,
|
||||
},
|
||||
polls: Polls {
|
||||
max_options: 10,
|
||||
max_characters_per_option: 10,
|
||||
min_expiration: 10,
|
||||
max_expiration: 10,
|
||||
},
|
||||
translation: Translation { enabled: false },
|
||||
},
|
||||
registrations: Registrations {
|
||||
enabled: false,
|
||||
approval_required: true,
|
||||
reason_required: true,
|
||||
message: None,
|
||||
min_age: 10,
|
||||
},
|
||||
contact: Contact {
|
||||
email: "no".to_string(),
|
||||
},
|
||||
})
|
||||
}
|
5
ferri-server/src/endpoints/api/mod.rs
Normal file
5
ferri-server/src/endpoints/api/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
pub mod user;
|
||||
pub mod apps;
|
||||
pub mod instance;
|
||||
pub mod status;
|
||||
pub mod preferences;
|
28
ferri-server/src/endpoints/api/preferences.rs
Normal file
28
ferri-server/src/endpoints/api/preferences.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use rocket::{get, serde::{json::Json, Deserialize, Serialize}};
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct Preferences {
|
||||
#[serde(rename = "posting:default:visibility")]
|
||||
pub posting_default_visibility: String,
|
||||
#[serde(rename = "posting:default:sensitive")]
|
||||
pub posting_default_sensitive: bool,
|
||||
#[serde(rename = "posting:default:language")]
|
||||
pub posting_default_language: Option<String>,
|
||||
#[serde(rename = "reading:expand:media")]
|
||||
pub reading_expand_media: String,
|
||||
#[serde(rename = "reading:expand:spoilers")]
|
||||
pub reading_expand_spoilers: bool,
|
||||
}
|
||||
|
||||
#[get("/preferences")]
|
||||
pub async fn preferences() -> Json<Preferences> {
|
||||
Json(Preferences {
|
||||
posting_default_visibility: "public".to_string(),
|
||||
posting_default_sensitive: false,
|
||||
posting_default_language: None,
|
||||
reading_expand_media: "default".to_string(),
|
||||
reading_expand_spoilers: false,
|
||||
})
|
||||
}
|
40
ferri-server/src/endpoints/api/status.rs
Normal file
40
ferri-server/src/endpoints/api/status.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use rocket::{
|
||||
FromForm,
|
||||
form::Form,
|
||||
post,
|
||||
serde::{Deserialize, Serialize},
|
||||
};
|
||||
use rocket_db_pools::Connection;
|
||||
use uuid::Uuid;
|
||||
use main::ap;
|
||||
|
||||
use crate::{AuthenticatedUser, Db};
|
||||
#[derive(Serialize, Deserialize, Debug, FromForm)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct Status {
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[post("/statuses", data = "<status>")]
|
||||
pub async fn new_status(mut db: Connection<Db>, status: Form<Status>, user: AuthenticatedUser) {
|
||||
let user = ap::User::from_actor_id(&user.actor_id, &mut **db).await;
|
||||
let post_id = Uuid::new_v4();
|
||||
let uri = format!("https://ferri.amy.mov/users/{}/posts/{}", user.username(), post_id);
|
||||
let id = user.id();
|
||||
|
||||
let post = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO post (id, user_id, content)
|
||||
VALUES (?1, ?2, ?3)
|
||||
RETURNING *
|
||||
"#,
|
||||
uri,
|
||||
id,
|
||||
status.status
|
||||
)
|
||||
.fetch_one(&mut **db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
dbg!(user, status, post);
|
||||
}
|
88
ferri-server/src/endpoints/api/user.rs
Normal file
88
ferri-server/src/endpoints/api/user.rs
Normal file
|
@ -0,0 +1,88 @@
|
|||
use chrono::Local;
|
||||
use main::ap;
|
||||
use rocket::{
|
||||
State, get, post,
|
||||
serde::{Deserialize, Serialize, json::Json},
|
||||
};
|
||||
use rocket_db_pools::Connection;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{AuthenticatedUser, Db, http::HttpClient};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct CredentialAcount {
|
||||
pub id: String,
|
||||
pub username: String,
|
||||
pub acct: String,
|
||||
pub display_name: String,
|
||||
pub locked: bool,
|
||||
pub bot: bool,
|
||||
pub created_at: String,
|
||||
pub attribution_domains: Vec<String>,
|
||||
pub note: String,
|
||||
pub url: String,
|
||||
pub avatar: String,
|
||||
pub avatar_static: String,
|
||||
pub header: String,
|
||||
pub header_static: String,
|
||||
pub followers_count: i64,
|
||||
pub following_count: i64,
|
||||
pub statuses_count: i64,
|
||||
pub last_status_at: String,
|
||||
}
|
||||
|
||||
#[get("/accounts/verify_credentials")]
|
||||
pub async fn verify_credentials() -> Json<CredentialAcount> {
|
||||
Json(CredentialAcount {
|
||||
id: "https://ferri.amy.mov/users/amy".to_string(),
|
||||
username: "amy".to_string(),
|
||||
acct: "amy@ferri.amy.mov".to_string(),
|
||||
display_name: "amy".to_string(),
|
||||
locked: false,
|
||||
bot: false,
|
||||
created_at: "2025-04-10T22:12:09Z".to_string(),
|
||||
attribution_domains: vec![],
|
||||
note: "".to_string(),
|
||||
url: "https://ferri.amy.mov/@amy".to_string(),
|
||||
avatar: "https://i.sstatic.net/l60Hf.png".to_string(),
|
||||
avatar_static: "https://i.sstatic.net/l60Hf.png".to_string(),
|
||||
header: "https://i.sstatic.net/l60Hf.png".to_string(),
|
||||
header_static: "https://i.sstatic.net/l60Hf.png".to_string(),
|
||||
followers_count: 1,
|
||||
following_count: 1,
|
||||
statuses_count: 1,
|
||||
last_status_at: "2025-04-10T22:14:34Z".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[post("/accounts/<account>/follow")]
|
||||
pub async fn new_follow(
|
||||
mut db: Connection<Db>,
|
||||
http: &State<HttpClient>,
|
||||
account: &str,
|
||||
user: AuthenticatedUser,
|
||||
) {
|
||||
let follower = ap::User::from_actor_id(&user.actor_id, &mut **db).await;
|
||||
let followed = ap::User::from_username(account, &mut **db).await;
|
||||
|
||||
let outbox = ap::Outbox::for_user(follower.clone(), http.inner());
|
||||
|
||||
let activity = ap::Activity {
|
||||
id: format!("https://ferri.amy.mov/activities/{}", Uuid::new_v4()),
|
||||
ty: ap::ActivityType::Follow,
|
||||
object: followed.actor_id().to_string(),
|
||||
published: Local::now(),
|
||||
};
|
||||
|
||||
let req = ap::OutgoingActivity {
|
||||
signed_by: format!(
|
||||
"https://ferri.amy.mov/users/{}#main-key",
|
||||
follower.username()
|
||||
),
|
||||
req: activity,
|
||||
to: followed.actor().clone(),
|
||||
};
|
||||
|
||||
outbox.post(req).await;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue