BlueGit

ict rusty-teams

Files

rusty-teams / crates / calling / examples / cleanup_recordings.rs

cleanup_recordings.rs

cleanup_recordings.rs 1.9 KiB Download Raw
1use chrono::{DateTime, Duration, Utc};
2use serde_json::Value;
3use session::{DEFAULT_ENDPOINT, Method, Scope, Session};
4
5const LIST_URL: &str = "https://graph.microsoft.com/v1.0/me/drive/root:/Videos/Recordings:/children?$select=id,name,createdDateTime&$top=50";
6const SUBJECT: &str = "Native client test";
7
8#[tokio::main]
9async fn main() {
10 let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
11 let session = Session::connect(&endpoint).await.expect("browser");
12 let scope = Scope::graph("Files.ReadWrite.All");
13 let listed = session.request(Method::Get, LIST_URL, &scope, None).await.expect("list");
14 println!("# list: HTTP {}", listed.status);
15 let cutoff = Utc::now() - Duration::minutes(60);
16 let items = listed.body.get("value").and_then(Value::as_array).cloned().unwrap_or_default();
17 let mut deleted = 0;
18 for item in items {
19 let name = item.get("name").and_then(Value::as_str).unwrap_or_default();
20 let created = item
21 .get("createdDateTime")
22 .and_then(Value::as_str)
23 .and_then(|text| DateTime::parse_from_rfc3339(text).ok())
24 .map(|time| time.with_timezone(&Utc));
25 let recent = created.is_some_and(|time| time > cutoff);
26 if recent {
27 println!("# recent recording, starts with test subject: {}", name.starts_with(SUBJECT));
28 }
29 if recent && name.starts_with(SUBJECT) {
30 let id = item.get("id").and_then(Value::as_str).unwrap_or_default();
31 let url = format!("https://graph.microsoft.com/v1.0/me/drive/items/{id}");
32 let answer = session.request(Method::Delete, &url, &scope, None).await.expect("delete");
33 println!("# delete recent test recording: HTTP {}", answer.status);
34 deleted += 1;
35 }
36 }
37 println!("# deleted {deleted} test recording(s)");
38}