Added spotify metric to dashboard

This commit is contained in:
r-freeman 2023-02-12 19:08:08 +00:00
parent 914493f214
commit 64239feff0
2 changed files with 11 additions and 2 deletions

View File

@ -16,9 +16,15 @@ export async function getDashboardData() {
const totalArticleViews = (await getViews()).views
const topArtist = await getTopArtist()
const {genre} = await getTopGenre()
const {minutesListened} = await getStats()
const {minutesListened, streams} = await getStats()
const metrics: Metric[] = [
{
title: "Streams",
value: +streams,
group: "Spotify",
href: "https://open.spotify.com/?"
},
{
title: "Minutes listened",
value: +minutesListened,

View File

@ -6,6 +6,7 @@ const STATSFM_LIFETIME_STATS = `https://beta-api.stats.fm/api/v1/users/${STATSFM
type StatsFmResponse = {
items: {
durationMs: number
count: number
}
}
@ -18,8 +19,10 @@ export const getStats = async () => {
}).then(r => r.json()) as StatsFmResponse
const minutesListened = ((response.items.durationMs / 1000) / 60).toFixed(0)
const streams = response.items.count
return {
minutesListened
minutesListened,
streams
}
}