This commit is contained in:
2025-03-22 19:47:23 +08:00
commit 5563ded0a1
9 changed files with 213 additions and 0 deletions

24
src/core/copy-object.ts Normal file
View File

@@ -0,0 +1,24 @@
import { Client, CopyDestinationOptions, CopySourceOptions } from 'minio';
type CopyObjectOpts = {
bucketName: string;
newMetadata: Record<string, string>;
prefix: string;
client: Client;
};
/**
* 复制对象 REPLACE 替换
* @param param0
* @returns
*/
export const copyObject = async ({ bucketName, newMetadata, prefix, client }: CopyObjectOpts) => {
const source = new CopySourceOptions({ Bucket: bucketName, Object: prefix });
const destination = new CopyDestinationOptions({
Bucket: bucketName,
Object: prefix,
UserMetadata: newMetadata,
MetadataDirective: 'REPLACE',
});
const copyResult = await client.copyObject(source, destination);
return copyResult;
};