From 6f88ab8f30b69beedaee2f738207676ed14beedd Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 15 Oct 2024 19:26:04 +0100 Subject: [PATCH] move og image to backend --- bun.lockb | Bin 309104 -> 317776 bytes projects/backend/package.json | 4 ++- .../src/common/open-graph.tsx} | 28 ++++++++---------- .../src/controller/player.controller.ts | 10 +++++++ .../{player.service.ts => player.service.tsx} | 14 +++++++++ projects/backend/tsconfig.json | 1 + .../src/app/(pages)/player/[...slug]/page.tsx | 8 +---- 7 files changed, 41 insertions(+), 24 deletions(-) rename projects/{website/src/app/(pages)/api/og/player/route.tsx => backend/src/common/open-graph.tsx} (73%) rename projects/backend/src/service/{player.service.ts => player.service.tsx} (93%) diff --git a/bun.lockb b/bun.lockb index 06e8afcc62fb64f0296e3c6052225440f6ac6573..ad0c102317085101079825d0f7b0bd9dbbc10411 100755 GIT binary patch delta 10809 zcmeHNcU)9Q*S>pqK^CMVML+?u;x0{Dkce2K#*P&+CW5RqWu;gX1x<`4!ID)cVmE5+ zB?_nn#THud#R`fbRzT73IlHrFzr1^!ZqEBe`f zv9g`^{?6)Gzh+NM&pjn>t+JQRDyV$%S%Gz^b>#B1<1Fl>3yWm}Jre1X$Y$b<+Pzb! zHffZqjvkvX2-@l5Mg;n+Om6IfGhFi+K` zS`ciYxBgo$?$FJ_k9w-NPm501q$UVL_ZmTH0^S#rysL$DgB&+*d~`ZWv4L(6{nax; zu!9^MJwZJ_VY*rZ9<}J38LytINR5jTo+D!`7?eX=K#mmk@)mSCbgP&8>PB%nF*->@ z)i!}n@qM0ZFFKCvmQ}0IW?XDSDn+ZOs>h-c1m}9a9~O{Q-}iO;?7l}sQ*ke$Q~fII zw9}oM*(JZ#n?-Xu*32beYL7{v1!rakT2SmeWj4kT(~R$LgcMQtpoOqe(iKk)8WnF!u%U< zE-eP1o|$Dm=hg2KgEYr#ZQBN3&M`IZ=zr!1)8{d*apUzY?`TmP#-zIx?Xw*A; z^4=9?-F;9*$+kxUM0M%u0NZ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^*gDUf=8gIQOUSEEe5{E=A-%16)> z>g7!^{0kj&oO^s5fChAb= zT<04;0K>m0q1e6v zWwt46VWisEv{ELkYV^QahA+JITAyXi9Sf2>VgHTQ$51}`S zp^zsQ?ovZGf3JorDRh=y3i&I94#@K%??DX6Umy!1B@hXrgLXD#n6G?VRVz(vWjnL_ zy6KPZRc5r&M#pA)r*J|>$sk|#b;a)Mp5?11n1U!Z(R&8Hi?|@8<*sI`p`20OPg>Lp zlWB$QXjP+a@d!(Yo8By*mcy)SqI}b;PLQ{(>gRHUpW4N`@)iaRS5kocs-Kz=>7oIo zpY$^|i5TqPI<0c{eyAUh$45l1rP1#plwwJ!5g$S76>PFc5R@H2iykfC=1xddlVdG#dM@{f zOm*5DT`kH4=OkCbBq2&Kct7V1bN9b{Am!)R6w`AKyTgtQ@&!D&U9ow_>1%sj{v#A= z+pk7OBOuw1KlBCx*rJM!b&(nKd;7FeWN!qR6gk2Z=Np122Ecy@aoE(0A8XMzqtmhC zzbSGa0*dHHo$RT0hiLjR)_3Lk#xp%n{#p5@b*<{WpUzILTU`3_g5o$&>$;+fX!<-B z-FuGlVr_L7PqQ3$lbEifU67o0@uX+ zys`QD1+K0?{p8-2n?Suxwd-=x0rhHh(^tK1e{fWEc-8-F&!dv<$nulrs)Op-p~gk; zw>HbG=a;`V*4!u5^judvo{6mnoPq%V!%5x{w!Aj|E zX|GfxQkp&^ep2@Qm1!9(-uJXHg$AJMLu1NUJ6fJ@c5jBqAIwY`se2gzUF z$WTM%_Da>N^uHtbSE`--BEIx4?(8yE4yrOox#O!;-PC>h4ev73k8bN;6Wx8Q0UHO~ z;@p1oX3lP>F8_D`%rft7ns0V5s8;*d$+J7mBjm$fW*_$}JI#G8GBz5;4u{Q0npp>I z_MSIh*erdj%n1o=m1VOwIQkyGmmfLz=em1aMy=eQc(~`Jz%?9~x @@ -42,7 +33,12 @@ export async function GET(request: NextRequest) {

#{formatNumberWithCommas(player.rank)}

- Player's Country + {/* eslint-disable-next-line @next/next/no-img-element */} + Player's Country

#{formatNumberWithCommas(player.countryRank)}

diff --git a/projects/backend/src/controller/player.controller.ts b/projects/backend/src/controller/player.controller.ts index 9e09b0b..4bfe294 100644 --- a/projects/backend/src/controller/player.controller.ts +++ b/projects/backend/src/controller/player.controller.ts @@ -51,4 +51,14 @@ export default class PlayerController { }; } } + + @Get("/og/:id", { + config: {}, + params: t.Object({ + id: t.String({ required: true }), + }), + }) + public async getOpenGraphImage({ params: { id } }: { params: { id: string } }) { + return await PlayerService.generateOpenGraphImage(id); + } } diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.tsx similarity index 93% rename from projects/backend/src/service/player.service.ts rename to projects/backend/src/service/player.service.tsx index 35537a0..26e2b52 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.tsx @@ -5,6 +5,7 @@ import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token"; import { InternalServerError } from "../error/internal-server-error"; import ScoreSaberPlayerScoreToken from "@ssr/common/types/token/scoresaber/score-saber-player-score-token"; +import { generatePlayerOgImage } from "../common/open-graph"; export class PlayerService { /** @@ -155,4 +156,17 @@ export class PlayerService { `Updated scores set statistic for "${playerName}"(${playerId}), scores today: ${scores.rankedScores} ranked, ${scores.unrankedScores} unranked` ); } + + /** + * Generates the OpenGraph image for the player + * + * @param id the player's id + */ + public static async generateOpenGraphImage(id: string) { + const player = await scoresaberService.lookupPlayer(id); + if (player == undefined) { + return undefined; + } + return generatePlayerOgImage(player); + } } diff --git a/projects/backend/tsconfig.json b/projects/backend/tsconfig.json index 0002c94..39cee78 100644 --- a/projects/backend/tsconfig.json +++ b/projects/backend/tsconfig.json @@ -10,5 +10,6 @@ "skipLibCheck": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, + "jsx": "react" } } diff --git a/projects/website/src/app/(pages)/player/[...slug]/page.tsx b/projects/website/src/app/(pages)/player/[...slug]/page.tsx index 155635c..2d5c015 100644 --- a/projects/website/src/app/(pages)/player/[...slug]/page.tsx +++ b/projects/website/src/app/(pages)/player/[...slug]/page.tsx @@ -95,15 +95,9 @@ export async function generateMetadata(props: Props): Promise { title: `${player.name}`, openGraph: { title: `ScoreSaber Reloaded - ${player.name}`, - // description: ` - // PP: ${formatPp(player.pp)}pp - // Rank: #${formatNumberWithCommas(player.rank)} (#${formatNumberWithCommas(player.countryRank)} ${player.country}) - // Joined ScoreSaber: ${format(player.joinedDate, { date: "medium", time: "short" })} - // - // View the scores for ${player.name}!`, images: [ { - url: `${config.siteUrl}/api/og/player/?id=${player.id}`, + url: `${config.siteApi}/player/og/${player.id}`, }, ], },