mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
add sort param for index api
This commit is contained in:
+15
-11
@@ -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
|
// 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:
|
// Set edge function caching for faster load times, check docs:
|
||||||
// https://vercel.com/docs/concepts/functions/edge-caching
|
// 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))
|
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()
|
const accessToken = await getAccessToken()
|
||||||
|
|
||||||
// Return error 403 if access_token is empty
|
// 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) {
|
if ('folder' in identityData) {
|
||||||
const { data: folderData } = await axios.get(`${requestUrl}${isRoot ? '' : ':'}/children`, {
|
const { data: folderData } = await axios.get(`${requestUrl}${isRoot ? '' : ':'}/children`, {
|
||||||
headers: { Authorization: `Bearer ${accessToken}` },
|
headers: { Authorization: `Bearer ${accessToken}` },
|
||||||
params: next
|
params: {
|
||||||
? {
|
...{
|
||||||
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
||||||
top: siteConfig.maxItems,
|
top: siteConfig.maxItems,
|
||||||
$skipToken: next,
|
},
|
||||||
}
|
...(next ? { $skipToken: next } : {}),
|
||||||
: {
|
...(sort ? { $orderby: sort } : {}),
|
||||||
select: 'name,size,id,lastModifiedDateTime,folder,file,video,image',
|
},
|
||||||
top: siteConfig.maxItems,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Extract next page token from full @odata.nextLink
|
// Extract next page token from full @odata.nextLink
|
||||||
|
|||||||
Reference in New Issue
Block a user