2023-02-22 22:17:24 +00:00
|
|
|
import fetcher from './fetcher'
|
2023-02-02 21:47:35 +00:00
|
|
|
|
2023-02-22 22:53:33 +00:00
|
|
|
const STATSFM_USERNAME = process.env.STATSFM_USERNAME
|
2023-02-02 21:47:35 +00:00
|
|
|
const STATSFM_LIFETIME_STATS = `https://beta-api.stats.fm/api/v1/users/${STATSFM_USERNAME}/streams/stats?range=lifetime`
|
|
|
|
|
|
|
|
type StatsFmResponse = {
|
|
|
|
items: {
|
|
|
|
durationMs: number
|
2023-02-12 19:08:08 +00:00
|
|
|
count: number
|
2023-02-02 21:47:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStats = async () => {
|
2023-02-22 22:17:24 +00:00
|
|
|
const response = await fetcher(STATSFM_LIFETIME_STATS, {
|
2023-02-02 21:47:35 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json'
|
|
|
|
}
|
2023-02-22 22:17:24 +00:00
|
|
|
}) as StatsFmResponse
|
2023-02-02 21:47:35 +00:00
|
|
|
|
2023-02-18 22:51:56 +00:00
|
|
|
const {durationMs} = response.items
|
|
|
|
const hoursListened = (durationMs / 3_600_000).toFixed(0)
|
|
|
|
const minutesListened = (durationMs / 60_000).toFixed(0)
|
2023-02-12 19:08:08 +00:00
|
|
|
const streams = response.items.count
|
2023-02-02 21:47:35 +00:00
|
|
|
|
|
|
|
return {
|
2023-02-18 22:51:56 +00:00
|
|
|
hoursListened,
|
2023-02-12 19:08:08 +00:00
|
|
|
minutesListened,
|
|
|
|
streams
|
2023-02-02 21:47:35 +00:00
|
|
|
}
|
|
|
|
}
|