mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-11 19:05:41 +00:00
31 lines
813 B
TypeScript
31 lines
813 B
TypeScript
import fetcher from './fetcher'
|
|
|
|
const STATSFM_USERNAME = process.env.STATSFM_USERNAME
|
|
const STATSFM_LIFETIME_STATS = `https://beta-api.stats.fm/api/v1/users/${STATSFM_USERNAME}/streams/stats?range=lifetime`
|
|
|
|
type StatsFmResponse = {
|
|
items: {
|
|
durationMs: number
|
|
count: number
|
|
}
|
|
}
|
|
|
|
export const getStats = async () => {
|
|
const response = await fetcher(STATSFM_LIFETIME_STATS, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
}) as StatsFmResponse
|
|
|
|
const {durationMs} = response.items
|
|
const hoursListened = (durationMs / 3_600_000).toFixed(0)
|
|
const minutesListened = (durationMs / 60_000).toFixed(0)
|
|
const streams = response.items.count
|
|
|
|
return {
|
|
hoursListened,
|
|
minutesListened,
|
|
streams
|
|
}
|
|
} |