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: add external_platform field to Course struct and update logic for subdomain handling

Tonho16a433ee4273
diff --git a/src-tauri/src/platforms/hotmart/api.rs b/src-tauri/src/platforms/hotmart/api.rs
index 7b6016ea..47c1eac8 100644
--- a/src-tauri/src/platforms/hotmart/api.rs
+++ b/src-tauri/src/platforms/hotmart/api.rs
@@ -14,6 +14,7 @@ pub struct Course {
pub price: Option<f64>,
pub image_url: Option<String>,
pub category: Option<String>,
+ pub external_platform: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -70,7 +71,6 @@ pub struct SubdomainInfo {
pub subdomain: String,
}
-/// CHAMADA 1: check_token — get subdomains mapping (productId → subdomain)
pub async fn get_subdomains(session: &HotmartSession) -> anyhow::Result<Vec<SubdomainInfo>> {
tracing::info!("Buscando subdomínios via check_token...");
@@ -128,7 +128,6 @@ pub async fn get_subdomains(session: &HotmartSession) -> anyhow::Result<Vec<Subd
Ok(subdomains)
}
-/// CHAMADA 2: list purchases — get all courses
pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course>> {
tracing::info!("Listando cursos Hotmart...");
@@ -149,8 +148,6 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
let body: serde_json::Value = serde_json::from_str(&body_text)?;
- // The API returns { "data": [...] } where each item has a nested "product" object
- // Fallback: try root array, then "purchases", then "data"
let purchases = body
.get("data")
.and_then(|d| d.as_array())
@@ -160,7 +157,6 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
let mut courses = Vec::new();
for p in purchases {
- // data[].product.id, data[].product.name, etc.
let product = p.get("product").unwrap_or(p);
let id = product
@@ -173,7 +169,6 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
.unwrap_or("")
.to_string();
- // data[].product.seller.name
let seller = product
.get("seller")
.and_then(|s| s.get("name").and_then(|n| n.as_str()))
@@ -185,7 +180,6 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
.unwrap_or("")
.to_string();
- // data[].product.hotmartClub.slug
let slug = product
.get("hotmartClub")
.and_then(|hc| hc.get("slug").and_then(|s| s.as_str()))
@@ -197,18 +191,14 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
.and_then(|v| v.as_bool())
.unwrap_or(false);
- // data[].product.category
let category = product
.get("category")
.and_then(|v| v.as_str())
.map(String::from);
- // Try to get image from logo or image fields
let image_url = product
- .get("logo")
+ .get("picture")
.and_then(|v| v.as_str())
- .or_else(|| product.get("image").and_then(|v| v.as_str()))
- .or_else(|| product.get("imageUrl").and_then(|v| v.as_str()))
.map(String::from);
courses.push(Course {
@@ -221,6 +211,7 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
price: None,
image_url,
category,
+ external_platform: false,
});
}
@@ -228,7 +219,6 @@ pub async fn list_courses(session: &HotmartSession) -> anyhow::Result<Vec<Course
Ok(courses)
}
-/// CHAMADA 3: get price for a single course
pub async fn get_course_price(session: &HotmartSession, product_id: u64) -> anyhow::Result<f64> {
let url = format!(
"https://api-hub.cb.hotmart.com/club-drive-api/rest/v2/purchase/products/{}",
@@ -251,7 +241,6 @@ pub async fn get_course_price(session: &HotmartSession, product_id: u64) -> anyh
let body: serde_json::Value = resp.json().await?;
- // purchases[0].value
let price = body
.get("purchases")
.and_then(|p| p.as_array())
@@ -268,15 +257,22 @@ pub fn merge_subdomains(courses: &mut [Course], subdomains: &[SubdomainInfo]) {
for course in courses.iter_mut() {
if let Some(info) = subdomains.iter().find(|s| s.product_id == course.id) {
course.subdomain = Some(info.subdomain.clone());
- // If slug wasn't set from the purchase API, use subdomain
if course.slug.is_none() {
course.slug = Some(info.subdomain.clone());
}
}
+
+ if course.slug.is_none() && course.subdomain.is_none() {
+ course.external_platform = true;
+ tracing::warn!(
+ "Curso '{}' (ID: {}) sem slug/subdomain — marcado como plataforma externa",
+ course.name,
+ course.id
+ );
+ }
}
}
-/// Navigation API — requires different headers (Origin/Referer = https://hotmart.com)
pub async fn get_modules(
session: &HotmartSession,
slug: &str,
@@ -284,7 +280,13 @@ pub async fn get_modules(
) -> anyhow::Result<Vec<Module>> {
tracing::info!("Buscando módulos do curso {} (slug={})", product_id, slug);
- // Navigation API needs different headers than the default session headers
+ tracing::info!(
+ "[get_modules] Headers: Authorization=Bearer {}..., slug={}, x-product-id={}, Origin=https://hotmart.com, Referer=https://hotmart.com",
+ &session.token[..20.min(session.token.len())],
+ slug,
+ product_id,
+ );
+
let resp = session
.client
.get("https://api-club-course-consumption-gateway.hotmart.com/v1/navigation")