diff --git a/src/module/proxy/http-proxy.ts b/src/module/proxy/http-proxy.ts index db6908b..ca826ba 100644 --- a/src/module/proxy/http-proxy.ts +++ b/src/module/proxy/http-proxy.ts @@ -34,10 +34,11 @@ export async function minioProxy( proxyUrl: string; userApp: UserApp; createNotFoundPage: (msg?: string) => any; + isDownload?: boolean; }, ) { const fileUrl = opts.proxyUrl; - const { userApp, createNotFoundPage } = opts; + const { userApp, createNotFoundPage, isDownload = false } = opts; const objectName = fileUrl.replace(minioResources + '/', ''); try { const stat = await minioClient.statObject(bucketName, objectName); @@ -58,7 +59,7 @@ export async function minioProxy( 'file-name': fileName, ...filterMetaData, }; - if (objectName.endsWith('.html')) { + if (objectName.endsWith('.html') && !isDownload) { const { html, contentLength } = await getTextFromStreamAndAddStat(objectStream); res.writeHead(200, { ...headers, @@ -109,8 +110,11 @@ export const httpProxy = async ( }, ) => { const { proxyUrl, userApp, createNotFoundPage } = opts; + const _u = new URL(req.url, 'http://localhost'); + const params = _u.searchParams; + const isDownload = params.get('download') === 'true'; if (proxyUrl.startsWith(minioResources)) { - return minioProxy(req, res, opts); + return minioProxy(req, res, { ...opts, isDownload }); } let protocol = proxyUrl.startsWith('https') ? https : http; // 代理 @@ -125,7 +129,7 @@ export const httpProxy = async ( res.writeHead(302, { Location: proxyRes.headers.location }); return res.end(); } - if (proxyUrl.endsWith('.html')) { + if (proxyUrl.endsWith('.html') && !isDownload) { try { const { html, contentLength } = await getTextFromStreamAndAddStat(proxyRes); res.writeHead(200, {