Browse Source

fix: dist文件名匹配bug和文件删除bug

devlop
qniao 3 years ago
parent
commit
38ef943b5f
1 changed files with 10 additions and 12 deletions
  1. 22
      pushOss.js

22
pushOss.js

@ -33,11 +33,11 @@ const instance = new WebpackAliyunOss({
timeout: 300000, // 5分钟 timeout: 300000, // 5分钟
setOssPath(filePath) { setOssPath(filePath) {
const fp = filePath.replace(/\\/g, '/') const fp = filePath.replace(/\\/g, '/')
const index = fp.lastIndexOf(buildDir)
const index = fp.indexOf(buildDir)
const Path = fp.substring(index + buildDir.length, filePath.length) const Path = fp.substring(index + buildDir.length, filePath.length)
return Path return Path
}, },
setHeaders(filePath) {
setHeaders() {
return { return {
//'Cache-Control': 'max-age=31536000' //'Cache-Control': 'max-age=31536000'
} }
@ -47,20 +47,18 @@ const instance = new WebpackAliyunOss({
let client = instance.client let client = instance.client
async function deleteAll() { async function deleteAll() {
const { objects } = await client.list()
if (objects.length) {
let { objects } = await client.list({ 'max-keys': 1000 })
while (objects.length > 0) {
let files = objects.map((item) => item.name) let files = objects.map((item) => item.name)
if (ignoreFiles.length > 0) { if (ignoreFiles.length > 0) {
files = files.filter((item) => !ignoreFiles.includes(item)) files = files.filter((item) => !ignoreFiles.includes(item))
} }
let count = 0
while (count < files.length) {
// 一次最多1000个文件
await client.deleteMulti(files.slice(count, count + 1000), {
quiet: true
})
count += 1000
}
// 一次最多1000个文件
await client.deleteMulti(files, {
quiet: true
})
let res = await client.list({ 'max-keys': 1000 })
objects = res.objects
} }
console.log('bucket 文件删除完成') console.log('bucket 文件删除完成')
} }

Loading…
Cancel
Save