temp add download check
This commit is contained in:
parent
e15d0be1e1
commit
b4fc1a545c
@ -34,10 +34,11 @@ export async function minioProxy(
|
|||||||
proxyUrl: string;
|
proxyUrl: string;
|
||||||
userApp: UserApp;
|
userApp: UserApp;
|
||||||
createNotFoundPage: (msg?: string) => any;
|
createNotFoundPage: (msg?: string) => any;
|
||||||
|
isDownload?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const fileUrl = opts.proxyUrl;
|
const fileUrl = opts.proxyUrl;
|
||||||
const { userApp, createNotFoundPage } = opts;
|
const { userApp, createNotFoundPage, isDownload = false } = opts;
|
||||||
const objectName = fileUrl.replace(minioResources + '/', '');
|
const objectName = fileUrl.replace(minioResources + '/', '');
|
||||||
try {
|
try {
|
||||||
const stat = await minioClient.statObject(bucketName, objectName);
|
const stat = await minioClient.statObject(bucketName, objectName);
|
||||||
@ -58,7 +59,7 @@ export async function minioProxy(
|
|||||||
'file-name': fileName,
|
'file-name': fileName,
|
||||||
...filterMetaData,
|
...filterMetaData,
|
||||||
};
|
};
|
||||||
if (objectName.endsWith('.html')) {
|
if (objectName.endsWith('.html') && !isDownload) {
|
||||||
const { html, contentLength } = await getTextFromStreamAndAddStat(objectStream);
|
const { html, contentLength } = await getTextFromStreamAndAddStat(objectStream);
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
...headers,
|
...headers,
|
||||||
@ -109,8 +110,11 @@ export const httpProxy = async (
|
|||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const { proxyUrl, userApp, createNotFoundPage } = opts;
|
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)) {
|
if (proxyUrl.startsWith(minioResources)) {
|
||||||
return minioProxy(req, res, opts);
|
return minioProxy(req, res, { ...opts, isDownload });
|
||||||
}
|
}
|
||||||
let protocol = proxyUrl.startsWith('https') ? https : http;
|
let protocol = proxyUrl.startsWith('https') ? https : http;
|
||||||
// 代理
|
// 代理
|
||||||
@ -125,7 +129,7 @@ export const httpProxy = async (
|
|||||||
res.writeHead(302, { Location: proxyRes.headers.location });
|
res.writeHead(302, { Location: proxyRes.headers.location });
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
if (proxyUrl.endsWith('.html')) {
|
if (proxyUrl.endsWith('.html') && !isDownload) {
|
||||||
try {
|
try {
|
||||||
const { html, contentLength } = await getTextFromStreamAndAddStat(proxyRes);
|
const { html, contentLength } = await getTextFromStreamAndAddStat(proxyRes);
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user