This commit is contained in:
skidoodle 2023-12-13 12:36:21 +01:00
parent 8ddc6cb182
commit 603a32b067
2 changed files with 11 additions and 14 deletions

View file

@ -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) {

View file

@ -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 response = await fetch(link, { method: 'HEAD' })
const status = response.status
res.status(200).json({ status })
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' })
}