Skip to content

Commit

Permalink
remove unused routes, fix get device
Browse files Browse the repository at this point in the history
  • Loading branch information
docimin committed Sep 26, 2024
1 parent 1bf06b5 commit c79c1ff
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 51 deletions.
38 changes: 23 additions & 15 deletions src/app/[locale]/(main)/app/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@ import { DownloadIcon } from 'lucide-react'
import { Button } from '@/components/ui/button'
import Link from 'next/link'

const isMobileDevice = () => {
const userAgent =
navigator.userAgent || navigator.vendor || (window as any).opera
if (/android/i.test(userAgent)) {
return 'android'
}
if (/iPad|iPhone|iPod/.test(userAgent) && !(window as any).MSStream) {
return 'ios'
interface DeviceType {
model?: string
type?: string
vendor?: string
}

const isMobileDevice = async () => {
const deviceType: DeviceType = await fetch('/api/device').then((res) =>
res.json()
)

if (deviceType.type === 'mobile') {
if (deviceType.vendor === 'Apple') {
window.location.href = 'https://apps.apple.com/app/headpat/id6502715063'
} else if (deviceType.vendor === 'Google') {
window.location.href =
'https://play.google.com/store/apps/details?id=com.headpat.app'
}
}
return null
return 'unknown'
}

export default function PageClient() {
useEffect(() => {
const deviceType = isMobileDevice()
if (deviceType === 'android') {
window.location.href =
'https://play.google.com/store/apps/details?id=com.headpat.app'
} else if (deviceType === 'ios') {
window.location.href = 'https://apps.apple.com/app/headpat/id6502715063'
const fetchDevice = async () => {
await isMobileDevice()
}

fetchDevice().then()
}, [])

return (
Expand Down
21 changes: 0 additions & 21 deletions src/app/api/account/gallery/singleImage/route.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/app/api/device/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NextRequest, NextResponse, userAgent } from 'next/server'

export async function GET(request: NextRequest) {
const { device } = userAgent(request)
return NextResponse.json(device)
}
14 changes: 0 additions & 14 deletions src/app/api/events/route.ts

This file was deleted.

15 changes: 14 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { Toaster } from '@/components/ui/toaster'
import { Toaster as SonnerToaster } from '@/components/ui/sonner'
import { cn } from '@/lib/utils'
import { UserProvider } from '@/components/contexts/UserContext'
import { Metadata } from 'next'

const inter = Inter({ subsets: ['latin'] })

export async function generateMetadata() {
export async function generateMetadata(): Promise<Metadata> {
return {
title: {
default: 'Headpat Community',
Expand All @@ -29,6 +30,7 @@ export async function generateMetadata() {
],
icons: {
icon: '/logos/Headpat_Logo_web_1024x1024_240518-02.png',
apple: '/logos/Headpat_Logo_web_1024x1024_240518-02.png',
},
openGraph: {
title: 'Headpat Community',
Expand All @@ -37,6 +39,17 @@ export async function generateMetadata() {
images: '/logos/Headpat_Logo_web_1024x1024_240518-02.png',
type: 'website',
},
appLinks: {
android: {
url: 'https://play.google.com/store/apps/details?id=com.headpat.app',
package: 'com.headpat.app',
},
ios: {
url: 'https://apps.apple.com/app/headpat/id6502715063',
app_store_id: '6502715063',
},
},
generator: 'Headpat',
metadataBase: new URL(process.env.NEXT_PUBLIC_DOMAIN),
}
}
Expand Down

0 comments on commit c79c1ff

Please sign in to comment.