feat(referral): marketing flyer PDF generator (#688)

@coderabbitai ignore

## Summary
- **Marketing Flyer Generator**: Print-ready PDF flyers (light + dark
themes) with personalized referral code, discount, and styled QR code
- Server-side rendering via headless Chromium (added to Dockerfile)
- Available from QR Code dialog (user) and admin referrals table (admin)

## Changes

### Backend
- **New:** `flyer_service.py` — Template rendering + headless Chromium
PDF generation
- **New:** `POST /api/referrals/me/flyer` — User flyer endpoint
- **New:** `POST /api/referrals/admin/links/{code}/flyer` — Admin flyer
endpoint
- **New:** Light + dark HTML flyer templates (from kjbox printables)
- **Modified:** `Dockerfile.base` — Added `chromium` package

### Frontend
- **Modified:** `QRCodeDialog.tsx` — Theme picker + Generate Flyer
button, error handling
- **Modified:** Admin referrals page — Flyer button per row
- **New:** `generateFlyer()` API client function (user + admin)
- **i18n:** 5 new flyer-related strings

### Infrastructure
- **Dockerfile.base change** — Adds Chromium (~200MB). Base image
rebuild required.

## Test plan
- [x] 8 backend unit tests (template substitution, validation, Chromium
flags)
- [x] 11 frontend tests (QR dialog + flyer controls)
- [x] 721 total frontend tests passing
- [x] Local Chrome PDF verification (user confirmed)
- [x] Docker container PDF verification (Chromium 146, fonts + gradients
correct)
- [x] End-to-end test with real styled QR code (user confirmed
scannable)
- [ ] Manual: QR dialog → pick theme → Generate Flyer → verify PDF
- [ ] Manual: Admin referrals → flyer button → verify PDF

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andrew Beveridge ☄️andClaude Opus 4.6 authored and GitHub committed 2026-04-05 22:36:03 -04:00
1 parent ab174f4d07
commit e441b854c6
14 files changed
+2256 -18

No files matched your search

+1
View File
@@ -23,6 +23,7 @@ RUN apt-get update && apt-get install -y \
build-essential \
curl \
xz-utils \
chromium \
&& rm -rf /var/lib/apt/lists/*
# Install comprehensive font support for international lyrics and symbols
+70
View File
@@ -11,6 +11,8 @@ import logging
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi.responses import Response
from pydantic import BaseModel, Field
from backend.api.dependencies import require_auth, require_admin
from backend.models.referral import (
@@ -18,6 +20,7 @@ from backend.models.referral import (
UpdateReferralLinkRequest,
ReferralInterstitialResponse,
)
from backend.services.flyer_service import get_flyer_service, FlyerError
from backend.services.referral_service import get_referral_service
@@ -26,6 +29,11 @@ logger = logging.getLogger(__name__)
router = APIRouter(prefix="/referrals", tags=["referrals"])
class GenerateFlyerRequest(BaseModel):
theme: str = Field(..., pattern="^(light|dark)$")
qr_data_url: str = Field(..., max_length=500_000)
# ============================================================================
# Public endpoints
# ============================================================================
@@ -118,6 +126,35 @@ async def start_stripe_connect(auth=Depends(require_auth)):
return {"account_id": account_id, "onboarding_url": onboarding_url}
@router.post("/me/flyer")
async def generate_flyer(
request: GenerateFlyerRequest,
auth=Depends(require_auth),
):
"""Generate a personalized referral flyer PDF."""
service = get_referral_service()
link = service.get_or_create_link(auth.user_email)
try:
flyer_service = get_flyer_service()
pdf_bytes = flyer_service.generate_pdf(
theme=request.theme,
referral_code=link.code,
discount_percent=link.discount_percent,
qr_data_url=request.qr_data_url,
)
except FlyerError as e:
raise HTTPException(status_code=400, detail=str(e))
return Response(
content=pdf_bytes,
media_type="application/pdf",
headers={
"Content-Disposition": 'attachment; filename="nomad-karaoke-referral-flyer.pdf"',
},
)
# ============================================================================
# Admin endpoints
# ============================================================================
@@ -231,3 +268,36 @@ async def update_link(
raise HTTPException(status_code=404, detail=message)
return {"ok": True, "message": message}
@router.post("/admin/links/{code}/flyer")
async def admin_generate_flyer(
code: str,
request: GenerateFlyerRequest,
auth=Depends(require_admin),
):
"""Admin: generate a personalized referral flyer PDF for any code."""
service = get_referral_service()
link = service.get_link_by_code(code)
if not link:
raise HTTPException(status_code=404, detail=f"Referral link '{code}' not found")
try:
flyer_service = get_flyer_service()
pdf_bytes = flyer_service.generate_pdf(
theme=request.theme,
referral_code=link.code,
discount_percent=link.discount_percent,
qr_data_url=request.qr_data_url,
)
except FlyerError as e:
raise HTTPException(status_code=400, detail=str(e))
return Response(
content=pdf_bytes,
media_type="application/pdf",
headers={
"Content-Disposition": f'attachment; filename="nomad-karaoke-flyer-{link.code}.pdf"',
},
)
+141
View File
@@ -0,0 +1,141 @@
"""Service for generating personalized referral flyer PDFs."""
import logging
import os
import shutil
import subprocess
import tempfile
logger = logging.getLogger(__name__)
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "..", "templates", "printables")
CHROMIUM_PATHS = [
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/bin/google-chrome",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
]
VALID_THEMES = {"light", "dark"}
MAX_QR_DATA_URL_BYTES = 500_000
class FlyerError(Exception):
"""Error during flyer generation."""
class FlyerService:
"""Generates personalized referral flyer PDFs."""
def __init__(self):
self._chromium_path: str | None = None
def _get_chromium(self) -> str:
"""Lazily find Chromium binary. Only needed when generating PDFs."""
if self._chromium_path:
return self._chromium_path
for path in CHROMIUM_PATHS:
if os.path.exists(path):
self._chromium_path = path
return path
for name in ["chromium", "chromium-browser", "google-chrome"]:
found = shutil.which(name)
if found:
self._chromium_path = found
return found
raise FlyerError("Chromium not found. Install chromium to generate flyer PDFs.")
def _validate_qr_data_url(self, qr_data_url: str) -> None:
if not qr_data_url.startswith("data:image/"):
raise FlyerError("Invalid QR data URL: must be a data:image/ URL")
if len(qr_data_url) > MAX_QR_DATA_URL_BYTES:
raise FlyerError(f"QR data URL too large (>{MAX_QR_DATA_URL_BYTES} bytes)")
def _render_template(
self,
theme: str,
referral_code: str,
discount_percent: int,
qr_data_url: str,
) -> str:
if theme not in VALID_THEMES:
raise FlyerError(f"Invalid theme: {theme}. Must be one of: {VALID_THEMES}")
suffix = "-dark" if theme == "dark" else ""
template_path = os.path.join(TEMPLATE_DIR, f"website-referral-flyer{suffix}.html")
with open(template_path) as f:
html = f.read()
html = html.replace("{{REFERRAL_CODE}}", referral_code.upper())
html = html.replace("{{REFERRAL_CODE_LOWER}}", referral_code.lower())
html = html.replace("{{DISCOUNT_PERCENT}}", str(discount_percent))
html = html.replace("{{QR_DATA_URL}}", qr_data_url)
return html
def generate_pdf(
self,
theme: str,
referral_code: str,
discount_percent: int,
qr_data_url: str,
) -> bytes:
"""Generate a personalized flyer PDF. Returns raw PDF bytes."""
self._validate_qr_data_url(qr_data_url)
html = self._render_template(theme, referral_code, discount_percent, qr_data_url)
with tempfile.NamedTemporaryFile(
suffix=".html", delete=False, mode="w", encoding="utf-8"
) as tmp_html:
tmp_html.write(html)
tmp_html_path = tmp_html.name
tmp_pdf_path = tmp_html_path.replace(".html", ".pdf")
try:
cmd = [
self._get_chromium(),
"--headless",
f"--print-to-pdf={tmp_pdf_path}",
"--no-margins",
"--print-background",
"--no-pdf-header-footer",
"--virtual-time-budget=5000",
"--paper-width=8.5",
"--paper-height=11",
"--disable-gpu",
"--no-sandbox",
tmp_html_path,
]
result = subprocess.run(
cmd, capture_output=True, text=True, timeout=30
)
if result.returncode != 0:
logger.error("Chromium PDF generation failed: %s", result.stderr)
raise FlyerError(f"PDF generation failed: {result.stderr[:200]}")
if not os.path.exists(tmp_pdf_path):
raise FlyerError("PDF generation failed: no output file created")
with open(tmp_pdf_path, "rb") as f:
return f.read()
finally:
for path in [tmp_html_path, tmp_pdf_path]:
try:
os.unlink(path)
except OSError:
pass
_flyer_service = None
def get_flyer_service() -> FlyerService:
global _flyer_service
if _flyer_service is None:
_flyer_service = FlyerService()
return _flyer_service
@@ -0,0 +1,362 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nomad Karaoke - Make Your Own Karaoke Videos</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Outfit:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<style>
*, html { margin: 0; padding: 0; box-sizing: border-box; }
@page {
size: 8.5in 11in;
margin: 0;
}
body {
width: 8.5in;
height: 11in;
overflow: hidden;
position: relative;
font-family: 'Outfit', sans-serif;
background: #0c0a1a;
color: #fff;
}
/* Dark atmospheric background */
.bg {
position: absolute;
inset: 0;
background:
radial-gradient(ellipse 80% 50% at 50% 0%, rgba(120, 40, 200, 0.35) 0%, transparent 70%),
radial-gradient(ellipse 60% 40% at 20% 80%, rgba(255, 50, 120, 0.2) 0%, transparent 60%),
radial-gradient(ellipse 50% 30% at 85% 70%, rgba(255, 180, 40, 0.15) 0%, transparent 60%),
linear-gradient(180deg, #0c0a1a 0%, #1a1035 40%, #0c0a1a 100%);
z-index: 0;
}
.content {
position: relative;
z-index: 2;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
padding: 0.6in 0.65in 0.5in;
}
/* Logo at top */
.logo-container {
margin-bottom: 24px;
}
.logo-svg {
width: 260px;
height: auto;
}
/* Headline */
.headline {
font-family: 'Bebas Neue', sans-serif;
text-align: center;
line-height: 0.92;
margin-bottom: 6px;
}
.headline-main {
font-size: 96px;
letter-spacing: 3px;
background: linear-gradient(180deg, #ffd86b 0%, #ff7acc 50%, #c45aff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.headline-sub {
font-size: 62px;
letter-spacing: 2px;
color: #fff;
}
/* Subtitle */
.subtitle {
font-size: 20px;
font-weight: 500;
color: rgba(255, 255, 255, 0.7);
text-align: center;
max-width: 5.5in;
line-height: 1.4;
margin-bottom: 28px;
}
/* Steps section */
.steps {
display: flex;
flex-direction: column;
gap: 18px;
width: 100%;
max-width: 6in;
margin-bottom: 28px;
}
.step {
display: flex;
align-items: center;
gap: 18px;
}
.step-number {
width: 52px;
height: 52px;
flex-shrink: 0;
border-radius: 50%;
background: linear-gradient(135deg, #c45aff, #ff7acc);
display: flex;
align-items: center;
justify-content: center;
font-family: 'Bebas Neue', sans-serif;
font-size: 30px;
color: #fff;
letter-spacing: 1px;
}
.step-content {
flex: 1;
}
.step-title {
font-size: 22px;
font-weight: 800;
color: #fff;
letter-spacing: -0.3px;
}
.step-desc {
font-size: 16px;
font-weight: 400;
color: rgba(255, 255, 255, 0.6);
margin-top: 2px;
}
/* Divider */
.divider {
width: 80%;
height: 2px;
background: linear-gradient(90deg, transparent, rgba(255, 122, 204, 0.4), rgba(255, 216, 107, 0.4), transparent);
margin: 4px 0 24px;
}
/* CTA section */
.cta-section {
display: flex;
align-items: center;
justify-content: center;
gap: 40px;
width: 100%;
margin-bottom: 20px;
}
.qr-container {
width: 180px;
height: 180px;
border-radius: 16px;
background: #fff;
border: 3px solid rgba(255, 255, 255, 0.15);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
box-shadow: 0 4px 20px rgba(0,0,0,0.06);
overflow: hidden;
}
.qr-container img {
width: 100%;
height: 100%;
object-fit: contain;
}
.qr-placeholder {
font-size: 14px;
color: #999;
text-align: center;
padding: 20px;
}
.cta-text {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.cta-label {
font-size: 16px;
font-weight: 600;
color: rgba(255, 255, 255, 0.6);
text-transform: uppercase;
letter-spacing: 2px;
margin-bottom: 6px;
}
.cta-url {
font-family: 'Bebas Neue', sans-serif;
font-size: 38px;
letter-spacing: 2px;
color: #ffd86b;
line-height: 1;
white-space: nowrap;
}
.cta-url .referral-code {
background: linear-gradient(135deg, #ff7acc 0%, #c45aff 40%, #ff5a8a 70%, #ffdf6b 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
letter-spacing: 4px;
}
.cta-note {
font-size: 15px;
color: rgba(255, 255, 255, 0.5);
margin-top: 8px;
font-weight: 500;
}
/* Bottom section */
.bottom {
margin-top: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.bottom-features {
display: flex;
gap: 24px;
}
.bottom-feature {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
color: rgba(255, 255, 255, 0.5);
}
.bottom-feature-icon {
font-size: 20px;
}
.bottom-tagline {
font-size: 14px;
font-weight: 500;
color: rgba(255, 255, 255, 0.4);
letter-spacing: 1px;
}
@media print {
body {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
</style>
</head>
<body>
<div class="bg"></div>
<div class="content">
<!-- Logo -->
<div class="logo-container">
<svg class="logo-svg" viewBox="45 60 255 135" xmlns="http://www.w3.org/2000/svg">
<g fill="#ff7acc" transform="translate(48.368003845214844,62.62239074707031)"><g transform="translate(0,0)"><g transform="scale(1.4000000000000004)"><g stroke="#ff7acc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" paint-order="stroke" fill-opacity="0"><path d="M1.4-33.44L1.4 0C31.48 0 3.96 0 34.04 0L34.04-32.64 17.81-32.64 17.81-20.61 1.4-33.44ZM52.21-33.76C42.6-33.76 34.81-25.97 34.81-16.37 34.81-6.76 42.6 1.03 52.21 1.03 61.81 1.03 69.6-6.76 69.6-16.37 69.6-25.97 61.81-33.76 52.21-33.76ZM70.7 0L103.34 0 103.25-33.9 86.93-21.54 70.61-33.9 70.7 0ZM102.34 0C138.2 0 107.52 0 143.56 0L122.95-34.93 102.34 0ZM158.84 0.05C167.84 0.05 175.16-7.27 175.16-16.27 175.16-25.27 167.84-32.64 158.84-32.64L142.52-32.64C142.52 0.75 142.52-33.34 142.52 0.05L158.84 0.05Z" transform="translate(-1.399999976158142, 34.93000030517578)"></path></g><g transform="translate(0,38.959999084472656)"><g stroke="#ff7acc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" paint-order="stroke" fill="#ff7acc" fill-opacity="0" transform="scale(1.02719)"><path d="M24.43 0L17.67 0 7.98-11.87 7.98 0 2.63 0 2.63-26.64 7.98-26.64 7.98-14.69 17.67-26.64 24.12-26.64 13.13-13.44 24.43 0ZM45.03 0L43.27-5.08 32.66-5.08 30.91 0 25.3 0 34.88-26.68 41.1-26.68 50.68 0 45.03 0ZM34.11-9.35L41.82-9.35 37.97-20.5 34.11-9.35ZM73.19 0L67.01 0 61.13-10.38 58.61-10.38 58.61 0 53.27 0 53.27-26.64 63.27-26.64Q66.36-26.64 68.53-25.55 70.71-24.47 71.8-22.61 72.89-20.76 72.89-18.47L72.89-18.47Q72.89-15.84 71.36-13.72 69.83-11.6 66.82-10.8L66.82-10.8 73.19 0ZM58.61-22.21L58.61-14.39 63.08-14.39Q65.25-14.39 66.32-15.44 67.39-16.49 67.39-18.36L67.39-18.36Q67.39-20.19 66.32-21.2 65.25-22.21 63.08-22.21L63.08-22.21 58.61-22.21ZM94.82 0L93.07-5.08 82.46-5.08 80.7 0 75.09 0 84.67-26.68 90.89-26.68 100.47 0 94.82 0ZM83.91-9.35L91.62-9.35 87.76-20.5 83.91-9.35ZM115.43 0.27Q111.69 0.27 108.56-1.49 105.43-3.24 103.6-6.35 101.76-9.47 101.76-13.4L101.76-13.4Q101.76-17.29 103.6-20.4 105.43-23.51 108.56-25.27 111.69-27.02 115.43-27.02L115.43-27.02Q119.21-27.02 122.32-25.27 125.43-23.51 127.24-20.4 129.05-17.29 129.05-13.4L129.05-13.4Q129.05-9.47 127.24-6.35 125.43-3.24 122.3-1.49 119.17 0.27 115.43 0.27L115.43 0.27ZM115.43-4.5Q117.83-4.5 119.66-5.59 121.5-6.68 122.53-8.7 123.56-10.73 123.56-13.4L123.56-13.4Q123.56-16.07 122.53-18.07 121.5-20.08 119.66-21.15 117.83-22.21 115.43-22.21L115.43-22.21Q113.02-22.21 111.17-21.15 109.32-20.08 108.29-18.07 107.26-16.07 107.26-13.4L107.26-13.4Q107.26-10.73 108.29-8.7 109.32-6.68 111.17-5.59 113.02-4.5 115.43-4.5L115.43-4.5ZM153.82 0L147.06 0 137.37-11.87 137.37 0 132.02 0 132.02-26.64 137.37-26.64 137.37-14.69 147.06-26.64 153.51-26.64 142.52-13.44 153.82 0ZM171.79-22.33L161.67-22.33 161.67-15.65 170.64-15.65 170.64-11.41 161.67-11.41 161.67-4.35 171.79-4.35 171.79 0 156.33 0 156.33-26.68 171.79-26.68 171.79-22.33Z" transform="translate(-2.630000114440918, 27.020000457763672)"></path></g></g></g></g>
<g fill-rule="" fill="#ffdf6b" transform="translate(5,111.788818359375)"><rect x="0" height="1" y="5.9832000732421875" width="14.278396606445312"></rect><rect height="1" y="5.9832000732421875" width="14.278396606445312" x="218.985595703125"></rect><g transform="translate(17.278396606445312,0)"><g transform="scale(1.2800000000000002)"><path d="M10.21-8.38L12.02-8.38L9.68 0L7.70 0L6.13-5.96L4.49 0L2.52 0.01L0.26-8.38L2.06-8.38L3.54-1.87L5.24-8.38L7.12-8.38L8.72-1.91L10.21-8.38ZM18.38-8.38L20.06-8.38L20.06 0L18.38 0L18.38-3.56L14.80-3.56L14.80 0L13.12 0L13.12-8.38L14.80-8.38L14.80-4.93L18.38-4.93L18.38-8.38ZM26.58-7.02L23.40-7.02L23.40-4.92L26.22-4.92L26.22-3.59L23.40-3.59L23.40-1.37L26.58-1.37L26.58 0L21.72 0L21.72-8.39L26.58-8.39L26.58-7.02ZM34.37 0L32.42 0L30.58-3.26L29.78-3.26L29.78 0L28.10 0L28.10-8.38L31.25-8.38Q32.22-8.38 32.90-8.03Q33.59-7.69 33.93-7.11Q34.27-6.53 34.27-5.81L34.27-5.81Q34.27-4.98 33.79-4.31Q33.31-3.65 32.36-3.40L32.36-3.40L34.37 0ZM29.78-6.98L29.78-4.52L31.19-4.52Q31.87-4.52 32.21-4.85Q32.54-5.18 32.54-5.77L32.54-5.77Q32.54-6.35 32.21-6.67Q31.87-6.98 31.19-6.98L31.19-6.98L29.78-6.98ZM40.66-7.02L37.48-7.02L37.48-4.92L40.30-4.92L40.30-3.59L37.48-3.59L37.48-1.37L40.66-1.37L40.66 0L35.80 0L35.80-8.39L40.66-8.39L40.66-7.02ZM47.92-8.38L49.70-8.38L46.63 0L44.59 0L41.52-8.38L43.32-8.38L45.62-1.72L47.92-8.38ZM55.57-7.02L52.39-7.02L52.39-4.92L55.21-4.92L55.21-3.59L52.39-3.59L52.39-1.37L55.57-1.37L55.57 0L50.71 0L50.71-8.39L55.57-8.39L55.57-7.02ZM63.36 0L61.42 0L59.57-3.26L58.78-3.26L58.78 0L57.10 0L57.10-8.38L60.24-8.38Q61.21-8.38 61.90-8.03Q62.58-7.69 62.92-7.11Q63.26-6.53 63.26-5.81L63.26-5.81Q63.26-4.98 62.78-4.31Q62.30-3.65 61.36-3.40L61.36-3.40L63.36 0ZM58.78-6.98L58.78-4.52L60.18-4.52Q60.86-4.52 61.20-4.85Q61.54-5.18 61.54-5.77L61.54-5.77Q61.54-6.35 61.20-6.67Q60.86-6.98 60.18-6.98L60.18-6.98L58.78-6.98ZM72.43-8.38L74.30-8.38L71.47-2.92L71.47 0L69.79 0L69.79-2.92L66.95-8.38L68.84-8.38L70.64-4.55L72.43-8.38ZM79.16 0.08Q77.99 0.08 77.00-0.47Q76.02-1.02 75.44-2.00Q74.87-2.98 74.87-4.21L74.87-4.21Q74.87-5.44 75.44-6.41Q76.02-7.39 77.00-7.94Q77.99-8.50 79.16-8.50L79.16-8.50Q80.35-8.50 81.33-7.94Q82.31-7.39 82.88-6.41Q83.45-5.44 83.45-4.21L83.45-4.21Q83.45-2.98 82.88-2.00Q82.31-1.02 81.32-0.47Q80.34 0.08 79.16 0.08L79.16 0.08ZM79.16-1.42Q79.92-1.42 80.50-1.76Q81.07-2.10 81.40-2.74Q81.72-3.37 81.72-4.21L81.72-4.21Q81.72-5.05 81.40-5.68Q81.07-6.31 80.50-6.65Q79.92-6.98 79.16-6.98L79.16-6.98Q78.41-6.98 77.83-6.65Q77.24-6.31 76.92-5.68Q76.60-5.05 76.60-4.21L76.60-4.21Q76.60-3.37 76.92-2.74Q77.24-2.10 77.83-1.76Q78.41-1.42 79.16-1.42L79.16-1.42ZM84.67-8.38L86.35-8.38L86.35-3.19Q86.35-2.34 86.80-1.89Q87.24-1.44 88.04-1.44L88.04-1.44Q88.86-1.44 89.30-1.89Q89.75-2.34 89.75-3.19L89.75-3.19L89.75-8.38L91.44-8.38L91.44-3.20Q91.44-2.14 90.98-1.40Q90.52-0.66 89.74-0.29Q88.97 0.08 88.02 0.08L88.02 0.08Q87.08 0.08 86.32-0.29Q85.56-0.66 85.12-1.40Q84.67-2.14 84.67-3.20L84.67-3.20L84.67-8.38ZM101.60 0L101.05-1.60L97.72-1.60L97.16 0L95.40 0L98.41-8.39L100.37-8.39L103.38 0L101.60 0ZM98.17-2.94L100.60-2.94L99.38-6.44L98.17-2.94ZM110.77 0L108.83 0L106.98-3.26L106.19-3.26L106.19 0L104.51 0L104.51-8.38L107.65-8.38Q108.62-8.38 109.31-8.03Q109.99-7.69 110.33-7.11Q110.68-6.53 110.68-5.81L110.68-5.81Q110.68-4.98 110.20-4.31Q109.72-3.65 108.77-3.40L108.77-3.40L110.77 0ZM106.19-6.98L106.19-4.52L107.59-4.52Q108.28-4.52 108.61-4.85Q108.95-5.18 108.95-5.77L108.95-5.77Q108.95-6.35 108.61-6.67Q108.28-6.98 107.59-6.98L107.59-6.98L106.19-6.98ZM117.06-7.02L113.88-7.02L113.88-4.92L116.70-4.92L116.70-3.59L113.88-3.59L113.88-1.37L117.06-1.37L117.06 0L112.20 0L112.20-8.39L117.06-8.39L117.06-7.02ZM118.72-1.76L120.42-1.76L119.02 1.61L117.94 1.61L118.72-1.76ZM127.38 0.08Q126.50 0.08 125.80-0.22Q125.10-0.52 124.69-1.08Q124.28-1.64 124.27-2.41L124.27-2.41L126.07-2.41Q126.11-1.90 126.44-1.60Q126.77-1.30 127.34-1.30L127.34-1.30Q127.93-1.30 128.27-1.58Q128.60-1.86 128.60-2.32L128.60-2.32Q128.60-2.69 128.38-2.93Q128.15-3.17 127.81-3.31Q127.46-3.44 126.86-3.61L126.86-3.61Q126.05-3.85 125.54-4.09Q125.03-4.32 124.66-4.79Q124.30-5.27 124.30-6.06L124.30-6.06Q124.30-6.80 124.67-7.36Q125.04-7.91 125.71-8.20Q126.38-8.50 127.25-8.50L127.25-8.50Q128.54-8.50 129.35-7.87Q130.16-7.24 130.25-6.11L130.25-6.11L128.40-6.11Q128.38-6.54 128.03-6.82Q127.69-7.10 127.13-7.10L127.13-7.10Q126.64-7.10 126.34-6.85Q126.05-6.60 126.05-6.12L126.05-6.12Q126.05-5.78 126.27-5.56Q126.49-5.34 126.82-5.20Q127.15-5.06 127.75-4.88L127.75-4.88Q128.57-4.64 129.08-4.40Q129.60-4.16 129.97-3.68Q130.34-3.20 130.34-2.42L130.34-2.42Q130.34-1.75 130.00-1.18Q129.65-0.60 128.98-0.26Q128.30 0.08 127.38 0.08L127.38 0.08ZM131.80-8.38L133.48-8.38L133.48 0L131.80 0L131.80-8.38ZM142.30-8.39L142.30 0L140.62 0L136.81-5.75L136.81 0L135.13 0L135.13-8.39L136.81-8.39L140.62-2.63L140.62-8.39L142.30-8.39ZM151.72-5.86L149.78-5.86Q149.50-6.38 148.99-6.66Q148.49-6.94 147.82-6.94L147.82-6.94Q147.07-6.94 146.50-6.60Q145.92-6.26 145.60-5.64Q145.27-5.02 145.27-4.20L145.27-4.20Q145.27-3.36 145.60Line truncated
</svg>
</svg>
</div>
<!-- Headline -->
<div class="headline">
<div class="headline-main">MAKE YOUR OWN</div>
<div class="headline-sub">KARAOKE VIDEOS</div>
</div>
<!-- Subtitle -->
<div class="subtitle">
Turn any song into a professional karaoke video with synced lyrics, vocal removal, and automatic YouTube publishing.
</div>
<!-- How it works -->
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<div class="step-title">Pick any song</div>
<div class="step-desc">Search by artist &amp; title or paste a YouTube link</div>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<div class="step-title">Our system does the work</div>
<div class="step-desc">Vocals removed, lyrics synced, video rendered automatically</div>
</div>
</div>
<div class="step">
<div class="step-number">3</div>
<div class="step-content">
<div class="step-title">Review &amp; correct the lyrics and instrumental</div>
<div class="step-desc">Fine-tune everything before publishing</div>
</div>
</div>
<div class="step">
<div class="step-number">4</div>
<div class="step-content">
<div class="step-title">Download or publish to YouTube</div>
<div class="step-desc">Get your finished karaoke video in minutes</div>
</div>
</div>
</div>
<div class="divider"></div>
<!-- CTA with QR code -->
<div class="cta-section">
<div class="qr-container">
<!-- Replace src with actual QR code image path -->
<img src="{{QR_DATA_URL}}" alt="QR Code - nomadkaraoke.com/r/{{REFERRAL_CODE_LOWER}}">
</div>
<div class="cta-text">
<div class="cta-label">First track free + {{DISCOUNT_PERCENT}}% off with this link</div>
<div class="cta-url">NOMADKARAOKE.COM/R/<span class="referral-code">{{REFERRAL_CODE}}</span></div>
<div class="cta-note">Scan the QR code or visit the link above</div>
</div>
</div>
<!-- Bottom -->
<div class="bottom">
<div class="bottom-features">
<div class="bottom-feature">
<span class="bottom-feature-icon">&#127908;</span>
<span>Any Song</span>
</div>
<div class="bottom-feature">
<span class="bottom-feature-icon">&#9889;</span>
<span>Automatic</span>
</div>
<div class="bottom-feature">
<span class="bottom-feature-icon">&#127916;</span>
<span>Pro Quality</span>
</div>
</div>
<div class="bottom-tagline">Wherever you are, sing!</div>
</div>
</div>
</body>
</html>
@@ -0,0 +1,359 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nomad Karaoke - Make Your Own Karaoke Videos</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Outfit:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<style>
*, html { margin: 0; padding: 0; box-sizing: border-box; }
@page {
size: 8.5in 11in;
margin: 0;
}
body {
width: 8.5in;
height: 11in;
overflow: hidden;
position: relative;
font-family: 'Outfit', sans-serif;
background: #faf8f5;
color: #1a1a1a;
position: relative;
}
/* Simple gradient background */
.bg {
position: absolute;
inset: 0;
background: linear-gradient(180deg, #faf8f5 0%, #f3eff8 100%);
z-index: 0;
}
.content {
position: relative;
z-index: 2;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
padding: 0.6in 0.65in 0.5in;
}
/* Logo at top */
.logo-container {
margin-bottom: 24px;
}
.logo-svg {
width: 260px;
height: auto;
}
/* Headline */
.headline {
font-family: 'Bebas Neue', sans-serif;
text-align: center;
line-height: 0.92;
margin-bottom: 6px;
}
.headline-main {
font-size: 96px;
letter-spacing: 3px;
background: linear-gradient(135deg, #c45aff 0%, #ff7acc 50%, #ff5a8a 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.headline-sub {
font-size: 62px;
letter-spacing: 2px;
color: #1a1a1a;
}
/* Subtitle */
.subtitle {
font-size: 20px;
font-weight: 500;
color: #555;
text-align: center;
max-width: 5.5in;
line-height: 1.4;
margin-bottom: 28px;
}
/* Steps section */
.steps {
display: flex;
flex-direction: column;
gap: 18px;
width: 100%;
max-width: 6in;
margin-bottom: 28px;
}
.step {
display: flex;
align-items: center;
gap: 18px;
}
.step-number {
width: 52px;
height: 52px;
flex-shrink: 0;
border-radius: 50%;
background: linear-gradient(135deg, #c45aff, #ff7acc);
display: flex;
align-items: center;
justify-content: center;
font-family: 'Bebas Neue', sans-serif;
font-size: 30px;
color: #fff;
letter-spacing: 1px;
}
.step-content {
flex: 1;
}
.step-title {
font-size: 22px;
font-weight: 800;
color: #1a1a1a;
letter-spacing: -0.3px;
}
.step-desc {
font-size: 16px;
font-weight: 400;
color: #666;
margin-top: 2px;
}
/* Divider */
.divider {
width: 80%;
height: 2px;
background: linear-gradient(90deg, transparent, rgba(196, 90, 255, 0.3), rgba(255, 122, 204, 0.3), transparent);
margin: 4px 0 24px;
}
/* CTA section */
.cta-section {
display: flex;
align-items: center;
justify-content: center;
gap: 40px;
width: 100%;
margin-bottom: 20px;
}
.qr-container {
width: 180px;
height: 180px;
border-radius: 16px;
background: #fff;
border: 3px solid #e8e4e0;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
box-shadow: 0 4px 20px rgba(0,0,0,0.06);
overflow: hidden;
}
.qr-container img {
width: 100%;
height: 100%;
object-fit: contain;
}
.qr-placeholder {
font-size: 14px;
color: #999;
text-align: center;
padding: 20px;
}
.cta-text {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.cta-label {
font-size: 16px;
font-weight: 600;
color: #888;
text-transform: uppercase;
letter-spacing: 2px;
margin-bottom: 6px;
}
.cta-url {
font-family: 'Bebas Neue', sans-serif;
font-size: 38px;
letter-spacing: 2px;
color: #1a1a1a;
line-height: 1;
white-space: nowrap;
}
.cta-url .referral-code {
background: linear-gradient(135deg, #ff7acc 0%, #c45aff 40%, #ff5a8a 70%, #ffdf6b 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
letter-spacing: 4px;
}
.cta-note {
font-size: 15px;
color: #888;
margin-top: 8px;
font-weight: 500;
}
/* Bottom section */
.bottom {
margin-top: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.bottom-features {
display: flex;
gap: 24px;
}
.bottom-feature {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
color: #888;
}
.bottom-feature-icon {
font-size: 20px;
}
.bottom-tagline {
font-size: 14px;
font-weight: 500;
color: #aaa;
letter-spacing: 1px;
}
@media print {
body {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
</style>
</head>
<body>
<div class="bg"></div>
<div class="content">
<!-- Logo -->
<div class="logo-container">
<svg class="logo-svg" viewBox="45 60 255 135" xmlns="http://www.w3.org/2000/svg">
<g fill="#ff7acc" transform="translate(48.368003845214844,62.62239074707031)"><g transform="translate(0,0)"><g transform="scale(1.4000000000000004)"><g stroke="#ff7acc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" paint-order="stroke" fill-opacity="0"><path d="M1.4-33.44L1.4 0C31.48 0 3.96 0 34.04 0L34.04-32.64 17.81-32.64 17.81-20.61 1.4-33.44ZM52.21-33.76C42.6-33.76 34.81-25.97 34.81-16.37 34.81-6.76 42.6 1.03 52.21 1.03 61.81 1.03 69.6-6.76 69.6-16.37 69.6-25.97 61.81-33.76 52.21-33.76ZM70.7 0L103.34 0 103.25-33.9 86.93-21.54 70.61-33.9 70.7 0ZM102.34 0C138.2 0 107.52 0 143.56 0L122.95-34.93 102.34 0ZM158.84 0.05C167.84 0.05 175.16-7.27 175.16-16.27 175.16-25.27 167.84-32.64 158.84-32.64L142.52-32.64C142.52 0.75 142.52-33.34 142.52 0.05L158.84 0.05Z" transform="translate(-1.399999976158142, 34.93000030517578)"></path></g><g transform="translate(0,38.959999084472656)"><g stroke="#ff7acc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" paint-order="stroke" fill="#ff7acc" fill-opacity="0" transform="scale(1.02719)"><path d="M24.43 0L17.67 0 7.98-11.87 7.98 0 2.63 0 2.63-26.64 7.98-26.64 7.98-14.69 17.67-26.64 24.12-26.64 13.13-13.44 24.43 0ZM45.03 0L43.27-5.08 32.66-5.08 30.91 0 25.3 0 34.88-26.68 41.1-26.68 50.68 0 45.03 0ZM34.11-9.35L41.82-9.35 37.97-20.5 34.11-9.35ZM73.19 0L67.01 0 61.13-10.38 58.61-10.38 58.61 0 53.27 0 53.27-26.64 63.27-26.64Q66.36-26.64 68.53-25.55 70.71-24.47 71.8-22.61 72.89-20.76 72.89-18.47L72.89-18.47Q72.89-15.84 71.36-13.72 69.83-11.6 66.82-10.8L66.82-10.8 73.19 0ZM58.61-22.21L58.61-14.39 63.08-14.39Q65.25-14.39 66.32-15.44 67.39-16.49 67.39-18.36L67.39-18.36Q67.39-20.19 66.32-21.2 65.25-22.21 63.08-22.21L63.08-22.21 58.61-22.21ZM94.82 0L93.07-5.08 82.46-5.08 80.7 0 75.09 0 84.67-26.68 90.89-26.68 100.47 0 94.82 0ZM83.91-9.35L91.62-9.35 87.76-20.5 83.91-9.35ZM115.43 0.27Q111.69 0.27 108.56-1.49 105.43-3.24 103.6-6.35 101.76-9.47 101.76-13.4L101.76-13.4Q101.76-17.29 103.6-20.4 105.43-23.51 108.56-25.27 111.69-27.02 115.43-27.02L115.43-27.02Q119.21-27.02 122.32-25.27 125.43-23.51 127.24-20.4 129.05-17.29 129.05-13.4L129.05-13.4Q129.05-9.47 127.24-6.35 125.43-3.24 122.3-1.49 119.17 0.27 115.43 0.27L115.43 0.27ZM115.43-4.5Q117.83-4.5 119.66-5.59 121.5-6.68 122.53-8.7 123.56-10.73 123.56-13.4L123.56-13.4Q123.56-16.07 122.53-18.07 121.5-20.08 119.66-21.15 117.83-22.21 115.43-22.21L115.43-22.21Q113.02-22.21 111.17-21.15 109.32-20.08 108.29-18.07 107.26-16.07 107.26-13.4L107.26-13.4Q107.26-10.73 108.29-8.7 109.32-6.68 111.17-5.59 113.02-4.5 115.43-4.5L115.43-4.5ZM153.82 0L147.06 0 137.37-11.87 137.37 0 132.02 0 132.02-26.64 137.37-26.64 137.37-14.69 147.06-26.64 153.51-26.64 142.52-13.44 153.82 0ZM171.79-22.33L161.67-22.33 161.67-15.65 170.64-15.65 170.64-11.41 161.67-11.41 161.67-4.35 171.79-4.35 171.79 0 156.33 0 156.33-26.68 171.79-26.68 171.79-22.33Z" transform="translate(-2.630000114440918, 27.020000457763672)"></path></g></g></g></g>
<g fill-rule="" fill="#ffdf6b" transform="translate(5,111.788818359375)"><rect x="0" height="1" y="5.9832000732421875" width="14.278396606445312"></rect><rect height="1" y="5.9832000732421875" width="14.278396606445312" x="218.985595703125"></rect><g transform="translate(17.278396606445312,0)"><g transform="scale(1.2800000000000002)"><path d="M10.21-8.38L12.02-8.38L9.68 0L7.70 0L6.13-5.96L4.49 0L2.52 0.01L0.26-8.38L2.06-8.38L3.54-1.87L5.24-8.38L7.12-8.38L8.72-1.91L10.21-8.38ZM18.38-8.38L20.06-8.38L20.06 0L18.38 0L18.38-3.56L14.80-3.56L14.80 0L13.12 0L13.12-8.38L14.80-8.38L14.80-4.93L18.38-4.93L18.38-8.38ZM26.58-7.02L23.40-7.02L23.40-4.92L26.22-4.92L26.22-3.59L23.40-3.59L23.40-1.37L26.58-1.37L26.58 0L21.72 0L21.72-8.39L26.58-8.39L26.58-7.02ZM34.37 0L32.42 0L30.58-3.26L29.78-3.26L29.78 0L28.10 0L28.10-8.38L31.25-8.38Q32.22-8.38 32.90-8.03Q33.59-7.69 33.93-7.11Q34.27-6.53 34.27-5.81L34.27-5.81Q34.27-4.98 33.79-4.31Q33.31-3.65 32.36-3.40L32.36-3.40L34.37 0ZM29.78-6.98L29.78-4.52L31.19-4.52Q31.87-4.52 32.21-4.85Q32.54-5.18 32.54-5.77L32.54-5.77Q32.54-6.35 32.21-6.67Q31.87-6.98 31.19-6.98L31.19-6.98L29.78-6.98ZM40.66-7.02L37.48-7.02L37.48-4.92L40.30-4.92L40.30-3.59L37.48-3.59L37.48-1.37L40.66-1.37L40.66 0L35.80 0L35.80-8.39L40.66-8.39L40.66-7.02ZM47.92-8.38L49.70-8.38L46.63 0L44.59 0L41.52-8.38L43.32-8.38L45.62-1.72L47.92-8.38ZM55.57-7.02L52.39-7.02L52.39-4.92L55.21-4.92L55.21-3.59L52.39-3.59L52.39-1.37L55.57-1.37L55.57 0L50.71 0L50.71-8.39L55.57-8.39L55.57-7.02ZM63.36 0L61.42 0L59.57-3.26L58.78-3.26L58.78 0L57.10 0L57.10-8.38L60.24-8.38Q61.21-8.38 61.90-8.03Q62.58-7.69 62.92-7.11Q63.26-6.53 63.26-5.81L63.26-5.81Q63.26-4.98 62.78-4.31Q62.30-3.65 61.36-3.40L61.36-3.40L63.36 0ZM58.78-6.98L58.78-4.52L60.18-4.52Q60.86-4.52 61.20-4.85Q61.54-5.18 61.54-5.77L61.54-5.77Q61.54-6.35 61.20-6.67Q60.86-6.98 60.18-6.98L60.18-6.98L58.78-6.98ZM72.43-8.38L74.30-8.38L71.47-2.92L71.47 0L69.79 0L69.79-2.92L66.95-8.38L68.84-8.38L70.64-4.55L72.43-8.38ZM79.16 0.08Q77.99 0.08 77.00-0.47Q76.02-1.02 75.44-2.00Q74.87-2.98 74.87-4.21L74.87-4.21Q74.87-5.44 75.44-6.41Q76.02-7.39 77.00-7.94Q77.99-8.50 79.16-8.50L79.16-8.50Q80.35-8.50 81.33-7.94Q82.31-7.39 82.88-6.41Q83.45-5.44 83.45-4.21L83.45-4.21Q83.45-2.98 82.88-2.00Q82.31-1.02 81.32-0.47Q80.34 0.08 79.16 0.08L79.16 0.08ZM79.16-1.42Q79.92-1.42 80.50-1.76Q81.07-2.10 81.40-2.74Q81.72-3.37 81.72-4.21L81.72-4.21Q81.72-5.05 81.40-5.68Q81.07-6.31 80.50-6.65Q79.92-6.98 79.16-6.98L79.16-6.98Q78.41-6.98 77.83-6.65Q77.24-6.31 76.92-5.68Q76.60-5.05 76.60-4.21L76.60-4.21Q76.60-3.37 76.92-2.74Q77.24-2.10 77.83-1.76Q78.41-1.42 79.16-1.42L79.16-1.42ZM84.67-8.38L86.35-8.38L86.35-3.19Q86.35-2.34 86.80-1.89Q87.24-1.44 88.04-1.44L88.04-1.44Q88.86-1.44 89.30-1.89Q89.75-2.34 89.75-3.19L89.75-3.19L89.75-8.38L91.44-8.38L91.44-3.20Q91.44-2.14 90.98-1.40Q90.52-0.66 89.74-0.29Q88.97 0.08 88.02 0.08L88.02 0.08Q87.08 0.08 86.32-0.29Q85.56-0.66 85.12-1.40Q84.67-2.14 84.67-3.20L84.67-3.20L84.67-8.38ZM101.60 0L101.05-1.60L97.72-1.60L97.16 0L95.40 0L98.41-8.39L100.37-8.39L103.38 0L101.60 0ZM98.17-2.94L100.60-2.94L99.38-6.44L98.17-2.94ZM110.77 0L108.83 0L106.98-3.26L106.19-3.26L106.19 0L104.51 0L104.51-8.38L107.65-8.38Q108.62-8.38 109.31-8.03Q109.99-7.69 110.33-7.11Q110.68-6.53 110.68-5.81L110.68-5.81Q110.68-4.98 110.20-4.31Q109.72-3.65 108.77-3.40L108.77-3.40L110.77 0ZM106.19-6.98L106.19-4.52L107.59-4.52Q108.28-4.52 108.61-4.85Q108.95-5.18 108.95-5.77L108.95-5.77Q108.95-6.35 108.61-6.67Q108.28-6.98 107.59-6.98L107.59-6.98L106.19-6.98ZM117.06-7.02L113.88-7.02L113.88-4.92L116.70-4.92L116.70-3.59L113.88-3.59L113.88-1.37L117.06-1.37L117.06 0L112.20 0L112.20-8.39L117.06-8.39L117.06-7.02ZM118.72-1.76L120.42-1.76L119.02 1.61L117.94 1.61L118.72-1.76ZM127.38 0.08Q126.50 0.08 125.80-0.22Q125.10-0.52 124.69-1.08Q124.28-1.64 124.27-2.41L124.27-2.41L126.07-2.41Q126.11-1.90 126.44-1.60Q126.77-1.30 127.34-1.30L127.34-1.30Q127.93-1.30 128.27-1.58Q128.60-1.86 128.60-2.32L128.60-2.32Q128.60-2.69 128.38-2.93Q128.15-3.17 127.81-3.31Q127.46-3.44 126.86-3.61L126.86-3.61Q126.05-3.85 125.54-4.09Q125.03-4.32 124.66-4.79Q124.30-5.27 124.30-6.06L124.30-6.06Q124.30-6.80 124.67-7.36Q125.04-7.91 125.71-8.20Q126.38-8.50 127.25-8.50L127.25-8.50Q128.54-8.50 129.35-7.87Q130.16-7.24 130.25-6.11L130.25-6.11L128.40-6.11Q128.38-6.54 128.03-6.82Q127.69-7.10 127.13-7.10L127.13-7.10Q126.64-7.10 126.34-6.85Q126.05-6.60 126.05-6.12L126.05-6.12Q126.05-5.78 126.27-5.56Q126.49-5.34 126.82-5.20Q127.15-5.06 127.75-4.88L127.75-4.88Q128.57-4.64 129.08-4.40Q129.60-4.16 129.97-3.68Q130.34-3.20 130.34-2.42L130.34-2.42Q130.34-1.75 130.00-1.18Q129.65-0.60 128.98-0.26Q128.30 0.08 127.38 0.08L127.38 0.08ZM131.80-8.38L133.48-8.38L133.48 0L131.80 0L131.80-8.38ZM142.30-8.39L142.30 0L140.62 0L136.81-5.75L136.81 0L135.13 0L135.13-8.39L136.81-8.39L140.62-2.63L140.62-8.39L142.30-8.39ZM151.72-5.86L149.78-5.86Q149.50-6.38 148.99-6.66Q148.49-6.94 147.82-6.94L147.82-6.94Q147.07-6.94 146.50-6.60Q145.92-6.26 145.60-5.64Q145.27-5.02 145.27-4.20L145.27-4.20Q145.27-3.36 145.60Line truncated
</svg>
</svg>
</div>
<!-- Headline -->
<div class="headline">
<div class="headline-main">MAKE YOUR OWN</div>
<div class="headline-sub">KARAOKE VIDEOS</div>
</div>
<!-- Subtitle -->
<div class="subtitle">
Turn any song into a professional karaoke video with synced lyrics, vocal removal, and automatic YouTube publishing.
</div>
<!-- How it works -->
<div class="steps">
<div class="step">
<div class="step-number">1</div>
<div class="step-content">
<div class="step-title">Pick any song</div>
<div class="step-desc">Search by artist &amp; title or paste a YouTube link</div>
</div>
</div>
<div class="step">
<div class="step-number">2</div>
<div class="step-content">
<div class="step-title">Our system does the work</div>
<div class="step-desc">Vocals removed, lyrics synced, video rendered automatically</div>
</div>
</div>
<div class="step">
<div class="step-number">3</div>
<div class="step-content">
<div class="step-title">Review &amp; correct the lyrics and instrumental</div>
<div class="step-desc">Fine-tune everything before publishing</div>
</div>
</div>
<div class="step">
<div class="step-number">4</div>
<div class="step-content">
<div class="step-title">Download or publish to YouTube</div>
<div class="step-desc">Get your finished karaoke video in minutes</div>
</div>
</div>
</div>
<div class="divider"></div>
<!-- CTA with QR code -->
<div class="cta-section">
<div class="qr-container">
<!-- Replace src with actual QR code image path -->
<img src="{{QR_DATA_URL}}" alt="QR Code - nomadkaraoke.com/r/{{REFERRAL_CODE_LOWER}}">
</div>
<div class="cta-text">
<div class="cta-label">First track free + {{DISCOUNT_PERCENT}}% off with this link</div>
<div class="cta-url">NOMADKARAOKE.COM/R/<span class="referral-code">{{REFERRAL_CODE}}</span></div>
<div class="cta-note">Scan the QR code or visit the link above</div>
</div>
</div>
<!-- Bottom -->
<div class="bottom">
<div class="bottom-features">
<div class="bottom-feature">
<span class="bottom-feature-icon">&#127908;</span>
<span>Any Song</span>
</div>
<div class="bottom-feature">
<span class="bottom-feature-icon">&#9889;</span>
<span>Automatic</span>
</div>
<div class="bottom-feature">
<span class="bottom-feature-icon">&#127916;</span>
<span>Pro Quality</span>
</div>
</div>
<div class="bottom-tagline">Wherever you are, sing!</div>
</div>
</div>
</body>
</html>
+97
View File
@@ -0,0 +1,97 @@
"""Tests for flyer PDF generation service."""
import os
from unittest.mock import patch, MagicMock
import pytest
from backend.services.flyer_service import FlyerService, FlyerError
class TestFlyerService:
"""Tests for FlyerService."""
def setup_method(self):
self.service = FlyerService()
def test_render_template_light_substitutes_placeholders(self):
html = self.service._render_template(
theme="light",
referral_code="MYCODE",
discount_percent=15,
qr_data_url="data:image/png;base64,abc123",
)
assert "MYCODE" in html
assert "{{REFERRAL_CODE}}" not in html
assert "{{QR_DATA_URL}}" not in html
assert "{{DISCOUNT_PERCENT}}" not in html
assert "{{REFERRAL_CODE_LOWER}}" not in html
assert "15% off" in html
assert "data:image/png;base64,abc123" in html
assert "mycode" in html # lowercase version in alt text
def test_render_template_dark_substitutes_placeholders(self):
html = self.service._render_template(
theme="dark",
referral_code="DARKCODE",
discount_percent=20,
qr_data_url="data:image/png;base64,xyz789",
)
assert "DARKCODE" in html
assert "{{REFERRAL_CODE}}" not in html
assert "data:image/png;base64,xyz789" in html
assert "20% off" in html
def test_render_template_invalid_theme_raises(self):
with pytest.raises(FlyerError, match="Invalid theme"):
self.service._render_template(
theme="neon",
referral_code="CODE",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
def test_render_template_uppercases_referral_code(self):
html = self.service._render_template(
theme="light",
referral_code="mycode",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
assert '<span class="referral-code">MYCODE</span>' in html
@patch("backend.services.flyer_service.subprocess.run")
def test_generate_pdf_calls_chromium_with_correct_flags(self, mock_run):
mock_run.return_value = MagicMock(returncode=0)
self.service._chromium_path = "/usr/bin/chromium"
with patch.object(self.service, "_render_template", return_value="<html>test</html>"):
with patch("os.path.exists", return_value=True):
with patch("builtins.open", MagicMock(return_value=MagicMock(read=MagicMock(return_value=b"%PDF")))):
with patch("os.unlink"):
self.service.generate_pdf(
theme="light",
referral_code="TEST",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
call_args = mock_run.call_args[0][0]
assert "--headless" in call_args
assert "--no-margins" in call_args
assert "--print-background" in call_args
assert "--no-pdf-header-footer" in call_args
assert "--virtual-time-budget=5000" in call_args
assert "--paper-width=8.5" in call_args
assert "--paper-height=11" in call_args
def test_validate_qr_data_url_rejects_non_data_url(self):
with pytest.raises(FlyerError, match="Invalid QR"):
self.service._validate_qr_data_url("https://evil.com/qr.png")
def test_validate_qr_data_url_rejects_too_large(self):
huge_url = "data:image/png;base64," + "A" * 600_000
with pytest.raises(FlyerError, match="too large"):
self.service._validate_qr_data_url(huge_url)
def test_validate_qr_data_url_accepts_valid(self):
self.service._validate_qr_data_url("data:image/png;base64,abc123")
@@ -0,0 +1,147 @@
# Referral Marketing Flyer Generator — Design Spec
**Date:** 2026-04-05
**Status:** Approved
**Scope:** Backend endpoint + frontend integration in karaoke-gen
## Overview
Add a "Generate Flyer" feature to the QR Code dialog that produces a professional print-ready PDF marketing flyer personalized with the referrer's code, discount, and styled QR code. Uses the existing flyer templates from kjbox (light + dark variants), rendered server-side with headless Chromium.
## User Flow
1. User opens QR Code dialog from referral dashboard
2. Customizes QR code style (dot style, colors, logo — already implemented)
3. Picks flyer theme: Light or Dark
4. Clicks "Generate Flyer"
5. Frontend generates QR as base64 PNG data URL using current style prefs
6. Frontend POSTs to backend with theme + QR data URL
7. Backend injects referral code + QR + discount into HTML template
8. Backend renders PDF with headless Chromium (same flags as kjbox)
9. PDF returned as download: `nomad-karaoke-referral-flyer.pdf`
## Backend
### New Endpoint
`POST /api/referrals/me/flyer`
**Auth:** Requires logged-in user (same as other `/me` endpoints).
**Request body:**
```json
{
"theme": "light" | "dark",
"qr_data_url": "data:image/png;base64,..."
}
```
**Logic:**
1. Look up user's referral link (code, discount_percent)
2. Read HTML template for the selected theme
3. Replace placeholders: `{{REFERRAL_CODE}}`, `{{QR_DATA_URL}}`, `{{DISCOUNT_PERCENT}}`
4. Write substituted HTML to temp file
5. Run headless Chromium to generate PDF
6. Return PDF as `application/pdf` with `Content-Disposition: attachment`
7. Clean up temp files
**Chromium command:**
```bash
chromium --headless --print-to-pdf=OUTPUT.pdf --no-margins --print-background \
--no-pdf-header-footer --virtual-time-budget=5000 \
--paper-width=8.5 --paper-height=11 INPUT.html
```
**Error handling:**
- Missing referral link → 404
- Chromium render failure → 500 with error message
- QR data URL too large (>500KB) → 400 validation error
### Template Storage
Two HTML files in `backend/templates/printables/`:
- `website-referral-flyer.html` (light theme)
- `website-referral-flyer-dark.html` (dark theme)
Copied from `kjbox/printables/` with three changes:
1. Replace `ANGEL` referral code with `{{REFERRAL_CODE}}`
2. Replace `src="qr-code-angel.svg"` with `src="{{QR_DATA_URL}}"`
3. Replace hardcoded "10% off" CTA text with `{{DISCOUNT_PERCENT}}% off`
### Flyer Service
New file `backend/services/flyer_service.py`:
- `generate_flyer_pdf(referral_code, discount_percent, theme, qr_data_url) -> bytes`
- Handles template loading, placeholder substitution, temp file management, Chromium invocation
- Returns raw PDF bytes
### Dockerfile Change
Add `chromium` to apt dependencies in `Dockerfile.base`:
```dockerfile
RUN apt-get update && apt-get install -y chromium && rm -rf /var/lib/apt/lists/*
```
Also need to find the Chromium binary path (typically `/usr/bin/chromium` on Debian).
## Frontend
### QRCodeDialog Changes
Add to the dialog footer (between the controls and download buttons):
- **Theme toggle:** Light / Dark radio buttons or segmented control
- **"Generate Flyer" button:** Secondary button alongside existing download buttons
**On click:**
1. Get QR as raw data: `qrRef.current.getRawData('png')` → Blob
2. Convert Blob to base64 data URL
3. POST to `/api/referrals/me/flyer` with `{ theme, qr_data_url }`
4. Download PDF from response blob
5. Show loading state while generating (flyer takes a few seconds)
### API Client
Add to `frontend/lib/api.ts`:
```typescript
generateFlyer(theme: 'light' | 'dark', qrDataUrl: string): Promise<Blob>
```
### i18n Strings
Add to `referrals` namespace:
```json
"flyerTheme": "Flyer Theme",
"flyerThemeLight": "Light",
"flyerThemeDark": "Dark",
"flyerGenerate": "Generate Flyer",
"flyerGenerating": "Generating..."
```
## Verification Strategy
### Phase 1: Local Chrome verification (before any backend changes)
- Create templatized HTML file with placeholders
- Write a Python script that substitutes values and runs local Chrome headless
- Verify PDF output looks correct
### Phase 2: Docker verification (before merge)
- Build the Docker base image locally with Chromium added
- Run the container and execute the same Chromium command inside it
- Verify PDF renders correctly with container's fonts + Chromium
- This catches missing deps, font issues, sandbox problems, etc.
### Phase 3: Standard CI + deploy
- Only after local Docker verification passes
## Testing
- **Unit tests:** Flyer service template substitution logic, input validation
- **Integration test:** Full endpoint test with mocked Chromium (verify correct flags passed)
- **Local Docker test:** Manual verification of PDF rendering in container environment
## Out of Scope
- Custom flyer text/messaging (uses fixed marketing copy)
- Additional flyer layouts beyond light/dark
- Batch flyer generation
- Flyer analytics
@@ -0,0 +1,891 @@
# Referral Marketing Flyer Generator — Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add a "Generate Flyer" feature to the QR Code dialog that produces a personalized print-ready PDF marketing flyer using headless Chromium.
**Architecture:** Frontend sends the user's styled QR code (as a base64 data URL) + theme choice to a new backend endpoint. Backend injects the QR code, referral code, and discount into an HTML template, renders it to PDF with headless Chromium, and returns the PDF. Templates are copied from kjbox with placeholder substitution.
**Tech Stack:** Python (FastAPI), headless Chromium (`--print-to-pdf`), HTML/CSS templates, React/TypeScript frontend, `qr-code-styling` (existing)
**Spec:** `docs/archive/2026-04-05-referral-flyer-generator-design.md`
---
## File Map
| Action | File | Responsibility |
|--------|------|----------------|
| Create | `backend/templates/printables/website-referral-flyer.html` | Light theme template with placeholders |
| Create | `backend/templates/printables/website-referral-flyer-dark.html` | Dark theme template with placeholders |
| Create | `backend/services/flyer_service.py` | Template rendering + Chromium PDF generation |
| Create | `backend/tests/test_flyer_service.py` | Unit tests for flyer service |
| Modify | `backend/api/routes/referrals.py` | Add `POST /me/flyer` endpoint |
| Modify | `backend/Dockerfile.base` | Add `chromium` apt package |
| Modify | `frontend/components/referrals/QRCodeDialog.tsx` | Add theme picker + Generate Flyer button |
| Modify | `frontend/lib/api.ts` | Add `generateFlyer()` function |
| Modify | `frontend/messages/en.json` | Add flyer i18n strings |
---
### Task 1: Local Chrome verification (proof of concept)
Verify the template + headless Chrome PDF approach works locally before writing any production code.
**Files:**
- Create (temporary): `backend/templates/printables/website-referral-flyer.html`
- [ ] **Step 1: Copy and templatize the light flyer**
Copy `/Users/andrew/Projects/nomadkaraoke/kjbox/printables/website-referral-flyer.html` to `backend/templates/printables/website-referral-flyer.html`.
Then make 3 substitutions in the new file:
1. Replace `src="qr-code-angel.svg"` with `src="{{QR_DATA_URL}}"` (line 330 of the original)
2. Replace `<span class="referral-code">ANGEL</span>` with `<span class="referral-code">{{REFERRAL_CODE}}</span>` (line 334)
3. Replace `First track free + 10% off with this link` with `First track free + {{DISCOUNT_PERCENT}}% off with this link` (line 336)
4. Replace `alt="QR Code - nomadkaraoke.com/r/angel"` with `alt="QR Code - nomadkaraoke.com/r/{{REFERRAL_CODE_LOWER}}"` (line 330)
- [ ] **Step 2: Write a quick test script**
Create a temporary script `backend/test_flyer_local.py` (gitignored — add `test_flyer_local.py` to `.gitignore` or just delete after):
```python
#!/usr/bin/env python3
"""Local verification: generate a flyer PDF using Chrome headless."""
import subprocess
import tempfile
import os
import sys
TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "templates/printables/website-referral-flyer.html")
# Read template
with open(TEMPLATE_PATH) as f:
html = f.read()
# Substitute placeholders
html = html.replace("{{REFERRAL_CODE}}", "TESTCODE")
html = html.replace("{{REFERRAL_CODE_LOWER}}", "testcode")
html = html.replace("{{DISCOUNT_PERCENT}}", "10")
# Use a simple black QR placeholder (1x1 black pixel as data URL for now)
html = html.replace("{{QR_DATA_URL}}", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==")
# Write to temp file
with tempfile.NamedTemporaryFile(suffix=".html", delete=False, mode="w") as tmp:
tmp.write(html)
tmp_html = tmp.name
output_pdf = "/tmp/test-flyer-output.pdf"
# Find Chrome
chrome_paths = [
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/bin/google-chrome",
]
chrome = None
for p in chrome_paths:
if os.path.exists(p):
chrome = p
break
if not chrome:
print("ERROR: No Chrome/Chromium found")
sys.exit(1)
print(f"Using: {chrome}")
print(f"Template: {tmp_html}")
print(f"Output: {output_pdf}")
cmd = [
chrome,
"--headless",
f"--print-to-pdf={output_pdf}",
"--no-margins",
"--print-background",
"--no-pdf-header-footer",
"--virtual-time-budget=5000",
"--paper-width=8.5",
"--paper-height=11",
tmp_html,
]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
os.unlink(tmp_html)
if result.returncode != 0:
print(f"FAILED (exit {result.returncode})")
print(result.stderr)
sys.exit(1)
if os.path.exists(output_pdf):
size = os.path.getsize(output_pdf)
print(f"SUCCESS: {output_pdf} ({size} bytes)")
# Open the PDF for visual inspection
subprocess.run(["open", output_pdf])
else:
print("FAILED: No output PDF generated")
sys.exit(1)
```
- [ ] **Step 3: Run the test**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
python3 backend/test_flyer_local.py
```
Expected: PDF opens in Preview showing the flyer with "TESTCODE" referral code and a placeholder QR image. Verify: correct layout, gradients render, fonts load, no second blank page, no margins.
- [ ] **Step 4: Clean up and commit the template**
Delete the test script:
```bash
rm backend/test_flyer_local.py
```
Commit the templatized flyer:
```bash
git add backend/templates/printables/website-referral-flyer.html
git commit -m "feat(referral): add templatized light flyer from kjbox printables"
```
---
### Task 2: Templatize dark flyer + add Chromium to Dockerfile
**Files:**
- Create: `backend/templates/printables/website-referral-flyer-dark.html`
- Modify: `backend/Dockerfile.base`
- [ ] **Step 1: Copy and templatize the dark flyer**
Copy `/Users/andrew/Projects/nomadkaraoke/kjbox/printables/website-referral-flyer-dark.html` to `backend/templates/printables/website-referral-flyer-dark.html`.
Make the same 4 substitutions as Task 1 Step 1:
1. `src="qr-code-angel.svg"` → `src="{{QR_DATA_URL}}"`
2. `<span class="referral-code">ANGEL</span>` → `<span class="referral-code">{{REFERRAL_CODE}}</span>`
3. `First track free + 10% off with this link` → `First track free + {{DISCOUNT_PERCENT}}% off with this link`
4. `alt="QR Code - nomadkaraoke.com/r/angel"` → `alt="QR Code - nomadkaraoke.com/r/{{REFERRAL_CODE_LOWER}}"`
- [ ] **Step 2: Add Chromium to Dockerfile.base**
In `backend/Dockerfile.base`, add `chromium` to the first `apt-get install` block (the system dependencies section, around line 19-26). Add it after `xz-utils`:
```dockerfile
RUN apt-get update && apt-get install -y \
libsndfile1 \
libsox-dev \
sox \
build-essential \
curl \
xz-utils \
chromium \
&& rm -rf /var/lib/apt/lists/*
```
- [ ] **Step 3: Commit**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
git add backend/templates/printables/website-referral-flyer-dark.html backend/Dockerfile.base
git commit -m "feat(referral): add dark flyer template and chromium to Dockerfile"
```
---
### Task 3: Implement flyer service with tests
**Files:**
- Create: `backend/services/flyer_service.py`
- Create: `backend/tests/test_flyer_service.py`
- [ ] **Step 1: Write the failing tests**
Create `backend/tests/test_flyer_service.py`:
```python
"""Tests for flyer PDF generation service."""
import os
from unittest.mock import patch, MagicMock
import pytest
from backend.services.flyer_service import FlyerService, FlyerError
class TestFlyerService:
"""Tests for FlyerService."""
def setup_method(self):
self.service = FlyerService()
def test_render_template_light_substitutes_placeholders(self):
html = self.service._render_template(
theme="light",
referral_code="MYCODE",
discount_percent=15,
qr_data_url="data:image/png;base64,abc123",
)
assert "MYCODE" in html
assert "{{REFERRAL_CODE}}" not in html
assert "{{QR_DATA_URL}}" not in html
assert "{{DISCOUNT_PERCENT}}" not in html
assert "{{REFERRAL_CODE_LOWER}}" not in html
assert "15% off" in html
assert "data:image/png;base64,abc123" in html
assert "mycode" in html # lowercase version in alt text
def test_render_template_dark_substitutes_placeholders(self):
html = self.service._render_template(
theme="dark",
referral_code="DARKCODE",
discount_percent=20,
qr_data_url="data:image/png;base64,xyz789",
)
assert "DARKCODE" in html
assert "{{REFERRAL_CODE}}" not in html
assert "data:image/png;base64,xyz789" in html
assert "20% off" in html
def test_render_template_invalid_theme_raises(self):
with pytest.raises(FlyerError, match="Invalid theme"):
self.service._render_template(
theme="neon",
referral_code="CODE",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
def test_render_template_uppercases_referral_code(self):
html = self.service._render_template(
theme="light",
referral_code="mycode",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
# The code in the URL display should be uppercased
assert '<span class="referral-code">MYCODE</span>' in html
@patch("backend.services.flyer_service.subprocess.run")
def test_generate_pdf_calls_chromium_with_correct_flags(self, mock_run):
mock_run.return_value = MagicMock(returncode=0)
# Mock the temp file to exist
with patch("backend.services.flyer_service.tempfile.NamedTemporaryFile") as mock_tmp:
mock_tmp_instance = MagicMock()
mock_tmp_instance.__enter__ = MagicMock(return_value=mock_tmp_instance)
mock_tmp_instance.__exit__ = MagicMock(return_value=False)
mock_tmp_instance.name = "/tmp/test.html"
mock_tmp.return_value = mock_tmp_instance
with patch("builtins.open", MagicMock()):
with patch("os.path.exists", return_value=True):
with patch("os.unlink"):
self.service.generate_pdf(
theme="light",
referral_code="TEST",
discount_percent=10,
qr_data_url="data:image/png;base64,abc",
)
# Verify chromium was called with the right flags
call_args = mock_run.call_args[0][0]
assert "--headless" in call_args
assert "--no-margins" in call_args
assert "--print-background" in call_args
assert "--no-pdf-header-footer" in call_args
assert "--virtual-time-budget=5000" in call_args
assert "--paper-width=8.5" in call_args
assert "--paper-height=11" in call_args
def test_validate_qr_data_url_rejects_non_data_url(self):
with pytest.raises(FlyerError, match="Invalid QR"):
self.service._validate_qr_data_url("https://evil.com/qr.png")
def test_validate_qr_data_url_rejects_too_large(self):
huge_url = "data:image/png;base64," + "A" * 600_000
with pytest.raises(FlyerError, match="too large"):
self.service._validate_qr_data_url(huge_url)
def test_validate_qr_data_url_accepts_valid(self):
# Should not raise
self.service._validate_qr_data_url("data:image/png;base64,abc123")
```
- [ ] **Step 2: Run tests to verify they fail**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
python -m pytest backend/tests/test_flyer_service.py -v 2>&1 | tail -20
```
Expected: FAIL — `backend.services.flyer_service` module doesn't exist.
- [ ] **Step 3: Implement the flyer service**
Create `backend/services/flyer_service.py`:
```python
"""Service for generating personalized referral flyer PDFs."""
import logging
import os
import shutil
import subprocess
import tempfile
logger = logging.getLogger(__name__)
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "..", "templates", "printables")
CHROMIUM_PATHS = [
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/bin/google-chrome",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
]
VALID_THEMES = {"light", "dark"}
MAX_QR_DATA_URL_BYTES = 500_000
class FlyerError(Exception):
"""Error during flyer generation."""
class FlyerService:
"""Generates personalized referral flyer PDFs."""
def __init__(self):
self._chromium_path = self._find_chromium()
def _find_chromium(self) -> str:
for path in CHROMIUM_PATHS:
if os.path.exists(path):
return path
# Also try shutil.which
for name in ["chromium", "chromium-browser", "google-chrome"]:
found = shutil.which(name)
if found:
return found
raise FlyerError("Chromium not found. Install chromium to generate flyer PDFs.")
def _validate_qr_data_url(self, qr_data_url: str) -> None:
if not qr_data_url.startswith("data:image/"):
raise FlyerError("Invalid QR data URL: must be a data:image/ URL")
if len(qr_data_url) > MAX_QR_DATA_URL_BYTES:
raise FlyerError(f"QR data URL too large (>{MAX_QR_DATA_URL_BYTES} bytes)")
def _render_template(
self,
theme: str,
referral_code: str,
discount_percent: int,
qr_data_url: str,
) -> str:
if theme not in VALID_THEMES:
raise FlyerError(f"Invalid theme: {theme}. Must be one of: {VALID_THEMES}")
suffix = "-dark" if theme == "dark" else ""
template_path = os.path.join(TEMPLATE_DIR, f"website-referral-flyer{suffix}.html")
with open(template_path) as f:
html = f.read()
html = html.replace("{{REFERRAL_CODE}}", referral_code.upper())
html = html.replace("{{REFERRAL_CODE_LOWER}}", referral_code.lower())
html = html.replace("{{DISCOUNT_PERCENT}}", str(discount_percent))
html = html.replace("{{QR_DATA_URL}}", qr_data_url)
return html
def generate_pdf(
self,
theme: str,
referral_code: str,
discount_percent: int,
qr_data_url: str,
) -> bytes:
"""Generate a personalized flyer PDF.
Returns the raw PDF bytes.
"""
self._validate_qr_data_url(qr_data_url)
html = self._render_template(theme, referral_code, discount_percent, qr_data_url)
# Write HTML to temp file (Chromium needs a file path)
with tempfile.NamedTemporaryFile(
suffix=".html", delete=False, mode="w", encoding="utf-8"
) as tmp_html:
tmp_html.write(html)
tmp_html_path = tmp_html.name
tmp_pdf_path = tmp_html_path.replace(".html", ".pdf")
try:
cmd = [
self._chromium_path,
"--headless",
f"--print-to-pdf={tmp_pdf_path}",
"--no-margins",
"--print-background",
"--no-pdf-header-footer",
"--virtual-time-budget=5000",
"--paper-width=8.5",
"--paper-height=11",
"--disable-gpu",
"--no-sandbox",
tmp_html_path,
]
result = subprocess.run(
cmd, capture_output=True, text=True, timeout=30
)
if result.returncode != 0:
logger.error("Chromium PDF generation failed: %s", result.stderr)
raise FlyerError(f"PDF generation failed: {result.stderr[:200]}")
if not os.path.exists(tmp_pdf_path):
raise FlyerError("PDF generation failed: no output file created")
with open(tmp_pdf_path, "rb") as f:
return f.read()
finally:
# Clean up temp files
for path in [tmp_html_path, tmp_pdf_path]:
try:
os.unlink(path)
except OSError:
pass
# Singleton
_flyer_service = None
def get_flyer_service() -> FlyerService:
global _flyer_service
if _flyer_service is None:
_flyer_service = FlyerService()
return _flyer_service
```
- [ ] **Step 4: Run tests to verify they pass**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
python -m pytest backend/tests/test_flyer_service.py -v 2>&1 | tail -20
```
Expected: All 8 tests PASS.
- [ ] **Step 5: Commit**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
git add backend/services/flyer_service.py backend/tests/test_flyer_service.py
git commit -m "feat(referral): add flyer PDF generation service with tests"
```
---
### Task 4: Add flyer endpoint to referral routes
**Files:**
- Modify: `backend/api/routes/referrals.py`
- [ ] **Step 1: Add the flyer endpoint**
In `backend/api/routes/referrals.py`, add after the existing imports at the top:
```python
from fastapi.responses import Response
from pydantic import BaseModel, Field
from backend.services.flyer_service import get_flyer_service, FlyerError
```
Add a request model after the existing imports:
```python
class GenerateFlyerRequest(BaseModel):
theme: str = Field(..., pattern="^(light|dark)$")
qr_data_url: str = Field(..., max_length=500_000)
```
Add the endpoint after the `start_stripe_connect` endpoint (around line 118), before the Admin section:
```python
@router.post("/me/flyer")
async def generate_flyer(
request: GenerateFlyerRequest,
auth=Depends(require_auth),
):
"""Generate a personalized referral flyer PDF."""
service = get_referral_service()
link = service.get_or_create_link(auth.user_email)
try:
flyer_service = get_flyer_service()
pdf_bytes = flyer_service.generate_pdf(
theme=request.theme,
referral_code=link.code,
discount_percent=link.discount_percent,
qr_data_url=request.qr_data_url,
)
except FlyerError as e:
raise HTTPException(status_code=400, detail=str(e))
return Response(
content=pdf_bytes,
media_type="application/pdf",
headers={
"Content-Disposition": 'attachment; filename="nomad-karaoke-referral-flyer.pdf"',
},
)
```
- [ ] **Step 2: Run backend tests**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
python -m pytest backend/tests/ -v --timeout=30 2>&1 | tail -30
```
Expected: All tests pass (new endpoint doesn't break existing tests).
- [ ] **Step 3: Commit**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
git add backend/api/routes/referrals.py
git commit -m "feat(referral): add POST /me/flyer endpoint for PDF generation"
```
---
### Task 5: Docker verification
Build the base image locally with Chromium and verify PDF generation works inside the container.
**Files:** None changed — this is a verification step.
- [ ] **Step 1: Build the Docker base image locally**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
docker build -f backend/Dockerfile.base -t karaoke-backend-base:local .
```
This will take a while (~5-10 min) as it installs Chromium + all deps. Watch for errors.
- [ ] **Step 2: Test Chromium works inside the container**
```bash
docker run --rm karaoke-backend-base:local chromium --version
```
Expected: Prints Chromium version (e.g., `Chromium 120.0.6099.224 built on Debian ...`).
- [ ] **Step 3: Test PDF generation inside the container**
```bash
docker run --rm -v $(pwd)/backend/templates:/app/backend/templates karaoke-backend-base:local \
python3 -c "
import subprocess, tempfile, os
# Read template
with open('/app/backend/templates/printables/website-referral-flyer.html') as f:
html = f.read()
html = html.replace('{{REFERRAL_CODE}}', 'DOCKERTEST')
html = html.replace('{{REFERRAL_CODE_LOWER}}', 'dockertest')
html = html.replace('{{DISCOUNT_PERCENT}}', '10')
html = html.replace('{{QR_DATA_URL}}', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==')
tmp = '/tmp/test.html'
with open(tmp, 'w') as f:
f.write(html)
result = subprocess.run([
'chromium', '--headless', '--print-to-pdf=/tmp/out.pdf',
'--no-margins', '--print-background', '--no-pdf-header-footer',
'--virtual-time-budget=5000', '--paper-width=8.5', '--paper-height=11',
'--disable-gpu', '--no-sandbox', tmp
], capture_output=True, text=True, timeout=30)
if result.returncode != 0:
print('FAILED:', result.stderr[:500])
elif os.path.exists('/tmp/out.pdf'):
print(f'SUCCESS: PDF generated ({os.path.getsize(\"/tmp/out.pdf\")} bytes)')
else:
print('FAILED: no output')
"
```
Expected: `SUCCESS: PDF generated (XXXXX bytes)`.
- [ ] **Step 4: Extract and verify the Docker-generated PDF**
```bash
# Run again but copy the PDF out
docker run --rm -v $(pwd)/backend/templates:/app/backend/templates -v /tmp:/output karaoke-backend-base:local \
python3 -c "
import subprocess, os
with open('/app/backend/templates/printables/website-referral-flyer.html') as f:
html = f.read()
html = html.replace('{{REFERRAL_CODE}}', 'DOCKERTEST')
html = html.replace('{{REFERRAL_CODE_LOWER}}', 'dockertest')
html = html.replace('{{DISCOUNT_PERCENT}}', '10')
html = html.replace('{{QR_DATA_URL}}', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==')
with open('/tmp/test.html', 'w') as f:
f.write(html)
subprocess.run([
'chromium', '--headless', '--print-to-pdf=/output/docker-flyer-test.pdf',
'--no-margins', '--print-background', '--no-pdf-header-footer',
'--virtual-time-budget=5000', '--paper-width=8.5', '--paper-height=11',
'--disable-gpu', '--no-sandbox', '/tmp/test.html'
], capture_output=True, text=True, timeout=30)
print(f'PDF size: {os.path.getsize(\"/output/docker-flyer-test.pdf\")} bytes')
"
open /tmp/docker-flyer-test.pdf
```
Expected: PDF opens showing the flyer with correct layout, fonts (Google Fonts loaded via `--virtual-time-budget`), gradients, and "DOCKERTEST" referral code. No second blank page, no margins, no URL header/footer.
If fonts are missing or rendering is wrong, troubleshoot before proceeding. Common fixes:
- Add `fonts-liberation` to apt-get for fallback fonts
- Increase `--virtual-time-budget` if Google Fonts don't load in time
- Add `--font-render-hinting=none` for better font rendering
- [ ] **Step 5: Report result**
No commit needed — this is a verification gate. If it passes, proceed. If it fails, fix the Dockerfile or template before continuing.
---
### Task 6: Frontend — add flyer generation to QRCodeDialog
**Files:**
- Modify: `frontend/components/referrals/QRCodeDialog.tsx`
- Modify: `frontend/lib/api.ts`
- Modify: `frontend/messages/en.json`
- [ ] **Step 1: Add i18n strings**
Add to the `"referrals"` namespace in `frontend/messages/en.json`, after the existing QR strings:
```json
"flyerTheme": "Flyer Theme",
"flyerThemeLight": "Light",
"flyerThemeDark": "Dark",
"flyerGenerate": "Generate Flyer",
"flyerGenerating": "Generating..."
```
- [ ] **Step 2: Add generateFlyer to API client**
Add to `frontend/lib/api.ts`, after the `startConnectOnboarding` function (around line 3550):
```typescript
export async function generateFlyer(theme: 'light' | 'dark', qrDataUrl: string): Promise<Blob> {
const response = await fetch(`${API_BASE_URL}/api/referrals/me/flyer`, {
method: 'POST',
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ theme, qr_data_url: qrDataUrl }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Failed to generate flyer' }));
throw new Error(error.detail || 'Failed to generate flyer');
}
return response.blob();
}
```
- [ ] **Step 3: Add flyer generation to QRCodeDialog**
In `frontend/components/referrals/QRCodeDialog.tsx`, make these changes:
**Add import** at the top:
```typescript
import { generateFlyer } from '@/lib/api';
```
**Add state** inside the component (after `const debounceRef`):
```typescript
const [flyerTheme, setFlyerTheme] = useState<'light' | 'dark'>('light');
const [flyerLoading, setFlyerLoading] = useState(false);
```
**Add the handleGenerateFlyer function** after `handleDownload`:
```typescript
const handleGenerateFlyer = async () => {
setFlyerLoading(true);
try {
// Get QR as PNG data URL from the qr-code-styling instance
let qrDataUrl: string;
if (qrRef.current) {
const blob = await qrRef.current.getRawData('png');
if (blob) {
qrDataUrl = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
} else {
throw new Error('Failed to generate QR code image');
}
} else {
throw new Error('QR code not initialized');
}
const pdfBlob = await generateFlyer(flyerTheme, qrDataUrl);
const url = URL.createObjectURL(pdfBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'nomad-karaoke-referral-flyer.pdf';
a.click();
URL.revokeObjectURL(url);
} catch (err) {
console.error('Failed to generate flyer:', err);
} finally {
setFlyerLoading(false);
}
};
```
**Add the flyer section in the dialog footer**, replacing the existing `<DialogFooter>` block with:
```tsx
<DialogFooter>
<div className="w-full space-y-3">
{/* Flyer generation */}
<div className="flex items-center gap-3 pt-2 border-t border-border">
<span className="text-sm font-medium text-foreground">{t('flyerTheme')}</span>
<div className="flex gap-1.5">
{(['light', 'dark'] as const).map(theme => (
<button
key={theme}
onClick={() => setFlyerTheme(theme)}
className={`px-2 py-1 text-xs rounded border transition-colors ${
flyerTheme === theme
? 'border-primary bg-primary/10 text-primary font-medium'
: 'border-border text-muted-foreground hover:border-primary/50'
}`}
>
{t(theme === 'light' ? 'flyerThemeLight' : 'flyerThemeDark')}
</button>
))}
</div>
<button
onClick={handleGenerateFlyer}
disabled={flyerLoading}
className="ml-auto px-4 py-2 bg-primary text-primary-foreground rounded text-sm flex items-center gap-2 disabled:opacity-50"
>
{flyerLoading ? t('flyerGenerating') : t('flyerGenerate')}
</button>
</div>
{/* QR download buttons */}
<div className="flex gap-2 sm:justify-end">
<button
onClick={() => handleDownload('png')}
className="flex-1 sm:flex-none px-4 py-2 bg-primary text-primary-foreground rounded text-sm flex items-center justify-center gap-2"
>
<Download className="w-4 h-4" />
{t('qrDownloadPng')}
</button>
<button
onClick={() => handleDownload('svg')}
className="flex-1 sm:flex-none px-4 py-2 rounded text-sm border border-border text-foreground flex items-center justify-center gap-2 hover:bg-secondary"
>
<Download className="w-4 h-4" />
{t('qrDownloadSvg')}
</button>
</div>
</div>
</DialogFooter>
```
- [ ] **Step 4: Run frontend tests**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator/frontend
npx jest components/referrals/__tests__/QRCodeDialog.test.tsx --no-coverage 2>&1 | tail -20
```
Expected: Existing tests still pass. The new flyer UI elements are present but don't break existing tests (they're just buttons and toggles). If the "Generate Flyer" text assertion is needed, add a quick test:
```typescript
it('renders flyer generation controls', () => {
renderDialog();
expect(screen.getByText('Generate Flyer')).toBeInTheDocument();
expect(screen.getByText('Light')).toBeInTheDocument();
expect(screen.getByText('Dark')).toBeInTheDocument();
});
```
- [ ] **Step 5: Commit**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
git add frontend/components/referrals/QRCodeDialog.tsx frontend/lib/api.ts frontend/messages/en.json
git commit -m "feat(referral): add flyer generation UI to QR code dialog"
```
---
### Task 7: Update tests and final verification
**Files:**
- Modify: `frontend/components/referrals/__tests__/QRCodeDialog.test.tsx` (add flyer test)
- [ ] **Step 1: Add flyer UI test**
Add this test to the existing `describe('QRCodeDialog')` block in `frontend/components/referrals/__tests__/QRCodeDialog.test.tsx`:
```typescript
it('renders flyer generation controls', () => {
renderDialog();
expect(screen.getByText('Generate Flyer')).toBeInTheDocument();
expect(screen.getByText('Light')).toBeInTheDocument();
expect(screen.getByText('Dark')).toBeInTheDocument();
expect(screen.getByText('Flyer Theme')).toBeInTheDocument();
});
```
- [ ] **Step 2: Run all frontend tests**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator/frontend
npx jest --no-coverage 2>&1 | tail -20
```
Expected: All tests pass.
- [ ] **Step 3: Run all backend tests**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
python -m pytest backend/tests/ -v --timeout=30 2>&1 | tail -30
```
Expected: All tests pass.
- [ ] **Step 4: Verify frontend build**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator/frontend
npx next build 2>&1 | tail -20
```
Expected: Build succeeds.
- [ ] **Step 5: Commit**
```bash
cd /Users/andrew/Projects/nomadkaraoke/karaoke-gen-affiliate-qr-generator
git add frontend/components/referrals/__tests__/QRCodeDialog.test.tsx
git commit -m "test(referral): add flyer UI rendering test"
```
+52 -1
View File
@@ -18,7 +18,7 @@ import {
} from "@/components/ui/dialog"
import {
Share2, Link as LinkIcon, Users, MousePointerClick, DollarSign,
Plus, Copy, Check, RefreshCw, Loader2, ToggleLeft, ToggleRight, Pencil,
Plus, Copy, Check, RefreshCw, Loader2, ToggleLeft, ToggleRight, Pencil, FileText,
} from "lucide-react"
function formatCents(cents: number): string {
@@ -43,6 +43,7 @@ export default function ReferralsPage() {
const [editLink, setEditLink] = useState<AdminReferralLink | null>(null)
const [saving, setSaving] = useState(false)
const [editError, setEditError] = useState<string | null>(null)
const [flyerGenerating, setFlyerGenerating] = useState<string | null>(null)
// Edit form state
const [editDisplayName, setEditDisplayName] = useState("")
@@ -106,6 +107,42 @@ export default function ReferralsPage() {
}
}
const handleGenerateFlyer = async (code: string, theme: 'light' | 'dark') => {
setFlyerGenerating(code)
try {
// Generate a standard black QR code for this referral link
const QRCodeStyling = (await import('qr-code-styling')).default
const qr = new QRCodeStyling({
width: 250, height: 250,
data: `https://nomadkaraoke.com/r/${code}`,
dotsOptions: { type: 'square', color: '#000000' },
cornersSquareOptions: { type: 'square', color: '#000000' },
cornersDotOptions: { type: 'square', color: '#000000' },
backgroundOptions: { color: '#ffffff' },
})
const blob = await qr.getRawData('svg')
if (!blob) throw new Error('Failed to generate QR')
const qrDataUrl = await new Promise<string>((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result as string)
reader.onerror = () => reject(new Error('Failed to read QR'))
reader.readAsDataURL(blob)
})
const pdfBlob = await adminApi.generateFlyer(code, theme, qrDataUrl)
const url = URL.createObjectURL(pdfBlob)
const a = document.createElement('a')
a.href = url
a.download = `nomad-karaoke-flyer-${code}.pdf`
a.click()
URL.revokeObjectURL(url)
} catch (err) {
console.error('Failed to generate flyer:', err)
alert(`Failed to generate flyer: ${err instanceof Error ? err.message : 'Unknown error'}`)
} finally {
setFlyerGenerating(null)
}
}
const handleCreate = async (e: React.FormEvent) => {
e.preventDefault()
setCreating(true)
@@ -446,6 +483,20 @@ export default function ReferralsPage() {
</TableCell>
<TableCell>
<div className="flex items-center gap-1">
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={() => handleGenerateFlyer(link.code, 'light')}
disabled={flyerGenerating === link.code}
title="Generate flyer (light)"
>
{flyerGenerating === link.code ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<FileText className="h-4 w-4" />
)}
</Button>
<Button
variant="ghost"
size="icon"
+95 -15
View File
@@ -3,6 +3,7 @@
import { useEffect, useRef, useState, useCallback } from 'react';
import { useTranslations } from 'next-intl';
import { QrCode, Download, Mic, Music } from 'lucide-react';
import { generateFlyer } from '@/lib/api';
import {
Dialog,
DialogContent,
@@ -117,6 +118,9 @@ export default function QRCodeDialog({ referralUrl, open, onOpenChange }: QRCode
const [prefs, setPrefs] = useState<QRStylePrefs>(DEFAULT_PREFS);
const [loaded, setLoaded] = useState(false);
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const [flyerTheme, setFlyerTheme] = useState<'light' | 'dark'>('light');
const [flyerLoading, setFlyerLoading] = useState(false);
const [flyerError, setFlyerError] = useState('');
// Load prefs from localStorage on open
useEffect(() => {
@@ -190,6 +194,13 @@ export default function QRCodeDialog({ referralUrl, open, onOpenChange }: QRCode
}
}, [open]);
// Clean up debounce timer on unmount
useEffect(() => {
return () => {
if (debounceRef.current) clearTimeout(debounceRef.current);
};
}, []);
const updatePref = <K extends keyof QRStylePrefs>(key: K, value: QRStylePrefs[K]) => {
setPrefs(prev => {
const next = { ...prev, [key]: value };
@@ -200,6 +211,43 @@ export default function QRCodeDialog({ referralUrl, open, onOpenChange }: QRCode
});
};
const handleGenerateFlyer = async () => {
setFlyerLoading(true);
setFlyerError('');
try {
let qrDataUrl: string;
if (qrRef.current) {
const blob = await qrRef.current.getRawData('svg');
if (blob) {
qrDataUrl = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.onerror = () => reject(new Error('Failed to read QR code data'));
reader.readAsDataURL(blob);
});
} else {
throw new Error('Failed to generate QR code image');
}
} else {
throw new Error('QR code not initialized');
}
const pdfBlob = await generateFlyer(flyerTheme, qrDataUrl);
const url = URL.createObjectURL(pdfBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'nomad-karaoke-referral-flyer.pdf';
a.click();
URL.revokeObjectURL(url);
} catch (err) {
const message = err instanceof Error ? err.message : 'Failed to generate flyer';
setFlyerError(message);
console.error('Failed to generate flyer:', err);
} finally {
setFlyerLoading(false);
}
};
const handleDownload = async (extension: 'png' | 'svg') => {
// Initialize QR instance if not yet ready (e.g., download clicked before init effect completes)
if (!qrRef.current) {
@@ -355,21 +403,53 @@ export default function QRCodeDialog({ referralUrl, open, onOpenChange }: QRCode
</div>
<DialogFooter>
<div className="flex gap-2 w-full sm:w-auto">
<button
onClick={() => handleDownload('png')}
className="flex-1 sm:flex-none px-4 py-2 bg-primary text-primary-foreground rounded text-sm flex items-center justify-center gap-2"
>
<Download className="w-4 h-4" />
{t('qrDownloadPng')}
</button>
<button
onClick={() => handleDownload('svg')}
className="flex-1 sm:flex-none px-4 py-2 rounded text-sm border border-border text-foreground flex items-center justify-center gap-2 hover:bg-secondary"
>
<Download className="w-4 h-4" />
{t('qrDownloadSvg')}
</button>
<div className="w-full space-y-3">
{/* Flyer generation */}
<div className="flex items-center gap-3 pt-2 border-t border-border">
<span className="text-sm font-medium text-foreground">{t('flyerTheme')}</span>
<div className="flex gap-1.5">
{(['light', 'dark'] as const).map(theme => (
<button
key={theme}
onClick={() => setFlyerTheme(theme)}
className={`px-2 py-1 text-xs rounded border transition-colors ${
flyerTheme === theme
? 'border-primary bg-primary/10 text-primary font-medium'
: 'border-border text-muted-foreground hover:border-primary/50'
}`}
>
{t(theme === 'light' ? 'flyerThemeLight' : 'flyerThemeDark')}
</button>
))}
</div>
<button
onClick={handleGenerateFlyer}
disabled={flyerLoading}
className="ml-auto px-4 py-2 bg-primary text-primary-foreground rounded text-sm flex items-center gap-2 disabled:opacity-50"
>
{flyerLoading ? t('flyerGenerating') : t('flyerGenerate')}
</button>
</div>
{flyerError && (
<p className="text-xs text-destructive">{flyerError}</p>
)}
{/* QR download buttons */}
<div className="flex gap-2 sm:justify-end">
<button
onClick={() => handleDownload('png')}
className="flex-1 sm:flex-none px-4 py-2 bg-primary text-primary-foreground rounded text-sm flex items-center justify-center gap-2"
>
<Download className="w-4 h-4" />
{t('qrDownloadPng')}
</button>
<button
onClick={() => handleDownload('svg')}
className="flex-1 sm:flex-none px-4 py-2 rounded text-sm border border-border text-foreground flex items-center justify-center gap-2 hover:bg-secondary"
>
<Download className="w-4 h-4" />
{t('qrDownloadSvg')}
</button>
</div>
</div>
</DialogFooter>
</DialogContent>
@@ -135,4 +135,12 @@ describe('QRCodeDialog', () => {
});
});
});
it('renders flyer generation controls', () => {
renderDialog();
expect(screen.getByText('Generate Flyer')).toBeInTheDocument();
expect(screen.getByText('Light')).toBeInTheDocument();
expect(screen.getByText('Dark')).toBeInTheDocument();
expect(screen.getByText('Flyer Theme')).toBeInTheDocument();
});
});
+26
View File
@@ -2573,6 +2573,19 @@ export const adminApi = {
});
return handleResponse(response);
},
async generateFlyer(code: string, theme: 'light' | 'dark', qrDataUrl: string): Promise<Blob> {
const response = await fetch(`${API_BASE_URL}/api/referrals/admin/links/${encodeURIComponent(code)}/flyer`, {
method: 'POST',
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ theme, qr_data_url: qrDataUrl }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Failed to generate flyer' }));
throw new Error(error.detail || 'Failed to generate flyer');
}
return response.blob();
},
};
export interface EditReviewSummary {
@@ -3570,3 +3583,16 @@ export async function startConnectOnboarding(): Promise<{ account_id: string; on
return response.json();
}
export async function generateFlyer(theme: 'light' | 'dark', qrDataUrl: string): Promise<Blob> {
const response = await fetch(`${API_BASE_URL}/api/referrals/me/flyer`, {
method: 'POST',
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ theme, qr_data_url: qrDataUrl }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Failed to generate flyer' }));
throw new Error(error.detail || 'Failed to generate flyer');
}
return response.blob();
}
+6 -1
View File
@@ -1278,6 +1278,11 @@
"qrStyleClassy": "Classy",
"qrStyleClassyRounded": "Classy Rounded",
"qrStyleExtraRounded": "Extra Rounded",
"qrStyleDot": "Dot"
"qrStyleDot": "Dot",
"flyerTheme": "Flyer Theme",
"flyerThemeLight": "Light",
"flyerThemeDark": "Dark",
"flyerGenerate": "Generate Flyer",
"flyerGenerating": "Generating..."
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.164.2"
version = "0.165.0"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"