-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring back client rendered music section
- Loading branch information
Showing
4 changed files
with
64 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import useSWR from "swr"; | ||
import ExtLink from "./ExtLink"; | ||
import { SWRResponse } from "swr"; | ||
import { SongInformation } from "../lib/Music.types"; | ||
|
||
const fetcher = (...args: any[]) => fetch(args[0]).then((res) => res.json()); | ||
|
||
const Music = () => { | ||
const { data, error }: SWRResponse<SongInformation, Error> = useSWR( | ||
"/api/v1/music", | ||
fetcher | ||
); | ||
|
||
if (error || !data || !data.listening) return null; | ||
|
||
return ( | ||
<p> | ||
I'm currently listening to{" "} | ||
<ExtLink href={data.url as string}> | ||
{data.title} by {data.artist} | ||
</ExtLink> | ||
<style jsx>{` | ||
p { | ||
opacity: 0.5; | ||
} | ||
`}</style> | ||
</p> | ||
); | ||
}; | ||
|
||
export default Music; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { SongInformation } from "../../../lib/Music.types"; | ||
|
||
export default async ( | ||
req: NextApiRequest, | ||
res: NextApiResponse<SongInformation> | ||
) => { | ||
if (!process.env?.LASTFMAPI) | ||
return res.status(500).json({ listening: false }); | ||
|
||
let result = await fetch( | ||
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=ghostwolfy&api_key=${process.env.LASTFMAPI}&format=json&limit=1` | ||
).then((request) => request.json()); | ||
|
||
if (!result?.recenttracks?.track[0]["@attr"]) | ||
return res.status(200).json({ listening: false }); | ||
|
||
res.setHeader("Cache-Control", "s-maxage=30, stale-while-revalidate"); | ||
|
||
res.status(200).json({ | ||
listening: true, | ||
artist: result.recenttracks.track[0].artist["#text"], | ||
title: result.recenttracks.track[0].name, | ||
url: `https://open.spotify.com/search/${encodeURIComponent( | ||
result.recenttracks.track[0].artist["#text"] + | ||
" " + | ||
result.recenttracks.track[0].name | ||
)}`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5cff54c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
updatedpersonalwebsite – ./
www.paulekas.eu
updatedpersonalwebsite-theonlyghostwolf.vercel.app
updatedpersonalwebsite.vercel.app
paulekas.eu
updatedpersonalwebsite-git-main-theonlyghostwolf.vercel.app