diff --git a/api/index.ts b/api/index.ts index a4dfc15..195b5b6 100644 --- a/api/index.ts +++ b/api/index.ts @@ -55,13 +55,12 @@ export default async function readmeStats(req: any, res: any): Promise { !isValidHexColor(uiConfig.strokeColor) ) throw new Error("Enter a valid hex color code"); - var fetchStats = await getData(username); res.setHeader("Cache-Control", "s-maxage=3600, stale-while-revalidate"); - if (req.query.format === "json") { + if (uiConfig.Format === "json") { res.json(fetchStats); - } else if (req.query.format === "png") { + } else if (uiConfig.Format === "png") { const svgBuffer = Buffer.from(cardStyle(fetchStats, uiConfig)) as any; const options = { resvg: { font: { defaultFontFamily: '"Segoe UI"', serifFamily: 'Ubuntu', sansSerifFamily: 'sans-serif' }, background: 'rgba(0, 0, 0, .0)' } as any, format: 'png' as any }; svg2img(svgBuffer as any, options, (error: Error | null, buffer: Buffer | null) => { diff --git a/src/card.ts b/src/card.ts index 975f8d8..0e2e1e4 100644 --- a/src/card.ts +++ b/src/card.ts @@ -3,24 +3,6 @@ import type { UiConfig } from "../api/index"; import { locales, Locales } from "./translations"; import { parseBoolean } from "./common/utils"; -type CardsUi = { - direction?: string; - titleXAngle?: number | string; - titleYAngle?: number | string; - textXAngle?: number | string; - textYAngle?: number | string; - dataXAngle?: number | string; - dataYAngle?: number | string; - iconXAngle?: number | string; - iconYAngle?: number | string; - imageXAngle?: number | string; - imageYAngle?: number | string; - userXAngle?: number | string; - userYAngle?: number | string; - follXAngle?: number | string; - follYAngle?: number | string; -}; - export default function cardStyle(data: GetData, uiConfig: UiConfig): string { let fallbackLocale = "en"; const defaultLocale: Locales[keyof Locales] = locales[fallbackLocale]; @@ -67,86 +49,47 @@ export default function cardStyle(data: GetData, uiConfig: UiConfig): string { animation: fadeInAnimation 0.3s ease-in-out forwards; }`; - var cardsUi: CardsUi = { - direction: "ltr", - titleXAngle: 5, - titleYAngle: -10, - textXAngle: 25, - textYAngle: 12.5, - dataXAngle: 225, - dataYAngle: 12.5, - iconXAngle: 0, - iconYAngle: 0, - imageXAngle: 125, - imageYAngle: 65, - userXAngle: 109.9, - userYAngle: 130, - follXAngle: 110, - follYAngle: 151, - }; + var direction = "ltr", + titleXAngle = 5, + titleYAngle = -10, + textXAngle = 25, + textYAngle = 12.5, + dataXAngle = 225, + dataYAngle = 12.5, + iconXAngle = 0, + iconYAngle = 0, + imageXAngle = 125, + imageYAngle = 65, + userXAngle = 109.9, + userYAngle = 130, + follXAngle = 110, + follYAngle = 151; if (parseBoolean(selectLocale.rtlDirection)) { - var cardsUi: CardsUi = { - direction: "rtl", - titleXAngle: 510, - titleYAngle: -10, - textXAngle: 215, - textYAngle: 12.5, - dataXAngle: 15, - dataYAngle: 12.5, - iconXAngle: 225, - iconYAngle: 0, - imageXAngle: 125, - imageYAngle: 65, - userXAngle: 109.9, - userYAngle: 130, - follXAngle: 110, - follYAngle: 151, - }; + var direction = "rtl", + titleXAngle = 510, + textXAngle = 215, + dataXAngle = 15, + iconXAngle = 225; }; - if (parseBoolean(uiConfig.disabledAnimations)) { + if (parseBoolean(uiConfig.disabledAnimations) || uiConfig.Format === "png") { var animations = ""; - var cardsUi: CardsUi = { - direction: "ltr", - titleXAngle: 15, - titleYAngle: 0, - textXAngle: 25, - textYAngle: 12.5, - dataXAngle: 225, - dataYAngle: 12.5, - iconXAngle: 0, - iconYAngle: 0, - imageXAngle: 120, - imageYAngle: 70, - userXAngle: 119.9, - userYAngle: 140, - follXAngle: 120, - follYAngle: 161, - }; + var titleXAngle = 15, + titleYAngle = 0, + imageXAngle = 120, + imageYAngle = 70, + userXAngle = 119.9, + userYAngle = 140, + follXAngle = 120, + follYAngle = 161; if (parseBoolean(selectLocale.rtlDirection)) { - var cardsUi: CardsUi = { - direction: "rtl", - titleXAngle: 520, - titleYAngle: 0, - textXAngle: 215, - textYAngle: 12.5, - dataXAngle: 15, - dataYAngle: 12.5, - iconXAngle: 225, - iconYAngle: 0, - imageXAngle: 120, - imageYAngle: 70, - userXAngle: 119.9, - userYAngle: 140, - follXAngle: 120, - follYAngle: 161, - }; + var titleXAngle = 520; }; }; - var card = ` + var card = `