mirror of
https://github.com/nullishamy/ferri.git
synced 2025-06-28 00:54:17 +00:00
fix: misc cleanup
This commit is contained in:
parent
90be7d570e
commit
fafaf243c5
13 changed files with 640 additions and 750 deletions
|
@ -1,20 +1,14 @@
|
|||
use rocket::{get, post, response::content::RawHtml};
|
||||
use rocket::{get, response::content::RawHtml};
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
struct IndexTemplate {
|
||||
val: String
|
||||
}
|
||||
|
||||
#[post("/clicked")]
|
||||
pub async fn button_clicked() -> RawHtml<String> {
|
||||
let tmpl = IndexTemplate { val: "clicked".to_string() };
|
||||
RawHtml(tmpl.render().unwrap())
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub async fn index() -> RawHtml<String> {
|
||||
let tmpl = IndexTemplate { val: "test".to_string() };
|
||||
let tmpl = IndexTemplate { };
|
||||
RawHtml(tmpl.render().unwrap())
|
||||
}
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
use main::types::api;
|
||||
use rocket::{
|
||||
get,
|
||||
serde::{Deserialize, Serialize, json::Json},
|
||||
serde::json::Json,
|
||||
};
|
||||
|
||||
#[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 {
|
||||
pub async fn preferences() -> Json<api::Preferences> {
|
||||
Json(api::Preferences {
|
||||
posting_default_visibility: "public".to_string(),
|
||||
posting_default_sensitive: false,
|
||||
posting_default_language: None,
|
||||
|
|
|
@ -1,48 +1,11 @@
|
|||
use crate::{AuthenticatedUser, Db, endpoints::api::user::CredentialAcount};
|
||||
use main::types::{api, get, ObjectUuid};
|
||||
use crate::{AuthenticatedUser, Db};
|
||||
use main::types::{api, get};
|
||||
use rocket::{
|
||||
get,
|
||||
serde::{Deserialize, Serialize, json::Json},
|
||||
serde::json::Json,
|
||||
};
|
||||
use rocket_db_pools::Connection;
|
||||
|
||||
pub type TimelineAccount = CredentialAcount;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct TimelineStatusAttachment {
|
||||
id: ObjectUuid,
|
||||
#[serde(rename = "type")]
|
||||
ty: String,
|
||||
url: String,
|
||||
description: String
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct TimelineStatus {
|
||||
pub id: String,
|
||||
pub created_at: String,
|
||||
pub in_reply_to_id: Option<String>,
|
||||
pub in_reply_to_account_id: Option<String>,
|
||||
pub content: String,
|
||||
pub visibility: String,
|
||||
pub spoiler_text: String,
|
||||
pub sensitive: bool,
|
||||
pub uri: String,
|
||||
pub url: String,
|
||||
pub replies_count: i64,
|
||||
pub reblogs_count: i64,
|
||||
pub favourites_count: i64,
|
||||
pub favourited: bool,
|
||||
pub reblogged: bool,
|
||||
pub muted: bool,
|
||||
pub bookmarked: bool,
|
||||
pub reblog: Option<Box<TimelineStatus>>,
|
||||
pub media_attachments: Vec<TimelineStatusAttachment>,
|
||||
pub account: TimelineAccount,
|
||||
}
|
||||
|
||||
#[get("/timelines/home")]
|
||||
pub async fn home(
|
||||
mut db: Connection<Db>,
|
||||
|
@ -50,7 +13,10 @@ pub async fn home(
|
|||
) -> Json<Vec<api::Status>> {
|
||||
let posts = get::home_timeline(user.actor_id, &mut **db)
|
||||
.await
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|p| p.into())
|
||||
.collect();
|
||||
|
||||
Json(posts.into_iter().map(Into::into).collect())
|
||||
Json(posts)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use main::ap;
|
||||
use main::types::{api, get, ObjectUuid};
|
||||
use rocket::response::status::NotFound;
|
||||
use rocket::{
|
||||
State, get, post,
|
||||
|
@ -6,8 +7,8 @@ use rocket::{
|
|||
};
|
||||
use rocket_db_pools::Connection;
|
||||
use uuid::Uuid;
|
||||
use tracing::info;
|
||||
|
||||
use crate::timeline::{TimelineAccount, TimelineStatus};
|
||||
use crate::{AuthenticatedUser, Db};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -34,7 +35,8 @@ pub struct CredentialAcount {
|
|||
}
|
||||
|
||||
#[get("/accounts/verify_credentials")]
|
||||
pub async fn verify_credentials() -> Json<CredentialAcount> {
|
||||
pub async fn verify_credentials(user: AuthenticatedUser) -> Json<CredentialAcount> {
|
||||
info!("verifying creds for {:#?}", user);
|
||||
Json(CredentialAcount {
|
||||
id: "9b9d497b-2731-435f-a929-e609ca69dac9".to_string(),
|
||||
username: "amy".to_string(),
|
||||
|
@ -98,31 +100,12 @@ pub async fn account(
|
|||
mut db: Connection<Db>,
|
||||
uuid: &str,
|
||||
_user: AuthenticatedUser,
|
||||
) -> Result<Json<TimelineAccount>, NotFound<String>> {
|
||||
let user = ap::User::from_id(uuid, &mut **db)
|
||||
) -> Result<Json<api::Account>, NotFound<String>> {
|
||||
let user = get::user_by_id(ObjectUuid(uuid.to_string()), &mut **db)
|
||||
.await
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
let user_uri = format!("https://ferri.amy.mov/users/{}", user.username());
|
||||
Ok(Json(CredentialAcount {
|
||||
id: user.id().to_string(),
|
||||
username: user.username().to_string(),
|
||||
acct: user.username().to_string(),
|
||||
display_name: user.display_name().to_string(),
|
||||
locked: false,
|
||||
bot: false,
|
||||
created_at: "2025-04-10T22:12:09Z".to_string(),
|
||||
attribution_domains: vec![],
|
||||
note: "".to_string(),
|
||||
url: user_uri,
|
||||
avatar: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
avatar_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
header: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
header_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
followers_count: 1,
|
||||
following_count: 1,
|
||||
statuses_count: 1,
|
||||
last_status_at: "2025-04-10T22:14:34Z".to_string(),
|
||||
}))
|
||||
|
||||
Ok(Json(user.into()))
|
||||
}
|
||||
|
||||
#[get("/accounts/<uuid>/statuses?<_limit>")]
|
||||
|
@ -131,69 +114,17 @@ pub async fn statuses(
|
|||
uuid: &str,
|
||||
_limit: Option<i64>,
|
||||
_user: AuthenticatedUser,
|
||||
) -> Result<Json<Vec<TimelineStatus>>, NotFound<String>> {
|
||||
let user = ap::User::from_id(uuid, &mut **db)
|
||||
) -> Result<Json<Vec<api::Status>>, NotFound<String>> {
|
||||
let user = get::user_by_id(ObjectUuid(uuid.to_string()), &mut **db)
|
||||
.await
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
|
||||
let uid = user.id();
|
||||
let posts = sqlx::query!(
|
||||
r#"
|
||||
SELECT p.id as "post_id", u.id as "user_id", p.content, p.uri as "post_uri", u.username, u.display_name, u.actor_id, p.created_at
|
||||
FROM post p
|
||||
INNER JOIN user u on p.user_id = u.id
|
||||
WHERE u.id = ?1
|
||||
ORDER BY p.created_at DESC
|
||||
"#, uid)
|
||||
.fetch_all(&mut **db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut out = Vec::<TimelineStatus>::new();
|
||||
for record in posts {
|
||||
let user_uri = format!("https://ferri.amy.mov/users/{}", record.username);
|
||||
out.push(TimelineStatus {
|
||||
id: record.post_id.clone(),
|
||||
created_at: record.created_at.clone(),
|
||||
in_reply_to_id: None,
|
||||
in_reply_to_account_id: None,
|
||||
content: record.content.clone(),
|
||||
visibility: "public".to_string(),
|
||||
spoiler_text: "".to_string(),
|
||||
sensitive: false,
|
||||
uri: record.post_uri.clone(),
|
||||
url: record.post_uri.clone(),
|
||||
replies_count: 0,
|
||||
reblogs_count: 0,
|
||||
favourites_count: 0,
|
||||
favourited: false,
|
||||
reblogged: false,
|
||||
reblog: None,
|
||||
muted: false,
|
||||
bookmarked: false,
|
||||
media_attachments: vec![],
|
||||
account: CredentialAcount {
|
||||
id: record.user_id.clone(),
|
||||
username: record.username.clone(),
|
||||
acct: record.username.clone(),
|
||||
display_name: record.display_name.clone(),
|
||||
locked: false,
|
||||
bot: false,
|
||||
created_at: "2025-04-10T22:12:09Z".to_string(),
|
||||
attribution_domains: vec![],
|
||||
note: "".to_string(),
|
||||
url: user_uri,
|
||||
avatar: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
avatar_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
header: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
header_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||
followers_count: 1,
|
||||
following_count: 1,
|
||||
statuses_count: 1,
|
||||
last_status_at: "2025-04-10T22:14:34Z".to_string(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Json(out))
|
||||
let posts = get::posts_for_user_id(user.id, &mut **db)
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|p| p.into())
|
||||
.collect();
|
||||
|
||||
Ok(Json(posts))
|
||||
}
|
||||
|
|
|
@ -22,10 +22,6 @@ impl<'a> HttpWrapper<'a> {
|
|||
Self { client, key_id }
|
||||
}
|
||||
|
||||
pub fn client(&self) -> &'a HttpClient {
|
||||
self.client
|
||||
}
|
||||
|
||||
async fn get<T: serde::de::DeserializeOwned + Debug>(
|
||||
&self,
|
||||
ty: &str,
|
||||
|
|
|
@ -134,7 +134,6 @@ pub fn launch(cfg: Config) -> Rocket<Build> {
|
|||
"/admin",
|
||||
routes![
|
||||
admin::index,
|
||||
admin::button_clicked
|
||||
]
|
||||
)
|
||||
.mount(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue