From 877f03a8cf6b9b21602a8bb086f17dbad6d155a4 Mon Sep 17 00:00:00 2001 From: eoao Date: Sat, 3 Jan 2026 00:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=99=84=E4=BB=B6=E5=92=8C?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=BF=9D=E5=AD=98=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mail-worker/src/service/r2-service.js | 29 +++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/mail-worker/src/service/r2-service.js b/mail-worker/src/service/r2-service.js index caf54d8..0a45392 100644 --- a/mail-worker/src/service/r2-service.js +++ b/mail-worker/src/service/r2-service.js @@ -1,7 +1,6 @@ import s3Service from './s3-service'; import settingService from './setting-service'; import kvObjService from './kv-obj-service'; -import { settingConst } from '../const/entity-const'; const r2Service = { @@ -23,22 +22,20 @@ const r2Service = { async putObj(c, key, content, metadata) { - const { kvStorage } = await settingService.query(c); - - if (kvStorage === settingConst.kvStorage.OPEN) { + const storageType = await this.storageType(c); + if (storageType === 'KV') { await kvObjService.putObj(c, key, content, metadata); + } - } else if (c.env.r2) { - + if (storageType === 'R2') { await c.env.r2.put(key, content, { httpMetadata: { ...metadata } }); + } - } else { - + if (storageType === 'S3') { await s3Service.putObj(c, key, content, metadata); - } }, @@ -49,20 +46,18 @@ const r2Service = { async delete(c, key) { - const { kvStorage } = await settingService.query(c); - - if (kvStorage === settingConst.kvStorage.OPEN) { + const storageType = await this.storageType(c); + if (storageType === 'KV') { await kvObjService.deleteObj(c, key); + } - } else if (c.env.r2) { - + if (storageType === 'R2') { await c.env.r2.delete(key); + } - } else { - + if (storageType === 'S3'){ await s3Service.deleteObj(c, key); - } }