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