Skip to content

Commit 8d0c960

Browse files
committed
monitor: add profile screenshot route (#6)
1 parent 8938741 commit 8d0c960

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

monitor/src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use warp::{
3939

4040
use crate::{
4141
dashboard::Dashboard,
42-
data::{get_runner_data_path, run_migrations},
42+
data::{get_profile_data_path, get_runner_data_path, run_migrations},
4343
github::{list_registered_runners_for_host, Cache},
4444
id::IdGen,
4545
libvirt::list_runner_guests,
@@ -69,6 +69,7 @@ static PNG: &str = "image/png";
6969
/// - GET `/` => templates/index.html
7070
/// - GET `/dashboard.html` => templates/dashboard.html
7171
/// - GET `/dashboard.json` => `{"profile_runner_counts": {}, "runners": []}`
72+
/// - GET `/profile/<profile key>/screenshot.png` => image/png
7273
/// - GET `/runner/<our runner id>/screenshot.png` => image/png
7374
#[derive(Debug)]
7475
enum Request {
@@ -229,7 +230,20 @@ async fn main() -> eyre::Result<()> {
229230
})
230231
.with(header("Content-Type", JSON));
231232

232-
let screenshot_route = warp::path!("runner" / usize / "screenshot.png")
233+
let profile_screenshot_route = warp::path!("profile" / String / "screenshot.png")
234+
.and(warp::filters::method::get())
235+
.and(warp::filters::header::optional("If-None-Match"))
236+
.and_then(
237+
|profile_key: String, if_none_match: Option<String>| async move {
238+
let path = get_profile_data_path(&profile_key, Path::new("screenshot.png"))
239+
.wrap_err("Failed to compute path")
240+
.map_err(InternalError)?;
241+
serve_static_file(path, if_none_match)
242+
},
243+
)
244+
.with(header("Content-Type", PNG));
245+
246+
let runner_screenshot_route = warp::path!("runner" / usize / "screenshot.png")
233247
.and(warp::filters::method::get())
234248
.and(warp::filters::header::optional("If-None-Match"))
235249
.and_then(|runner_id, if_none_match: Option<String>| async move {
@@ -240,7 +254,7 @@ async fn main() -> eyre::Result<()> {
240254
})
241255
.with(header("Content-Type", PNG));
242256

243-
let screenshot_now_route = warp::path!("runner" / usize / "screenshot" / "now")
257+
let runner_screenshot_now_route = warp::path!("runner" / usize / "screenshot" / "now")
244258
.and(warp::filters::method::get())
245259
.and_then(|runner_id| async move {
246260
|| -> eyre::Result<Vec<u8>> {
@@ -267,8 +281,9 @@ async fn main() -> eyre::Result<()> {
267281
.or(dashboard_html_route)
268282
.or(dashboard_json_route)
269283
.or(take_runner_route)
270-
.or(screenshot_route)
271-
.or(screenshot_now_route);
284+
.or(profile_screenshot_route)
285+
.or(runner_screenshot_route)
286+
.or(runner_screenshot_now_route);
272287
let routes = routes.recover(recover);
273288

274289
warp::serve(routes)

0 commit comments

Comments
 (0)