feat: query the download api for download counts

This commit is contained in:
2026-02-20 10:27:53 +10:30
parent d64962147a
commit f242928682
+9 -14
View File
@@ -486,7 +486,8 @@ export class ThemeManager {
} }
/** /**
* Download and install a theme from the store * Download and install a theme from the store.
* Always calls the download API first to increment download_count on the server.
*/ */
public async downloadTheme(themeContent: { public async downloadTheme(themeContent: {
id: string; id: string;
@@ -499,20 +500,14 @@ export class ThemeManager {
try { try {
if (!themeContent.id) return; if (!themeContent.id) return;
let themeJsonUrl: string; // Always call download endpoint to increment download_count
const downloadData = (await this.fetchFromUrl(
// Use theme_json_url if provided (from API list), otherwise call download endpoint `${this.THEME_API_BASE}/themes/${themeContent.id}/download`
if (themeContent.theme_json_url) { )) as { success?: boolean; data?: { theme_json_url: string } };
themeJsonUrl = themeContent.theme_json_url; if (!downloadData?.success || !downloadData?.data?.theme_json_url) {
} else { throw new Error("Failed to get theme download URL");
const downloadData = await this.fetchFromUrl(
`${this.THEME_API_BASE}/themes/${themeContent.id}/download`
) as { success?: boolean; data?: { theme_json_url: string } };
if (!downloadData?.success || !downloadData?.data?.theme_json_url) {
throw new Error("Failed to get theme download URL");
}
themeJsonUrl = downloadData.data.theme_json_url;
} }
const themeJsonUrl = downloadData.data.theme_json_url;
const themeData = (await this.fetchFromUrl(themeJsonUrl)) as ThemeContent; const themeData = (await this.fetchFromUrl(themeJsonUrl)) as ThemeContent;