temp add download check

This commit is contained in:
熊潇 2025-04-15 23:33:18 +08:00
parent e15d0be1e1
commit b4fc1a545c

View File

@ -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, {