|
1 | | -import React, {useEffect, useState} from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import styles from './DownloadBadge.module.css'; |
3 | 3 |
|
4 | 4 | export default function DownloadBadge() { |
5 | 5 | const [downloadsText, setDownloadsText] = useState('Loading...'); |
6 | 6 |
|
7 | 7 | useEffect(() => { |
8 | | - // Fetch from Docker Hub API |
9 | | - fetch('https://hub.docker.com/v2/repositories/sparkison/m3u-editor/') |
10 | | - .then((r) => { |
11 | | - if (!r.ok) throw new Error('Failed to fetch'); |
12 | | - return r.json(); |
| 8 | + // Fetch from shields.io JSON endpoint (no CORS issues) |
| 9 | + fetch('https://img.shields.io/docker/pulls/sparkison/m3u-editor.json') |
| 10 | + .then((r) => { |
| 11 | + if (!r.ok) throw new Error('Failed to fetch'); |
| 12 | + return r.json(); |
13 | 13 | }) |
14 | 14 | .then((data) => { |
15 | | - if (data && typeof data.pull_count === 'number') { |
16 | | - // Format the number with commas |
17 | | - const formatted = data.pull_count.toLocaleString('en-US'); |
18 | | - setDownloadsText(`${formatted}+`); |
| 15 | + if (data && data.value) { |
| 16 | + // shields.io returns the value already formatted (e.g., "178k") |
| 17 | + // If you want to show the exact number with "+", you can parse it |
| 18 | + setDownloadsText(`${data.value}+`); |
19 | 19 | } |
20 | 20 | }) |
21 | 21 | .catch(() => { |
22 | | - // Fallback to hardcoded value |
23 | | - setDownloadsText('120,000+'); |
| 22 | + // Fallback to hardcoded value (update periodically) |
| 23 | + setDownloadsText('100,000+'); |
24 | 24 | }); |
25 | 25 | }, []); |
26 | 26 |
|
27 | 27 | return ( |
28 | | - <a |
29 | | - href="https://hub.docker.com/r/sparkison/m3u-editor" |
30 | | - target="_blank" |
| 28 | + <a |
| 29 | + href="https://hub.docker.com/r/sparkison/m3u-editor" |
| 30 | + target="_blank" |
31 | 31 | rel="noopener noreferrer" |
32 | | - className={styles.downloadBadge} |
33 | | - role="status" |
| 32 | + className={styles.downloadBadge} |
| 33 | + role="status" |
34 | 34 | aria-live="polite" |
35 | 35 | > |
36 | 36 | <span className={styles.emoji} aria-hidden="true">🚀</span> |
|
0 commit comments