Skip to content

Commit

Permalink
修复文件无法通过第三方客户端在线打开的问题
Browse files Browse the repository at this point in the history
原因:Alist的第三方客户端链接由前端页面生成未加密路径导致
  • Loading branch information
AlgernonGuo committed Jul 4, 2024
1 parent 13b91cb commit 139a828
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion node-proxy/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 139a828

Please sign in to comment.