Files
mdrs-client-rust/src/api/laboratories.rs
T
orrisroot a67f9a72a6 fix(auth): refresh tokens before authenticated requests
Move token refresh checks into the shared Rust connection/API path so long-running authenticated operations stop reusing stale access tokens. This covers recursive download and upload traversal, recursive ls via the shared APIs, and direct authenticated commands such as cp, mv, rm, and chacl.

Also surface HTTP failures earlier in the affected API methods instead of failing later during response parsing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-20 16:26:47 +09:00

30 lines
1.1 KiB
Rust

use crate::connection::MDRSConnection;
use crate::models::laboratory::{Laboratories, Laboratory};
use serde::Deserialize;
/// API response is a flat list; we wrap it in `Laboratories { items }` for cache compatibility.
#[derive(Debug, Deserialize)]
struct LabListResponse {
results: Option<Vec<Laboratory>>,
}
impl MDRSConnection {
pub async fn list_laboratories(&self) -> Result<Laboratories, anyhow::Error> {
let resp = self.get("v3/laboratories/").await?;
if !resp.status().is_success() {
anyhow::bail!("List laboratories failed: {}", resp.status());
}
// The API may return a paginated object or a direct array
let text = resp.text().await?;
let items: Vec<Laboratory> =
if let Ok(list) = serde_json::from_str::<Vec<Laboratory>>(&text) {
list
} else if let Ok(paged) = serde_json::from_str::<LabListResponse>(&text) {
paged.results.unwrap_or_default()
} else {
vec![]
};
Ok(Laboratories { items })
}
}