This commit is contained in:
skidoodle 2024-01-23 09:55:57 +01:00
parent 3e8dfabcc4
commit 50df2a4739
3 changed files with 67 additions and 7 deletions

60
src/pages/_error.tsx Normal file
View file

@ -0,0 +1,60 @@
import { Footer } from '@/components/Footer'
import { Button } from '@nextui-org/button'
import Link from 'next/link'
import type { GetServerSideProps, GetServerSidePropsContext } from 'next'
interface ErrorProps {
statusCode: number
}
const ErrorPage: React.FC<ErrorProps> = ({ statusCode }) => {
return (
<>
<main className='dark:bg-[#121212] text-foreground bg-background py-5'>
<h1 className='text-7xl font-bold text-blue-400 text-center mt-16'>
{statusCode}
</h1>
<div className='flex min-h-screen flex-col items-center justify-between'>
<div className='container mx-auto'>
<div className='flex flex-col items-center justify-center'>
<div className='mt-5 mb-3'>
<div className='text-2xl font-semibold text-gray-600'>
{statusCode == 404 ? (
<>
<p className='mt-2'>Az keresett oldal nem található.</p>
<p className='mt-8 text-center'>
<Button color='primary'>
<Link href='/'>{'Vissza'}</Link>
</Button>
</p>
</>
) : (
<>
<p className='mt-2'>Váratlan hiba történt.</p>
<p className='mt-8 text-center'>
<Button color='primary'>
<Link href='/'>{'Vissza'}</Link>
</Button>
</p>
</>
)}
</div>
</div>
</div>
</div>
</div>
<Footer />
</main>
</>
)
}
export const getServerSideProps: GetServerSideProps<ErrorProps> = async (
context: GetServerSidePropsContext
) => ({
props: {
statusCode: context.res ? context.res.statusCode : 404,
},
})
export default ErrorPage

View file

@ -23,11 +23,11 @@ export default async function handler(
res.setHeader('Cache-Control', 's-maxage=31536000')
const response = await fetch(link, { method: 'GET' })
const contentType = response.headers.get('content-type')
if (contentType == 'application/pdf') {
const filename = link.split('/').pop() ?? 'document.pdf'
res.setHeader('Content-Type', contentType)
} else {
const filename = link.split('/').pop() ?? 'download'
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`)
res.setHeader('Content-Disposition', `inline; filename="${filename}"`)
}
if (response.ok) {

View file

@ -5,13 +5,13 @@ export default async function handler(
res: NextApiResponse
) {
const { link } = req.query as { link: string }
let MissingParam: string | null = null
let missingParam: string | null = null
if (!link) {
MissingParam = 'link'
missingParam = 'link'
}
if (MissingParam) {
return res.status(400).json({ error: `Hiányzó paraméter: ${MissingParam}` })
if (missingParam) {
return res.status(400).json({ error: `Hiányzó paraméter: ${missingParam}` })
}
try {