From 942c018bd942279a929f9577f38e1e4930493ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Mon, 22 May 2023 23:39:24 -0700 Subject: [PATCH] Fallbacks custom logo if no team was found (#9051) Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> --- apps/web/pages/api/logo.ts | 53 +++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/apps/web/pages/api/logo.ts b/apps/web/pages/api/logo.ts index 5afdedeb16..6abe10e3ae 100644 --- a/apps/web/pages/api/logo.ts +++ b/apps/web/pages/api/logo.ts @@ -23,35 +23,40 @@ const logoApiSchema = z.object({ const SYSTEM_SUBDOMAINS = ["console", "app", "www"]; async function getTeamLogos(subdomain: string) { - if ( - // if not cal.com - IS_SELF_HOSTED || - // missing subdomain (empty string) - !subdomain || - // in SYSTEM_SUBDOMAINS list - SYSTEM_SUBDOMAINS.includes(subdomain) - ) { + try { + if ( + // if not cal.com + IS_SELF_HOSTED || + // missing subdomain (empty string) + !subdomain || + // in SYSTEM_SUBDOMAINS list + SYSTEM_SUBDOMAINS.includes(subdomain) + ) { + throw new Error("No custom logo needed"); + } + // load from DB + const { default: prisma } = await import("@calcom/prisma"); + const team = await prisma.team.findUniqueOrThrow({ + where: { + slug: subdomain, + }, + select: { + appLogo: true, + appIconLogo: true, + }, + }); + // try to use team logos, otherwise default to LOGO/LOGO_ICON regardless + return { + appLogo: team.appLogo || `${WEBAPP_URL}${LOGO}`, + appIconLogo: team.appIconLogo || `${WEBAPP_URL}${LOGO_ICON}`, + }; + } catch (error) { + if (error instanceof Error) console.error(error.message); return { appLogo: `${WEBAPP_URL}${LOGO}`, appIconLogo: `${WEBAPP_URL}${LOGO_ICON}`, }; } - // load from DB - const { default: prisma } = await import("@calcom/prisma"); - const team = await prisma.team.findUniqueOrThrow({ - where: { - slug: subdomain, - }, - select: { - appLogo: true, - appIconLogo: true, - }, - }); - // try to use team logos, otherwise default to LOGO/LOGO_ICON regardless - return { - appLogo: team.appLogo || `${WEBAPP_URL}${LOGO}`, - appIconLogo: team.appIconLogo || `${WEBAPP_URL}${LOGO_ICON}`, - }; } /**