mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
finish raw file redirect on server side, close #4
This commit is contained in:
+15
-2
@@ -39,9 +39,10 @@ const getAccessToken = async () => {
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { path = '/' } = req.query
|
||||
const { path = '/', raw = false } = req.query
|
||||
if (path === '[...path]') {
|
||||
res.status(400).json({ error: 'Path query invalid.' })
|
||||
res.status(400).json({ error: 'No path specified.' })
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof path === 'string') {
|
||||
@@ -55,9 +56,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
})
|
||||
|
||||
if (raw) {
|
||||
if ('folder' in data) {
|
||||
res.status(400).json({ error: "Folders doesn't have raw download urls." })
|
||||
return
|
||||
}
|
||||
if ('file' in data) {
|
||||
res.redirect(data['@microsoft.graph.downloadUrl'])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({ path, data })
|
||||
return
|
||||
}
|
||||
|
||||
res.status(404).json({ error: 'Path query invalid.' })
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user