mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-27 11:10:25 +08:00
✨ Feature: album remote deletion now Support picgo-plugin-s3
This commit is contained in:
@@ -5,6 +5,7 @@ import QiniuApi from './qiniu'
|
||||
import ImgurApi from './imgur'
|
||||
import GithubApi from './github'
|
||||
import UpyunApi from './upyun'
|
||||
import AwsS3Api from './awss3'
|
||||
|
||||
const apiMap: IStringKeyMap = {
|
||||
smms: SmmsApi,
|
||||
@@ -13,7 +14,8 @@ const apiMap: IStringKeyMap = {
|
||||
qiniu: QiniuApi,
|
||||
imgur: ImgurApi,
|
||||
github: GithubApi,
|
||||
upyun: UpyunApi
|
||||
upyun: UpyunApi,
|
||||
'aws-s3': AwsS3Api
|
||||
}
|
||||
|
||||
export default class ALLApi {
|
||||
|
||||
39
src/renderer/apis/awss3.ts
Normal file
39
src/renderer/apis/awss3.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
try {
|
||||
const url = new URL(imgUrl)
|
||||
const fileKey = url.pathname
|
||||
let endpointUrl
|
||||
if (endpoint) {
|
||||
endpointUrl = endpoint
|
||||
} else {
|
||||
if (region) {
|
||||
endpointUrl = `https://s3.${region}.amazonaws.com`
|
||||
} else {
|
||||
endpointUrl = 'https://s3.us-east-1.amazonaws.com'
|
||||
}
|
||||
}
|
||||
let sslEnabled = true
|
||||
const endpointUrlObj = new URL(endpointUrl)
|
||||
sslEnabled = endpointUrlObj.protocol === 'https:'
|
||||
const client = new S3({
|
||||
accessKeyId: accessKeyID,
|
||||
secretAccessKey,
|
||||
endpoint: endpointUrl,
|
||||
s3ForcePathStyle: pathStyleAccess,
|
||||
sslEnabled,
|
||||
region: region || 'us-east-1'
|
||||
})
|
||||
const result = await client.deleteObject({
|
||||
Bucket: bucketName,
|
||||
Key: fileKey.replace(/^\//, '')
|
||||
}).promise()
|
||||
return result.$response.httpResponse.statusCode === 204
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ function remove (item: ImgInfo) {
|
||||
}).then(async () => {
|
||||
const file = await $$db.getById(item.id!)
|
||||
await $$db.removeById(item.id!)
|
||||
const picBedsCanbeDeleted = ['smms', 'github', 'imgur', 'tcyun', 'aliyun', 'qiniu', 'upyun']
|
||||
const picBedsCanbeDeleted = ['smms', 'github', 'imgur', 'tcyun', 'aliyun', 'qiniu', 'upyun', 'aws-s3']
|
||||
if (await getConfig('settings.deleteCloudFile')) {
|
||||
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user