Browse Source

Rebase

add-license-1
novatorem 5 years ago
parent
commit
2cf67d2f42
7 changed files with 25 additions and 1021 deletions
  1. +2
    -0
      README.md
  2. +8
    -12
      api/now-playing.ts
  3. +2
    -988
      package-lock.json
  4. +2
    -14
      package.json
  5. +1
    -2
      tsconfig.json
  6. +5
    -2
      utils/spotify.ts
  7. +5
    -3
      vercel.json

+ 2
- 0
README.md View File

@ -1,3 +1,5 @@
**Now Playing**
<a href="https://novatorem.vercel.app/now-playing?open">
<img src="https://novatorem.vercel.app/now-playing" width="256" height="64" alt="Now Playing">
</a>

+ 8
- 12
api/now-playing.ts View File

@ -1,20 +1,16 @@
import { renderToString } from "react-dom/server";
import { renderToString } from 'react-dom/server';
import { NowRequest, NowResponse } from "@vercel/node";
import { decode } from "querystring";
import { decode } from 'querystring';
import { nowPlaying } from "../utils/spotify";
import { Player } from "../components/NowPlaying";
import { Player } from '../components/NowPlaying';
export default async function (req: NowRequest, res: NowResponse) {
const {
item = {},
is_playing: isPlaying = false,
progress_ms: progress = 0,
} = await nowPlaying();
const { item = {}, is_playing: isPlaying = false, progress_ms: progress = 0 } = await nowPlaying();
const params = decode(req.url.split("?")[1]) as any;
const params = decode(req.url.split('?')[1]) as any;
if (params && typeof params.open !== "undefined") {
if (params && typeof params.open !== 'undefined') {
if (item && item.external_urls) {
res.writeHead(302, {
Location: item.external_urls.spotify,
@ -43,9 +39,9 @@ export default async function (req: NowRequest, res: NowResponse) {
)}`;
}
const artist = (item.artists || []).map(({ name }) => name).join(", ");
const artist = (item.artists || []).map(({ name }) => name).join(', ');
const text = renderToString(
Player({ cover: coverImg, artist, track, isPlaying, progress, duration })
);
return res.status(200).send(text);
}
}

+ 2
- 988
package-lock.json
File diff suppressed because it is too large
View File


+ 2
- 14
package.json View File

@ -5,7 +5,6 @@
"description": "Github profile",
"main": "index.js",
"dependencies": {
"faunadb": "^2.14.2",
"isomorphic-unfetch": "^3.0.0",
"querystring": "^0.2.0",
"react": "^16.13.1",
@ -16,10 +15,7 @@
"@types/node": "^14.0.22",
"@types/react": "^16.9.42",
"@types/react-dom": "^16.9.8",
"@vercel/node": "^1.7.2",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5"
"@vercel/node": "^1.7.2"
},
"repository": {
"type": "git",
@ -31,13 +27,5 @@
"bugs": {
"url": "https://github.com/novatorem/novatorem/issues"
},
"homepage": "https://github.com/novatorem/novatorem#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
"homepage": "https://github.com/novatorem/novatorem#readme"
}

+ 1
- 2
tsconfig.json View File

@ -1,11 +1,10 @@
{
"compilerOptions": {
"module": "ES2015",
"moduleResolution": "node",
"target": "ES2017",
"jsx": "react",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true
}
}

+ 5
- 2
utils/spotify.ts View File

@ -7,7 +7,9 @@ const {
SPOTIFY_REFRESH_TOKEN: refresh_token,
} = process.env;
const basic = Buffer.from(`${client_id}:${client_secret}`).toString("base64");
const basic = Buffer.from(`${client_id}:${client_secret}`).toString(
"base64"
);
const Authorization = `Basic ${basic}`;
async function getAuthorizationToken() {
@ -28,8 +30,9 @@ async function getAuthorizationToken() {
return `Bearer ${response.access_token}`;
}
const NOW_PLAYING_ENDPOINT = `https://api.spotify.com/v1/me/player/currently-playing`;
export async function nowPlaying() {
export async function nowPlaying () {
const Authorization = await getAuthorizationToken();
const response = await fetch(NOW_PLAYING_ENDPOINT, {
headers: {


+ 5
- 3
vercel.json View File

@ -1,4 +1,6 @@
{
"version": 2,
"rewrites": [{ "source": "/(.*)", "destination": "/api/$1" }]
}
"version": 2,
"rewrites": [
{ "source": "/now-playing", "destination": "/api/now-playing" }
]
}

Loading…
Cancel
Save