mirror of
https://github.com/nullishamy/ferri.git
synced 2025-04-29 20:29:23 +00:00
chore: move a bunch of instance types; deprecate old types
This commit is contained in:
parent
e6b654a0b3
commit
5f346922f5
9 changed files with 128 additions and 137 deletions
|
@ -171,6 +171,107 @@ pub mod api {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
pub verified_at: Option<String>,
|
pub verified_at: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Instance {
|
||||||
|
pub domain: String,
|
||||||
|
pub title: String,
|
||||||
|
pub version: String,
|
||||||
|
pub source_url: String,
|
||||||
|
pub description: String,
|
||||||
|
pub thumbnail: Thumbnail,
|
||||||
|
pub icon: Vec<Icon>,
|
||||||
|
pub languages: Vec<String>,
|
||||||
|
pub configuration: Configuration,
|
||||||
|
pub registrations: Registrations,
|
||||||
|
pub contact: Contact,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Configuration {
|
||||||
|
pub urls: Urls,
|
||||||
|
pub accounts: Accounts,
|
||||||
|
pub statuses: Statuses,
|
||||||
|
pub media_attachments: MediaAttachments,
|
||||||
|
pub polls: Polls,
|
||||||
|
pub translation: Translation,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Accounts {
|
||||||
|
pub max_featured_tags: i64,
|
||||||
|
pub max_pinned_statuses: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct MediaAttachments {
|
||||||
|
pub supported_mime_types: Vec<String>,
|
||||||
|
pub description_limit: i64,
|
||||||
|
pub image_size_limit: i64,
|
||||||
|
pub image_matrix_limit: i64,
|
||||||
|
pub video_size_limit: i64,
|
||||||
|
pub video_frame_rate_limit: i64,
|
||||||
|
pub video_matrix_limit: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Polls {
|
||||||
|
pub max_options: i64,
|
||||||
|
pub max_characters_per_option: i64,
|
||||||
|
pub min_expiration: i64,
|
||||||
|
pub max_expiration: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Statuses {
|
||||||
|
pub max_characters: i64,
|
||||||
|
pub max_media_attachments: i64,
|
||||||
|
pub characters_reserved_per_url: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Translation {
|
||||||
|
pub enabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Urls {
|
||||||
|
pub streaming: String,
|
||||||
|
pub about: String,
|
||||||
|
pub privacy_policy: String,
|
||||||
|
pub terms_of_service: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Contact {
|
||||||
|
pub email: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Field {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Icon {
|
||||||
|
pub src: String,
|
||||||
|
pub size: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Registrations {
|
||||||
|
pub enabled: bool,
|
||||||
|
pub approval_required: bool,
|
||||||
|
pub reason_required: bool,
|
||||||
|
pub message: Option<String>,
|
||||||
|
pub min_age: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Thumbnail {
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -2,7 +2,7 @@ use rocket::{get, serde::json::Json, State};
|
||||||
|
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
|
||||||
use crate::types::instance::{
|
use main::types_rewrite::api::{
|
||||||
Accounts, Configuration, Contact, Instance, MediaAttachments, Polls, Registrations, Statuses,
|
Accounts, Configuration, Contact, Instance, MediaAttachments, Polls, Registrations, Statuses,
|
||||||
Thumbnail, Translation, Urls,
|
Thumbnail, Translation, Urls,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
use main::ap;
|
|
||||||
use rocket::serde::json::serde_json;
|
use rocket::serde::json::serde_json;
|
||||||
use rocket::{State, post};
|
use rocket::{State, post};
|
||||||
use rocket_db_pools::Connection;
|
use rocket_db_pools::Connection;
|
||||||
|
@ -11,12 +10,12 @@ use uuid::Uuid;
|
||||||
use tracing::{event, span, Level, debug, warn, info, error};
|
use tracing::{event, span, Level, debug, warn, info, error};
|
||||||
use crate::http_wrapper::HttpWrapper;
|
use crate::http_wrapper::HttpWrapper;
|
||||||
|
|
||||||
use main::types_rewrite::{make, db, ObjectUuid, ObjectUri, self};
|
use main::types_rewrite::{make, db, ObjectUuid, ObjectUri, self, ap};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Db,
|
Db,
|
||||||
http::HttpClient,
|
http::HttpClient,
|
||||||
types::{Person, content::Post, activity},
|
types::{content::Post, activity},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn handle_delete_activity(activity: activity::DeleteActivity) {
|
fn handle_delete_activity(activity: activity::DeleteActivity) {
|
||||||
|
@ -24,7 +23,7 @@ fn handle_delete_activity(activity: activity::DeleteActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_actor(
|
async fn create_actor(
|
||||||
user: &Person,
|
user: &ap::Person,
|
||||||
actor: &str,
|
actor: &str,
|
||||||
conn: impl sqlx::Executor<'_, Database = Sqlite>,
|
conn: impl sqlx::Executor<'_, Database = Sqlite>,
|
||||||
) {
|
) {
|
||||||
|
@ -44,7 +43,7 @@ async fn create_actor(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_user(
|
async fn create_user(
|
||||||
user: &Person,
|
user: &ap::Person,
|
||||||
actor: &str,
|
actor: &str,
|
||||||
conn: impl sqlx::Executor<'_, Database = Sqlite>,
|
conn: impl sqlx::Executor<'_, Database = Sqlite>,
|
||||||
) {
|
) {
|
||||||
|
@ -112,7 +111,7 @@ struct RemoteInfo {
|
||||||
is_remote: bool,
|
is_remote: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_remote_info(actor_url: &str, person: &Person) -> RemoteInfo {
|
fn get_remote_info(actor_url: &str, person: &ap::Person) -> RemoteInfo {
|
||||||
let url = Url::parse(&actor_url).unwrap();
|
let url = Url::parse(&actor_url).unwrap();
|
||||||
let host = url.host_str().unwrap();
|
let host = url.host_str().unwrap();
|
||||||
|
|
||||||
|
@ -194,18 +193,18 @@ async fn handle_follow_activity<'a>(
|
||||||
|
|
||||||
create_follow(&activity, &mut **db).await;
|
create_follow(&activity, &mut **db).await;
|
||||||
|
|
||||||
let follower = ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
let follower = main::ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
||||||
let followed = ap::User::from_id(&followed_account, &mut **db).await.unwrap();
|
let followed = main::ap::User::from_id(&followed_account, &mut **db).await.unwrap();
|
||||||
let outbox = ap::Outbox::for_user(followed.clone(), http.client());
|
let outbox = main::ap::Outbox::for_user(followed.clone(), http.client());
|
||||||
|
|
||||||
let activity = ap::Activity {
|
let activity = main::ap::Activity {
|
||||||
id: format!("https://ferri.amy.mov/activities/{}", Uuid::new_v4()),
|
id: format!("https://ferri.amy.mov/activities/{}", Uuid::new_v4()),
|
||||||
ty: ap::ActivityType::Accept,
|
ty: main::ap::ActivityType::Accept,
|
||||||
object: activity.id,
|
object: activity.id,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = ap::OutgoingActivity {
|
let req = main::ap::OutgoingActivity {
|
||||||
signed_by: format!(
|
signed_by: format!(
|
||||||
"https://ferri.amy.mov/users/{}#main-key",
|
"https://ferri.amy.mov/users/{}#main-key",
|
||||||
followed.username()
|
followed.username()
|
||||||
|
@ -290,13 +289,13 @@ async fn handle_boost_activity<'a>(
|
||||||
debug!("creating user {}", attribution);
|
debug!("creating user {}", attribution);
|
||||||
create_user(&post_user, &attribution, &mut **db).await;
|
create_user(&post_user, &attribution, &mut **db).await;
|
||||||
|
|
||||||
let attributed_user = ap::User::from_actor_id(&attribution, &mut **db).await;
|
let attributed_user = main::ap::User::from_actor_id(&attribution, &mut **db).await;
|
||||||
let actor_user = ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
let actor_user = main::ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
||||||
|
|
||||||
let base_id = ap::new_id();
|
let base_id = main::ap::new_id();
|
||||||
let now = ap::new_ts();
|
let now = main::ap::new_ts();
|
||||||
|
|
||||||
let reblog_id = ap::new_id();
|
let reblog_id = main::ap::new_id();
|
||||||
|
|
||||||
let attr_id = attributed_user.id();
|
let attr_id = attributed_user.id();
|
||||||
// HACK: ON CONFLICT is to avoid duplicate remote posts coming in
|
// HACK: ON CONFLICT is to avoid duplicate remote posts coming in
|
||||||
|
@ -345,7 +344,7 @@ async fn handle_create_activity<'a>(
|
||||||
debug!("creating user {}", activity.actor);
|
debug!("creating user {}", activity.actor);
|
||||||
create_user(&user, &activity.actor, &mut **db).await;
|
create_user(&user, &activity.actor, &mut **db).await;
|
||||||
|
|
||||||
let user = ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
let user = main::ap::User::from_actor_id(&activity.actor, &mut **db).await;
|
||||||
debug!("user created {:?}", user);
|
debug!("user created {:?}", user);
|
||||||
|
|
||||||
let user_id = user.id();
|
let user_id = user.id();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, event, Level};
|
use tracing::{error, event, Level};
|
||||||
use crate::http::HttpClient;
|
use crate::http::HttpClient;
|
||||||
use crate::types::Person;
|
use main::types_rewrite::ap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub struct HttpWrapper<'a> {
|
pub struct HttpWrapper<'a> {
|
||||||
|
@ -65,7 +65,7 @@ impl <'a> HttpWrapper<'a> {
|
||||||
Ok(decoded.unwrap())
|
Ok(decoded.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_person(&self, url: &str) -> Result<Person, HttpError> {
|
pub async fn get_person(&self, url: &str) -> Result<ap::Person, HttpError> {
|
||||||
self.get("Person", url).await
|
self.get("Person", url).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use rocket::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
// FIXME: This is because Masto sends an array but we don't care
|
// FIXME: This is because Masto sends an array but we don't care
|
||||||
#[serde(rename = "@context")]
|
#[serde(rename = "@context")]
|
||||||
|
|
|
@ -1,115 +0,0 @@
|
||||||
use rocket::serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Instance {
|
|
||||||
pub domain: String,
|
|
||||||
pub title: String,
|
|
||||||
pub version: String,
|
|
||||||
pub source_url: String,
|
|
||||||
pub description: String,
|
|
||||||
pub thumbnail: Thumbnail,
|
|
||||||
pub icon: Vec<Icon>,
|
|
||||||
pub languages: Vec<String>,
|
|
||||||
pub configuration: Configuration,
|
|
||||||
pub registrations: Registrations,
|
|
||||||
pub contact: Contact,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Configuration {
|
|
||||||
pub urls: Urls,
|
|
||||||
pub accounts: Accounts,
|
|
||||||
pub statuses: Statuses,
|
|
||||||
pub media_attachments: MediaAttachments,
|
|
||||||
pub polls: Polls,
|
|
||||||
pub translation: Translation,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Accounts {
|
|
||||||
pub max_featured_tags: i64,
|
|
||||||
pub max_pinned_statuses: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct MediaAttachments {
|
|
||||||
pub supported_mime_types: Vec<String>,
|
|
||||||
pub description_limit: i64,
|
|
||||||
pub image_size_limit: i64,
|
|
||||||
pub image_matrix_limit: i64,
|
|
||||||
pub video_size_limit: i64,
|
|
||||||
pub video_frame_rate_limit: i64,
|
|
||||||
pub video_matrix_limit: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Polls {
|
|
||||||
pub max_options: i64,
|
|
||||||
pub max_characters_per_option: i64,
|
|
||||||
pub min_expiration: i64,
|
|
||||||
pub max_expiration: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Statuses {
|
|
||||||
pub max_characters: i64,
|
|
||||||
pub max_media_attachments: i64,
|
|
||||||
pub characters_reserved_per_url: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Translation {
|
|
||||||
pub enabled: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Urls {
|
|
||||||
pub streaming: String,
|
|
||||||
pub about: String,
|
|
||||||
pub privacy_policy: String,
|
|
||||||
pub terms_of_service: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Contact {
|
|
||||||
pub email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Field {
|
|
||||||
pub name: String,
|
|
||||||
pub value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Icon {
|
|
||||||
pub src: String,
|
|
||||||
pub size: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Registrations {
|
|
||||||
pub enabled: bool,
|
|
||||||
pub approval_required: bool,
|
|
||||||
pub reason_required: bool,
|
|
||||||
pub message: Option<String>,
|
|
||||||
pub min_age: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
|
||||||
pub struct Thumbnail {
|
|
||||||
pub url: String,
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod activity;
|
pub mod activity;
|
||||||
pub mod content;
|
pub mod content;
|
||||||
pub mod instance;
|
|
||||||
pub mod oauth;
|
pub mod oauth;
|
||||||
pub mod webfinger;
|
pub mod webfinger;
|
||||||
|
|
||||||
|
@ -9,6 +8,7 @@ use rocket::serde::{Deserialize, Serialize};
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct UserKey {
|
pub struct UserKey {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub owner: String,
|
pub owner: String,
|
||||||
|
@ -19,6 +19,7 @@ pub struct UserKey {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct Person {
|
pub struct Person {
|
||||||
// FIXME: This is because Masto sends an array but we don't care
|
// FIXME: This is because Masto sends an array but we don't care
|
||||||
#[serde(rename = "@context")]
|
#[serde(rename = "@context")]
|
||||||
|
|
|
@ -5,6 +5,7 @@ use rocket::{
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, FromForm, Clone)]
|
#[derive(Serialize, Deserialize, Debug, FromForm, Clone)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub client_name: String,
|
pub client_name: String,
|
||||||
pub redirect_uris: Vec<String>,
|
pub redirect_uris: Vec<String>,
|
||||||
|
@ -13,6 +14,7 @@ pub struct App {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct CredentialApplication {
|
pub struct CredentialApplication {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub scopes: String,
|
pub scopes: String,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use rocket::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
pub rel: String,
|
pub rel: String,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -11,6 +12,7 @@ pub struct Link {
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[deprecated]
|
||||||
pub struct WebfingerResponse {
|
pub struct WebfingerResponse {
|
||||||
pub subject: String,
|
pub subject: String,
|
||||||
pub aliases: Vec<String>,
|
pub aliases: Vec<String>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue