finish raw file redirect on server side, close #4

This commit is contained in:
spencerwooo
2021-06-25 19:22:22 +01:00
parent 1cbb33644f
commit d09bc1c362
4 changed files with 48 additions and 12 deletions
+15 -2
View File
@@ -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
}