๐Ÿ“๐Ÿ–ผ๏ธ๐Ÿน A small thing where I can upload a file and get a link back. https://media.strawmelonjuice.com/
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add /api/user/fetch endpoint

+33 -8
+4 -7
README.md
··· 17 17 - Session destruction (`/api/session/destroy`) 18 18 - Simple file upload (`/api/upload`) with quota checking 19 19 - Simple redirect from (`/favicon.ico`) to the strawmelonjuice.png file 20 + - User info retrieval from ('/api/user/fetch') 20 21 21 22 22 23 ### โŒ **Missing from Rust:** ··· 26 27 - [x] Admins see all files, regular users see only their own 27 28 - [ ] Returns file sizes in MB 28 29 29 - 2. **`/api/user/fetch` - User Info Retrieval** 30 - - Returns current user details (username, quotas, admin status) 31 - - Excludes password hash 32 - 33 - 3. **`/api/files/delete` - File Deletion** 30 + 2. **`/api/files/delete` - File Deletion** 34 31 - Deletes files with permission checking 35 32 - Updates user quotas 36 33 - Cleans up physical files and directories 37 34 38 - 4. **`/api/upload-streamed` - WebSocket Upload** 35 + 3. **`/api/upload-streamed` - WebSocket Upload** 39 36 - Handles large file uploads via WebSocket 40 37 - Chunks data to avoid memory issues 41 38 - Real-time quota validation during upload 42 39 43 - 5. **Automatic Sample File Creation** 40 + 4. **Automatic Sample File Creation** 44 41 - TS version downloads strawmelonjuice.png from strawmelonjuice.com 45 42 - Rust version doesn't have this initialization 46 43
+2
server-rs/src/main.rs
··· 45 45 // /api/files -> lists all files for authenticated users. 46 46 // (admins see all, users just their own) 47 47 routes::api::list_files, 48 + // /api/user/fetch -> return current user details (excluding password hash) 49 + routes::api::fetch_user, 48 50 ], 49 51 ) 50 52 .manage(app)
+27 -1
server-rs/src/routes/api.rs
··· 259 259 }); 260 260 } 261 261 262 - struct User { 262 + #[derive(Serialize)] 263 + #[serde(crate = "rocket::serde")] 264 + pub(crate) struct User { 263 265 id: Uuid, 264 266 username: String, 265 267 max_megabytes: i64, ··· 275 277 filename: String, 276 278 size_mb: i32, 277 279 } 280 + 281 + #[post("/user/fetch", data = "<single_identify>")] 282 + pub(crate) async fn fetch_user( 283 + single_identify: Json<SingleIdentify>, 284 + app: &State<App>, 285 + ) -> Result<Json<User>, (Status, &'static str)> { 286 + // Validate the session 287 + let sid = match Uuid::parse_str(&single_identify.session) { 288 + Ok(v) => v, 289 + Err(_) => return Err((Status::BadRequest, "Invalid session ID format.")), 290 + }; 291 + let user_id = match app.validate_session(sid).await { 292 + Ok(v) => v, 293 + Err(_) => return Err((Status::Unauthorized, "Invalid session token.")), 294 + }; 295 + 296 + // get the user data from the id 297 + let user = match user_from_id(&app.db, user_id).await { 298 + Ok(v) => v, 299 + Err(_) => return Err((Status::NotFound, "Couldn't find the user for session id")), 300 + }; 301 + 302 + Ok(Json(user)) 303 + }