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