add spotify and placeholder

This commit is contained in:
Conrad
2021-06-18 00:42:03 -04:00
parent 45ca247e44
commit cdfa522feb
2 changed files with 133 additions and 55 deletions

View File

@@ -8,17 +8,23 @@ type Data = {
error?: any; error?: any;
} }
type Parameters = {
animated?: string;
}
export default function handler( export default function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse<Data> res: NextApiResponse<Data>
) { ) {
let params: Parameters = req.query;
let userid = req.query.id[0]; let userid = req.query.id[0];
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8"); res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
axios.get(`https://api.lanyard.rest/v1/users/${userid}`) axios.get(`https://api.lanyard.rest/v1/users/${userid}`)
.then((response) => { .then((response) => {
// let svg = renderCard(response.data); // let svg = renderCard(response.data);
res.send(renderCard(response.data)); res.send(renderCard(response.data, params));
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);

View File

@@ -1,11 +1,20 @@
import * as LanyardTypes from './LanyardTypes'; import * as LanyardTypes from './LanyardTypes';
import { useState } from "react"; import { useState } from "react";
import { getFlags } from "./getFlags"; import { getFlags } from "./getFlags";
const renderCard = (body: LanyardTypes.Root): any => {
type Parameters = {
animated?: string;
}
const renderCard = (body: LanyardTypes.Root, params: Parameters): any => {
//create svg, foreign object almost everything lol //create svg, foreign object almost everything lol
let avatarBorderColor: string = "#747F8D"; let avatarBorderColor: string = "#747F8D";
let userStatus: string = ""; let userStatus: string = "";
let avatarExtension: string = "webp";
if(body.data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
if(params.animated === "false") avatarExtension = "webp";
switch(body.data.discord_status){ switch(body.data.discord_status){
case "online": case "online":
@@ -29,26 +38,37 @@ const renderCard = (body: LanyardTypes.Root): any => {
console.log(flags); console.log(flags);
return ` return `
<svg width="100px" height="100px"> <svg width="400px" height="218px">
<foreignObject> <foreignObject>
<div xmlns="http://www.w3.org/1999/xhtml" style=" <div xmlns="http://www.w3.org/1999/xhtml" style="
position: absolute; position: absolute;
width: 400px; width: 400px;
height: 150px; height: 200px;
inset: 0; inset: 0;
background-color: #000; background-color: #000;
color: #fff; color: #fff;
font-family: Century Gothic; font-family: Century Gothic;
font-size: 16px; font-size: 16px;
display: flex; display: flex;
flex-direction: column;
padding: 5px;
border-radius: 10px;
">
<div style="
position: relative;
width: 400px;
height: 100px;
inset: 0;
display: flex;
flex-direction: row; flex-direction: row;
border-bottom: solid 0.5px #333;
"> ">
<div style=" <div style="
display: flex; display: flex;
flex-direction: row; flex-direction: row;
height: auto; height: auto;
"> ">
<img src="https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.webp?size=2048" style=" <img src="https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=2048" style="
border: solid 3px ${avatarBorderColor}; border: solid 3px ${avatarBorderColor};
border-radius: 50%; border-radius: 50%;
width: 50px; width: 50px;
@@ -107,6 +127,58 @@ const renderCard = (body: LanyardTypes.Root): any => {
</div> </div>
</div> </div>
${body.data.spotify ?
`
<div style="
display: flex;
flex-direction: row;
height: 100px;
margin-left: 15px;
font-size: 0.75rem;
">
<img src="${body.data.spotify.album_art_url}" style="
width: 80px;
height: 80px;
border: solid 0.5px #222;
border-radius: 10px;
margin-right: 15px;
"/>
<div style="
color: #999;
line-height: 0.9rem;
margin-top: -5px;
">
<p style="color: #fff; font-weight: bold;">${body.data.spotify.song}</p>
<p>by <span style="color: #fff">${body.data.spotify.artist}</span></p>
<p style="font-style: italic;">on <span style="color: #e6e6e6">${body.data.spotify.album}</span></p>
</div>
</div>
`
: `
<div style="
display: flex;
flex-direction: row;
height: 150px;
justify-content: center;
align-items: center;
">
<p style="
font-style: italic;
font-size: 0.75rem;
color: #777;
height: auto;
">
I'm not currently doing anything!
</p>
</div>
`}
</div>
</foreignObject> </foreignObject>
</svg> </svg>
`; `;