Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat(api): enhance get_item_detail to support pagination and return sub_blocks

Tonhoa3fad121f244
diff --git a/src-tauri/src/platforms/estrategia_militares/api.rs b/src-tauri/src/platforms/estrategia_militares/api.rs
index bd2b774d..d1c29ac1 100644
--- a/src-tauri/src/platforms/estrategia_militares/api.rs
+++ b/src-tauri/src/platforms/estrategia_militares/api.rs
@@ -395,23 +395,66 @@ pub async fn get_item_detail(
session: &EstrategiaMilitaresSession,
item_id: &str,
) -> anyhow::Result<serde_json::Value> {
- let url = format!(
- "{}/v3/mci/items/{}?page=1&per_page=50",
- API_BASE, item_id
- );
+ let mut all_sub_blocks = Vec::new();
+ let mut page = 1u32;
+
+ loop {
+ let url = format!("{}/v3/mci/items/{}", API_BASE, item_id);
+
+ let resp = session.client.get(&url)
+ .query(&[
+ ("page", page.to_string().as_str()),
+ ("order", "asc"),
+ ("per_page", "30"),
+ ("view_mode", "complete"),
+ ("should_load_metadata", "true"),
+ ("video_only", "false"),
+ ("text_only", "false"),
+ ("question_only", "false"),
+ ("cast_only", "false"),
+ ("attachment_only", "false"),
+ ])
+ .send()
+ .await?;
+
+ let status = resp.status();
+ let body_text = resp.text().await?;
+
+ if !status.is_success() {
+ if all_sub_blocks.is_empty() {
+ return Err(anyhow!(
+ "get_item_detail returned status {}: {}",
+ status,
+ &body_text[..body_text.len().min(300)]
+ ));
+ }
+ break;
+ }
- let resp = session.client.get(&url).send().await?;
- let status = resp.status();
- let body_text = resp.text().await?;
+ let body: serde_json::Value = serde_json::from_str(&body_text)?;
+ let item_data = body.get("data").unwrap_or(&body);
- if !status.is_success() {
- return Err(anyhow!(
- "get_item_detail returned status {}: {}",
- status,
- &body_text[..body_text.len().min(300)]
- ));
+ if let Some(blocks) = item_data.get("sub_blocks").and_then(|v| v.as_array()) {
+ all_sub_blocks.extend(blocks.clone());
+ }
+
+ let total_pages = body
+ .get("meta")
+ .and_then(|m| m.get("last_page"))
+ .and_then(|v| v.as_u64())
+ .unwrap_or(1) as u32;
+
+ if page >= total_pages {
+ break;
+ }
+ page += 1;
}
+ let result = serde_json::json!({
+ "sub_blocks": all_sub_blocks
+ });
+ return Ok(result);
+
let body: serde_json::Value = serde_json::from_str(&body_text)?;
Ok(body)
}