优化文件流处理,添加对 Bun 环境的支持,重构管道传输函数,改进内容类型获取逻辑
This commit is contained in:
@@ -8,6 +8,7 @@ import { bucketName } from '@/modules/minio.ts';
|
||||
import { getLoginUser } from '../middleware/auth.ts';
|
||||
import { BucketItemStat } from 'minio';
|
||||
import { UserPermission, Permission } from '@kevisual/permission';
|
||||
import { pipeMinioStream } from '@/modules/fm-manager/index.ts';
|
||||
|
||||
/**
|
||||
* 过滤 metaData 中的 key, 去除 password, accesskey, secretkey,
|
||||
@@ -101,5 +102,6 @@ export const authMinio = async (req: IncomingMessage, res: ServerResponse, objec
|
||||
});
|
||||
const objectStream = await minioClient.getObject(bucketName, objectName);
|
||||
|
||||
objectStream.pipe(res, { end: true });
|
||||
// objectStream.pipe(res, { end: true });
|
||||
pipeMinioStream(objectStream, res);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDNS, isIpv4OrIpv6, isLocalhost, pipeFileStream } from '../modules/fm-manager/index.ts';
|
||||
import { getDNS, isIpv4OrIpv6, isLocalhost, pipeFileStream, pipeProxyReq, pipeProxyRes } from '../modules/fm-manager/index.ts';
|
||||
import http from 'node:http';
|
||||
import https from 'node:https';
|
||||
import { UserApp } from '../modules/user-app/index.ts';
|
||||
@@ -110,7 +110,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
||||
// 将代理服务器的响应头和状态码返回给客户端
|
||||
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
||||
// 将代理响应流写入客户端响应
|
||||
proxyRes.pipe(res, { end: true });
|
||||
// proxyRes.pipe(res, { end: true });
|
||||
pipeProxyRes(proxyRes, res);
|
||||
});
|
||||
// 处理代理请求的错误事件
|
||||
proxyReq.on('error', (err) => {
|
||||
@@ -119,7 +120,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
||||
res.write(`Proxy request error: ${err.message}`);
|
||||
});
|
||||
// 处理 POST 请求的请求体(传递数据到目标服务器)
|
||||
req.pipe(proxyReq, { end: true });
|
||||
// req.pipe(proxyReq, { end: true });
|
||||
pipeProxyReq(req, proxyReq, res);
|
||||
return;
|
||||
}
|
||||
if (req.url.startsWith('/api') || req.url.startsWith('/v1')) {
|
||||
|
||||
Reference in New Issue
Block a user