mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
Merge pull request #308 from myl7/slash
This commit is contained in:
+4
-3
@@ -19,7 +19,7 @@ const clientSecret = revealObfuscatedToken(apiConfig.obfuscatedClientSecret)
|
|||||||
* @returns Absolute path of the file inside OneDrive
|
* @returns Absolute path of the file inside OneDrive
|
||||||
*/
|
*/
|
||||||
export function encodePath(path: string): string {
|
export function encodePath(path: string): string {
|
||||||
let encodedPath = pathPosix.join(basePath, pathPosix.resolve('/', path))
|
let encodedPath = pathPosix.join(basePath, path)
|
||||||
if (encodedPath === '/' || encodedPath === '') {
|
if (encodedPath === '/' || encodedPath === '') {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
@@ -109,6 +109,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
res.status(400).json({ error: 'Path query invalid.' })
|
res.status(400).json({ error: 'Path query invalid.' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const cleanPath = pathPosix.resolve('/', pathPosix.normalize(path))
|
||||||
|
|
||||||
const accessToken = await getAccessToken()
|
const accessToken = await getAccessToken()
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const protectedRoutes = siteConfig.protectedRoutes
|
const protectedRoutes = siteConfig.protectedRoutes
|
||||||
let authTokenPath = ''
|
let authTokenPath = ''
|
||||||
for (const r of protectedRoutes) {
|
for (const r of protectedRoutes) {
|
||||||
if (path.startsWith(r)) {
|
if (cleanPath.startsWith(r)) {
|
||||||
authTokenPath = `${r}/.password`
|
authTokenPath = `${r}/.password`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -161,7 +162,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestPath = encodePath(path)
|
const requestPath = encodePath(cleanPath)
|
||||||
// Handle response from OneDrive API
|
// Handle response from OneDrive API
|
||||||
const requestUrl = `${apiConfig.driveApi}/root${requestPath}`
|
const requestUrl = `${apiConfig.driveApi}/root${requestPath}`
|
||||||
// Whether path is root, which requires some special treatment
|
// Whether path is root, which requires some special treatment
|
||||||
|
|||||||
Reference in New Issue
Block a user