From 7f7f400ce9e137275e3d47560cda39ef4bebf559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Fri, 17 Feb 2023 15:42:49 +0800 Subject: [PATCH] :bug: Fix: fix S3 deletion endpoint parse bug --- README.md | 2 +- src/renderer/apis/awss3.ts | 26 ++++++++++++++++---------- src/renderer/pages/Gallery.vue | 1 + src/renderer/utils/common.ts | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f556215..a484145 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ ## 已支持平台 | 平台 | 相册云删除 | 云存储管理 | -| :--: | :--: | :--- | +| :--: | :--: | :--: | | SM.MS | :heavy_check_mark: | :heavy_check_mark: | | Github | :heavy_check_mark: | :heavy_check_mark: | | Imgur | :heavy_check_mark: | :heavy_check_mark: | diff --git a/src/renderer/apis/awss3.ts b/src/renderer/apis/awss3.ts index 9a9c5f4..2a7d2f2 100644 --- a/src/renderer/apis/awss3.ts +++ b/src/renderer/apis/awss3.ts @@ -2,30 +2,36 @@ import { S3 } from 'aws-sdk' export default class AwsS3Api { static async delete (configMap: IStringKeyMap): Promise { - const { imgUrl, config: { accessKeyID, secretAccessKey, bucketName, region, endpoint, pathStyleAccess } } = configMap + const { imgUrl, config: { accessKeyID, secretAccessKey, bucketName, region, endpoint, pathStyleAccess, bucketEndpoint, rejectUnauthorized } } = configMap try { - const url = new URL(imgUrl) + const url = new URL((!imgUrl.startsWith('http') && !imgUrl.startsWith('https')) ? `http://${imgUrl}` : imgUrl) const fileKey = url.pathname let endpointUrl if (endpoint) { - endpointUrl = endpoint - } else { - if (region) { - endpointUrl = `https://s3.${region}.amazonaws.com` + if (!endpoint.startsWith('http') && !endpoint.startsWith('https')) { + endpointUrl = `http://${endpoint}` } else { - endpointUrl = 'https://s3.us-east-1.amazonaws.com' + endpointUrl = endpoint } } let sslEnabled = true - const endpointUrlObj = new URL(endpointUrl) - sslEnabled = endpointUrlObj.protocol === 'https:' + if (endpointUrl) { + sslEnabled = endpointUrl.startsWith('https') + } + const http = sslEnabled ? require('https') : require('http') const client = new S3({ accessKeyId: accessKeyID, secretAccessKey, endpoint: endpointUrl, s3ForcePathStyle: pathStyleAccess, sslEnabled, - region: region || 'us-east-1' + region, + s3BucketEndpoint: bucketEndpoint, + httpOptions: { + agent: new http.Agent({ + rejectUnauthorized + }) + } }) const result = await client.deleteObject({ Bucket: bucketName, diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index 07d9cc9..42ed785 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -446,6 +446,7 @@ function remove (item: ImgInfo) { }, 0) } } + console.log(file) sendToMain('removeFiles', [file]) const obj = { title: $T('OPERATION_SUCCEED'), diff --git a/src/renderer/utils/common.ts b/src/renderer/utils/common.ts index 11bf6e0..964cb67 100644 --- a/src/renderer/utils/common.ts +++ b/src/renderer/utils/common.ts @@ -35,7 +35,7 @@ export const getRawData = (args: any): any => { }) return data } - if (typeof args === 'object') { + if (typeof args === 'object' && args !== null) { const data = {} as IStringKeyMap Object.keys(args).forEach(key => { const item = args[key]