atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
14de3e1e8dc2a460103dbac0f56b745af96da78e
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/http/runs.rs

782069860236atagen2026-10-10 12:44 UTC1
//! The resources under `/runs/{id}`.
782069860236atagen2026-10-10 12:44 UTC2
782069860236atagen2026-10-10 12:44 UTC3
use std::{convert::Infallible, fmt::Write as _};
782069860236atagen2026-10-10 12:44 UTC4
782069860236atagen2026-10-10 12:44 UTC5
use axum::{
782069860236atagen2026-10-10 12:44 UTC6
    Json,
782069860236atagen2026-10-10 12:44 UTC7
    body::{Body, Bytes},
782069860236atagen2026-10-10 12:44 UTC8
    http::{StatusCode, header},
782069860236atagen2026-10-10 12:44 UTC9
    response::{IntoResponse, Response},
782069860236atagen2026-10-10 12:44 UTC10
};
782069860236atagen2026-10-10 12:44 UTC11
use serde_json::{Value, json};
782069860236atagen2026-10-10 12:44 UTC12
782069860236atagen2026-10-10 12:44 UTC13
use super::{
782069860236atagen2026-10-10 12:44 UTC14
    ctx::Ctx,
782069860236atagen2026-10-10 12:44 UTC15
    resource::{Resource, Verb},
782069860236atagen2026-10-10 12:44 UTC16
    response::respond,
782069860236atagen2026-10-10 12:44 UTC17
    run::{Greeting, RunResource, Scope},
782069860236atagen2026-10-10 12:44 UTC18
};
782069860236atagen2026-10-10 12:44 UTC19
use crate::{
782069860236atagen2026-10-10 12:44 UTC20
    game::{
782069860236atagen2026-10-10 12:44 UTC21
        Cause, Floor, Grip, Item, LUBRICANTS, Lube, PatchOp, Run, Technique,
782069860236atagen2026-10-10 12:44 UTC22
        balance::{EQ_BAND, MM_PER_INCH},
782069860236atagen2026-10-10 12:44 UTC23
        shaft,
782069860236atagen2026-10-10 12:44 UTC24
    },
782069860236atagen2026-10-10 12:44 UTC25
    headers::ACCEPT_PATCH,
782069860236atagen2026-10-10 12:44 UTC26
    problem::Problem,
782069860236atagen2026-10-10 12:44 UTC27
};
782069860236atagen2026-10-10 12:44 UTC28
782069860236atagen2026-10-10 12:44 UTC29
const fn home(verbs: &'static [Verb<Run>]) -> RunResource {
782069860236atagen2026-10-10 12:44 UTC30
    RunResource {
782069860236atagen2026-10-10 12:44 UTC31
        scope: Scope::Home,
782069860236atagen2026-10-10 12:44 UTC32
        resource: Resource::new(verbs),
782069860236atagen2026-10-10 12:44 UTC33
    }
782069860236atagen2026-10-10 12:44 UTC34
}
782069860236atagen2026-10-10 12:44 UTC35
782069860236atagen2026-10-10 12:44 UTC36
const fn pockets(verbs: &'static [Verb<Run>]) -> RunResource {
782069860236atagen2026-10-10 12:44 UTC37
    RunResource {
782069860236atagen2026-10-10 12:44 UTC38
        scope: Scope::Pockets,
782069860236atagen2026-10-10 12:44 UTC39
        resource: Resource::new(verbs),
782069860236atagen2026-10-10 12:44 UTC40
    }
782069860236atagen2026-10-10 12:44 UTC41
}
782069860236atagen2026-10-10 12:44 UTC42
782069860236atagen2026-10-10 12:44 UTC43
fn not_in_clinic(run: &Run) -> bool {
782069860236atagen2026-10-10 12:44 UTC44
    run.floor != Floor::Clinic
782069860236atagen2026-10-10 12:44 UTC45
}
782069860236atagen2026-10-10 12:44 UTC46
782069860236atagen2026-10-10 12:44 UTC47
fn never(_: &Run) -> bool {
782069860236atagen2026-10-10 12:44 UTC48
    false
782069860236atagen2026-10-10 12:44 UTC49
}
782069860236atagen2026-10-10 12:44 UTC50
782069860236atagen2026-10-10 12:44 UTC51
fn unreachable_handler(_: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC52
    StatusCode::METHOD_NOT_ALLOWED.into_response()
782069860236atagen2026-10-10 12:44 UTC53
}
782069860236atagen2026-10-10 12:44 UTC54
782069860236atagen2026-10-10 12:44 UTC55
pub static RUN: RunResource = RunResource {
782069860236atagen2026-10-10 12:44 UTC56
    scope: Scope::Home,
782069860236atagen2026-10-10 12:44 UTC57
    resource: Resource {
782069860236atagen2026-10-10 12:44 UTC58
        verbs: &[
782069860236atagen2026-10-10 12:44 UTC59
            Verb::new("GET", get_run),
782069860236atagen2026-10-10 12:44 UTC60
            Verb::new("JELQ", jelq)
782069860236atagen2026-10-10 12:44 UTC61
                .only_when(not_in_clinic, "JELQ is not performed in the clinic."),
4347977b8192atagen2026-10-11 04:56 UTC62
            Verb::new("HOLD", hold_run).only_when(
4347977b8192atagen2026-10-11 04:56 UTC63
                Run::can_hold,
4347977b8192atagen2026-10-11 04:56 UTC64
                "HOLD is only available above 70 EQ or at 2 stamina or less.",
4347977b8192atagen2026-10-11 04:56 UTC65
            ),
782069860236atagen2026-10-10 12:44 UTC66
            Verb::new("PUT", put_run),
782069860236atagen2026-10-10 12:44 UTC67
            Verb::new("PATCH", patch_run),
782069860236atagen2026-10-10 12:44 UTC68
            Verb::new("DELETE", delete_run),
782069860236atagen2026-10-10 12:44 UTC69
            Verb::new("TRACE", trace_run),
782069860236atagen2026-10-10 12:44 UTC70
        ],
782069860236atagen2026-10-10 12:44 UTC71
        accept_patch: true,
782069860236atagen2026-10-10 12:44 UTC72
    },
782069860236atagen2026-10-10 12:44 UTC73
};
782069860236atagen2026-10-10 12:44 UTC74
pub static LENGTH: RunResource = home(&[Verb::new("GET", get_length)]);
782069860236atagen2026-10-10 12:44 UTC75
pub static FORESKIN: RunResource = home(&[
782069860236atagen2026-10-10 12:44 UTC76
    Verb::new("GET", get_foreskin),
782069860236atagen2026-10-10 12:44 UTC77
    Verb::new("DELETE", delete_foreskin),
782069860236atagen2026-10-10 12:44 UTC78
]);
782069860236atagen2026-10-10 12:44 UTC79
pub static INVENTORY: RunResource = pockets(&[Verb::new("GET", get_inventory)]);
782069860236atagen2026-10-10 12:44 UTC80
pub static ITEM: RunResource =
782069860236atagen2026-10-10 12:44 UTC81
    pockets(&[Verb::new("GET", get_item), Verb::new("DELETE", delete_item)]);
