Skip to content

Commit 930fec4

Browse files
committed
fix: 🐛 download count
1 parent 0ab82b3 commit 930fec4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/components/DownloadModal.astro

+12-7
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ const { links } = Astro.props
265265
}
266266
private readonly downloadCount: HTMLElement
267267
private readonly atlasVersion = '0.4.1'
268-
private readonly apiEndpoint = 'https://api.atlasos.net/atlas'
268+
private readonly apiEndpoint = 'https://api.atlasos.net'
269269

270270
constructor() {
271271
const elements = {
@@ -344,11 +344,13 @@ const { links } = Astro.props
344344

345345
private async fetchDownloadCount(): Promise<number | null> {
346346
try {
347-
const response = await fetch(`${this.apiEndpoint}/stats`)
347+
const response = await fetch(this.apiEndpoint)
348348
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
349349

350350
const data = await response.json()
351-
return data.downloads || 0
351+
const atlasDownload = data.find((download: { version: string }) => download.version === 'atlas')
352+
353+
return atlasDownload?.count || 0
352354
} catch (error) {
353355
console.error('Error fetching download count:', error)
354356
return null
@@ -357,9 +359,8 @@ const { links } = Astro.props
357359

358360
private async incrementDownloadCount(): Promise<void> {
359361
try {
360-
const response = await fetch(`${this.apiEndpoint}/increment`, {
361-
method: 'POST',
362-
headers: { 'Content-Type': 'application/json' }
362+
const response = await fetch(`${this.apiEndpoint}/atlas/increment`, {
363+
method: 'POST'
363364
})
364365

365366
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
@@ -374,7 +375,11 @@ const { links } = Astro.props
374375

375376
window.open(`https://cdn.jsdelivr.net/atlas/${this.atlasVersion}/AtlasPlaybook_v${this.atlasVersion}.zip`, '_self')
376377

377-
await this.incrementDownloadCount()
378+
try {
379+
await this.incrementDownloadCount()
380+
} catch (error) {
381+
console.error('Failed to increment download count:', error)
382+
}
378383

379384
setTimeout(() => {
380385
this.buttons.playbook.innerHTML = originalContent

0 commit comments

Comments
 (0)