an http based roguelike rpg about jelqing
Blame: src/http/runs.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | //! The resources under `/runs/{id}`. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use axum::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | Json, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | http::{StatusCode, header}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | response::{IntoResponse, Response}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | use serde_json::{Value, json}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | ctx::Ctx, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | inventory::{delete_item, get_inventory, get_item}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | parse::{parse_intensity, parse_techniques}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | resource::{Resource, Verb}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | response::respond, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | run::{Greeting, RunResource, Scope}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | shaft::{get_foreskin, get_length}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | use crate::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | game::{ |
6619c458c23e | atagen | 2026-10-14 08:08 UTC | 21 | Branch, Cause, Floor, Grip, Item, LUBRICANTS, Lube, Run, Technique, |
e028a4184d00 | atagen | 2026-10-14 10:49 UTC | 22 | balance::VIEWS_PER_SECOND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | problem::Problem, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | const fn home(verbs: &'static [Verb<Run>]) -> RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | scope: Scope::Home, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | resource: Resource::new(verbs), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | const fn pockets(verbs: &'static [Verb<Run>]) -> RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | scope: Scope::Pockets, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | resource: Resource::new(verbs), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | fn not_in_clinic(run: &Run) -> bool { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | run.floor != Floor::Clinic |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | pub static RUN: RunResource = RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | scope: Scope::Home, |
6619c458c23e | atagen | 2026-10-14 08:08 UTC | 47 | resource: Resource::new(&[ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | Verb::new("GET", get_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | Verb::new("JELQ", jelq).only_when(not_in_clinic, "JELQ is not performed in the clinic."), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | Verb::new("HOLD", hold_run).only_when( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | Run::can_hold, |
e028a4184d00 | atagen | 2026-10-14 10:49 UTC | 52 | "HOLD is only available once Swollen or at 2 stamina or less.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | Verb::new("PUT", put_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Verb::new("DELETE", delete_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | Verb::new("TRACE", trace_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | ]), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | pub static LENGTH: RunResource = home(&[Verb::new("GET", get_length)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | pub static FORESKIN: RunResource = home(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | Verb::new("GET", get_foreskin), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | Verb::new("DELETE", delete_foreskin), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | pub static INVENTORY: RunResource = pockets(&[Verb::new("GET", get_inventory)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | pub static ITEM: RunResource = |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | pockets(&[Verb::new("GET", get_item), Verb::new("DELETE", delete_item)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | pub static TECHNIQUES: RunResource = home(&[Verb::new("GET", get_techniques)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | pub static DRAWER: RunResource = home(&[Verb::new("POST", search_drawer)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | pub static BRANCH: RunResource = home(&[Verb::new("POST", choose_branch)]); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 70 | pub static KITCHEN: RunResource = home(&[Verb::new("POST", raid_kitchen)]); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 71 | pub static MELON: RunResource = home(&[Verb::new("POST", commit_melon)]); |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 72 | pub static THREAD: RunResource = pockets(&[Verb::new("GET", get_thread)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | pub static FLOOR: RunResource = |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 74 | home(&[Verb::new("GET", get_floor), Verb::new("POST", leave_floor)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | pub static SHOP: RunResource = home(&[Verb::new("GET", get_shop)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | pub static BUY: RunResource = home(&[Verb::new("POST", buy)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | pub static PORTAL: RunResource = pockets(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | Verb::new("GET", get_portal), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | Verb::new("POST", accept_portal), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | pub static ELDER: RunResource = home(&[Verb::new("GET", get_elder)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | pub static GRIP: RunResource = home(&[Verb::new("GET", get_grip)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | pub static DIAGNOSIS: RunResource = pockets(&[Verb::new("GET", get_diagnosis)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | pub static FOOTAGE: RunResource = pockets(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | Verb::new("GET", get_footage), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | Verb::refused( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 87 | "DELETE", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | "The footage has been cached by intermediaries. It cannot be deleted.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | fn get_run(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | if ctx |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | .header(header::ACCEPT) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | .is_some_and(|accept| accept.contains("reassurance")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | StatusCode::NOT_ACCEPTABLE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | "no-reassurance", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | "The server does not produce reassurance.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | [(header::ETAG, run.etag())], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | Json(run.view()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | fn jelq(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | let parsed = parse_techniques(run, ctx).and_then(|techniques| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | let intensity = parse_intensity(ctx)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | let lube = Lube::from_content_type(ctx.header(header::CONTENT_TYPE))?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | Ok((techniques, intensity, lube)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | match parsed { |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 119 | Ok((techniques, intensity, lube)) => respond(run.jelq(&techniques, intensity, lube)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | Err(problem) => problem.into_response(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | fn put_run(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | run.put().into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 128 | fn hold_run(run: &mut Run, _: &Ctx) -> Response { |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 129 | respond(run.hold()) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 130 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 131 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | fn delete_run(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | run.end(Cause::Abandoned); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | StatusCode::NO_CONTENT.into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | fn trace_run(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 138 | run.trace(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | [(header::CONTENT_TYPE, "message/http")], |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 142 | ctx.echo(), |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 143 | ) |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 144 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | fn delete_foreskin(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | respond(run.delete_foreskin(ctx.header(header::IF_MATCH))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | fn get_techniques(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | let listed: Vec<Value> = Technique::ALL |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | .into_iter() |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 154 | .map(|t| t.describe(run.knows(t))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | .collect(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | "usage": format!("JELQ {}?technique=<name>[,<name>]&intensity=<1-10>", run.path("")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | "lubricant": "Declared with Content-Type.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | "lubricants": LUBRICANTS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | "techniques": listed, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | })) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | fn search_drawer(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | respond(run.search_drawer()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | fn choose_branch(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 170 | match ctx.param("choice").parse::<Branch>() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 171 | Ok(choice) => respond(run.choose(choice)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 172 | Err(()) => Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 173 | StatusCode::NOT_FOUND, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 174 | "no-such-choice", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 175 | "That was not one of the choices.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 176 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 177 | .into_response(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 178 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | fn get_floor(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | Json(run.floor_view()).into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | fn leave_floor(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | respond(run.advance()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | fn get_shop(run: &mut Run, _: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 190 | respond(run.browse_shop().map(Json)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 191 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | fn buy(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 194 | respond(run.buy(Item::parse(ctx.param("item")))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 195 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 196 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 197 | fn raid_kitchen(run: &mut Run, _: &Ctx) -> Response { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 198 | respond(run.raid_kitchen()) |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 199 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 200 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 201 | fn commit_melon(run: &mut Run, _: &Ctx) -> Response { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 202 | respond(run.commit_melon()) |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 203 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 204 | |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 205 | fn get_thread(run: &mut Run, _: &Ctx) -> Response { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 206 | respond(run.read_thread()) |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 207 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 208 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 209 | fn get_portal(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 210 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 211 | "terms": "By connecting you agree that the hotel is not responsible for anything that happens in this room, and that it does not want to know.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 212 | "accept": { "href": run.path("/portal"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 213 | })) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 214 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 215 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 216 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 217 | fn accept_portal(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 218 | respond(run.accept_terms()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 219 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 220 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 221 | fn get_elder(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 222 | respond(run.elder( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 223 | ctx.header(header::PROXY_AUTHORIZATION), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 224 | ctx.header(header::IF_MODIFIED_SINCE), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 225 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 226 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 227 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 228 | fn requested_grip(ctx: &Ctx) -> Option<Grip> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 229 | let connection = ctx.header(header::CONNECTION)?.to_ascii_lowercase(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 230 | if !connection.split(',').any(|token| token.trim() == "upgrade") { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 231 | return None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 232 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 233 | ctx.header(header::UPGRADE)? |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | .split(',') |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 235 | .find_map(|protocol| protocol.trim().parse::<Grip>().ok()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | fn get_grip(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | if let Some(grip) = requested_grip(ctx) { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 240 | if let Err(problem) = run.set_grip(grip) { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 241 | return problem.into_response(); |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 242 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 243 | let mut response = ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | StatusCode::SWITCHING_PROTOCOLS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 246 | (header::UPGRADE, grip.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 247 | (header::CONNECTION, "upgrade"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 250 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | response.extensions_mut().insert(Greeting(format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 252 | "You are now jelqing {}.\r\n", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 253 | grip.name() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 254 | ))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 255 | return response; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 256 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 257 | let detail = match ctx.header(header::UPGRADE) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 258 | Some(protocol) => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 259 | format!("The server does not know the {protocol} grip. Grips are protocols.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 260 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 261 | None => "Grips are protocols. Change grip by upgrading the connection.".to_owned(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 262 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 263 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 264 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 265 | [(header::UPGRADE, "overhand, underhand")], |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 266 | Json(json!({ "grip": run.grip().name(), "detail": detail })), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 267 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 268 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 269 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 270 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 271 | fn get_diagnosis(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 272 | respond(run.diagnose( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 273 | ctx.header(header::AUTHORIZATION), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 274 | ctx.header(header::IF_NONE_MATCH), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 275 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 276 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 277 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 278 | fn get_footage(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 279 | let Some((filmed, age)) = run.footage() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 280 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 281 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 282 | "no-footage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 283 | "There is no footage. Yet.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 284 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 285 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 286 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 287 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 288 | [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 289 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 290 | header::CACHE_CONTROL, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 291 | "public, max-age=31536000, immutable".to_owned(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 292 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 293 | (header::AGE, age.to_string()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 294 | (header::LAST_MODIFIED, httpdate::fmt_http_date(filmed)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 295 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 296 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 297 | "detail": "A recording. It is grainy. It is unmistakably you. It has been shared.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 298 | "views": 1 + age * VIEWS_PER_SECOND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 299 | })), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 300 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 301 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 302 | } |