feat: show tv or movie if checked in, music if not

This commit is contained in:
Cory Dransfeldt 2023-10-07 17:20:26 -07:00
parent a7ac48e501
commit 84077283b4

View file

@ -3,6 +3,39 @@ export default async () => {
const API_APPLE_MUSIC_DEVELOPER_TOKEN = Netlify.env.get('API_APPLE_MUSIC_DEVELOPER_TOKEN') const API_APPLE_MUSIC_DEVELOPER_TOKEN = Netlify.env.get('API_APPLE_MUSIC_DEVELOPER_TOKEN')
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const API_APPLE_MUSIC_USER_TOKEN = Netlify.env.get('API_APPLE_MUSIC_USER_TOKEN') const API_APPLE_MUSIC_USER_TOKEN = Netlify.env.get('API_APPLE_MUSIC_USER_TOKEN')
// eslint-disable-next-line no-undef
const TV_KEY = Netlify.env.get('API_KEY_TRAKT')
const traktRes = await fetch('https://api.trakt.tv/users/cdransf/watching', {
headers: {
'Content-Type': 'application/json',
'trakt-api-version': 2,
'trakt-api-key': TV_KEY,
},
})
.then((data) => {
if (data.body) return data.json()
return {}
})
.catch()
if (Object.keys(traktRes).length) {
if (traktRes['type'] === 'episode') {
return Response.json({
title: traktRes['show']['title'],
episode: traktRes['episode']['title'],
text: `📺 ${traktRes['show']['title']}: ${traktRes['episode']['title']}`,
})
}
if (traktRes['type'] === 'movie') {
return Response.json({
title: traktRes['movie']['title'],
text: `🎥 ${traktRes['movie']['title']}`,
})
}
}
const trackRes = await fetch('https://api.music.apple.com/v1/me/recent/played/tracks?limit=1', { const trackRes = await fetch('https://api.music.apple.com/v1/me/recent/played/tracks?limit=1', {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',