973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1 | use std::sync::Arc; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 2 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 3 | use axum::{ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 4 | Router, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 5 | extract::{DefaultBodyLimit, Multipart, Query, State}, |
dffd63b58af4 | atagen | 2026-09-28 09:10 UTC | 6 | http::{HeaderMap, StatusCode}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 7 | middleware, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 8 | response::{IntoResponse, Response, Sse, sse::Event as SseEvent}, |
dffd63b58af4 | atagen | 2026-09-28 09:10 UTC | 9 | routing::{get, post}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 10 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 11 | use futures_util::StreamExt; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 12 | use macltok::Retain; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 13 | use malice_core::{ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 14 | feed::subscribe, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 15 | login::LoginInput, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 16 | request::{Reply, Request, SendKind, dispatch}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 17 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 18 | use serde::{Deserialize, Serialize}; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 19 | use tower_http::{ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 20 | services::{ServeDir, ServeFile}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 21 | trace::TraceLayer, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 22 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 23 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 24 | use crate::{ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 25 | csrf::{csrf_guard, session_sid, set_cookie_value}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 26 | error::{ApiError, json_ok, no_content}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 27 | state::{AppState, RestoreError, UserSession}, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 28 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 29 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 30 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 31 | struct RoomIdBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 32 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 33 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 34 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 35 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 36 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 37 | struct SendBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 38 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 39 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 40 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 41 | body: String, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 42 | #[serde(default)] |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 43 | formatted_body: Option<String>, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 44 | #[serde(default)] |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 45 | reply_to: Option<String>, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 46 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 47 | mentions: Vec<String>, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 48 | #[serde(default)] |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 49 | kind: SendKind, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 50 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 51 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 52 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 53 | struct PaginateBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 54 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 55 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 56 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 57 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 58 | #[derive(Debug, Deserialize)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 59 | struct EventContextBody { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 60 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 61 | room_id: String, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 62 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 63 | event_id: String, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 64 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 65 | before_limit: u32, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 66 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 67 | after_limit: u32, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 68 | } |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 69 | |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 70 | #[derive(Debug, Deserialize)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 71 | struct EventContextPageBody { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 72 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 73 | room_id: String, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 74 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 75 | token: String, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 76 | #[serde(default)] |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 77 | limit: u32, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 78 | } |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 79 | |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 80 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 81 | struct JoinBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 82 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 83 | room: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 84 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 85 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 86 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 87 | struct CreateBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 88 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 89 | name: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 90 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 91 | topic: Option<String>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 92 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 93 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 94 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 95 | struct ReactBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 96 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 97 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 98 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 99 | event_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 100 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 101 | key: String, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 102 | #[serde(default)] |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 103 | shortcode: Option<String>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 104 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 105 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 106 | #[derive(Debug, Deserialize)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 107 | struct EditBody { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 108 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 109 | room_id: String, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 110 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 111 | event_id: String, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 112 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 113 | body: String, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 114 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 115 | formatted_body: Option<String>, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 116 | #[serde(default)] |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 117 | mentions: Vec<String>, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 118 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 119 | |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 120 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 121 | struct ReadBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 122 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 123 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 124 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 125 | event_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 126 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 127 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 128 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 129 | struct MembersQuery { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 130 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 131 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 132 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 133 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 134 | struct RecoverBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 135 | recovery_key: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 136 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 137 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 138 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 139 | struct VerifyBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 140 | action: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 141 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 142 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 143 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 144 | struct MediaQuery { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 145 | mxc: String, |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 146 | size: Option<u32>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 147 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 148 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 149 | struct MessageMediaQuery { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 150 | media_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 151 | size: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 152 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 153 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 154 | #[derive(Debug, Deserialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 155 | struct TypingBody { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 156 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 157 | room_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 158 | #[serde(default)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 159 | typing: bool, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 160 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 161 | |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 162 | #[derive(Debug, Deserialize)] |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 163 | struct AccountDataQuery { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 164 | event_type: String, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 165 | } |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 166 | |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 167 | #[derive(Debug, Deserialize)] |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 168 | struct UrlPreviewQuery { |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 169 | #[serde(default)] |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 170 | room_id: String, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 171 | #[serde(default)] |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 172 | url: String, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 173 | } |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 174 | |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 175 | #[derive(Debug, Deserialize)] |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 176 | struct AccountDataBody { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 177 | event_type: String, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 178 | content: serde_json::Value, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 179 | } |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 180 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 181 | #[derive(Debug, Serialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 182 | struct SoftLogoutInfo { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 183 | user_id: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 184 | homeserver: String, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 185 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 186 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 187 | #[derive(Debug, Serialize)] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 188 | struct SessionResponse { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 189 | user_id: Option<String>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 190 | #[serde(skip_serializing_if = "Option::is_none")] |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 191 | soft_logout: Option<SoftLogoutInfo>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 192 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 193 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 194 | async fn auth( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 195 | state: &AppState, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 196 | headers: &HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 197 | ) -> Result<(Arc<UserSession>, String), ApiError> { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 198 | let Some(sid) = session_sid(headers) else { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 199 | return Err(ApiError::unauthorized("not signed in")); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 200 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 201 | match state.get_or_restore(&sid).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 202 | Ok(user) => Ok((user, sid)), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 203 | Err(RestoreError::NotFound) => Err(ApiError::unauthorized_stale( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 204 | "session expired; sign in again", |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 205 | state.cookie_secure(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 206 | )), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 207 | Err(RestoreError::SoftLoggedOut { .. }) => Err(ApiError::unauthorized( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 208 | "signed out by the server, sign in again", |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 209 | )), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 210 | Err(RestoreError::Stale(message)) => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 211 | state.remove_session(&sid, Retain::Nothing).await; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 212 | Err(ApiError::unauthorized_stale(message, state.cookie_secure())) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 213 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 214 | Err(RestoreError::Unavailable(message)) => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 215 | Err(ApiError::new(StatusCode::BAD_GATEWAY, message)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 216 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 217 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 218 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 219 | |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 220 | fn avatar_response(bytes: Vec<u8>, content_type: &'static str) -> Response { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 221 | ( |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 222 | [ |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 223 | (axum::http::header::CONTENT_TYPE, content_type), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 224 | // mxc uris name immutable content, a changed avatar gets a new uri |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 225 | ( |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 226 | axum::http::header::CACHE_CONTROL, |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 227 | "private, max-age=31536000, immutable", |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 228 | ), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 229 | (axum::http::header::X_CONTENT_TYPE_OPTIONS, "nosniff"), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 230 | ], |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 231 | bytes, |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 232 | ) |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 233 | .into_response() |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 234 | } |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 235 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 236 | /// commands answer when they're done, so the browser gets the outcome in the response |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 237 | fn respond(result: Result<Reply, malice_core::error::CoreError>) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 238 | match result { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 239 | Ok(Reply::Done) => no_content(None), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 240 | Ok(Reply::Json(value)) => json_ok(&value, None), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 241 | Ok(Reply::Avatar(source)) => { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 242 | let (bytes, content_type) = source.render(); |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 243 | avatar_response(bytes, content_type) |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 244 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 245 | Ok(Reply::Attachment { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 246 | bytes, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 247 | content_type, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 248 | }) => ( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 249 | [ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 250 | ( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 251 | axum::http::header::CONTENT_TYPE, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 252 | content_type.unwrap_or("application/octet-stream"), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 253 | ), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 254 | ( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 255 | axum::http::header::CONTENT_DISPOSITION, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 256 | if content_type.is_some() { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 257 | "inline" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 258 | } else { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 259 | "attachment" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 260 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 261 | ), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 262 | (axum::http::header::CACHE_CONTROL, "private, max-age=3600"), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 263 | (axum::http::header::X_CONTENT_TYPE_OPTIONS, "nosniff"), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 264 | (axum::http::header::CONTENT_SECURITY_POLICY, "sandbox"), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 265 | ], |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 266 | bytes, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 267 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 268 | .into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 269 | Err(error) => ApiError::from(error).into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 270 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 271 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 272 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 273 | async fn get_session(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 274 | let Some(sid) = session_sid(&headers) else { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 275 | return json_ok( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 276 | &SessionResponse { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 277 | user_id: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 278 | soft_logout: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 279 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 280 | None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 281 | ); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 282 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 283 | match state.get_or_restore(&sid).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 284 | Ok(user) => json_ok( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 285 | &SessionResponse { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 286 | user_id: Some(user.user_id.clone()), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 287 | soft_logout: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 288 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 289 | None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 290 | ), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 291 | Err(RestoreError::NotFound) => json_ok( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 292 | &SessionResponse { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 293 | user_id: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 294 | soft_logout: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 295 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 296 | None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 297 | ), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 298 | Err(RestoreError::SoftLoggedOut { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 299 | user_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 300 | homeserver, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 301 | }) => json_ok( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 302 | &SessionResponse { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 303 | user_id: None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 304 | soft_logout: Some(SoftLogoutInfo { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 305 | user_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 306 | homeserver, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 307 | }), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 308 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 309 | None, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 310 | ), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 311 | Err(RestoreError::Stale(message)) => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 312 | state.remove_session(&sid, Retain::Nothing).await; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 313 | ApiError::unauthorized_stale(message, state.cookie_secure()).into_response() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 314 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 315 | Err(RestoreError::Unavailable(message)) => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 316 | ApiError::new(StatusCode::BAD_GATEWAY, message).into_response() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 317 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 318 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 319 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 320 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 321 | async fn post_login( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 322 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 323 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 324 | body: axum::Json<LoginInput>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 325 | ) -> Response { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 326 | let username = body.0.username.trim().to_owned(); |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 327 | let password = body.0.password.clone(); |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 328 | let login = match body.0.into_login(state.allow_http_homeserver()) { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 329 | Ok(login) => login, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 330 | Err(error) => return ApiError::from(error).into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 331 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 332 | let cookie_sid = session_sid(&headers); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 333 | match state |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 334 | .login(cookie_sid.as_deref(), login, &username, password) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 335 | .await |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 336 | { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 337 | Ok(user) => json_ok( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 338 | &serde_json::json!({ "user_id": user.user_id }), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 339 | Some(set_cookie_value(&user.sid, state.cookie_secure())), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 340 | ), |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 341 | Err(error) => ApiError::from(error).into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 342 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 343 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 344 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 345 | async fn post_logout(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 346 | if let Some(sid) = session_sid(&headers) { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 347 | state.logout(&sid).await; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 348 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 349 | let mut response = no_content(Some(crate::csrf::clear_cookie_value(state.cookie_secure()))); |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 350 | response.headers_mut().insert( |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 351 | axum::http::header::HeaderName::from_static("clear-site-data"), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 352 | axum::http::HeaderValue::from_static("\"cache\""), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 353 | ); |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 354 | response |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 355 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 356 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 357 | async fn get_rooms(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 358 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 359 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 360 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 361 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 362 | respond(dispatch(&user.handle, &user.mirror, Request::Rooms).await) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 363 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 364 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 365 | async fn get_members( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 366 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 367 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 368 | Query(query): Query<MembersQuery>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 369 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 370 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 371 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 372 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 373 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 374 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 375 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 376 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 377 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 378 | Request::Members { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 379 | room_id: query.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 380 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 381 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 382 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 383 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 384 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 385 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 386 | async fn rooms_open( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 387 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 388 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 389 | body: axum::Json<RoomIdBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 390 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 391 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 392 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 393 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 394 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 395 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 396 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 397 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 398 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 399 | Request::Open { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 400 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 401 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 402 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 403 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 404 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 405 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 406 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 407 | async fn rooms_close( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 408 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 409 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 410 | body: axum::Json<RoomIdBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 411 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 412 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 413 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 414 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 415 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 416 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 417 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 418 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 419 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 420 | Request::Close { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 421 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 422 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 423 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 424 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 425 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 426 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 427 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 428 | async fn rooms_send( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 429 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 430 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 431 | body: axum::Json<SendBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 432 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 433 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 434 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 435 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 436 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 437 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 438 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 439 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 440 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 441 | Request::Send { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 442 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 443 | body: body.0.body, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 444 | formatted_body: body.0.formatted_body, |
df3c0f2b3da4 | atagen | 2026-10-22 13:07 UTC | 445 | reply_to: body.0.reply_to, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 446 | mentions: body.0.mentions, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 447 | kind: body.0.kind, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 448 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 449 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 450 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 451 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 452 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 453 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 454 | async fn rooms_upload( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 455 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 456 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 457 | mut upload: Multipart, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 458 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 459 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 460 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 461 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 462 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 463 | let mut room_id = None; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 464 | let mut caption = None; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 465 | let mut formatted_caption = None; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 466 | let mut reply_to = None; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 467 | let mut mentions = Vec::new(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 468 | let mut file = None; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 469 | loop { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 470 | let field = match upload.next_field().await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 471 | Ok(Some(field)) => field, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 472 | Ok(None) => break, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 473 | Err(_) => return ApiError::bad_request("invalid upload form").into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 474 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 475 | match field.name() { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 476 | Some("room_id") if room_id.is_none() => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 477 | room_id = match field.text().await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 478 | Ok(value) => Some(value), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 479 | Err(_) => return ApiError::bad_request("invalid room_id").into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 480 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 481 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 482 | Some("caption") if caption.is_none() => { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 483 | caption = match field.text().await { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 484 | Ok(value) => Some(value), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 485 | Err(_) => return ApiError::bad_request("invalid caption").into_response(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 486 | }; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 487 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 488 | Some("formatted_caption") if formatted_caption.is_none() => { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 489 | formatted_caption = match field.text().await { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 490 | Ok(value) => Some(value), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 491 | Err(_) => return ApiError::bad_request("invalid caption").into_response(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 492 | }; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 493 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 494 | Some("reply_to") if reply_to.is_none() => { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 495 | reply_to = match field.text().await { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 496 | Ok(value) => Some(value), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 497 | Err(_) => return ApiError::bad_request("invalid reply_to").into_response(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 498 | }; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 499 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 500 | Some("mentions") => match field.text().await { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 501 | Ok(value) => mentions.push(value), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 502 | Err(_) => return ApiError::bad_request("invalid mention").into_response(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 503 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 504 | Some("file") if file.is_none() => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 505 | let filename = field.file_name().unwrap_or("attachment").to_owned(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 506 | let mimetype = field |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 507 | .content_type() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 508 | .unwrap_or("application/octet-stream") |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 509 | .to_owned(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 510 | let bytes = match field.bytes().await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 511 | Ok(bytes) => bytes, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 512 | Err(_) => return ApiError::bad_request("invalid file").into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 513 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 514 | if bytes.is_empty() || bytes.len() > 20 * 1024 * 1024 { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 515 | return ApiError::bad_request("file must be between 1 byte and 20 MiB") |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 516 | .into_response(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 517 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 518 | file = Some((filename, mimetype, bytes)); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 519 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 520 | _ => return ApiError::bad_request("unexpected upload field").into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 521 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 522 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 523 | let Some(room_id) = room_id else { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 524 | return ApiError::bad_request("room_id is required").into_response(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 525 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 526 | let Some((filename, mimetype, bytes)) = file else { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 527 | return ApiError::bad_request("file is required").into_response(); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 528 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 529 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 530 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 531 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 532 | &user.mirror, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 533 | Request::Upload { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 534 | room_id, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 535 | filename, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 536 | mimetype, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 537 | caption, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 538 | formatted_caption, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 539 | reply_to, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 540 | mentions, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 541 | bytes: bytes.to_vec(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 542 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 543 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 544 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 545 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 546 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 547 | |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 548 | /// Ops added after the per-route handlers, taken as the core request JSON. Anything |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 549 | /// carrying bytes stays on its own route. |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 550 | async fn post_command( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 551 | State(state): State<AppState>, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 552 | headers: HeaderMap, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 553 | body: axum::Json<Request>, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 554 | ) -> Response { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 555 | let (user, _) = match auth(&state, &headers).await { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 556 | Ok(pair) => pair, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 557 | Err(error) => return error.into_response(), |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 558 | }; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 559 | let request = body.0; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 560 | if !matches!( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 561 | request, |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 562 | Request::MentionsPage { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 563 | | Request::MentionContext { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 564 | | Request::RetryMentionContext { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 565 | | Request::SetMentionsRead { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 566 | | Request::MarkMentionsReadThrough { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 567 | | Request::RecoverMentions |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 568 | | Request::HistoryRepair { .. } |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 569 | | Request::ContinueHistoryRepair { .. } |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 570 | | Request::CancelHistoryRepair { .. } |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 571 | | Request::StartRecentHistory { .. } |
43c2cc753052 | atagen | 2026-10-25 07:50 UTC | 572 | | Request::FillHistoryGap { .. } |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 573 | | Request::HistoryRepairPolicy |
f40cf95cc4fe | atagen | 2026-10-25 03:17 UTC | 574 | | Request::SetHistoryRepairPolicy { .. } |
ed3363baaf01 | atagen | 2026-10-25 03:09 UTC | 575 | | Request::Kick { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 576 | | Request::Ban { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 577 | | Request::Unban { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 578 | | Request::SetPowerLevel { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 579 | | Request::SetDisplayName { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 580 | | Request::SetAvatar { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 581 | | Request::Invite { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 582 | | Request::Direct { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 583 | | Request::Redact { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 584 | | Request::SetFavourite { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 585 | | Request::ReorderSpaces { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 586 | | Request::SetRoomDisplayName { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 587 | | Request::SetRoomAvatar { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 588 | | Request::Mute { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 589 | | Request::Ignore { .. } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 590 | | Request::Unignore { .. } |
d8624c214c04 | atagen | 2026-10-24 08:24 UTC | 591 | | Request::PowerLevels { .. } |
77eddb6b710f | atagen | 2026-10-24 09:32 UTC | 592 | | Request::OpenPinned { .. } |
77eddb6b710f | atagen | 2026-10-24 09:32 UTC | 593 | | Request::ClosePinned { .. } |
77eddb6b710f | atagen | 2026-10-24 09:32 UTC | 594 | | Request::SetPinned { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 595 | | Request::SendSticker { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 596 | | Request::CreateRoomPack { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 597 | | Request::DeletePack { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 598 | | Request::SetPackMeta { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 599 | | Request::PutPackImage { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 600 | | Request::RenamePackImage { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 601 | | Request::RemovePackImage { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 602 | | Request::SetPackEnabled { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 603 | | Request::ClonePackImage { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 604 | | Request::CloneSticker { .. } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 605 | | Request::ClonePack { .. } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 606 | ) { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 607 | return ApiError::bad_request("op is not available as a command").into_response(); |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 608 | } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 609 | respond(dispatch(&user.handle, &user.mirror, request).await) |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 610 | } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 611 | |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 612 | async fn profile_avatar( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 613 | State(state): State<AppState>, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 614 | headers: HeaderMap, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 615 | bytes: axum::body::Bytes, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 616 | ) -> Response { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 617 | let (user, _) = match auth(&state, &headers).await { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 618 | Ok(pair) => pair, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 619 | Err(error) => return error.into_response(), |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 620 | }; |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 621 | respond( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 622 | dispatch( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 623 | &user.handle, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 624 | &user.mirror, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 625 | Request::UploadAvatar { |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 626 | bytes: bytes.to_vec(), |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 627 | }, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 628 | ) |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 629 | .await, |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 630 | ) |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 631 | } |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 632 | |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 633 | #[derive(Debug, Deserialize)] |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 634 | struct RoomAvatarQuery { |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 635 | room_id: String, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 636 | } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 637 | |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 638 | async fn rooms_avatar( |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 639 | State(state): State<AppState>, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 640 | headers: HeaderMap, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 641 | Query(query): Query<RoomAvatarQuery>, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 642 | bytes: axum::body::Bytes, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 643 | ) -> Response { |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 644 | let (user, _) = match auth(&state, &headers).await { |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 645 | Ok(pair) => pair, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 646 | Err(error) => return error.into_response(), |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 647 | }; |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 648 | respond( |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 649 | dispatch( |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 650 | &user.handle, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 651 | &user.mirror, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 652 | Request::UploadRoomAvatar { |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 653 | room_id: query.room_id, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 654 | bytes: bytes.to_vec(), |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 655 | }, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 656 | ) |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 657 | .await, |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 658 | ) |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 659 | } |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 660 | |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 661 | async fn media_upload( |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 662 | State(state): State<AppState>, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 663 | headers: HeaderMap, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 664 | bytes: axum::body::Bytes, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 665 | ) -> Response { |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 666 | let (user, _) = match auth(&state, &headers).await { |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 667 | Ok(pair) => pair, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 668 | Err(error) => return error.into_response(), |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 669 | }; |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 670 | respond( |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 671 | dispatch( |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 672 | &user.handle, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 673 | &user.mirror, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 674 | Request::UploadMedia { |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 675 | bytes: bytes.to_vec(), |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 676 | }, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 677 | ) |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 678 | .await, |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 679 | ) |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 680 | } |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 681 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 682 | async fn rooms_paginate( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 683 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 684 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 685 | body: axum::Json<PaginateBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 686 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 687 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 688 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 689 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 690 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 691 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 692 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 693 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 694 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 695 | Request::Paginate { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 696 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 697 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 698 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 699 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 700 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 701 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 702 | |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 703 | async fn rooms_context( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 704 | State(state): State<AppState>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 705 | headers: HeaderMap, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 706 | body: axum::Json<EventContextBody>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 707 | ) -> Response { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 708 | let (user, _) = match auth(&state, &headers).await { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 709 | Ok(pair) => pair, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 710 | Err(error) => return error.into_response(), |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 711 | }; |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 712 | respond( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 713 | dispatch( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 714 | &user.handle, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 715 | &user.mirror, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 716 | Request::EventContext { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 717 | room_id: body.0.room_id, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 718 | event_id: body.0.event_id, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 719 | before_limit: body.0.before_limit, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 720 | after_limit: body.0.after_limit, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 721 | }, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 722 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 723 | .await, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 724 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 725 | } |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 726 | |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 727 | async fn rooms_context_before( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 728 | State(state): State<AppState>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 729 | headers: HeaderMap, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 730 | body: axum::Json<EventContextPageBody>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 731 | ) -> Response { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 732 | let (user, _) = match auth(&state, &headers).await { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 733 | Ok(pair) => pair, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 734 | Err(error) => return error.into_response(), |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 735 | }; |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 736 | respond( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 737 | dispatch( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 738 | &user.handle, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 739 | &user.mirror, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 740 | Request::EventContextBefore { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 741 | room_id: body.0.room_id, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 742 | token: body.0.token, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 743 | limit: body.0.limit, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 744 | }, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 745 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 746 | .await, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 747 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 748 | } |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 749 | |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 750 | async fn rooms_context_after( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 751 | State(state): State<AppState>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 752 | headers: HeaderMap, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 753 | body: axum::Json<EventContextPageBody>, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 754 | ) -> Response { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 755 | let (user, _) = match auth(&state, &headers).await { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 756 | Ok(pair) => pair, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 757 | Err(error) => return error.into_response(), |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 758 | }; |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 759 | respond( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 760 | dispatch( |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 761 | &user.handle, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 762 | &user.mirror, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 763 | Request::EventContextAfter { |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 764 | room_id: body.0.room_id, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 765 | token: body.0.token, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 766 | limit: body.0.limit, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 767 | }, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 768 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 769 | .await, |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 770 | ) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 771 | } |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 772 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 773 | async fn rooms_join( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 774 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 775 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 776 | body: axum::Json<JoinBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 777 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 778 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 779 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 780 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 781 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 782 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 783 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 784 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 785 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 786 | Request::Join { room: body.0.room }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 787 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 788 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 789 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 790 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 791 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 792 | async fn rooms_create( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 793 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 794 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 795 | body: axum::Json<CreateBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 796 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 797 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 798 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 799 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 800 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 801 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 802 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 803 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 804 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 805 | Request::Create { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 806 | name: body.0.name, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 807 | topic: body.0.topic, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 808 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 809 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 810 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 811 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 812 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 813 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 814 | async fn rooms_leave( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 815 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 816 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 817 | body: axum::Json<RoomIdBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 818 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 819 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 820 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 821 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 822 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 823 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 824 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 825 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 826 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 827 | Request::Leave { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 828 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 829 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 830 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 831 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 832 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 833 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 834 | |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 835 | async fn rooms_edit( |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 836 | State(state): State<AppState>, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 837 | headers: HeaderMap, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 838 | body: axum::Json<EditBody>, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 839 | ) -> Response { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 840 | let (user, _) = match auth(&state, &headers).await { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 841 | Ok(pair) => pair, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 842 | Err(error) => return error.into_response(), |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 843 | }; |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 844 | respond( |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 845 | dispatch( |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 846 | &user.handle, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 847 | &user.mirror, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 848 | Request::Edit { |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 849 | room_id: body.0.room_id, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 850 | event_id: body.0.event_id, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 851 | body: body.0.body, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 852 | formatted_body: body.0.formatted_body, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 853 | mentions: body.0.mentions, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 854 | }, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 855 | ) |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 856 | .await, |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 857 | ) |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 858 | } |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 859 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 860 | async fn rooms_react( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 861 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 862 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 863 | body: axum::Json<ReactBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 864 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 865 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 866 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 867 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 868 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 869 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 870 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 871 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 872 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 873 | Request::React { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 874 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 875 | event_id: body.0.event_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 876 | key: body.0.key, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 877 | shortcode: body.0.shortcode, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 878 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 879 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 880 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 881 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 882 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 883 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 884 | async fn rooms_read( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 885 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 886 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 887 | body: axum::Json<ReadBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 888 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 889 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 890 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 891 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 892 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 893 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 894 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 895 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 896 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 897 | Request::Read { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 898 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 899 | event_id: body.0.event_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 900 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 901 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 902 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 903 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 904 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 905 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 906 | async fn get_profile(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 907 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 908 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 909 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 910 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 911 | respond(dispatch(&user.handle, &user.mirror, Request::Profile).await) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 912 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 913 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 914 | async fn get_space_children( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 915 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 916 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 917 | Query(query): Query<MembersQuery>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 918 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 919 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 920 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 921 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 922 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 923 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 924 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 925 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 926 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 927 | Request::SpaceChildren { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 928 | room_id: query.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 929 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 930 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 931 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 932 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 933 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 934 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 935 | async fn get_media( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 936 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 937 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 938 | Query(query): Query<MediaQuery>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 939 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 940 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 941 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 942 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 943 | }; |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 944 | let request = Request::Avatar { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 945 | mxc: query.mxc, |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 946 | size: query.size.unwrap_or(malice_core::media::AVATAR_SIZE), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 947 | }; |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 948 | match dispatch(&user.handle, &user.mirror, request).await { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 949 | Ok(Reply::Avatar(source)) => { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 950 | match tokio::task::spawn_blocking(move || source.render()).await { |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 951 | Ok((bytes, content_type)) => avatar_response(bytes, content_type), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 952 | Err(_) => ApiError::new( |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 953 | StatusCode::INTERNAL_SERVER_ERROR, |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 954 | "avatar could not be rendered", |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 955 | ) |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 956 | .into_response(), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 957 | } |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 958 | } |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 959 | other => respond(other), |
7643577c76bb | atagen | 2026-10-25 07:37 UTC | 960 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 961 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 962 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 963 | async fn get_message_media( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 964 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 965 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 966 | Query(query): Query<MessageMediaQuery>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 967 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 968 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 969 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 970 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 971 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 972 | // the declared mimetype is the sender's claim, so the bytes get sniffed instead |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 973 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 974 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 975 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 976 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 977 | Request::Media { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 978 | media_id: query.media_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 979 | size: query.size, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 980 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 981 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 982 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 983 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 984 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 985 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 986 | async fn get_encryption(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 987 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 988 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 989 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 990 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 991 | respond(dispatch(&user.handle, &user.mirror, Request::Encryption).await) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 992 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 993 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 994 | async fn recover_encryption( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 995 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 996 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 997 | body: axum::Json<RecoverBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 998 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 999 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1000 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1001 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1002 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1003 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1004 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1005 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1006 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1007 | Request::Recover { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1008 | recovery_key: body.0.recovery_key, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1009 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1010 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1011 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1012 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1013 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1014 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1015 | async fn start_verification(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1016 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1017 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1018 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1019 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1020 | respond(dispatch(&user.handle, &user.mirror, Request::StartVerification).await) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1021 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1022 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1023 | async fn verify_encryption( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1024 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1025 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1026 | body: axum::Json<VerifyBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1027 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1028 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1029 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1030 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1031 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1032 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1033 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1034 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1035 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1036 | Request::Verify { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1037 | action: body.0.action, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1038 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1039 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1040 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1041 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1042 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1043 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1044 | async fn rooms_typing( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1045 | State(state): State<AppState>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1046 | headers: HeaderMap, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1047 | body: axum::Json<TypingBody>, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1048 | ) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1049 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1050 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1051 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1052 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1053 | respond( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1054 | dispatch( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1055 | &user.handle, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1056 | &user.mirror, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1057 | Request::Typing { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1058 | room_id: body.0.room_id, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1059 | typing: body.0.typing, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1060 | }, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1061 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1062 | .await, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1063 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1064 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1065 | |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1066 | async fn get_account_data( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1067 | State(state): State<AppState>, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1068 | headers: HeaderMap, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1069 | Query(query): Query<AccountDataQuery>, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1070 | ) -> Response { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1071 | let (user, _) = match auth(&state, &headers).await { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1072 | Ok(pair) => pair, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1073 | Err(error) => return error.into_response(), |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1074 | }; |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1075 | respond( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1076 | dispatch( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1077 | &user.handle, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1078 | &user.mirror, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1079 | Request::GetAccountData { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1080 | event_type: query.event_type, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1081 | }, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1082 | ) |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1083 | .await, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1084 | ) |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1085 | } |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1086 | |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1087 | async fn get_url_preview( |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1088 | State(state): State<AppState>, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1089 | headers: HeaderMap, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1090 | Query(query): Query<UrlPreviewQuery>, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1091 | ) -> Response { |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1092 | let (user, _) = match auth(&state, &headers).await { |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1093 | Ok(pair) => pair, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1094 | Err(error) => return error.into_response(), |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1095 | }; |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1096 | respond( |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1097 | dispatch( |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1098 | &user.handle, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1099 | &user.mirror, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1100 | Request::UrlPreview { |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1101 | room_id: query.room_id, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1102 | url: query.url, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1103 | }, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1104 | ) |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1105 | .await, |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1106 | ) |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1107 | } |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1108 | |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1109 | async fn set_account_data( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1110 | State(state): State<AppState>, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1111 | headers: HeaderMap, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1112 | body: axum::Json<AccountDataBody>, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1113 | ) -> Response { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1114 | let (user, _) = match auth(&state, &headers).await { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1115 | Ok(pair) => pair, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1116 | Err(error) => return error.into_response(), |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1117 | }; |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1118 | let body = body.0; |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1119 | respond( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1120 | dispatch( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1121 | &user.handle, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1122 | &user.mirror, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1123 | Request::SetAccountData { |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1124 | event_type: body.event_type, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1125 | content: body.content, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1126 | }, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1127 | ) |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1128 | .await, |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1129 | ) |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1130 | } |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1131 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1132 | async fn get_events(State(state): State<AppState>, headers: HeaderMap) -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1133 | let (user, _) = match auth(&state, &headers).await { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1134 | Ok(pair) => pair, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1135 | Err(error) => return error.into_response(), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1136 | }; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1137 | let body = subscribe(&user.mirror).map(|event| { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1138 | let json = serde_json::to_string(&event).unwrap_or_else(|_| "{\"type\":\"error\"}".into()); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1139 | Ok::<_, std::convert::Infallible>(SseEvent::default().data(json)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1140 | }); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1141 | Sse::new(body).into_response() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1142 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1143 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1144 | async fn get_health() -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1145 | json_ok(&serde_json::json!({ "status": "ok" }), None) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1146 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1147 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1148 | async fn static_shell() -> Response { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1149 | ( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1150 | StatusCode::SERVICE_UNAVAILABLE, |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1151 | axum::Json(serde_json::json!({ "message": "frontend assets missing; run npm --prefix web run build or use the Nix package" })), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1152 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1153 | .into_response() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1154 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1155 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1156 | pub fn router(state: AppState, web_dir: Option<String>) -> Router { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1157 | let api = Router::new() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1158 | .route("/session", get(get_session)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1159 | .route("/login", post(post_login)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1160 | .route("/logout", post(post_logout)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1161 | .route("/rooms", get(get_rooms)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1162 | .route("/events", get(get_events)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1163 | .route("/health", get(get_health)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1164 | .route("/rooms/open", post(rooms_open)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1165 | .route("/rooms/close", post(rooms_close)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1166 | .route("/rooms/send", post(rooms_send)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1167 | .route("/rooms/paginate", post(rooms_paginate)) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 1168 | .route("/rooms/context", post(rooms_context)) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 1169 | .route("/rooms/context/before", post(rooms_context_before)) |
824dfd38cdf3 | atagen | 2026-10-24 13:43 UTC | 1170 | .route("/rooms/context/after", post(rooms_context_after)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1171 | .route( |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1172 | "/rooms/upload", |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1173 | post(rooms_upload).layer(DefaultBodyLimit::max(21 * 1024 * 1024)), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1174 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1175 | .route("/rooms/join", post(rooms_join)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1176 | .route("/rooms/create", post(rooms_create)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1177 | .route("/rooms/leave", post(rooms_leave)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1178 | .route("/rooms/react", post(rooms_react)) |
cf23dbf4e77c | atagen | 2026-10-23 06:36 UTC | 1179 | .route("/rooms/edit", post(rooms_edit)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1180 | .route("/rooms/read", post(rooms_read)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1181 | .route("/rooms/typing", post(rooms_typing)) |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1182 | .route( |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1183 | "/account-data", |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1184 | get(get_account_data).post(set_account_data), |
544a170ead2c | atagen | 2026-10-20 11:47 UTC | 1185 | ) |
ecb8598b38af | atagen | 2026-10-22 09:19 UTC | 1186 | .route("/url-preview", get(get_url_preview)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1187 | .route("/profile", get(get_profile)) |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1188 | .route( |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1189 | "/profile/avatar", |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1190 | post(profile_avatar).layer(DefaultBodyLimit::max(10 * 1024 * 1024)), |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1191 | ) |
e4c64c36f105 | atagen | 2026-10-24 07:09 UTC | 1192 | .route("/command", post(post_command)) |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 1193 | .route( |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 1194 | "/rooms/avatar", |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 1195 | post(rooms_avatar).layer(DefaultBodyLimit::max(10 * 1024 * 1024)), |
7cca1d5628d1 | atagen | 2026-10-24 07:36 UTC | 1196 | ) |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 1197 | .route( |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 1198 | "/media/upload", |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 1199 | post(media_upload).layer(DefaultBodyLimit::max(10 * 1024 * 1024)), |
d095131eec0e | atagen | 2026-10-24 08:39 UTC | 1200 | ) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1201 | .route("/media", get(get_media)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1202 | .route("/message-media", get(get_message_media)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1203 | .route("/spaces/children", get(get_space_children)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1204 | .route("/rooms/members", get(get_members)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1205 | .route("/encryption", get(get_encryption)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1206 | .route("/encryption/recover", post(recover_encryption)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1207 | .route("/encryption/start", post(start_verification)) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1208 | .route("/encryption/verify", post(verify_encryption)); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1209 | let api = Router::new() |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1210 | .nest("/api", api) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1211 | .layer(middleware::from_fn(csrf_guard)); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1212 | let router = api.with_state(state).layer(TraceLayer::new_for_http()); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1213 | match web_dir { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1214 | Some(dir) => { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1215 | let files = |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1216 | ServeDir::new(&dir).not_found_service(ServeFile::new(format!("{dir}/index.html"))); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1217 | router.fallback_service(files) |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1218 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1219 | None => router.fallback(static_shell), |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1220 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1221 | } |