From 139a828ecca0556e032b3a1034350d39a7e7d45e Mon Sep 17 00:00:00 2001 From: AlgernonGuo <38326506+GEXRain@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=9A=E8=BF=87=E7=AC=AC=E4=B8=89=E6=96=B9=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=9C=A8=E7=BA=BF=E6=89=93=E5=BC=80=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原因:Alist的第三方客户端链接由前端页面生成未加密路径导致 --- node-proxy/app.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/node-proxy/app.js b/node-proxy/app.js index 6f555a2..cf2bf9b 100644 --- a/node-proxy/app.js +++ b/node-proxy/app.js @@ -27,6 +27,7 @@ import { cacheFileInfo, getFileInfo } from '@/dao/fileDao' import { getWebdavFileInfo } from '@/utils/webdavClient' import staticServer from 'koa-static' import { logger } from '@/common/logger' +import { encodeName } from '@/utils/commonUtil' async function sleep(time) { return new Promise((resolve) => { @@ -165,7 +166,21 @@ async function proxyHandle(ctx, next) { if (filePath.indexOf('/d/') === 0) { filePath = filePath.replace('/d/', '/') } - const fileInfo = await getFileInfo(filePath) + // 尝试获取文件信息,如果未找到相应的文件信息,则对文件名进行加密处理后重新尝试获取文件信息 + let fileInfo = await getFileInfo(filePath); + + if (fileInfo === null) { + const rawFileName = decodeURIComponent(path.basename(filePath)); + const ext = path.extname(rawFileName); + const encodedRawFileName = encodeURIComponent(rawFileName); + const encFileName = encodeName(passwdInfo.password, passwdInfo.encType, rawFileName); + const newFileName = encFileName + ext; + + filePath = filePath.replace(encodedRawFileName, newFileName); + request.urlAddr = request.urlAddr.replace(encodedRawFileName, newFileName); + + fileInfo = await getFileInfo(filePath); + } logger.info('@@getFileInfo:', filePath, fileInfo, request.urlAddr) if (fileInfo) { request.fileSize = fileInfo.size * 1