diff --git a/lib/storage.js b/lib/storage.js index 879f982..efdaee2 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -38,8 +38,13 @@ export async function saveObject(name, buffer, contentType) { headers: { 'Content-Type': contentType || 'application/octet-stream' }, body: new Uint8Array(buffer), }); + // 公开域名直连 bucket(对象 key = 文件名,不带 bucket 前缀); + // 无公开域名时回退到 S3 endpoint 路径式(endpoint/bucket/name) const base = (S3_PUBLIC_URL || S3_ENDPOINT).replace(/\/$/, ''); - return { url: `${base}/${S3_BUCKET}/${name}` }; + const url = S3_PUBLIC_URL + ? `${base}/${name}` + : `${base}/${S3_BUCKET}/${name}`; + return { url }; } // 读取对象 → Buffer 或 null