782069860236atagen2026-10-10 12:44 UTC82
pub static TECHNIQUES: RunResource = home(&[Verb::new("GET", get_techniques)]);
782069860236atagen2026-10-10 12:44 UTC83
pub static DRAWER: RunResource = home(&[Verb::new("POST", search_drawer)]);
782069860236atagen2026-10-10 12:44 UTC84
pub static BRANCH: RunResource = home(&[Verb::new("POST", choose_branch)]);
0a0bfee8329eatagen2026-10-11 05:11 UTC85
pub static KITCHEN: RunResource = home(&[Verb::new("POST", raid_kitchen)]);
0a0bfee8329eatagen2026-10-11 05:11 UTC86
pub static MELON: RunResource = home(&[Verb::new("POST", commit_melon)]);
782069860236atagen2026-10-10 12:44 UTC87
pub static FLOOR: RunResource =
0d604ee39751atagen2026-10-10 14:15 UTC88
    home(&[Verb::new("GET", get_floor), Verb::new("POST", leave_floor)]);
782069860236atagen2026-10-10 12:44 UTC89
pub static SHOP: RunResource = home(&[Verb::new("GET", get_shop)]);
782069860236atagen2026-10-10 12:44 UTC90
pub static BUY: RunResource = home(&[Verb::new("POST", buy)]);
782069860236atagen2026-10-10 12:44 UTC91
pub static PORTAL: RunResource = pockets(&[
782069860236atagen2026-10-10 12:44 UTC92
    Verb::new("GET", get_portal),
782069860236atagen2026-10-10 12:44 UTC93
    Verb::new("POST", accept_portal),
782069860236atagen2026-10-10 12:44 UTC94
]);
782069860236atagen2026-10-10 12:44 UTC95
pub static ELDER: RunResource = home(&[Verb::new("GET", get_elder)]);
782069860236atagen2026-10-10 12:44 UTC96
pub static GRIP: RunResource = home(&[Verb::new("GET", get_grip)]);
782069860236atagen2026-10-10 12:44 UTC97
pub static DIAGNOSIS: RunResource = pockets(&[Verb::new("GET", get_diagnosis)]);
782069860236atagen2026-10-10 12:44 UTC98
pub static FOOTAGE: RunResource = pockets(&[
782069860236atagen2026-10-10 12:44 UTC99
    Verb::new("GET", get_footage),
782069860236atagen2026-10-10 12:44 UTC100
    Verb::new("DELETE", unreachable_handler).only_when(
782069860236atagen2026-10-10 12:44 UTC101
        never,
782069860236atagen2026-10-10 12:44 UTC102
        "The footage has been cached by intermediaries. It cannot be deleted.",
782069860236atagen2026-10-10 12:44 UTC103
    ),
782069860236atagen2026-10-10 12:44 UTC104
]);
782069860236atagen2026-10-10 12:44 UTC105
782069860236atagen2026-10-10 12:44 UTC106
fn get_run(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC107
    if ctx
782069860236atagen2026-10-10 12:44 UTC108
        .header(header::ACCEPT)
782069860236atagen2026-10-10 12:44 UTC109
        .is_some_and(|accept| accept.contains("reassurance"))
782069860236atagen2026-10-10 12:44 UTC110
    {
782069860236atagen2026-10-10 12:44 UTC111
        return Problem::new(
782069860236atagen2026-10-10 12:44 UTC112
            StatusCode::NOT_ACCEPTABLE,
782069860236atagen2026-10-10 12:44 UTC113
            "no-reassurance",
782069860236atagen2026-10-10 12:44 UTC114
            "The server does not produce reassurance.",
782069860236atagen2026-10-10 12:44 UTC115
        )
782069860236atagen2026-10-10 12:44 UTC116
        .into_response();
782069860236atagen2026-10-10 12:44 UTC117
    }
782069860236atagen2026-10-10 12:44 UTC118
    (
782069860236atagen2026-10-10 12:44 UTC119
        StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC120
        [(header::ETAG, run.etag())],
782069860236atagen2026-10-10 12:44 UTC121
        Json(run.view()),
782069860236atagen2026-10-10 12:44 UTC122
    )
782069860236atagen2026-10-10 12:44 UTC123
        .into_response()
782069860236atagen2026-10-10 12:44 UTC124
}
782069860236atagen2026-10-10 12:44 UTC125
782069860236atagen2026-10-10 12:44 UTC126
fn parse_techniques(run: &Run, ctx: &Ctx) -> Result<Vec<Technique>, Problem> {
782069860236atagen2026-10-10 12:44 UTC127
    let required = || {
782069860236atagen2026-10-10 12:44 UTC128
        Problem::new(
782069860236atagen2026-10-10 12:44 UTC129
            StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC130
            "technique-required",
782069860236atagen2026-10-10 12:44 UTC131
            "No technique was specified.",
782069860236atagen2026-10-10 12:44 UTC132
        )
782069860236atagen2026-10-10 12:44 UTC133
        .with("techniques", run.path("/techniques"))
782069860236atagen2026-10-10 12:44 UTC134
    };
782069860236atagen2026-10-10 12:44 UTC135
    let names = ctx
782069860236atagen2026-10-10 12:44 UTC136
        .query("technique")
782069860236atagen2026-10-10 12:44 UTC137
        .filter(|n| !n.trim().is_empty())
782069860236atagen2026-10-10 12:44 UTC138
        .ok_or_else(required)?;
782069860236atagen2026-10-10 12:44 UTC139
    names
782069860236atagen2026-10-10 12:44 UTC140
        .split(',')
782069860236atagen2026-10-10 12:44 UTC141
        .map(str::trim)
782069860236atagen2026-10-10 12:44 UTC142
        .filter(|n| !n.is_empty())
782069860236atagen2026-10-10 12:44 UTC143
        .map(|name| {
782069860236atagen2026-10-10 12:44 UTC144
            Technique::parse(name).ok_or_else(|| {
782069860236atagen2026-10-10 12:44 UTC145
                Problem::new(
782069860236atagen2026-10-10 12:44 UTC146
                    StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC147
                    "unknown-technique",
782069860236atagen2026-10-10 12:44 UTC148
                    format!("{name} is not a technique."),
782069860236atagen2026-10-10 12:44 UTC149
                )
782069860236atagen2026-10-10 12:44 UTC150
                .with("techniques", run.path("/techniques"))
782069860236atagen2026-10-10 12:44 UTC151
            })
782069860236atagen2026-10-10 12:44 UTC152
        })
782069860236atagen2026-10-10 12:44 UTC153
        .collect()
782069860236atagen2026-10-10 12:44 UTC154
}
782069860236atagen2026-10-10 12:44 UTC155
782069860236atagen2026-10-10 12:44 UTC156
fn parse_intensity(ctx: &Ctx) -> Result<i32, Problem> {
782069860236atagen2026-10-10 12:44 UTC157
    match ctx.query("intensity").map(str::parse::<i32>) {
782069860236atagen2026-10-10 12:44 UTC158
        None => Ok(5),
782069860236atagen2026-10-10 12:44 UTC159
        Some(Ok(i)) if (1..=10).contains(&i) => Ok(i),
782069860236atagen2026-10-10 12:44 UTC160
        Some(_) => Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC161
            StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC162
            "intensity-out-of-range",
782069860236atagen2026-10-10 12:44 UTC163
            "Intensity is measured from 1 to 10.",
782069860236atagen2026-10-10 12:44 UTC164
        )),
