Skip to content

Commit

Permalink
🐛 Fix: fix S3 deletion endpoint parse bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Feb 17, 2023
1 parent 0263351 commit 7f7f400
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
26 changes: 16 additions & 10 deletions src/renderer/apis/awss3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@ import { S3 } from 'aws-sdk'

export default class AwsS3Api {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
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,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ function remove (item: ImgInfo) {
}, 0)
}
}
console.log(file)
sendToMain('removeFiles', [file])
const obj = {
title: $T('OPERATION_SUCCEED'),
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7f7f400

Please sign in to comment.