add sort param for index api
This commit is contained in:
parent
9e887b2b38
commit
2d2beadbba
1 changed files with 15 additions and 11 deletions
|
@ -169,7 +169,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
}
|
||||
|
||||
// If method is GET, then the API is a normal request to the OneDrive API for files or folders
|
||||
const { path = '/', raw = false, next = '' } = req.query
|
||||
const { path = '/', raw = false, next = '', sort = '' } = req.query
|
||||
|
||||
// Set edge function caching for faster load times, check docs:
|
||||
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||
|
@ -187,6 +187,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
}
|
||||
const cleanPath = pathPosix.resolve('/', pathPosix.normalize(path))
|
||||
|
||||
// Validate sort param
|
||||
if (typeof sort !== 'string') {
|
||||
res.status(400).json({ error: 'Sort query invalid.' })
|
||||
return
|
||||
}
|
||||
|
||||
const accessToken = await getAccessToken()
|
||||
|
||||
// Return error 403 if access_token is empty
|
||||
|
@ -248,16 +254,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
if ('folder' in identityData) {
|
||||
const { data: folderData } = await axios.get(`${requestUrl}${isRoot ? '' : ':'}/children`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
params: next
|
||||
? {
|
||||
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
||||
top: siteConfig.maxItems,
|
||||
$skipToken: next,
|
||||
}
|
||||
: {
|
||||
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
||||
top: siteConfig.maxItems,
|
||||
},
|
||||
params: {
|
||||
...{
|
||||
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
||||
top: siteConfig.maxItems,
|
||||
},
|
||||
...(next ? { $skipToken: next } : {}),
|
||||
...(sort ? { $orderby: sort } : {}),
|
||||
},
|
||||
})
|
||||
|
||||
// Extract next page token from full @odata.nextLink
|
||||
|
|
Loading…
Reference in a new issue