Skip to content

Commit

Permalink
Merge pull request #65 from AlgernonGuo/fix/third-party-client-link
Browse files Browse the repository at this point in the history
修复文件无法通过第三方客户端在线打开的问题
  • Loading branch information
traceless committed Jul 10, 2024
2 parents 13b91cb + 139a828 commit 77c3284
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 77c3284

Please sign in to comment.