782069860236atagen2026-10-10 12:44 UTC165
    }
782069860236atagen2026-10-10 12:44 UTC166
}
782069860236atagen2026-10-10 12:44 UTC167
782069860236atagen2026-10-10 12:44 UTC168
fn jelq(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC169
    let parsed = parse_techniques(run, ctx).and_then(|techniques| {
782069860236atagen2026-10-10 12:44 UTC170
        let intensity = parse_intensity(ctx)?;
782069860236atagen2026-10-10 12:44 UTC171
        let lube = Lube::from_content_type(ctx.header(header::CONTENT_TYPE))?;
782069860236atagen2026-10-10 12:44 UTC172
        Ok((techniques, intensity, lube))
782069860236atagen2026-10-10 12:44 UTC173
    });
782069860236atagen2026-10-10 12:44 UTC174
    match parsed {
782069860236atagen2026-10-10 12:44 UTC175
        Ok((techniques, intensity, lube)) => {
782069860236atagen2026-10-10 12:44 UTC176
            respond(run.jelq(&techniques, intensity, lube, ctx.now))
782069860236atagen2026-10-10 12:44 UTC177
        }
782069860236atagen2026-10-10 12:44 UTC178
        Err(problem) => problem.into_response(),
782069860236atagen2026-10-10 12:44 UTC179
    }
782069860236atagen2026-10-10 12:44 UTC180
}
782069860236atagen2026-10-10 12:44 UTC181
782069860236atagen2026-10-10 12:44 UTC182
fn put_run(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC183
    run.put().into_response()
782069860236atagen2026-10-10 12:44 UTC184
}
782069860236atagen2026-10-10 12:44 UTC185
4347977b8192atagen2026-10-11 04:56 UTC186
fn hold_run(run: &mut Run, ctx: &Ctx) -> Response {
4347977b8192atagen2026-10-11 04:56 UTC187
    respond(run.hold(ctx.now))
4347977b8192atagen2026-10-11 04:56 UTC188
}
4347977b8192atagen2026-10-11 04:56 UTC189
782069860236atagen2026-10-10 12:44 UTC190
fn patch_run(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC191
    let is_patch = ctx
782069860236atagen2026-10-10 12:44 UTC192
        .header(header::CONTENT_TYPE)
782069860236atagen2026-10-10 12:44 UTC193
        .is_some_and(|ct| ct.starts_with("application/json-patch+json"));
782069860236atagen2026-10-10 12:44 UTC194
    if !is_patch {
782069860236atagen2026-10-10 12:44 UTC195
        return Problem::new(
782069860236atagen2026-10-10 12:44 UTC196
            StatusCode::UNSUPPORTED_MEDIA_TYPE,
782069860236atagen2026-10-10 12:44 UTC197
            "patch-format",
782069860236atagen2026-10-10 12:44 UTC198
            "Patches are accepted as application/json-patch+json.",
782069860236atagen2026-10-10 12:44 UTC199
        )
782069860236atagen2026-10-10 12:44 UTC200
        .header(ACCEPT_PATCH, "application/json-patch+json")
782069860236atagen2026-10-10 12:44 UTC201
        .into_response();
782069860236atagen2026-10-10 12:44 UTC202
    }
782069860236atagen2026-10-10 12:44 UTC203
    match serde_json::from_slice::<Vec<PatchOp>>(&ctx.body) {
782069860236atagen2026-10-10 12:44 UTC204
        Ok(ops) => respond(run.patch(&ops)),
782069860236atagen2026-10-10 12:44 UTC205
        Err(_) => Problem::new(
782069860236atagen2026-10-10 12:44 UTC206
            StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC207
            "malformed-patch",
782069860236atagen2026-10-10 12:44 UTC208
            "The patch could not be parsed.",
782069860236atagen2026-10-10 12:44 UTC209
        )
782069860236atagen2026-10-10 12:44 UTC210
        .into_response(),
782069860236atagen2026-10-10 12:44 UTC211
    }
782069860236atagen2026-10-10 12:44 UTC212
}
782069860236atagen2026-10-10 12:44 UTC213
782069860236atagen2026-10-10 12:44 UTC214
fn delete_run(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC215
    run.end(Cause::Abandoned);
782069860236atagen2026-10-10 12:44 UTC216
    StatusCode::NO_CONTENT.into_response()
782069860236atagen2026-10-10 12:44 UTC217
}
782069860236atagen2026-10-10 12:44 UTC218
782069860236atagen2026-10-10 12:44 UTC219
fn trace_run(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC220
    run.shame += 1;
782069860236atagen2026-10-10 12:44 UTC221
    let mut message = format!("{} {} {:?}\r\n", ctx.method, ctx.uri, ctx.version);
782069860236atagen2026-10-10 12:44 UTC222
    for (name, value) in &ctx.headers {
782069860236atagen2026-10-10 12:44 UTC223
        let _ = write!(
782069860236atagen2026-10-10 12:44 UTC224
            message,
782069860236atagen2026-10-10 12:44 UTC225
            "{name}: {}\r\n",
782069860236atagen2026-10-10 12:44 UTC226
            value.to_str().unwrap_or("<binary>")
782069860236atagen2026-10-10 12:44 UTC227
        );
782069860236atagen2026-10-10 12:44 UTC228
    }
782069860236atagen2026-10-10 12:44 UTC229
    message.push_str("\r\n");
782069860236atagen2026-10-10 12:44 UTC230
    (
782069860236atagen2026-10-10 12:44 UTC231
        StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC232
        [(header::CONTENT_TYPE, "message/http")],
782069860236atagen2026-10-10 12:44 UTC233
        message,
782069860236atagen2026-10-10 12:44 UTC234
    )
782069860236atagen2026-10-10 12:44 UTC235
        .into_response()
782069860236atagen2026-10-10 12:44 UTC236
}
782069860236atagen2026-10-10 12:44 UTC237
782069860236atagen2026-10-10 12:44 UTC238
fn millimetres(inches: f64) -> usize {
782069860236atagen2026-10-10 12:44 UTC239
    (inches * MM_PER_INCH).round() as usize
782069860236atagen2026-10-10 12:44 UTC240
}
782069860236atagen2026-10-10 12:44 UTC241
d46f9d0b953aatagen2026-10-10 14:41 UTC242
enum InchRange {
d46f9d0b953aatagen2026-10-10 14:41 UTC243
    Satisfiable(f64, f64),
d46f9d0b953aatagen2026-10-10 14:41 UTC244
    Unsatisfiable,
d46f9d0b953aatagen2026-10-10 14:41 UTC245
}
d46f9d0b953aatagen2026-10-10 14:41 UTC246
d46f9d0b953aatagen2026-10-10 14:41 UTC247
/// `None` means the header is not a valid range, which RFC 9110 §14.2 says to ignore rather than refuse.
d46f9d0b953aatagen2026-10-10 14:41 UTC248
fn parse_inch_range(range: &str, total: f64) -> Option<InchRange> {
782069860236atagen2026-10-10 12:44 UTC249
    let (start, end) = range.strip_prefix("inches=")?.split_once('-')?;
d46f9d0b953aatagen2026-10-10 14:41 UTC250
    let number = |text: &str| {
d46f9d0b953aatagen2026-10-10 14:41 UTC251
        text.parse::<f64>()
d46f9d0b953aatagen2026-10-10 14:41 UTC252
            .ok()
d46f9d0b953aatagen2026-10-10 14:41 UTC253
            .filter(|n| n.is_finite() && *n >= 0.0)
782069860236atagen2026-10-10 12:44 UTC254
    };
d46f9d0b953aatagen2026-10-10 14:41 UTC255
    let (start, end) = match (start.trim(), end.trim()) {
d46f9d0b953aatagen2026-10-10 14:41 UTC256
        ("", "") => return None,
d46f9d0b953aatagen2026-10-10 14:41 UTC257
        ("", suffix) => ((total - number(suffix)?).max(0.0), total),
d46f9d0b953aatagen2026-10-10 14:41 UTC258
        (start, "") => (number(start)?, total),
d46f9d0b953aatagen2026-10-10 14:41 UTC259
        (start, end) => {
d46f9d0b953aatagen2026-10-10 14:41 UTC260
            let (start, end) = (number(start)?, number(end)?);
d46f9d0b953aatagen2026-10-10 14:41 UTC261
            if start > end {
d46f9d0b953aatagen2026-10-10 14:41 UTC262
                return None;
d46f9d0b953aatagen2026-10-10 14:41 UTC263
            }
d46f9d0b953aatagen2026-10-10 14:41 UTC264
            (start, end)
d46f9d0b953aatagen2026-10-10 14:41 UTC265
        }
d46f9d0b953aatagen2026-10-10 14:41 UTC266
    };
d46f9d0b953aatagen2026-10-10 14:41 UTC267
    Some(if start < total {
d46f9d0b953aatagen2026-10-10 14:41 UTC268
        InchRange::Satisfiable(start, end.min(total))
d46f9d0b953aatagen2026-10-10 14:41 UTC269
    } else {
d46f9d0b953aatagen2026-10-10 14:41 UTC270
        InchRange::Unsatisfiable
d46f9d0b953aatagen2026-10-10 14:41 UTC271
    })
782069860236atagen2026-10-10 12:44 UTC272
}
782069860236atagen2026-10-10 12:44 UTC273
ec6fd4bb5b60atagen2026-10-11 04:34 UTC274
fn unsatisfied_range(inches: f64) -> Response {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC275
    Problem::new(
ec6fd4bb5b60atagen2026-10-11 04:34 UTC276
        StatusCode::RANGE_NOT_SATISFIABLE,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC277
        "range-not-satisfiable",
ec6fd4bb5b60atagen2026-10-11 04:34 UTC278
        format!("The requested range is not available. {inches:.2} inches are."),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC279
    )
ec6fd4bb5b60atagen2026-10-11 04:34 UTC280
    .header(header::CONTENT_RANGE, format!("inches */{inches:.2}"))
ec6fd4bb5b60atagen2026-10-11 04:34 UTC281
    .into_response()
ec6fd4bb5b60atagen2026-10-11 04:34 UTC282
}
ec6fd4bb5b60atagen2026-10-11 04:34 UTC283
ec6fd4bb5b60atagen2026-10-11 04:34 UTC284
fn partial_inches(body: &str, offset: usize, start: f64, end: f64, total: f64) -> Response {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC285
    let from = (millimetres(start) + offset).min(body.len() - 1);
ec6fd4bb5b60atagen2026-10-11 04:34 UTC286
    let to = (millimetres(end) + offset).clamp(from + 1, body.len());
ec6fd4bb5b60atagen2026-10-11 04:34 UTC287
    (
ec6fd4bb5b60atagen2026-10-11 04:34 UTC288
        StatusCode::PARTIAL_CONTENT,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC289
        [
ec6fd4bb5b60atagen2026-10-11 04:34 UTC290
            (
ec6fd4bb5b60atagen2026-10-11 04:34 UTC291
                header::CONTENT_TYPE,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC292
                "text/plain; charset=us-ascii".to_owned(),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC293
            ),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC294
            (header::ACCEPT_RANGES, "inches".to_owned()),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC295
            (
ec6fd4bb5b60atagen2026-10-11 04:34 UTC296
                header::CONTENT_RANGE,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC297
                format!("inches {start:.2}-{end:.2}/{total:.2}"),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC298
            ),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC299
        ],
ec6fd4bb5b60atagen2026-10-11 04:34 UTC300
        body[from..to].to_owned(),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC301
    )
ec6fd4bb5b60atagen2026-10-11 04:34 UTC302
        .into_response()
ec6fd4bb5b60atagen2026-10-11 04:34 UTC303
}
ec6fd4bb5b60atagen2026-10-11 04:34 UTC304
782069860236atagen2026-10-10 12:44 UTC305
fn get_length(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC306
    let inches = if run.items.ruler {
782069860236atagen2026-10-10 12:44 UTC307
        run.current_length()
782069860236atagen2026-10-10 12:44 UTC308
    } else {
782069860236atagen2026-10-10 12:44 UTC309
        run.self_reported()
782069860236atagen2026-10-10 12:44 UTC310
    };
782069860236atagen2026-10-10 12:44 UTC311
    let body = shaft(millimetres(inches));
782069860236atagen2026-10-10 12:44 UTC312
    let content_type = (
782069860236atagen2026-10-10 12:44 UTC313
        header::CONTENT_TYPE,
782069860236atagen2026-10-10 12:44 UTC314
        "text/plain; charset=us-ascii".to_owned(),
782069860236atagen2026-10-10 12:44 UTC315
    );
782069860236atagen2026-10-10 12:44 UTC316
    let accept_ranges = (header::ACCEPT_RANGES, "inches".to_owned());
782069860236atagen2026-10-10 12:44 UTC317
d46f9d0b953aatagen2026-10-10 14:41 UTC318
    if let Some(range) = ctx
d46f9d0b953aatagen2026-10-10 14:41 UTC319
        .header(header::RANGE)
d46f9d0b953aatagen2026-10-10 14:41 UTC320
        .and_then(|range| parse_inch_range(range, inches))
782069860236atagen2026-10-10 12:44 UTC321
    {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC322
        match range {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC323
            InchRange::Satisfiable(start, end) => {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC324
                return partial_inches(&body, 0, start, end, inches);
ec6fd4bb5b60atagen2026-10-11 04:34 UTC325
            }
ec6fd4bb5b60atagen2026-10-11 04:34 UTC326
            InchRange::Unsatisfiable => return unsatisfied_range(inches),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC327
        }
782069860236atagen2026-10-10 12:44 UTC328
    }
782069860236atagen2026-10-10 12:44 UTC329
782069860236atagen2026-10-10 12:44 UTC330
    if run.items.ruler {
782069860236atagen2026-10-10 12:44 UTC331
        return (StatusCode::OK, [content_type, accept_ranges], body).into_response();
782069860236atagen2026-10-10 12:44 UTC332
    }
782069860236atagen2026-10-10 12:44 UTC333
    let chunks: Vec<Result<Bytes, Infallible>> = body
782069860236atagen2026-10-10 12:44 UTC334
        .into_bytes()
782069860236atagen2026-10-10 12:44 UTC335
        .chunks(16)
782069860236atagen2026-10-10 12:44 UTC336
        .map(|c| Ok(Bytes::copy_from_slice(c)))
782069860236atagen2026-10-10 12:44 UTC337
        .collect();
782069860236atagen2026-10-10 12:44 UTC338
    let body = Body::from_stream(futures_util::stream::iter(chunks));
782069860236atagen2026-10-10 12:44 UTC339
    (StatusCode::OK, [content_type, accept_ranges], body).into_response()
782069860236atagen2026-10-10 12:44 UTC340
}
782069860236atagen2026-10-10 12:44 UTC341
ec6fd4bb5b60atagen2026-10-11 04:34 UTC342
fn get_foreskin(run: &mut Run, ctx: &Ctx) -> Response {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC343
    let Some(inches) = run.foreskin else {
782069860236atagen2026-10-10 12:44 UTC344
        return Problem::new(
782069860236atagen2026-10-10 12:44 UTC345
            StatusCode::GONE,
782069860236atagen2026-10-10 12:44 UTC346
            "foreskin-gone",
782069860236atagen2026-10-10 12:44 UTC347
            "The foreskin is gone. It will not be returning.",
782069860236atagen2026-10-10 12:44 UTC348
        )
782069860236atagen2026-10-10 12:44 UTC349
        .into_response();
ec6fd4bb5b60atagen2026-10-11 04:34 UTC350
    };
ec6fd4bb5b60atagen2026-10-11 04:34 UTC351
    let body = format!("8({})D", "~".repeat(millimetres(inches)));
ec6fd4bb5b60atagen2026-10-11 04:34 UTC352
    if let Some(range) = ctx
ec6fd4bb5b60atagen2026-10-11 04:34 UTC353
        .header(header::RANGE)
ec6fd4bb5b60atagen2026-10-11 04:34 UTC354
        .and_then(|range| parse_inch_range(range, inches))
ec6fd4bb5b60atagen2026-10-11 04:34 UTC355
    {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC356
        match range {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC357
            InchRange::Satisfiable(start, end) => {
ec6fd4bb5b60atagen2026-10-11 04:34 UTC358
                return partial_inches(&body, 2, start, end, inches);
ec6fd4bb5b60atagen2026-10-11 04:34 UTC359
            }
ec6fd4bb5b60atagen2026-10-11 04:34 UTC360
            InchRange::Unsatisfiable => return unsatisfied_range(inches),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC361
        }
782069860236atagen2026-10-10 12:44 UTC362
    }
ec6fd4bb5b60atagen2026-10-11 04:34 UTC363
    (
ec6fd4bb5b60atagen2026-10-11 04:34 UTC364
        StatusCode::OK,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC365
        [
ec6fd4bb5b60atagen2026-10-11 04:34 UTC366
            (header::ETAG, run.etag()),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC367
            (
ec6fd4bb5b60atagen2026-10-11 04:34 UTC368
                header::CONTENT_TYPE,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC369
                "text/plain; charset=us-ascii".to_owned(),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC370
            ),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC371
            (header::ACCEPT_RANGES, "inches".to_owned()),
ec6fd4bb5b60atagen2026-10-11 04:34 UTC372
        ],
ec6fd4bb5b60atagen2026-10-11 04:34 UTC373
        body,
ec6fd4bb5b60atagen2026-10-11 04:34 UTC374
    )
ec6fd4bb5b60atagen2026-10-11 04:34 UTC375
        .into_response()
782069860236atagen2026-10-10 12:44 UTC376
}
782069860236atagen2026-10-10 12:44 UTC377
782069860236atagen2026-10-10 12:44 UTC378
fn delete_foreskin(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC379
    respond(run.delete_foreskin(ctx.header(header::IF_MATCH)))
782069860236atagen2026-10-10 12:44 UTC380
}
782069860236atagen2026-10-10 12:44 UTC381
782069860236atagen2026-10-10 12:44 UTC382
fn get_inventory(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC383
    let items: Vec<Value> = run
782069860236atagen2026-10-10 12:44 UTC384
        .items
782069860236atagen2026-10-10 12:44 UTC385
        .owned()
782069860236atagen2026-10-10 12:44 UTC386
        .into_iter()
782069860236atagen2026-10-10 12:44 UTC387
        .map(|item| {
782069860236atagen2026-10-10 12:44 UTC388
            json!({
782069860236atagen2026-10-10 12:44 UTC389
                "name": item.slug(),
782069860236atagen2026-10-10 12:44 UTC390
                "href": run.path(&format!("/inventory/{}", item.slug())),
782069860236atagen2026-10-10 12:44 UTC391
            })
782069860236atagen2026-10-10 12:44 UTC392
        })
782069860236atagen2026-10-10 12:44 UTC393
        .collect();
782069860236atagen2026-10-10 12:44 UTC394
    Json(json!({
782069860236atagen2026-10-10 12:44 UTC395
        "items": items,
782069860236atagen2026-10-10 12:44 UTC396
        "ice_packs": run.items.ice_packs,
782069860236atagen2026-10-10 12:44 UTC397
        "supplements": run.items.supplements,
782069860236atagen2026-10-10 12:44 UTC398
        "excuses": run.excuses(),
782069860236atagen2026-10-10 12:44 UTC399
    }))
782069860236atagen2026-10-10 12:44 UTC400
    .into_response()
782069860236atagen2026-10-10 12:44 UTC401
}
782069860236atagen2026-10-10 12:44 UTC402
782069860236atagen2026-10-10 12:44 UTC403
fn owned_item(run: &Run, ctx: &Ctx) -> Result<Item, Problem> {
782069860236atagen2026-10-10 12:44 UTC404
    Item::parse(ctx.param("item"))
782069860236atagen2026-10-10 12:44 UTC405
        .filter(|&item| run.items.has(item))
782069860236atagen2026-10-10 12:44 UTC406
        .ok_or_else(|| {
782069860236atagen2026-10-10 12:44 UTC407
            Problem::new(
782069860236atagen2026-10-10 12:44 UTC408
                StatusCode::NOT_FOUND,
782069860236atagen2026-10-10 12:44 UTC409
                "no-such-item",
782069860236atagen2026-10-10 12:44 UTC410
                "You do not have that.",
782069860236atagen2026-10-10 12:44 UTC411
            )
782069860236atagen2026-10-10 12:44 UTC412
        })
782069860236atagen2026-10-10 12:44 UTC413
}
782069860236atagen2026-10-10 12:44 UTC414
782069860236atagen2026-10-10 12:44 UTC415
fn get_item(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC416
    match owned_item(run, ctx) {
782069860236atagen2026-10-10 12:44 UTC417
        Ok(item) => {
782069860236atagen2026-10-10 12:44 UTC418
            Json(json!({ "name": item.slug(), "description": item.description() })).into_response()
782069860236atagen2026-10-10 12:44 UTC419
        }
782069860236atagen2026-10-10 12:44 UTC420
        Err(problem) => problem.into_response(),
782069860236atagen2026-10-10 12:44 UTC421
    }
782069860236atagen2026-10-10 12:44 UTC422
}
782069860236atagen2026-10-10 12:44 UTC423
782069860236atagen2026-10-10 12:44 UTC424
fn delete_item(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC425
    match owned_item(run, ctx) {
782069860236atagen2026-10-10 12:44 UTC426
        Ok(item) => respond(run.drop_item(item)),
782069860236atagen2026-10-10 12:44 UTC427
        Err(problem) => problem.into_response(),
782069860236atagen2026-10-10 12:44 UTC428
    }
782069860236atagen2026-10-10 12:44 UTC429
}
782069860236atagen2026-10-10 12:44 UTC430
782069860236atagen2026-10-10 12:44 UTC431
fn get_techniques(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC432
    let listed: Vec<Value> = Technique::ALL
782069860236atagen2026-10-10 12:44 UTC433
        .into_iter()
782069860236atagen2026-10-10 12:44 UTC434
        .map(|t| t.describe(run.forum_read()))
782069860236atagen2026-10-10 12:44 UTC435
        .collect();
782069860236atagen2026-10-10 12:44 UTC436
    Json(json!({
782069860236atagen2026-10-10 12:44 UTC437
        "usage": format!("JELQ {}?technique=<name>[,<name>]&intensity=<1-10>", run.path("")),
782069860236atagen2026-10-10 12:44 UTC438
        "lubricant": "Declared with Content-Type.",
782069860236atagen2026-10-10 12:44 UTC439
        "lubricants": LUBRICANTS,
782069860236atagen2026-10-10 12:44 UTC440
        "eq_band": [EQ_BAND.start(), EQ_BAND.end()],
782069860236atagen2026-10-10 12:44 UTC441
        "techniques": listed,
782069860236atagen2026-10-10 12:44 UTC442
    }))
782069860236atagen2026-10-10 12:44 UTC443
    .into_response()
782069860236atagen2026-10-10 12:44 UTC444
}
782069860236atagen2026-10-10 12:44 UTC445
782069860236atagen2026-10-10 12:44 UTC446
fn search_drawer(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC447
    respond(run.search_drawer())
782069860236atagen2026-10-10 12:44 UTC448
}
782069860236atagen2026-10-10 12:44 UTC449
782069860236atagen2026-10-10 12:44 UTC450
fn choose_branch(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC451
    respond(run.choose(ctx.param("choice")))
782069860236atagen2026-10-10 12:44 UTC452
}
782069860236atagen2026-10-10 12:44 UTC453
782069860236atagen2026-10-10 12:44 UTC454
fn get_floor(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC455
    Json(run.floor_view()).into_response()
782069860236atagen2026-10-10 12:44 UTC456
}
782069860236atagen2026-10-10 12:44 UTC457
782069860236atagen2026-10-10 12:44 UTC458
fn leave_floor(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC459
    respond(run.advance())
782069860236atagen2026-10-10 12:44 UTC460
}
782069860236atagen2026-10-10 12:44 UTC461
782069860236atagen2026-10-10 12:44 UTC462
fn get_shop(run: &mut Run, _: &Ctx) -> Response {
7d3fb63208bfatagen2026-10-11 04:38 UTC463
    let view = run.shop_view();
7d3fb63208bfatagen2026-10-11 04:38 UTC464
    if view.is_ok() {
7d3fb63208bfatagen2026-10-11 04:38 UTC465
        run.here.shopping = true;
7d3fb63208bfatagen2026-10-11 04:38 UTC466
    }
7d3fb63208bfatagen2026-10-11 04:38 UTC467
    respond(view.map(Json))
782069860236atagen2026-10-10 12:44 UTC468
}
782069860236atagen2026-10-10 12:44 UTC469
782069860236atagen2026-10-10 12:44 UTC470
fn buy(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC471
    respond(run.buy(ctx.param("item")))
782069860236atagen2026-10-10 12:44 UTC472
}
782069860236atagen2026-10-10 12:44 UTC473
0a0bfee8329eatagen2026-10-11 05:11 UTC474
fn raid_kitchen(run: &mut Run, _: &Ctx) -> Response {
0a0bfee8329eatagen2026-10-11 05:11 UTC475
    respond(run.raid_kitchen())
0a0bfee8329eatagen2026-10-11 05:11 UTC476
}
0a0bfee8329eatagen2026-10-11 05:11 UTC477
0a0bfee8329eatagen2026-10-11 05:11 UTC478
fn commit_melon(run: &mut Run, _: &Ctx) -> Response {
0a0bfee8329eatagen2026-10-11 05:11 UTC479
    respond(run.commit_melon())
0a0bfee8329eatagen2026-10-11 05:11 UTC480
}
0a0bfee8329eatagen2026-10-11 05:11 UTC481
782069860236atagen2026-10-10 12:44 UTC482
fn get_portal(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC483
    Json(json!({
782069860236atagen2026-10-10 12:44 UTC484
        "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.",
782069860236atagen2026-10-10 12:44 UTC485
        "accept": { "href": run.path("/portal"), "method": "POST" },
782069860236atagen2026-10-10 12:44 UTC486
    }))
782069860236atagen2026-10-10 12:44 UTC487
    .into_response()
782069860236atagen2026-10-10 12:44 UTC488
}
782069860236atagen2026-10-10 12:44 UTC489
782069860236atagen2026-10-10 12:44 UTC490
fn accept_portal(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC491
    respond(run.accept_terms())
782069860236atagen2026-10-10 12:44 UTC492
}
782069860236atagen2026-10-10 12:44 UTC493
782069860236atagen2026-10-10 12:44 UTC494
fn get_elder(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC495
    respond(run.elder(
782069860236atagen2026-10-10 12:44 UTC496
        ctx.header(header::PROXY_AUTHORIZATION),
782069860236atagen2026-10-10 12:44 UTC497
        ctx.header(header::IF_MODIFIED_SINCE),
782069860236atagen2026-10-10 12:44 UTC498
    ))
782069860236atagen2026-10-10 12:44 UTC499
}
782069860236atagen2026-10-10 12:44 UTC500
782069860236atagen2026-10-10 12:44 UTC501
fn requested_grip(ctx: &Ctx) -> Option<Grip> {
782069860236atagen2026-10-10 12:44 UTC502
    let connection = ctx.header(header::CONNECTION)?.to_ascii_lowercase();
782069860236atagen2026-10-10 12:44 UTC503
    if !connection.split(',').any(|token| token.trim() == "upgrade") {
782069860236atagen2026-10-10 12:44 UTC504
        return None;
782069860236atagen2026-10-10 12:44 UTC505
    }
782069860236atagen2026-10-10 12:44 UTC506
    ctx.header(header::UPGRADE)?
782069860236atagen2026-10-10 12:44 UTC507
        .split(',')
782069860236atagen2026-10-10 12:44 UTC508
        .find_map(|protocol| Grip::parse(protocol.trim()))
782069860236atagen2026-10-10 12:44 UTC509
}
782069860236atagen2026-10-10 12:44 UTC510
782069860236atagen2026-10-10 12:44 UTC511
fn get_grip(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC512
    if let Some(grip) = requested_grip(ctx) {
782069860236atagen2026-10-10 12:44 UTC513
        run.set_grip(grip);
782069860236atagen2026-10-10 12:44 UTC514
        let mut response = (
782069860236atagen2026-10-10 12:44 UTC515
            StatusCode::SWITCHING_PROTOCOLS,
782069860236atagen2026-10-10 12:44 UTC516
            [
782069860236atagen2026-10-10 12:44 UTC517
                (header::UPGRADE, grip.name()),
782069860236atagen2026-10-10 12:44 UTC518
                (header::CONNECTION, "upgrade"),
782069860236atagen2026-10-10 12:44 UTC519
            ],
782069860236atagen2026-10-10 12:44 UTC520
        )
782069860236atagen2026-10-10 12:44 UTC521
            .into_response();
782069860236atagen2026-10-10 12:44 UTC522
        response.extensions_mut().insert(Greeting(format!(
782069860236atagen2026-10-10 12:44 UTC523
            "You are now jelqing {}.\r\n",
782069860236atagen2026-10-10 12:44 UTC524
            grip.name()
782069860236atagen2026-10-10 12:44 UTC525
        )));
782069860236atagen2026-10-10 12:44 UTC526
        return response;
782069860236atagen2026-10-10 12:44 UTC527
    }
782069860236atagen2026-10-10 12:44 UTC528
    let detail = match ctx.header(header::UPGRADE) {
782069860236atagen2026-10-10 12:44 UTC529
        Some(protocol) => {
782069860236atagen2026-10-10 12:44 UTC530
            format!("The server does not know the {protocol} grip. Grips are protocols.")
782069860236atagen2026-10-10 12:44 UTC531
        }
782069860236atagen2026-10-10 12:44 UTC532
        None => "Grips are protocols. Change grip by upgrading the connection.".to_owned(),
782069860236atagen2026-10-10 12:44 UTC533
    };
782069860236atagen2026-10-10 12:44 UTC534
    (
782069860236atagen2026-10-10 12:44 UTC535
        StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC536
        [(header::UPGRADE, "overhand, underhand")],
782069860236atagen2026-10-10 12:44 UTC537
        Json(json!({ "grip": run.grip.name(), "detail": detail })),
782069860236atagen2026-10-10 12:44 UTC538
    )
782069860236atagen2026-10-10 12:44 UTC539
        .into_response()
782069860236atagen2026-10-10 12:44 UTC540
}
782069860236atagen2026-10-10 12:44 UTC541
782069860236atagen2026-10-10 12:44 UTC542
fn get_diagnosis(run: &mut Run, ctx: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC543
    respond(run.diagnose(
782069860236atagen2026-10-10 12:44 UTC544
        ctx.header(header::AUTHORIZATION),
782069860236atagen2026-10-10 12:44 UTC545
        ctx.header(header::IF_NONE_MATCH),
782069860236atagen2026-10-10 12:44 UTC546
    ))
782069860236atagen2026-10-10 12:44 UTC547
}
782069860236atagen2026-10-10 12:44 UTC548
782069860236atagen2026-10-10 12:44 UTC549
fn get_footage(run: &mut Run, _: &Ctx) -> Response {
782069860236atagen2026-10-10 12:44 UTC550
    let Some((filmed, age)) = run.footage() else {
782069860236atagen2026-10-10 12:44 UTC551
        return Problem::new(
782069860236atagen2026-10-10 12:44 UTC552
            StatusCode::NOT_FOUND,
782069860236atagen2026-10-10 12:44 UTC553
            "no-footage",
782069860236atagen2026-10-10 12:44 UTC554
            "There is no footage. Yet.",
782069860236atagen2026-10-10 12:44 UTC555
        )
782069860236atagen2026-10-10 12:44 UTC556
        .into_response();
782069860236atagen2026-10-10 12:44 UTC557
    };
782069860236atagen2026-10-10 12:44 UTC558
    (
782069860236atagen2026-10-10 12:44 UTC559
        [
782069860236atagen2026-10-10 12:44 UTC560
            (
782069860236atagen2026-10-10 12:44 UTC561
                header::CACHE_CONTROL,
782069860236atagen2026-10-10 12:44 UTC562
                "public, max-age=31536000, immutable".to_owned(),
782069860236atagen2026-10-10 12:44 UTC563
            ),
782069860236atagen2026-10-10 12:44 UTC564
            (header::AGE, age.to_string()),
782069860236atagen2026-10-10 12:44 UTC565
            (header::LAST_MODIFIED, httpdate::fmt_http_date(filmed)),
782069860236atagen2026-10-10 12:44 UTC566
        ],
782069860236atagen2026-10-10 12:44 UTC567
        Json(json!({
782069860236atagen2026-10-10 12:44 UTC568
            "detail": "A recording. It is grainy. It is unmistakably you. It has been shared.",
782069860236atagen2026-10-10 12:44 UTC569
            "views": 1 + age * 37,
782069860236atagen2026-10-10 12:44 UTC570
        })),
782069860236atagen2026-10-10 12:44 UTC571
    )
782069860236atagen2026-10-10 12:44 UTC572
        .into_response()
782069860236atagen2026-10-10 12:44 UTC573
}