feat(apps): update mobile app store links and implement unified device-detecting QR code
This commit is contained in:
@@ -7,39 +7,44 @@ export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { tool: string; app: string } }
|
||||
) {
|
||||
const tool = getToolBySlug(params.tool) || getToolById(params.tool);
|
||||
const app = getAppBySlug(params.app) || getAppById(params.app);
|
||||
try {
|
||||
const tool = getToolBySlug(params.tool) || getToolById(params.tool);
|
||||
const app = getAppBySlug(params.app) || getAppById(params.app);
|
||||
|
||||
if (!app) {
|
||||
return NextResponse.redirect(new URL('/apps', req.url));
|
||||
if (!app) {
|
||||
return NextResponse.redirect(new URL('/apps', req.url));
|
||||
}
|
||||
|
||||
const userAgent = req.headers.get('user-agent') || '';
|
||||
const isAndroid = /android/i.test(userAgent);
|
||||
const isIOS = /ipad|iphone|ipod/i.test(userAgent);
|
||||
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const source = searchParams.get('utm_source') || 'web_try';
|
||||
const campaign = searchParams.get('utm_campaign') || (tool ? tool.slug : 'general');
|
||||
|
||||
if (isAndroid) {
|
||||
const playUrl = app.stores.android?.url || 'https://play.google.com';
|
||||
const finalUrl = new URL(playUrl);
|
||||
finalUrl.searchParams.set('referrer', `utm_source=${source}&utm_campaign=${campaign}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
if (isIOS) {
|
||||
const iosUrl = app.stores.ios?.url || 'https://apps.apple.com';
|
||||
const finalUrl = new URL(iosUrl);
|
||||
finalUrl.searchParams.set('pt', '123456');
|
||||
finalUrl.searchParams.set('ct', `${source}_${campaign}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
// Desktop visitor -> Redirect to app page with QR code & deep link info
|
||||
const desktopUrl = new URL(`/apps/${app.slug}`, req.url);
|
||||
desktopUrl.searchParams.set('src', source);
|
||||
desktopUrl.searchParams.set('tool', tool ? tool.slug : '');
|
||||
return NextResponse.redirect(desktopUrl.toString());
|
||||
} catch (err: any) {
|
||||
console.error('[go route error]', err);
|
||||
return NextResponse.json({ error: err?.message || String(err) }, { status: 500 });
|
||||
}
|
||||
|
||||
const userAgent = req.headers.get('user-agent') || '';
|
||||
const isAndroid = /android/i.test(userAgent);
|
||||
const isIOS = /ipad|iphone|ipod/i.test(userAgent);
|
||||
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const source = searchParams.get('utm_source') || 'web_try';
|
||||
const campaign = searchParams.get('utm_campaign') || (tool ? tool.slug : 'general');
|
||||
|
||||
if (isAndroid) {
|
||||
const playUrl = app.stores.android?.url || 'https://play.google.com';
|
||||
const finalUrl = new URL(playUrl);
|
||||
finalUrl.searchParams.set('referrer', `utm_source=${source}&utm_campaign=${campaign}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
if (isIOS) {
|
||||
const iosUrl = app.stores.ios?.url || 'https://apps.apple.com';
|
||||
const finalUrl = new URL(iosUrl);
|
||||
finalUrl.searchParams.set('pt', '123456');
|
||||
finalUrl.searchParams.set('ct', `${source}_${campaign}`);
|
||||
return NextResponse.redirect(finalUrl.toString());
|
||||
}
|
||||
|
||||
// Desktop visitor -> Redirect to app page with QR code & deep link info
|
||||
const desktopUrl = new URL(`/apps/${app.slug}`, req.url);
|
||||
desktopUrl.searchParams.set('src', source);
|
||||
desktopUrl.searchParams.set('tool', tool ? tool.slug : '');
|
||||
return NextResponse.redirect(desktopUrl.toString());
|
||||
}
|
||||
|
||||
@@ -40,13 +40,21 @@ export function AppHandoffSection({
|
||||
|
||||
if (!app) return null;
|
||||
|
||||
const baseHost = origin || 'http://localhost:3000';
|
||||
const androidUrl = app.stores?.android?.url || 'https://play.google.com';
|
||||
const iosUrl = app.stores?.ios?.url || 'https://apps.apple.com';
|
||||
|
||||
const redirectHost =
|
||||
process.env.NEXT_PUBLIC_APP_REDIRECT_HOST ||
|
||||
process.env.NEXT_PUBLIC_SITE_URL ||
|
||||
origin ||
|
||||
'http://localhost:3000';
|
||||
|
||||
const targetUrl = tool
|
||||
? `${baseHost}/go/${tool.slug}/${app.slug}`
|
||||
: `${baseHost}/apps/${app.slug}`;
|
||||
? `${redirectHost}/go/${tool.slug}/${app.slug}`
|
||||
: `${redirectHost}/go/explore/${app.slug}`;
|
||||
|
||||
useEffect(() => {
|
||||
if (showQr) {
|
||||
if (showQr && targetUrl) {
|
||||
QRCode.toDataURL(targetUrl, {
|
||||
width: 220,
|
||||
margin: 1,
|
||||
@@ -132,7 +140,7 @@ export function AppHandoffSection({
|
||||
<span className="text-xs text-muted font-body block">Direct store installation</span>
|
||||
<div className="flex flex-col sm:flex-row flex-wrap gap-3">
|
||||
<a
|
||||
href={app.stores?.ios?.url || `/go/${tool?.slug || 'explore'}/${app.slug}`}
|
||||
href={iosUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
|
||||
@@ -143,7 +151,7 @@ export function AppHandoffSection({
|
||||
</a>
|
||||
|
||||
<a
|
||||
href={app.stores?.android?.url || `/go/${tool?.slug || 'explore'}/${app.slug}`}
|
||||
href={androidUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
|
||||
@@ -157,7 +165,7 @@ export function AppHandoffSection({
|
||||
type="button"
|
||||
onClick={copyLink}
|
||||
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
|
||||
aria-label="Copy direct deep link"
|
||||
aria-label="Copy smart redirect link"
|
||||
>
|
||||
{copiedLink ? <Check className="w-4 h-4 text-accent" aria-hidden="true" /> : <Copy className="w-4 h-4 text-muted" aria-hidden="true" />}
|
||||
<span>{copiedLink ? 'Link copied' : 'Copy link'}</span>
|
||||
@@ -170,22 +178,28 @@ export function AppHandoffSection({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column: Clean QR Code Card */}
|
||||
{/* Right Column: Single Smart QR Code Card */}
|
||||
{showQr && qrDataUrl && (
|
||||
<div className="lg:col-span-5 studio-sheet rounded-3xl p-6 sm:p-8 text-center flex flex-col items-center">
|
||||
<span className="text-xs text-muted font-body mb-4">Scan with phone camera</span>
|
||||
<span className="text-xs text-muted font-body mb-3 font-semibold uppercase tracking-wider">
|
||||
Scan with Phone Camera
|
||||
</span>
|
||||
|
||||
<div className="p-4 bg-paper-hi border border-rule rounded-2xl inline-block shadow-sm">
|
||||
<img
|
||||
src={qrDataUrl}
|
||||
alt={`Scan QR code to install ${appName}`}
|
||||
alt={`Scan single QR code to open ${appName}`}
|
||||
className="w-44 h-44 object-contain rounded-xl"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 space-y-1 text-xs font-body text-muted">
|
||||
<p className="font-medium text-ink">Instant mobile handoff</p>
|
||||
<p>Directs to App Store or Google Play for instantaneous installation.</p>
|
||||
<div className="mt-4 space-y-1.5 text-xs font-body text-muted">
|
||||
<p className="font-semibold text-ink flex items-center justify-center gap-1.5">
|
||||
<span>⚡ Automatic Store Detection</span>
|
||||
</p>
|
||||
<p className="text-[11.5px] text-muted max-w-xs leading-relaxed">
|
||||
Single QR code — automatically opens <strong>Google Play</strong> on Android or <strong>Apple App Store</strong> on iPhone.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -94,7 +94,7 @@ const DEFAULT_RECOMMENDED_APPS = [
|
||||
{
|
||||
id: 'app-enhancer',
|
||||
slug: 'photo-enhancer-pro',
|
||||
name: 'Enhance Ultra AI',
|
||||
name: 'Enhance Photo Quality',
|
||||
tagline: 'Generative 4K super-resolution and archival restoration',
|
||||
category: 'Super resolution',
|
||||
platforms: ['iOS 17+', 'Android 14+'],
|
||||
@@ -104,7 +104,7 @@ const DEFAULT_RECOMMENDED_APPS = [
|
||||
{
|
||||
id: 'app-cutout',
|
||||
slug: 'bg-cleaner-app',
|
||||
name: 'Magic Cutout Studio',
|
||||
name: 'BG Remove: Background Editor',
|
||||
tagline: 'Sub-pixel P3M alpha matting and background removal',
|
||||
category: 'Background cutout',
|
||||
platforms: ['iOS 17+', 'Android 14+'],
|
||||
|
||||
@@ -77,23 +77,33 @@ export function PostResultAppHandoff({
|
||||
const appName = resolveLocalised(appData.name, locale);
|
||||
const toolName = tool.name ? resolveLocalised(tool.name, locale) : 'Photo Tools';
|
||||
|
||||
const baseHost = origin || 'http://localhost:3000';
|
||||
const targetUrl = `${baseHost}/go/${tool.slug}/${appData.slug}?src=${variant}`;
|
||||
const iosUrl = appData.stores?.ios?.url || `/go/${tool.slug}/${appData.slug}?src=ios`;
|
||||
const androidUrl = appData.stores?.android?.url || `/go/${tool.slug}/${appData.slug}?src=android`;
|
||||
const redirectHost =
|
||||
process.env.NEXT_PUBLIC_APP_REDIRECT_HOST ||
|
||||
process.env.NEXT_PUBLIC_SITE_URL ||
|
||||
origin ||
|
||||
'http://localhost:3000';
|
||||
|
||||
const targetUrl = tool
|
||||
? `${redirectHost}/go/${tool.slug}/${appData.slug}?src=${variant}`
|
||||
: `${redirectHost}/go/explore/${appData.slug}?src=${variant}`;
|
||||
|
||||
const iosUrl = appData.stores?.ios?.url || 'https://apps.apple.com';
|
||||
const androidUrl = appData.stores?.android?.url || 'https://play.google.com';
|
||||
|
||||
// Generate dynamic QR Code for instant phone handoff
|
||||
useEffect(() => {
|
||||
QRCode.toDataURL(targetUrl, {
|
||||
width: 240,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark: '#0f172a',
|
||||
light: '#ffffff',
|
||||
},
|
||||
})
|
||||
.then((url) => setQrDataUrl(url))
|
||||
.catch((err) => console.error('Failed to generate QR code:', err));
|
||||
if (targetUrl) {
|
||||
QRCode.toDataURL(targetUrl, {
|
||||
width: 240,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark: '#0f172a',
|
||||
light: '#ffffff',
|
||||
},
|
||||
})
|
||||
.then((url) => setQrDataUrl(url))
|
||||
.catch((err) => console.error('Failed to generate QR code:', err));
|
||||
}
|
||||
}, [targetUrl]);
|
||||
|
||||
const handleCopyLink = (e: React.MouseEvent) => {
|
||||
@@ -315,7 +325,7 @@ export function PostResultAppHandoff({
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={qrDataUrl}
|
||||
alt={`Scan QR code to install ${appName}`}
|
||||
alt={`Scan single QR code to install ${appName}`}
|
||||
className="w-40 h-40 object-contain rounded-xl select-none"
|
||||
/>
|
||||
) : (
|
||||
@@ -326,12 +336,12 @@ export function PostResultAppHandoff({
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<p className="text-[11px] text-slate-600 font-sans leading-tight">
|
||||
Instantly opens App Store or Google Play directly on your phone.
|
||||
<p className="text-[11.5px] text-slate-800 font-sans font-semibold leading-tight">
|
||||
⚡ Automatic Store Detection
|
||||
</p>
|
||||
<p className="text-[11px] text-slate-500 font-sans leading-relaxed">
|
||||
Automatically opens <strong>Google Play</strong> on Android or <strong>App Store</strong> on iPhone.
|
||||
</p>
|
||||
<span className="inline-block text-[10px] text-slate-400 font-sans">
|
||||
Works on iOS 15+ and Android 9+
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user