Merge pull request #308 from myl7/slash

This commit is contained in:
Spencer Woo
2022-01-25 09:27:30 +08:00
committed by GitHub
+4 -3
View File
@@ -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