Feature(custom): optimize detele function for aws s3

This commit is contained in:
Kuingsmile
2023-10-23 18:11:00 +08:00
parent 9ad13d4bbd
commit b7b86b2616
3 changed files with 242 additions and 29 deletions

View File

@@ -73,7 +73,8 @@ async function getDogeToken (accessKey: string, secretKey: string): Promise<{} |
export async function removeFileFromS3InMain (configMap: IStringKeyMap, dogeMode: boolean = false) {
try {
const { imgUrl, config: { accessKeyID, secretAccessKey, bucketName, region, endpoint, pathStyleAccess, rejectUnauthorized, proxy } } = configMap
const { imgUrl, config: { accessKeyID, secretAccessKey, bucketName, endpoint, pathStyleAccess, rejectUnauthorized, proxy } } = configMap
let { config: { region } } = configMap
const url = new URL(!/^https?:\/\//.test(imgUrl) ? `http://${imgUrl}` : imgUrl)
let fileKey = url.pathname.replace(/^\/+/, '')
if (pathStyleAccess) {
@@ -84,6 +85,9 @@ export async function removeFileFromS3InMain (configMap: IStringKeyMap, dogeMode
? endpoint
: `http://${endpoint}`
: undefined
if (endpointUrl && endpointUrl.includes('cloudflarestorage')) {
region = region || 'auto'
}
const sslEnabled = endpointUrl ? endpointUrl.startsWith('https') : true
const agent = getAgent(proxy, sslEnabled)
const commonOptions: AgentOptions = {