Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

mamba fix og (#34483)

Goszczuacdef459e02d
diff --git a/apps/www/app/api-v2/ticket-og/route.tsx b/apps/www/app/api-v2/ticket-og/route.tsx
index e8cef7087b1..54fef782eb5 100644
--- a/apps/www/app/api-v2/ticket-og/route.tsx
+++ b/apps/www/app/api-v2/ticket-og/route.tsx
@@ -18,20 +18,157 @@ const SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL
const STORAGE_URL = `${SUPABASE_URL}/storage/v1/object/public/images/launch-week/lw14`
// Load custom font
-const FONT_URL = `${STORAGE_URL}/assets/font/Nippo-Regular.otf`
-const MONO_FONT_URL = `${STORAGE_URL}/assets/font/DepartureMono-Regular.otf`
-const font = fetch(new URL(FONT_URL, import.meta.url)).then((res) => res.arrayBuffer())
-const mono_font = fetch(new URL(MONO_FONT_URL, import.meta.url)).then((res) => res.arrayBuffer())
+// const FONT_URL = `${STORAGE_URL}/assets/font/Nippo-Regular.otf`
+// const MONO_FONT_URL = `${STORAGE_URL}/assets/font/DepartureMono-Regular.otf`
+
+const FONT_URL = '/fonts/launchweek/14/Nippo-Regular.otf'
+const MONO_FONT_URL = '/fonts/launchweek/14/DepartureMono-Regular.otf'
const LW_TABLE = 'tickets'
const LW_MATERIALIZED_VIEW = 'tickets_view'
+const usernameToLines = (username: string): string[] => {
+ const maxLineLength = 14
+
+ const nonBreakingReplacements = [
+ { regexp: new RegExp(' ', 'g'), replacement: '\u00A0' }, // Space → Non-breaking space
+ { regexp: new RegExp('-', 'g'), replacement: '\u2011' }, // Hyphen → Non-breaking hyphen
+ { regexp: new RegExp('/', 'g'), replacement: '\u2060\u002F\u2060' }, // Slash with word joiners
+ { regexp: new RegExp('\\.', 'g'), replacement: '\u2024' }, // One dot leader (alternative to period)
+ ]
+ const allowList = [...nonBreakingReplacements.map((x) => x.regexp), new RegExp('\\w', 'g')]
+ .map((x) => x.source.replace('-', '\\-'))
+ .join('|')
+ const allowRegexp = new RegExp(`[^${allowList}]`, 'g')
+ const allowdUsername = username.replace(allowRegexp, '')
+ // Split only by spaces, keeping hyphenated words together
+ const words = allowdUsername.split(' ')
+ const lines: string[] = []
+ let currentLine = ''
+
+ // First try to break at word boundaries (spaces only)
+ for (const word of words) {
+ // If adding this word would exceed the line length and we already have content
+ if (
+ currentLine.length + (currentLine ? 1 : 0) + word.length > maxLineLength &&
+ currentLine.length > 0
+ ) {
+ // Add current line to lines array and start a new line
+ lines.push(currentLine)
+ currentLine = word
+ } else {
+ // Add word to current line with a space if needed
+ currentLine = currentLine ? `${currentLine} ${word}` : word
+ }
+ }
+
+ // Add the last line if it has content
+ if (currentLine) {
+ lines.push(currentLine)
+ }
+
+ // If we still have too few lines but some are too long, split them by character
+ // but try to avoid splitting at hyphens
+ let finalLines: string[] = []
+ for (const line of lines) {
+ if (line.length > maxLineLength) {
+ // For long words, try to find good break points
+ let remainingText = line
+ while (remainingText.length > 0) {
+ if (remainingText.length <= maxLineLength) {
+ finalLines.push(remainingText)
+ break
+ }
+
+ // Try to find a good break point that's not a hyphen
+ let breakPoint = maxLineLength
+
+ // Look for a hyphen in the potential break area (a few chars before maxLineLength)
+ const searchArea = remainingText.substring(Math.max(0, breakPoint - 5), breakPoint + 1)
+ const hyphenPos = searchArea.indexOf('-')
+
+ // If we found a hyphen, adjust the break point to keep the hyphenated word together
+ if (hyphenPos >= 0) {
+ // Calculate the actual position in the original string
+ const actualHyphenPos = Math.max(0, breakPoint - 5) + hyphenPos
+
+ // If hyphen is near the beginning, include the whole hyphenated word on next line
+ if (actualHyphenPos < maxLineLength / 2) {
+ breakPoint = actualHyphenPos
+ }
+ // If hyphen is near the end, include the whole hyphenated word on this line
+ else {
+ // Find the end of the hyphenated word
+ const spaceAfterHyphen = remainingText.indexOf(' ', actualHyphenPos)
+ if (spaceAfterHyphen > 0 && spaceAfterHyphen - actualHyphenPos < 10) {
+ // If the rest of the hyphenated word is reasonably short, keep it together
+ breakPoint = spaceAfterHyphen
+ }
+ }
+ }
+
+ finalLines.push(remainingText.substring(0, breakPoint))
+ remainingText = remainingText.substring(breakPoint).trim()
+ }
+ } else {
+ finalLines.push(line)
+ }
+ }
+
+ // Limit to 3 lines maximum
+ if (finalLines.length > 3) {
+ finalLines = finalLines.slice(0, 2)
+ // Truncate the last line if needed and add ellipsis
+ let lastLine = finalLines[2] || ''
+ if (lastLine.length > 8) {
+ lastLine = lastLine.slice(0, 8) + '...'
+ }
+ finalLines.push(lastLine)
+ }
+
+ finalLines = finalLines.map((line, index) => {
+ let result = line
+ nonBreakingReplacements.forEach(({ regexp, replacement }) => {
+ result = result.replace(regexp, replacement)
+ })
+
+ if (index < finalLines.length - 1) {
+ result = result.padEnd(maxLineLength, '\u00A0')
+ }
+ return result
+ })
+
+ // Ensure we don't have more than 3 lines
+ return finalLines.slice(0, 3)
+}
+
export async function GET(req: Request, res: Response) {
const url = new URL(req.url)
+
+ // Just here to silence snyk false positives
+ // Verify that req.url is from an allowed domain
+ const allowedDomains = ['supabase.com', '-supabase.vercel.app', 'localhost:3000']
+
+ const isAllowedDomain = allowedDomains.some(
+ (domain) =>
+ url.hostname === domain ||
+ (domain.startsWith('-') && url.hostname.endsWith(domain)) ||
+ (url.hostname === 'localhost' && url.port === '3000')
+ )
+
+ if (!isAllowedDomain) {
+ return new Response(JSON.stringify({ error: 'Unauthorized domain' }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 403,
+ })
+ }
+
const username = url.searchParams.get('username') ?? url.searchParams.get('amp;username')
- const assumePlatinum = url.searchParams.get('platinum') ?? url.searchParams.get('amp;platinum')
const userAgent = req.headers.get('user-agent')
+ const font = fetch(new URL(FONT_URL, url)).then((res) => res.arrayBuffer())
+ const mono_font = fetch(new URL(MONO_FONT_URL, url)).then((res) => res.arrayBuffer())
+
try {
if (!username) throw new Error('missing username param')
@@ -80,12 +217,18 @@ export async function GET(req: Request, res: Response) {
} = user
const platinum = isPlatinum ?? (!!sharedOnTwitter && !!sharedOnLinkedIn) ?? false
- if (assumePlatinum && !platinum) return await fetch(`${STORAGE_URL}/images/og-14-platinum.png`)
+ const platinumSecret = platinum && secret
const seatCode = (466561 + (ticket_number || 0)).toString(36).toUpperCase()
// Generate image and upload to storage.
- const ticketType = secret ? 'secret' : platinum ? 'platinum' : 'regular'
+ const ticketType = secret
+ ? platinum
+ ? 'platinumSecret'
+ : 'secret'
+ : platinum
+ ? 'platinum'
+ : 'regular'
const STYLING_CONFIG = () => ({
TICKET_FOREGROUND: themes()[ticketType].TICKET_FOREGROUND,
@@ -104,6 +247,10 @@ export async function GET(req: Request, res: Response) {
color: 'rgba(255, 199, 58)',
background: 'rgba(255, 199, 58, 0.2)',
},
+ platinumSecret: {
+ color: 'rgba(255, 199, 58)',
+ background: 'rgba(255, 199, 58, 0.2)',
+ },
}
const fontData = await font
@@ -115,46 +262,44 @@ export async function GET(req: Request, res: Response) {
const BACKGROUND = () => ({
regular: {
- LOGO: `${STORAGE_URL}/assets/supabase/supabase-logo-icon.png?v4`,
- BACKGROUND_IMG: `${STORAGE_URL}/assets/og-14-regular.png`,
+ BACKGROUND_IMG: new URL(`/images/launchweek/14/og-14-regular.png`, url).href,
},
platinum: {
- LOGO: `${STORAGE_URL}/assets/supabase/supabase-logo-icon.png?v4`,
- BACKGROUND_IMG: `${STORAGE_URL}/assets/og-14-platinum.png`,
+ BACKGROUND_IMG: new URL(`/images/launchweek/14/og-14-platinum.png`, url).href,
+ },
+ platinumSecret: {
+ BACKGROUND_IMG: new URL(`/images/launchweek/14/og-14-platinum-secret.png`, url).href,
},
secret: {
- LOGO: `${STORAGE_URL}/assets/supabase/supabase-logo-icon.png?v4`,
- BACKGROUND_IMG: `${STORAGE_URL}/assets/og-14-secret.png`,
+ BACKGROUND_IMG: new URL(`/images/launchweek/14/og-14-secret.png`, url).href,
},
})
- const usernameToLines = (username: string): string[] => {
- const lineLenght = 12
-
- const line1 = username.slice(0, lineLenght).trim().replace(/ /g, '\u00A0')
- const line2 = username
- .slice(lineLenght, lineLenght * 2)
- .trim()
- .replace(/ /g, '\u00A0')
- let line3 = username
- .slice(lineLenght * 2)
- .trim()
- .replace(/ /g, '\u00A0')
-
- // NOTE: If third line is too long, trim to 8 characters and add '...'
- if (line3.length > lineLenght) {
- line3 = line3.slice(0, 8) + '...'
- }
-
- // NOTE: Only include non-empty lines
- return [line1, line2, line3].filter((line) => line.length > 0)
- }
+ const NOISE = new URL('/images/launchweek/14/noise-pattern.png', url).href
const computeBackgroundWidth = (letters: number) => {
return 100 + (letters * 40 + (letters - 1) * 12)
}
const lines = usernameToLines(name ?? username)
+ const secretStyles = {
+ background: 'linear-gradient(0deg, rgb(18 18 18 / 0.5) 50%, transparent 50%)',
+ backgroundSize: '100% 6px, 0px 100%',
+ }
+
+ const testStyles = {
+ background: 'red',
+ backgroundSize: '100% 6px, 0px 100%',
+ }
+
+ const secretTextStyles = {
+ textShadow: '0 0 15px rgba(52,211,153,0.8)',
+ }
+
+ const platinumSecretTextStyles = {
+ textShadow: '0 0 15px rgba(255,199,58,0.8)',
+ }
+
const generatedTicketImage = new ImageResponse(
(
<>
@@ -181,7 +326,6 @@ export async function GET(req: Request, res: Response) {
left: '-2px',
bottom: '-2px',
right: '-2px',
- zIndex: '0',
backgroundSize: 'cover',
backgroundColor: STYLING_CONFIG().TICKET_FOREGROUND,
}}
@@ -197,6 +341,8 @@ export async function GET(req: Request, res: Response) {
color: TICKET_THEME[ticketType].color,
top: 70,
right: 135,
+ ...(secret ? secretTextStyles : {}),
+ ...(platinumSecret ? platinumSecretTextStyles : {}),
}}
>
{seatCode}
@@ -227,12 +373,41 @@ export async function GET(req: Request, res: Response) {
fontSize: '82px',
lineHeight: '56px',
display: 'flex',
+ ...(secret ? secretTextStyles : {}),
+ ...(platinumSecret ? platinumSecretTextStyles : {}),
}}
>
{line}
</p>
</div>
))}
+
+ {secret && (
+ <div
+ style={{
+ position: 'absolute',
+ top: '0px',
+ left: '0px',
+ right: '0px',
+ bottom: '0px',
+ ...secretStyles,
+ }}
+ />
+ )}
+
+ {secret && (
+ <img
+ src={NOISE}
+ style={{
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ opacity: '0.1',
+ }}
+ />
+ )}
</div>
</>
),
@@ -260,7 +435,7 @@ export async function GET(req: Request, res: Response) {
)
// [Note] Uncomment only for local testing to return the image directly and skip storage upload.
- // return await generatedTicketImage
+ // return generatedTicketImage
// Upload image to storage.
const { error: storageError } = await supabaseAdminClient.storage
diff --git a/apps/www/components/LaunchWeek/14/utils/ticketThemes.tsx b/apps/www/components/LaunchWeek/14/utils/ticketThemes.tsx
index b692fef56ed..7693a461b66 100644
--- a/apps/www/components/LaunchWeek/14/utils/ticketThemes.tsx
+++ b/apps/www/components/LaunchWeek/14/utils/ticketThemes.tsx
@@ -8,4 +8,7 @@ export const themes = () => ({
secret: {
TICKET_FOREGROUND: '#1F1F1F',
},
+ platinumSecret: {
+ TICKET_FOREGROUND: '#1F1F1F',
+ },
})
diff --git a/apps/www/public/images/launchweek/14/noise-pattern.png b/apps/www/public/images/launchweek/14/noise-pattern.png
new file mode 100644
index 00000000000..be5bfb97529
Binary files /dev/null and b/apps/www/public/images/launchweek/14/noise-pattern.png differ
diff --git a/apps/www/public/images/launchweek/14/og-14-platinum-secret.png b/apps/www/public/images/launchweek/14/og-14-platinum-secret.png
new file mode 100644
index 00000000000..43ad06285ef
Binary files /dev/null and b/apps/www/public/images/launchweek/14/og-14-platinum-secret.png differ
diff --git a/apps/www/public/images/launchweek/14/og-14-secret.png b/apps/www/public/images/launchweek/14/og-14-secret.png
index 22dbb998e83..c34fc38b8dd 100644
Binary files a/apps/www/public/images/launchweek/14/og-14-secret.png and b/apps/www/public/images/launchweek/14/og-14-secret.png differ