| 134 | } |
| 135 | |
| 136 | async fn fetch(&self) -> ModelsData { |
| 137 | let url = format!("{}/api.json", MODELS_DEV_URL); |
| 138 | |
| 139 | match reqwest::Client::new() |
| 140 | .get(&url) |
| 141 | .header("User-Agent", "opencode-rust") |
| 142 | .timeout(std::time::Duration::from_secs(10)) |
| 143 | .send() |
| 144 | .await |
| 145 | { |
| 146 | Ok(response) if response.status().is_success() => match response.text().await { |
| 147 | Ok(text) => { |
| 148 | if let Ok(parsed) = serde_json::from_str::<ModelsData>(&text) { |
| 149 | let _ = tokio::fs::write(&self.cache_path, &text).await; |
| 150 | let mut data = self.data.write().await; |
| 151 | *data = Some(parsed.clone()); |
| 152 | return parsed; |
| 153 | } |
| 154 | } |
| 155 | _ => {} |
| 156 | }, |
| 157 | _ => {} |
| 158 | } |
| 159 | |
| 160 | HashMap::new() |
| 161 | } |
| 162 | |
| 163 | pub async fn refresh(&self) { |
| 164 | self.fetch().await; |