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>
This commit is contained in:
2026-04-20 16:26:47 +09:00
co-authored by Copilot
parent d05bd8a08d
commit a67f9a72a6
12 changed files with 165 additions and 113 deletions
+1 -12
View File
@@ -110,19 +110,8 @@ pub async fn upload(
let folder_id = remote_id.clone();
let remote_path_prefix = folder_detail.path.clone();
let fname = filename.clone();
let remote = remote.clone();
futs.push(tokio::spawn(async move {
// Refresh the access token if it has expired or is about to
// expire. conn.with_token() reuses the shared HTTP client
// (connection pool) while supplying a fresh Bearer token.
let task_conn = match load_cache_with_token_refresh(&remote).await {
Ok(c) => conn.with_token(c.token.access),
Err(e) => {
eprintln!("Error: {}", e);
return;
}
};
match task_conn.upload_file(&folder_id, &file_path_str).await {
match conn.upload_file(&folder_id, &file_path_str).await {
Ok(_) => println!("{}{}", remote_path_prefix, fname),
Err(e) => eprintln!("Error: {}", e),
}