-
-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8d3dd1
commit d266693
Showing
7 changed files
with
165 additions
and
11 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
|
||
# Hey, I'm Nate! | ||
|
||
**Now Playing** on Spotify | ||
| Now Playing | | ||
| ------------------------------------------------------------------------------------------------------------------------------ | | ||
| <a href="https://status.nmoo.dev/now-playing?open"><img src="https://status.nmoo.dev/now-playing" width="540" height="64"></a> | | ||
|
||
<a href="https://status.nmoo.dev/now-playing?open"> | ||
<img src="https://status.nmoo.dev/now-playing" width="256" height="64" alt="Now Playing"> | ||
</a> | ||
| Top Tracks | | ||
| ------------------------------------------------------------------------------------------------------------------------------------ | | ||
| <a href="https://status.nmoo.dev/top-tracks?i=1&open"><img src="https://status.nmoo.dev/top-tracks?i=1" width="540" height="64"></a> | | ||
| <a href="https://status.nmoo.dev/top-tracks?i=2&open"><img src="https://status.nmoo.dev/top-tracks?i=2" width="540" height="64"></a> | | ||
| <a href="https://status.nmoo.dev/top-tracks?i=3&open"><img src="https://status.nmoo.dev/top-tracks?i=3" width="540" height="64"></a> | |
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
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,43 @@ | ||
import { NowRequest, NowResponse } from "@vercel/node"; | ||
import { renderToString } from "react-dom/server"; | ||
import { Track } from "../components/Track"; | ||
import { topTrack } from "../utils/spotify"; | ||
|
||
export default async function (req: NowRequest, res: NowResponse) { | ||
let { i, open } = req.query; | ||
i = Array.isArray(i) ? i[0] : i; | ||
const item = await topTrack({ index: Number.parseInt(i) }); | ||
|
||
if (!item) { | ||
return res.status(404).end(); | ||
} | ||
|
||
if (typeof open !== "undefined") { | ||
if (item && item.external_urls) { | ||
res.writeHead(302, { | ||
Location: item.external_urls.spotify, | ||
}); | ||
return res.end(); | ||
} | ||
return res.status(200).end(); | ||
} | ||
|
||
res.setHeader("Content-Type", "image/svg+xml"); | ||
res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate"); | ||
|
||
const { name: track } = item; | ||
const { images = [] } = item.album || {}; | ||
|
||
const cover = images[images.length - 1]?.url; | ||
let coverImg = null; | ||
if (cover) { | ||
const buff = await (await fetch(cover)).arrayBuffer(); | ||
coverImg = `data:image/jpeg;base64,${Buffer.from(buff).toString("base64")}`; | ||
} | ||
|
||
const artist = (item.artists || []).map(({ name }) => name).join(", "); | ||
const text = renderToString( | ||
Track({ index: Number.parseInt(i), cover: coverImg, artist, track }) | ||
); | ||
return res.status(200).send(text); | ||
} |
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
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
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,78 @@ | ||
import React from "react"; | ||
import ReadmeImg from "./ReadmeImg"; | ||
import Text from "./Text"; | ||
|
||
export interface Props { | ||
index?: number, | ||
cover?: string; | ||
track: string; | ||
artist: string; | ||
} | ||
|
||
export const Track: React.FC<Props> = ({ | ||
index, | ||
cover, | ||
track, | ||
artist, | ||
}) => { | ||
return ( | ||
<ReadmeImg width="540" height="64"> | ||
<style> | ||
{` | ||
@media (prefers-color-scheme: dark) { | ||
color: #FFF; | ||
} | ||
img:not([src]) { | ||
content: url("data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="); | ||
background: #FFF; | ||
border: 1px solid #e1e4e8; | ||
} | ||
img { | ||
border-radius: 3px; | ||
} | ||
p { | ||
display: block; | ||
} | ||
#cover { | ||
box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 3px 10px rgba(0,0,0,0.05); | ||
} | ||
#cover:not([src]) { | ||
box-shadow: none; | ||
} | ||
`} | ||
</style> | ||
<div | ||
style={{ | ||
display: "flex", | ||
alignItems: "center", | ||
paddingTop: 8, | ||
paddingLeft: 4, | ||
}} | ||
> | ||
<Text style={{ width: '16px', marginRight: '16px' }} size="large" weight="bold">{index}</Text> | ||
<img id="cover" src={cover ?? null} width="48" height="48" /> | ||
<div | ||
style={{ | ||
display: "flex", | ||
flex: 1, | ||
flexDirection: "column", | ||
marginTop: -4, | ||
marginLeft: 8, | ||
}} | ||
> | ||
<Text id="track" weight="bold"> | ||
{`${track ?? ""} `.trim()} | ||
</Text> | ||
<Text id="artist" color={!track ? "gray" : undefined}> | ||
{artist || "Nothing playing..."} | ||
</Text> | ||
</div> | ||
</div> | ||
</ReadmeImg> | ||
); | ||
}; |
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
d266693
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: