mirror of
https://github.com/skidoodle/erettsegi-browser.git
synced 2025-02-15 05:39:15 +01:00
fix pdf
This commit is contained in:
parent
8ddc6cb182
commit
603a32b067
2 changed files with 11 additions and 14 deletions
|
@ -22,11 +22,11 @@ export default async function handler(
|
|||
try {
|
||||
const response = await fetch(link, { method: 'GET' })
|
||||
const contentType = response.headers.get('content-type')
|
||||
|
||||
if (contentType) {
|
||||
if (contentType == 'application/pdf') {
|
||||
res.setHeader('Content-Type', contentType)
|
||||
} else {
|
||||
const filename = link.split('/').pop() ?? 'download'
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`)
|
||||
res.setHeader('Content-Type', contentType)
|
||||
}
|
||||
|
||||
if (response.ok) {
|
||||
|
|
|
@ -14,18 +14,15 @@ export default async function handler(
|
|||
return res.status(400).json({ error: `Hiányzó paraméter: ${MissingParam}` })
|
||||
}
|
||||
|
||||
const secure = req.headers['x-forwarded-proto'] === 'https'
|
||||
const protocol = secure ? 'https' : 'http'
|
||||
const address = req.headers.host
|
||||
|
||||
if (!link.startsWith(`${protocol}://${address}`)) {
|
||||
return res.status(400).json({ error: 'Érvénytelen link' })
|
||||
}
|
||||
|
||||
try {
|
||||
const { protocol, host } = new URL(link)
|
||||
if (protocol && host) {
|
||||
const response = await fetch(link, { method: 'HEAD' })
|
||||
const status = response.status
|
||||
res.status(200).json({ status })
|
||||
} else {
|
||||
return res.status(400).json({ error: 'Érvénytelen link' })
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Internal Server Error' })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue