mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-28 03:44:27 +00:00
fix(asset): delete entire S3 directory for composite assets to clean up transcodes
This commit is contained in:
@@ -51,6 +51,7 @@ export interface S3Service {
|
||||
getObject(bucket: string, key: string): Promise<S3Object>
|
||||
downloadToFile(bucket: string, key: string, filePath: string): Promise<void>
|
||||
deleteObject(bucket: string, key: string): Promise<void>
|
||||
deletePrefix(bucket: string, prefix: string): Promise<void>
|
||||
headObject(bucket: string, key: string): Promise<ObjectInfo>
|
||||
listObjects(bucket: string, prefix: string): Promise<string[]>
|
||||
uploadFile(filePath: string, contentType: string): Promise<string>
|
||||
@@ -167,6 +168,13 @@ export class S3StorageService implements S3Service {
|
||||
await this.client.send(command)
|
||||
}
|
||||
|
||||
async deletePrefix(bucket: string, prefix: string): Promise<void> {
|
||||
const keys = await this.listObjects(bucket, prefix)
|
||||
if (keys.length > 0) {
|
||||
await Promise.all(keys.map((key) => this.deleteObject(bucket, key)))
|
||||
}
|
||||
}
|
||||
|
||||
async headObject(bucket: string, key: string): Promise<ObjectInfo> {
|
||||
const command = new HeadObjectCommand({
|
||||
Bucket: bucket,
|
||||
@@ -334,6 +342,18 @@ export class LocalStorageService implements S3Service {
|
||||
}
|
||||
}
|
||||
|
||||
async deletePrefix(bucket: string, prefix: string): Promise<void> {
|
||||
const dirPath = this.getFilePath(bucket, prefix)
|
||||
try {
|
||||
await fs.promises.rm(dirPath, { recursive: true, force: true })
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error && (e as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||
return
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
async headObject(bucket: string, key: string): Promise<ObjectInfo> {
|
||||
const filePath = this.getFilePath(bucket, key)
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user