feat: 添加 listObjects 方法的 getMeta 选项以获取对象元数据
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/oss",
|
||||
"version": "0.0.18",
|
||||
"version": "0.0.19",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "bun run bun.config.ts"
|
||||
|
||||
@@ -258,12 +258,12 @@ export class OssBase implements OssBaseOperation {
|
||||
*/
|
||||
async listObjects<IS_FILE = false>(
|
||||
objectName: string,
|
||||
opts?: { recursive?: boolean; startAfter?: string; maxKeys?: number },
|
||||
opts?: { recursive?: boolean; startAfter?: string; maxKeys?: number, getMeta?: boolean },
|
||||
): Promise<IS_FILE extends true ? ListFileObject[] : ListObjectResult[]> {
|
||||
const prefix = `${this.prefix}${objectName}`;
|
||||
const results: ListObjectResult[] = [];
|
||||
let continuationToken: string | undefined;
|
||||
|
||||
const getMeta = opts?.getMeta ?? false;
|
||||
do {
|
||||
const command = new ListObjectsV2Command({
|
||||
Bucket: this.bucketName,
|
||||
@@ -279,12 +279,19 @@ export class OssBase implements OssBaseOperation {
|
||||
// 处理文件对象
|
||||
if (response.Contents) {
|
||||
for (const item of response.Contents) {
|
||||
results.push({
|
||||
const result: ListFileObject = {
|
||||
name: item.Key || '',
|
||||
size: item.Size || 0,
|
||||
lastModified: item.LastModified || new Date(),
|
||||
etag: item.ETag?.replace(/"/g, '') || '',
|
||||
});
|
||||
}
|
||||
if (getMeta) {
|
||||
const stat = await this.statObject(item.Key || '', false);
|
||||
if (stat?.metaData) {
|
||||
result.metaData = stat.metaData;
|
||||
}
|
||||
}
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export type ListFileObject = {
|
||||
size: number;
|
||||
lastModified: Date;
|
||||
etag: string;
|
||||
metaData?: ItemBucketMetadata;
|
||||
};
|
||||
|
||||
export type ListDirectoryObject = {
|
||||
|
||||
Reference in New Issue
Block a user