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 {
|
try {
|
||||||
const response = await fetch(link, { method: 'GET' })
|
const response = await fetch(link, { method: 'GET' })
|
||||||
const contentType = response.headers.get('content-type')
|
const contentType = response.headers.get('content-type')
|
||||||
|
if (contentType == 'application/pdf') {
|
||||||
if (contentType) {
|
res.setHeader('Content-Type', contentType)
|
||||||
|
} else {
|
||||||
const filename = link.split('/').pop() ?? 'download'
|
const filename = link.split('/').pop() ?? 'download'
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`)
|
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`)
|
||||||
res.setHeader('Content-Type', contentType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
|
@ -14,18 +14,15 @@ export default async function handler(
|
||||||
return res.status(400).json({ error: `Hiányzó paraméter: ${MissingParam}` })
|
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 {
|
try {
|
||||||
const response = await fetch(link, { method: 'HEAD' })
|
const { protocol, host } = new URL(link)
|
||||||
const status = response.status
|
if (protocol && host) {
|
||||||
res.status(200).json({ status })
|
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) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: 'Internal Server Error' })
|
res.status(500).json({ error: 'Internal Server Error' })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue