mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
🐛 Fix: fix S3 deletion endpoint parse bug
This commit is contained in:
parent
02633513df
commit
7f7f400ce9
@ -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: |
|
||||
|
@ -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,
|
||||
|
@ -446,6 +446,7 @@ function remove (item: ImgInfo) {
|
||||
}, 0)
|
||||
}
|
||||
}
|
||||
console.log(file)
|
||||
sendToMain('removeFiles', [file])
|
||||
const obj = {
|
||||
title: $T('OPERATION_SUCCEED'),
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user