Files
breakpilot-core/pitch-deck/lib/short-links.ts
T
Sharang Parnerkar 76aad8b1d1
Build pitch-deck / build-push-deploy (push) Successful in 1m31s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 32s
CI / test-python-voice (push) Successful in 34s
CI / test-bqas (push) Successful in 30s
feat(pitch-deck): branded short links for magic URLs (pitch.breakpilot.ai/p/ab3xk2)
- New pitch_short_links table stores 6-char alphanumeric codes mapped to magic link tokens
- GET /p/[code] redirects to /auth/verify?token=... (302, validates expiry)
- All magic link generation points (invite, generate-link, resend) now create a short code
- Emails (invite + resend) use the short URL — less token-like, cleaner for spam filters
- Copy-link UI shows short URL prominently with full URL as fallback
- Migration 008 added to /api/admin/migrate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 10:34:24 +02:00

29 lines
908 B
TypeScript

import 'server-only'
import { randomBytes } from 'crypto'
import pool from '@/lib/db'
// Alphanumeric, confusable chars removed (0, 1, i, l, o)
const CHARS = 'abcdefghjkmnpqrstuvwxyz23456789'
function generateCode(): string {
const bytes = randomBytes(6)
return Array.from(bytes, b => CHARS[b % CHARS.length]).join('')
}
export async function createShortLink(token: string): Promise<string> {
for (let attempt = 0; attempt < 10; attempt++) {
const code = generateCode()
try {
await pool.query(
`INSERT INTO pitch_short_links (short_code, token) VALUES ($1, $2)`,
[code, token],
)
const baseUrl = process.env.PITCH_BASE_URL || 'https://pitch.breakpilot.ai'
return `${baseUrl}/p/${code}`
} catch {
// Unique constraint collision — retry with a new code
}
}
throw new Error('Failed to generate unique short code after 10 attempts')
}