mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
✨ Feature: album remote deletion now Support picgo-plugin-s3
This commit is contained in:
parent
681da4af47
commit
21e870deaf
@ -26,7 +26,7 @@
|
|||||||
"@picgo/store": "^2.0.4",
|
"@picgo/store": "^2.0.4",
|
||||||
"@types/mime-types": "^2.1.1",
|
"@types/mime-types": "^2.1.1",
|
||||||
"ali-oss": "^6.17.1",
|
"ali-oss": "^6.17.1",
|
||||||
"aws-sdk": "^2.1304.0",
|
"aws-sdk": "^2.1317.0",
|
||||||
"axios": "^1.3.2",
|
"axios": "^1.3.2",
|
||||||
"compare-versions": "^4.1.3",
|
"compare-versions": "^4.1.3",
|
||||||
"core-js": "^3.27.1",
|
"core-js": "^3.27.1",
|
||||||
|
@ -5,6 +5,7 @@ import QiniuApi from './qiniu'
|
|||||||
import ImgurApi from './imgur'
|
import ImgurApi from './imgur'
|
||||||
import GithubApi from './github'
|
import GithubApi from './github'
|
||||||
import UpyunApi from './upyun'
|
import UpyunApi from './upyun'
|
||||||
|
import AwsS3Api from './awss3'
|
||||||
|
|
||||||
const apiMap: IStringKeyMap = {
|
const apiMap: IStringKeyMap = {
|
||||||
smms: SmmsApi,
|
smms: SmmsApi,
|
||||||
@ -13,7 +14,8 @@ const apiMap: IStringKeyMap = {
|
|||||||
qiniu: QiniuApi,
|
qiniu: QiniuApi,
|
||||||
imgur: ImgurApi,
|
imgur: ImgurApi,
|
||||||
github: GithubApi,
|
github: GithubApi,
|
||||||
upyun: UpyunApi
|
upyun: UpyunApi,
|
||||||
|
'aws-s3': AwsS3Api
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ALLApi {
|
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 () => {
|
}).then(async () => {
|
||||||
const file = await $$db.getById(item.id!)
|
const file = await $$db.getById(item.id!)
|
||||||
await $$db.removeById(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 (await getConfig('settings.deleteCloudFile')) {
|
||||||
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
|
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -3432,10 +3432,10 @@ available-typed-arrays@^1.0.5:
|
|||||||
resolved "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
|
resolved "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
|
||||||
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
|
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
|
||||||
|
|
||||||
aws-sdk@^2.1304.0:
|
aws-sdk@^2.1317.0:
|
||||||
version "2.1304.0"
|
version "2.1317.0"
|
||||||
resolved "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1304.0.tgz#92a57d96394185fbeb790a85e71c47154c1cd150"
|
resolved "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1317.0.tgz#b1534696b840654a55660eed467ed7ddbbb2e1d1"
|
||||||
integrity sha512-9mf2uafa2M9yFC5IlMe85TIc7OUo1HSProCQWzpRmAAYhcSwmfbRyt02Wtr5YSVvJJPmcSgcyI92snsQR1c3nw==
|
integrity sha512-9gQ3ApcG4OhM19LEcmd/1jclwHvI3jjVaFYNQkY88g2eFJDW5T8qP+u2epdv+o3bPWxzg0TcyPhOSlN4xAnIJQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
buffer "4.9.2"
|
buffer "4.9.2"
|
||||||
events "1.1.1"
|
events "1.1.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user