修复删除S3文件没有MD5异常
This commit is contained in:
@@ -187,7 +187,7 @@
|
|||||||
<div class="settings-card">
|
<div class="settings-card">
|
||||||
<div class="card-title">{{ $t('oss') }}</div>
|
<div class="card-title">{{ $t('oss') }}</div>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="setting-item">
|
<div class="r2domain-item">
|
||||||
<div><span>{{ $t('osDomain') }}</span></div>
|
<div><span>{{ $t('osDomain') }}</span></div>
|
||||||
<div class="r2domain">
|
<div class="r2domain">
|
||||||
<span>{{ setting.r2Domain || '' }}</span>
|
<span>{{ setting.r2Domain || '' }}</span>
|
||||||
@@ -199,9 +199,7 @@
|
|||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div><span>{{ $t('s3Configuration') }}</span></div>
|
<div><span>{{ $t('s3Configuration') }}</span></div>
|
||||||
<div class="r2domain">
|
<div class="r2domain">
|
||||||
<el-button @mouseenter="s3IsDisabled = true"
|
<el-button class="opt-button" size="small" type="primary" @click="addS3Show = true">
|
||||||
@mouseleave="s3IsDisabled = false"
|
|
||||||
:disabled="setting.hasR2 && s3IsDisabled" class="opt-button" size="small" type="primary" @click="addS3Show = true">
|
|
||||||
<Icon icon="fluent:settings-48-regular" width="16" height="16"/>
|
<Icon icon="fluent:settings-48-regular" width="16" height="16"/>
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -699,7 +697,6 @@ const r2DomainInput = ref('')
|
|||||||
const loginOpacity = ref(0)
|
const loginOpacity = ref(0)
|
||||||
const backgroundUrl = ref('')
|
const backgroundUrl = ref('')
|
||||||
let backgroundFile = {}
|
let backgroundFile = {}
|
||||||
const s3IsDisabled = ref(false)
|
|
||||||
const showSetBackground = ref(false)
|
const showSetBackground = ref(false)
|
||||||
let regVerifyCount = ref(1)
|
let regVerifyCount = ref(1)
|
||||||
let addVerifyCount = ref(1)
|
let addVerifyCount = ref(1)
|
||||||
@@ -1348,6 +1345,21 @@ function editSetting(settingForm, refreshStatus = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.r2domain-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
> div:first-child {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
> div:last-child {
|
||||||
|
flex: 1;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.title-icon.warning {
|
.title-icon.warning {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 2px;
|
top: 2px;
|
||||||
|
|||||||
@@ -28,34 +28,57 @@ const s3Service = {
|
|||||||
await client.send(new PutObjectCommand(obj))
|
await client.send(new PutObjectCommand(obj))
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteObj(c,keys) {
|
async deleteObj(c, keys) {
|
||||||
|
|
||||||
if (typeof keys === 'string') {
|
if (typeof keys === 'string') {
|
||||||
keys = [keys]
|
keys = [keys];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys.length === 0) {
|
if (keys.length === 0) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await this.client(c)
|
const client = await this.client(c);
|
||||||
|
|
||||||
const { bucket } = await settingService.query(c);
|
const { bucket } = await settingService.query(c);
|
||||||
|
|
||||||
|
|
||||||
|
client.middlewareStack.add(
|
||||||
|
(next) => async (args) => {
|
||||||
|
|
||||||
|
const body = args.request.body
|
||||||
|
|
||||||
|
// 计算 MD5 校验和并转换为 Base64 编码
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const data = encoder.encode(body);
|
||||||
|
|
||||||
|
// 使用 Web Crypto API 计算 MD5 校验和
|
||||||
|
const hashBuffer = await crypto.subtle.digest('MD5', data);
|
||||||
|
const hashArray = new Uint8Array(hashBuffer);
|
||||||
|
const contentMD5 = btoa(String.fromCharCode.apply(null, hashArray));
|
||||||
|
|
||||||
|
args.request.headers["Content-MD5"] = contentMD5;
|
||||||
|
|
||||||
|
return next(args);
|
||||||
|
},
|
||||||
|
{ step: "build", name: "inspectRequestMiddleware" }
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
await client.send(
|
await client.send(
|
||||||
new DeleteObjectsCommand({
|
new DeleteObjectsCommand({
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Delete: {
|
Delete: {
|
||||||
Objects: keys.map(key => ({Key: key}))
|
Objects: keys.map(key => ({ Key: key }))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
async client(c) {
|
async client(c) {
|
||||||
const { region, endpoint, s3AccessKey, s3SecretKey } = await settingService.query(c);
|
const { region, endpoint, s3AccessKey, s3SecretKey } = await settingService.query(c);
|
||||||
return new S3Client({
|
return new S3Client({
|
||||||
region: region,
|
region: region || 'auto',
|
||||||
endpoint: domainUtils.toOssDomain(endpoint),
|
endpoint: domainUtils.toOssDomain(endpoint),
|
||||||
credentials: {
|
credentials: {
|
||||||
accessKeyId: s3AccessKey,
|
accessKeyId: s3AccessKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user