Browse Source

Fix iteming

add-license-1
novatorem 5 years ago
parent
commit
5a6d428f53
3 changed files with 22 additions and 15 deletions
  1. +19
    -12
      api/now-playing.ts
  2. +2
    -2
      package.json
  3. +1
    -1
      vercel.json

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

@ -1,18 +1,19 @@
import { NowRequest, NowResponse } from "@vercel/node";
import { renderToString } from "react-dom/server";
import { NowRequest, NowResponse } from "@vercel/node";
import { decode } from "querystring";
import { Player } from "../components/NowPlaying";
import { nowPlaying } from "../utils/spotify";
import { Player } from "../components/NowPlaying";
export default async function (req: NowRequest, res: NowResponse) {
const {
item = {},
is_playing: isPlaying = false,
const {
item = {},
is_playing: isPlaying = false,
progress_ms: progress = 0,
} = await nowPlaying();
} = await nowPlaying();
const params = decode(req.url.split("?")[1]) as any;
if (params && typeof params.open !== "undefined") {
if (item && item.external_urls) {
res.writeHead(302, {
@ -24,16 +25,22 @@ export default async function (req: NowRequest, res: NowResponse) {
}
res.setHeader("Content-Type", "image/svg+xml");
res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
// res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
res.setHeader("Cache-Control", "no-cache");
const { duration_ms: duration, name: track } = item;
const {
duration_ms: duration,
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 buff = await(await fetch(cover)).arrayBuffer();
coverImg = `data:image/jpeg;base64,${Buffer.from(buff).toString(
"base64"
)}`;
}
const artist = (item.artists || []).map(({ name }) => name).join(", ");
@ -41,4 +48,4 @@ export default async function (req: NowRequest, res: NowResponse) {
Player({ cover: coverImg, artist, track, isPlaying, progress, duration })
);
return res.status(200).send(text);
}
}

+ 2
- 2
package.json View File

@ -26,8 +26,8 @@
"url": "git+https://github.com/novatorem/novatorem.git"
},
"keywords": [],
"author": "Nate Moore",
"license": "ISC",
"author": "Andrew Novac",
"license": "MIT",
"bugs": {
"url": "https://github.com/novatorem/novatorem/issues"
},


+ 1
- 1
vercel.json View File

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

Loading…
Cancel
Save