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;
};

49
src/core/type.ts Normal file
View File

@@ -0,0 +1,49 @@
import { ItemBucketMetadata, Client } from 'minio';
type UploadedObjectInfo = {
etag: string;
lastModified: Date;
size: number;
versionId: string;
metadata: ItemBucketMetadata;
};
export interface OssBaseOperation {
/**
* 获取对象
* @param objectName 对象名
*/
getObject(objectName: string): Promise<any>;
/**
* 上传对象
* @param objectName 对象名
* @param data 数据
*/
putObject(objectName: string, data: Buffer | string, metaData?: ItemBucketMetadata): Promise<UploadedObjectInfo>;
/**
* 上传文件
* @param objectName 对象名
* @param filePath 文件路径
*/
fPutObject(objectName: string, filePath: string, metaData?: ItemBucketMetadata): Promise<UploadedObjectInfo>;
/**
* 获取对象信息
* @param objectName 对象名
*/
statObject(objectName: string): Promise<any>;
/**
* 删除对象
* @param objectName 对象名
*/
deleteObject(objectName: string): Promise<any>;
/**
* 列出对象
* @param prefix 前缀
*/
listObjects(prefix: string, opts?: { recursive?: boolean }): Promise<any>;
/**
* 复制对象
* @param sourceObject 源对象
* @param targetObject 目标对象
*/
copyObject: Client['copyObject'];
}