优化 S3 客户端配置,动态设置 forcePathStyle 属性以支持 Minio, 暂时只发现minio需要frocePathSylte,tos不需要

This commit is contained in:
2026-02-06 19:45:17 +08:00
parent cb742807b4
commit 32f4e9c40f
2 changed files with 4 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ export async function minioProxy(
const fileUrl = opts.proxyUrl; const fileUrl = opts.proxyUrl;
const { createNotFoundPage, isDownload = false } = opts; const { createNotFoundPage, isDownload = false } = opts;
const objectName = fileUrl.replace(minioResources + '/', ''); const objectName = fileUrl.replace(minioResources + '/', '');
console.log('proxy url objectName', objectName)
try { try {
const stat = await oss.statObject(objectName); const stat = await oss.statObject(objectName);
if (stat?.size === 0) { if (stat?.size === 0) {
@@ -124,6 +125,7 @@ export const httpProxy = async (
const params = _u.searchParams; const params = _u.searchParams;
const isDownload = params.get('download') === 'true'; const isDownload = params.get('download') === 'true';
if (proxyUrl.startsWith(minioResources)) { if (proxyUrl.startsWith(minioResources)) {
console.log('isMinio', proxyUrl)
const isOk = await minioProxy(req, res, { ...opts, isDownload }); const isOk = await minioProxy(req, res, { ...opts, isDownload });
if (!isOk) { if (!isOk) {
userApp.clearCacheData(); userApp.clearCacheData();

View File

@@ -5,6 +5,7 @@ const config = useConfig();
export const bucketName = config.S3_BUCKET_NAME || 'resources'; export const bucketName = config.S3_BUCKET_NAME || 'resources';
const isMinio = config.S3_ENDPOINT?.includes?.('9000');
export const s3Client = new S3Client({ export const s3Client = new S3Client({
credentials: { credentials: {
accessKeyId: config.S3_ACCESS_KEY_ID || '', accessKeyId: config.S3_ACCESS_KEY_ID || '',
@@ -13,7 +14,7 @@ export const s3Client = new S3Client({
region: config.S3_REGION, region: config.S3_REGION,
endpoint: config.S3_ENDPOINT, endpoint: config.S3_ENDPOINT,
// minio配置 // minio配置
forcePathStyle: true, forcePathStyle: isMinio ? true : undefined,
}); });
// 判断 bucketName 是否存在,不存在则创建 // 判断 bucketName 是否存在,不存在则创建