Merge pull request #8 from callumok2004/master

This commit is contained in:
Conrad Crawford
2021-06-20 23:45:24 -04:00
committed by GitHub
11 changed files with 190 additions and 261 deletions

View File

@@ -54,4 +54,5 @@ If you don't want people seeing your status, append the query param `hideStatus=
[![Discord Presence](https://lanyard-profile-readme.vercel.app/api/94490510688792576?theme=light&bg=809ecf&animated=false&hideDiscrim=true)](https://discord.com/users/94490510688792576)
\
Note: Discord nitro and Nitro Boosting badges do not work due to discord api limitations.
_If you're using this in your profile, feel free to show support and give this repo a ⭐ star! It means a lot, thank you :)_

View File

@@ -19,6 +19,7 @@
"styled-components": "^5.3.0"
},
"devDependencies": {
"@types/image-to-base64": "^2.1.0",
"@types/react": "17.0.11",
"eslint": "7.28.0",
"eslint-config-next": "11.0.0",

View File

@@ -1,6 +1,5 @@
import type { AppProps } from 'next/app'
function MyApp({ Component, pageProps }: AppProps) {
export default function LanyardReadMe({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp

View File

@@ -3,8 +3,8 @@ import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage
const sheet = new ServerStyleSheet(),
originalRenderPage = ctx.renderPage
try {
ctx.renderPage = () =>

View File

@@ -9,7 +9,7 @@ type Data = {
}
type Parameters = {
animated?: string;
animated?: string;
}
export default async function handler(
@@ -17,24 +17,20 @@ export default async function handler(
res: NextApiResponse<Data>
) {
let params: Parameters = req.query;
let userid = req.query.id[0];
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'");
let params: Parameters = req.query,
userid = req.query.id[0],
lanyardData: any;
let lanyardData: any;
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'");
await axios.get(`https://api.lanyard.rest/v1/users/${userid}`)
.then((response) => {
return lanyardData = response;
})
.catch((err) => {
console.log(err);
res.send({ error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.` })
});
try {
lanyardData = await axios.get(`https://api.lanyard.rest/v1/users/${userid}`);
} catch (e) {
console.log(e)
res.send({ error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.` })
}
let svg = await renderCard(lanyardData.data, params);
res.status(200).send(svg);
console.log(req.query);
let svg = await renderCard(lanyardData.data, params);
res.status(200).send(svg as any);
}

View File

@@ -3,15 +3,13 @@ import styled from 'styled-components';
import { useState } from 'react';
export default function Home() {
let [userId, setUserId] = useState(':id')
const [userId, setUserId] = useState(':id')
return (
<>
<Head>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400&display=swap" rel="stylesheet" />
<title>Lanyard for GitHub Profile</title>
</Head>
@@ -19,28 +17,16 @@ export default function Home() {
<Header>
🏷 lanyard-profile-readme
</Header>
<Container>
<p style={{fontSize: "1rem", fontWeight: "bold", marginTop: "1rem"}}>Make sure you're in the <a style={{color: "#fff"}} rel="noreferrer" href="https://discord.com/invite/WScAm7vNGF">Discord</a> for this to work.</p>
<Input maxLength={18} type="text" placeholder="Paste your Discord user ID here" onChange={((e) => setUserId(e.target.value))}>
</Input>
<span style={{fontSize: "1rem", marginTop: "1rem"}}>Copy the following and paste it into your README.md</span>
<p style={{ fontSize: "1rem", fontWeight: "bold", marginTop: "1rem" }}>Make sure you're in the <a style={{ color: "#fff" }} rel="noreferrer" href="https://discord.com/invite/WScAm7vNGF">Discord</a> for this to work.</p>
<Input maxLength={18} type="text" placeholder="Paste your Discord user ID here" onChange={((e) => setUserId(e.target.value))} />
<span style={{ fontSize: "1rem", marginTop: "1rem" }}>Copy the following and paste it into your README.md</span>
<Link>
[![Discord Presence](https://lanyard-profile-readme.vercel.app/api/{userId})](https://discord.com/users/{userId})
</Link>
<span style={{fontSize: "1rem", fontStyle: "italic", marginTop: "1rem"}}>For further customization, check out the <a rel="noreferrer" target="_blank" href="https://github.com/cnrad/lanyard-profile-readme" style={{color: "#fff", fontWeight: "bold"}}>repo</a>!</span>
<Example src={`https://lanyard-profile-readme.vercel.app/api/${userId}`} alt="[Please provide a valid user ID!]" style={{color: "#ff8787"}}/>
<span style={{ fontSize: "1rem", fontStyle: "italic", marginTop: "1rem" }}>For further customization, check out the <a rel="noreferrer" target="_blank" href="https://github.com/cnrad/lanyard-profile-readme" style={{ color: "#fff", fontWeight: "bold" }}>repo</a>!</span>
<Example src={`https://lanyard-profile-readme.vercel.app/api/${userId}`} alt="[Please provide a valid user ID!]" style={{ color: "#ff8787" }} />
</Container>
</Background>
</>
)

View File

@@ -1,36 +1,16 @@
export const getFlags = (flag:number): string[] => {
export const getFlags = (flag: number): string[] => {
let flags: string[] = [];
if(flag & 1){
flags.push("Discord_Employee")
}
if(flag & 2){
flags.push("Partnered_Server_Owner")
}
if(flag & 4){
flags.push("HypeSquad_Events")
}
if(flag & 8){
flags.push("Bug_Hunter_Level_1")
}
if(flag & 64){
flags.push("House_Bravery")
}
if(flag & 128){
flags.push("House_Brilliance")
}
if(flag & 256){
flags.push("House_Balance")
}
if(flag & 512){
flags.push("Early_Supporter")
}
if(flag & 16384){
flags.push("Bug_Hunter_Level_2")
}
if(flag & 131072){
flags.push("Early_Verified_Bot_Developer")
}
if (flag & 1) flags.push("Discord_Employee")
if (flag & 2) flags.push("Partnered_Server_Owner")
if (flag & 4) flags.push("HypeSquad_Events")
if (flag & 8) flags.push("Bug_Hunter_Level_1")
if (flag & 64) flags.push("House_Bravery")
if (flag & 128) flags.push("House_Brilliance")
if (flag & 256) flags.push("House_Balance")
if (flag & 512) flags.push("Early_Supporter")
if (flag & 16384) flags.push("Bug_Hunter_Level_2")
if (flag & 131072) flags.push("Early_Verified_Bot_Developer")
return flags;
}

View File

@@ -1,9 +1,9 @@
//probably the messiest code i've ever written but it works so :)
import { Badges } from '../public/assets/badges/BadgesEncoded';
import { getFlags } from './getFlags';
import * as LanyardTypes from './LanyardTypes';
import { getFlags } from "./getFlags";
import encodeBase64 from './toBase64';
import { Badges } from '../public/assets/badges/BadgesEncoded'
import { encodeBase64 } from './toBase64';
type Parameters = {
theme?: string;
@@ -13,57 +13,49 @@ type Parameters = {
hideStatus?: string;
}
const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<any> => {
let avatarBorderColor: string = "#747F8D";
let userStatus: string = "";
let avatarExtension: string = "webp";
let statusExtension: string = "webp";
let activity: any = false;
let backgroundColor: string = '1a1c1f';
let theme = 'dark';
let discrim = 'show';
let hideStatus = 'false';
const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<string> => {
const defaultAvatar: string = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAY1BMVEVYZfJib/OMlfahqPeWn/eBi/XLz/vq6/7////19f5tePTq7P22vPnV2Pyrsvirsvl3gvT09f7Axfp3gfRtePNsePPg4v22vPq2u/qCi/WhqPjf4/zf4v2Xn/essvjLzvuXnvdbidFTAAAETElEQVR4AezBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAIDZudMtV1UlDuCFRKlWIEJ6uOwbzXn/lzzzYc/GWiT6zya/79WrLeYSc5Vq9IFWa3Sr6JehWt0ZZn5RtFJvmHnodPsrPLx1/B9PKx1ziLOPnIRRO84EXaAP/CWnR3pArTWcybpA5G8NsX20pw+cSbpAngEeOQenY+Cf8KIZ4FuDfSV4Ko/7hS7wNjYH7W3MvNeHtn2jvxn+OXcgaP0x8KJo43vgnwqu85EXDfGVULWON9G1BOmDN/M/AnTgDSWC0xve0KAITeSsykFw4qzOQWB4YwNBOfLmPAHpeXsvr5XOgJkjGA3vIlU6A2bvOHvAnXwiCMrwTl5UpUtg5us7BAB2gcg78nXugaC6QORd+bo7AEAXiLwzX+8SANEFNHPdXcAwV90FDgxA037+zwAc7aZlCKnSNTDrADZBdU6DBwbha5wCAabBkWGkSqfAzFa6C8xeADYB9Y2ByEBsbSMAYAy0zHWPActQLPQuKBh3DiwiDRlwzwFOv9JfTpORh5x5rVfQc8CQiLLJiEMaA1oW6XgVq+grVh4yY56JA68x07fm8hCIhXCUPn823zgkG/HK4Rf6kYv8YBt5BQ03BQyv9CMq8M/JQ7IItw+e6cd8QQjKTqCX3OMTtOdCCNZOoCnqkrYgZEFD2/FF/08qDAE4Dji+TtHPKHknVmBboVB2i9HI9zIGahZUhaVqVxCyQEEVQ7rSBMj3QiPUUTCWJkC+8zrQVjzmELBYG2H5jDYUFqAiQDlMtAwKQgjr+nwoq9O2BSEQJQFVWKeNBSEQ6+BYeG3BFIUAHIfasmsLh7IQgLcjDZd0AWXEIZRDMDYCuuj73g95yJGxEuBLPmr6VBSyzMO9Fpzko3kqeA1r8W4GHOWNKQ/JIl4COL4SZf2lPAQhAY4lYrv860rlIVmHlYAsuBhjFwpCwO4LOkb0TMAzAc8EPBPwTMAGngl4JuCZgMig4jMB27AMykJUhCr4ekwzKI10T9hpwzcz6DNSUbRdORzThW/CJSKagd4LjKurof1suFCYVR54MDckpsBXDLk3pliQgxBTHneBrwiaNtOfeUUKCnMQYlKC32x2r7SlmSUpoOQdi5xtoqx1DNP8WW9kKSCVvAu8QnC2USR4/I2bP5vDmhS80pdOjXULw8dc7HSiL6ljYLTmz/ooKvJTdkqTt9G5s/mHczH6qXlV9I32Ehi0+QVfQbn7HryHhvY033V1Tuu3CRncOIj3rL3EV9pf7+53ced0bY+MIZm7ndEt9uNnkxN8OSWhAvjjZ8ktnIoKaMDHF0yH8S416C4Rpv7bU094pWJ9QFv4BJOBvnkFzjWKMvhu4G78IibMIz2EFM3KFUAwCEI+ID9MDia6kd/+enpFj+YE+af+aA8OZAAAAAAG+Vvf46sAAAAAAAAAAAAAAAAAAAAAAFYCeHSjWah9hFcAAAAASUVORK5CYII=";
if(body.data.activities[0]){
if(body.data.activities[0].emoji && body.data.activities[0].emoji.animated === true) statusExtension = "gif";
}
let avatarBorderColor: string = "#747F8D",
userStatus: string = "",
avatarExtension: string = "webp",
statusExtension: string = "webp",
activity: any = false,
backgroundColor: string = '1a1c1f',
theme = 'dark',
discrim = 'show',
hideStatus = 'false';
if(body.data.activities.length > 0) {
if(body.data.activities[Object.keys(body.data.activities).length - 1].type === 0) activity = body.data.activities[Object.keys(body.data.activities).length - 1];
}
let defaultAvatar: string = "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAY1BMVEVYZfJib/OMlfahqPeWn/eBi/XLz/vq6/7////19f5tePTq7P22vPnV2Pyrsvirsvl3gvT09f7Axfp3gfRtePNsePPg4v22vPq2u/qCi/WhqPjf4/zf4v2Xn/essvjLzvuXnvdbidFTAAAETElEQVR4AezBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAIDZudMtV1UlDuCFRKlWIEJ6uOwbzXn/lzzzYc/GWiT6zya/79WrLeYSc5Vq9IFWa3Sr6JehWt0ZZn5RtFJvmHnodPsrPLx1/B9PKx1ziLOPnIRRO84EXaAP/CWnR3pArTWcybpA5G8NsX20pw+cSbpAngEeOQenY+Cf8KIZ4FuDfSV4Ko/7hS7wNjYH7W3MvNeHtn2jvxn+OXcgaP0x8KJo43vgnwqu85EXDfGVULWON9G1BOmDN/M/AnTgDSWC0xve0KAITeSsykFw4qzOQWB4YwNBOfLmPAHpeXsvr5XOgJkjGA3vIlU6A2bvOHvAnXwiCMrwTl5UpUtg5us7BAB2gcg78nXugaC6QORd+bo7AEAXiLwzX+8SANEFNHPdXcAwV90FDgxA037+zwAc7aZlCKnSNTDrADZBdU6DBwbha5wCAabBkWGkSqfAzFa6C8xeADYB9Y2ByEBsbSMAYAy0zHWPActQLPQuKBh3DiwiDRlwzwFOv9JfTpORh5x5rVfQc8CQiLLJiEMaA1oW6XgVq+grVh4yY56JA68x07fm8hCIhXCUPn823zgkG/HK4Rf6kYv8YBt5BQ03BQyv9CMq8M/JQ7IItw+e6cd8QQjKTqCX3OMTtOdCCNZOoCnqkrYgZEFD2/FF/08qDAE4Dji+TtHPKHknVmBboVB2i9HI9zIGahZUhaVqVxCyQEEVQ7rSBMj3QiPUUTCWJkC+8zrQVjzmELBYG2H5jDYUFqAiQDlMtAwKQgjr+nwoq9O2BSEQJQFVWKeNBSEQ6+BYeG3BFIUAHIfasmsLh7IQgLcjDZd0AWXEIZRDMDYCuuj73g95yJGxEuBLPmr6VBSyzMO9Fpzko3kqeA1r8W4GHOWNKQ/JIl4COL4SZf2lPAQhAY4lYrv860rlIVmHlYAsuBhjFwpCwO4LOkb0TMAzAc8EPBPwTMAGngl4JuCZgMig4jMB27AMykJUhCr4ekwzKI10T9hpwzcz6DNSUbRdORzThW/CJSKagd4LjKurof1suFCYVR54MDckpsBXDLk3pliQgxBTHneBrwiaNtOfeUUKCnMQYlKC32x2r7SlmSUpoOQdi5xtoqx1DNP8WW9kKSCVvAu8QnC2USR4/I2bP5vDmhS80pdOjXULw8dc7HSiL6ljYLTmz/ooKvJTdkqTt9G5s/mHczH6qXlV9I32Ehi0+QVfQbn7HryHhvY033V1Tuu3CRncOIj3rL3EV9pf7+53ced0bY+MIZm7ndEt9uNnkxN8OSWhAvjjZ8ktnIoKaMDHF0yH8S416C4Rpv7bU094pWJ9QFv4BJOBvnkFzjWKMvhu4G78IibMIz2EFM3KFUAwCEI+ID9MDia6kd/+enpFj+YE+af+aA8OZAAAAAAG+Vvf46sAAAAAAAAAAAAAAAAAAAAAAFYCeHSjWah9hFcAAAAASUVORK5CYII=";
if(body.data.discord_user.avatar !== null && body.data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
if(params.animated === "false") avatarExtension = "webp";
if(params.hideDiscrim === "true") discrim = "hide";
if(params.theme === 'light'){
if (body.data.activities[0]?.emoji?.animated) statusExtension = "gif";
if (body.data.discord_user.avatar && body.data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
if (body.data.activities.length > 0 && body.data.activities[Object.keys(body.data.activities).length - 1].type === 0) activity = body.data.activities[Object.keys(body.data.activities).length - 1];
if (params.animated === "false") avatarExtension = "webp";
if (params.hideStatus === 'true') hideStatus = 'true';
if (params.hideDiscrim === "true") discrim = "hide";
if (params.bg) backgroundColor = params.bg;
if (params.theme === 'light') {
backgroundColor = '#eee';
theme = 'light';
}
if(params.bg) backgroundColor = params.bg;
if(params.hideStatus === 'true') hideStatus = 'true';
switch(body.data.discord_status){
case "online":
switch (body.data.discord_status) {
case "online":
avatarBorderColor = "#43B581";
break;
case "idle":
case "idle":
avatarBorderColor = "#FAA61A";
break;
case "dnd":
case "dnd":
avatarBorderColor = "#F04747";
break;
case "offline":
case "offline":
avatarBorderColor = "#747F8D";
break;
}
let flags: string[] = getFlags(body.data.discord_user.public_flags);
const flags: string[] = getFlags(body.data.discord_user.public_flags);
if(body.data.activities[0] && body.data.activities[0].state && body.data.activities[0].type === 4) userStatus = body.data.activities[0].state;
if (body.data.activities[0] && body.data.activities[0].state && body.data.activities[0].type === 4) userStatus = body.data.activities[0].state;
console.log(Object.keys(body.data.activities).length);
@@ -100,8 +92,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
width: 80px;
">
<img ${body.data.discord_user.avatar !== null ?
`src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256`)}"` :
`src="data:image/png;base64,${defaultAvatar}"`}
`src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256`)}"` :
`src="data:image/png;base64,${defaultAvatar}"`}
style="
border: solid 3px ${avatarBorderColor};
border-radius: 50%;
@@ -125,33 +117,24 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
transform: translate(0, -50%);
height: 25px;
">
<h1 style="
font-size: 1.15rem;
margin: 0 5px 0 0;
">
${body.data.discord_user.username}${discrim !== 'hide' ?
`<span style="color: ${theme === 'dark' ? '#ccc' : '#666'}; font-weight: lighter;">#${body.data.discord_user.discriminator}</span>`
: ''}
${body.data.discord_user.username}${discrim !== 'hide' ? `
<span style="color: ${theme === 'dark' ? '#ccc' : '#666'}; font-weight: lighter;">#${body.data.discord_user.discriminator}</span>` : ''}
</h1>
${
flags.map((v) => {
return(
`<img src="data:image/png;base64,${Badges[v]}" style="
width: 20px;
height: 20px;
position: relative;
top: 50%;
transform: translate(0%, -50%);
margin: 0 0 0 4px;
" />`
)
}).join('')
}
${flags.map((v) => `
<img src="data:image/png;base64,${Badges[v]}" style="
width: 20px;
height: 20px;
position: relative;
top: 50%;
transform: translate(0%, -50%);
margin: 0 0 0 4px;
" />`).join('')}
</div>
${userStatus.length > 0 && hideStatus !== "true" ? `
<h1 style="
font-size: 0.9rem;
@@ -162,31 +145,21 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
white-space: nowrap;
text-overflow: ellipsis;
">
${body.data.activities[0].emoji && body.data.activities[0].emoji.id ?
`<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/emojis/${body.data.activities[0].emoji.id}.${statusExtension}`)}" style="
width: 15px;
height: 15px;
position: relative;
top: 10px;
transform: translate(0%, -50%);
margin: 0 2px 0 0;
" />`
: ``}
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id ?
body.data.activities[0].emoji.name + ' ' + userStatus
:
userStatus
}
</h1>`
: ``}
${body.data.activities[0].emoji && body.data.activities[0].emoji.id ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/emojis/${body.data.activities[0].emoji.id}.${statusExtension}`)}" style="
width: 15px;
height: 15px;
position: relative;
top: 10px;
transform: translate(0%, -50%);
margin: 0 2px 0 0;
" />`: ``}
${body.data.activities[0].emoji && !body.data.activities[0].emoji.id ? body.data.activities[0].emoji.name + ' ' + userStatus : userStatus}
</h1>` : ``}
</div>
</div>
${activity ?
`
${activity ? `
<div style="
display: flex;
flex-direction: row;
@@ -200,16 +173,14 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
width: auto;
height: auto;
">
${activity.assets && activity.assets.large_image ?
`
${activity.assets && activity.assets.large_image ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.webp`)}" style="
width: 80px;
height: 80px;
border: solid 0.5px #222;
border-radius: 10px;
"/>
`
: `
` : `
<img src="data:image/png;base64,${await encodeBase64(`https://lanyard-profile-readme.vercel.app/assets/unknown.png`)}" style="
width: 70px;
height: 70px;
@@ -217,17 +188,14 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
filter: invert(100);
"/>
`}
${activity.assets && activity.assets.small_image ?
`<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.webp`)}" style="
${activity.assets && activity.assets.small_image ? `
<img src="data:image/png;base64,${await encodeBase64(`https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.webp`)}" style="
width: 30px;
height: 30px;
border-radius: 50%;
margin-left: -26px;
margin-bottom: -8px;
"/>`
: ``}
"/>`: ``}
</div>
<div style="
color: #999;
@@ -245,90 +213,81 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
height: 15px;
margin: 7px 0;
">${activity.name}</p>
${activity.details ?
`<p style="
${activity.details ? `
<p style="
color: ${theme === 'dark' ? '#ccc' : '#777'};
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
height: 15px;
margin: 7px 0;
">${activity.details}</p>`
: ``}
">${activity.details}</p>` : ``}
</div>
</div>
`
: ``}
`: ``}
${body.data.listening_to_spotify === true && body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 ?
${body.data.listening_to_spotify === true && body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 ? `
<div style="
display: flex;
flex-direction: row;
height: 120px;
margin-left: 15px;
font-size: 0.8rem;
padding-top: 18px;
">
<img src="data:image/png;base64,${await encodeBase64(body.data.spotify.album_art_url)}" style="
width: 80px;
height: 80px;
border: solid 0.5px #222;
border-radius: 10px;
margin-right: 15px;
"/>
`
<div style="
display: flex;
flex-direction: row;
height: 120px;
margin-left: 15px;
font-size: 0.8rem;
padding-top: 18px;
">
<img src="data:image/png;base64,${await encodeBase64(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;
margin-top: -3px;
line-height: 1;
width: 279px;
">
<p style="font-size: 0.75rem; color: ${theme === 'dark' ? '#1CB853' : '#0d943d'}; margin-bottom: 15px;">LISTENING NOW...</p>
<p style="
height: 15px;
color: ${theme === 'dark' ? '#fff' : '#000'};
font-weight: bold;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin: 7px 0;
">${body.data.spotify.song.replace(/\&/g, "and")}</p>
<p style="
margin: 7px 0;
height: 15px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: ${theme === 'dark' ? '#ccc' : '#777'};
">By ${body.data.spotify.artist.replace(/\;/g, ",").replace(/\&/g, "and")}</p>
</div>
</div>
`
: ``}
${!activity && body.data.listening_to_spotify === false ?
`<div style="
display: flex;
flex-direction: row;
height: 150px;
justify-content: center;
align-items: center;
">
<p style="
font-style: italic;
font-size: 0.8rem;
color: ${theme === 'dark' ? '#aaa' : '#444'};
height: auto;
">
I'm not currently doing anything!
</p>
</div>`
: ``}
<div style="
color: #999;
margin-top: -3px;
line-height: 1;
width: 279px;
">
<p style="font-size: 0.75rem; color: ${theme === 'dark' ? '#1CB853' : '#0d943d'}; margin-bottom: 15px;">LISTENING NOW...</p>
<p style="
height: 15px;
color: ${theme === 'dark' ? '#fff' : '#000'};
font-weight: bold;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin: 7px 0;
">${body.data.spotify.song.replace(/\&/g, "and")}</p>
<p style="
margin: 7px 0;
height: 15px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: ${theme === 'dark' ? '#ccc' : '#777'};
">By ${body.data.spotify.artist.replace(/\;/g, ",").replace(/\&/g, "and")}</p>
</div>
</div>
` : ``}
${!activity && body.data.listening_to_spotify === false ?
`<div style="
display: flex;
flex-direction: row;
height: 150px;
justify-content: center;
align-items: center;
">
<p style="
font-style: italic;
font-size: 0.8rem;
color: ${theme === 'dark' ? '#aaa' : '#444'};
height: auto;
">
I'm not currently doing anything!
</p>
</div>`
: ``}
</div>
</foreignObject>

View File

@@ -1,22 +1,13 @@
const imageToBase64 = require('image-to-base64');
import imageToBase64 from "image-to-base64";
const encodeBase64 = async (url: string): Promise<string> => {
export const encodeBase64 = async (url: string): Promise<string> => {
let response = "";
let encoded: string = '';
try {
response = await imageToBase64(url);
} catch (e) {
console.log(e)
}
await imageToBase64(url)
.then(
(response: string) => {
return encoded = response;
}
)
.catch(
(error: any) => {
console.log(error);
}
)
return encoded;
}
export default encodeBase64;
return response;
}

View File

@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
@@ -14,6 +18,13 @@
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"pages/_document.js"
],
"exclude": [
"node_modules"
]
}

View File

@@ -279,6 +279,11 @@
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
"@types/image-to-base64@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@types/image-to-base64/-/image-to-base64-2.1.0.tgz#8c77b09b7988df3a9a2a4278bbcc27efabbec379"
integrity sha512-UgmqJVJyPIkzzI23TWqLc9iO+hZTzNoVD0rEf+I70FeKtcxxvLIlKJ5CrejkxkvDc/8/lk9yswSYZoAv8eyOYQ==
"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"