{{ item.name }}/
@@ -124,7 +146,12 @@
-
@@ -213,7 +240,7 @@ const clearAllFiles = () => {
if (typeof window !== 'undefined' && 'gc' in window && typeof (window as any).gc === 'function') {
try {
- ; (window as any).gc()
+ ;(window as any).gc()
} catch {
// ignore
}
diff --git a/components/object/versions.vue b/components/object/versions.vue
index a3f9915..f1e353b 100644
--- a/components/object/versions.vue
+++ b/components/object/versions.vue
@@ -118,8 +118,8 @@ watch(
const fetchVersions = async () => {
loading.value = true
try {
- const response = await objectApi.getObjectVersions(props.objectKey)
- versions.value = response.Versions ?? []
+ const response = await objectApi.listObjectVersions(props.objectKey)
+ versions.value = response.Versions
} catch (error) {
message.error(t('Failed to fetch versions'))
versions.value = []
diff --git a/composables/useObject.ts b/composables/useObject.ts
index b0f696c..4d2d2be 100644
--- a/composables/useObject.ts
+++ b/composables/useObject.ts
@@ -1,18 +1,18 @@
import {
DeleteObjectCommand,
+ DeleteObjectTaggingCommand,
GetObjectCommand,
+ GetObjectLegalHoldCommand,
+ GetObjectRetentionCommand,
+ GetObjectTaggingCommand,
HeadObjectCommand,
ListObjectsV2Command,
- PutObjectCommand,
- GetObjectTaggingCommand,
- PutObjectTaggingCommand,
- DeleteObjectTaggingCommand,
- GetObjectRetentionCommand,
- PutObjectRetentionCommand,
- GetObjectLegalHoldCommand,
- PutObjectLegalHoldCommand,
ListObjectVersionsCommand,
ObjectLockRetentionMode,
+ PutObjectCommand,
+ PutObjectLegalHoldCommand,
+ PutObjectRetentionCommand,
+ PutObjectTaggingCommand,
} from '@aws-sdk/client-s3'
import { getSignedUrl as _getSignedUrl } from '@aws-sdk/s3-request-presigner'
@@ -211,19 +211,29 @@ export function useObject({ bucket, region }: { bucket: string; region?: string
return await $client.send(new PutObjectLegalHoldCommand(params))
}
- async function getObjectVersions(key: string) {
+ async function listObjectVersions(key: string) {
const params = {
Bucket: bucket,
- Prefix: key,
+ Prefix: key, // match "abc" and "abcd"
+ Delimiter: '/', // has no effect on "abcd", can keep or remove
}
- return await $client.send(new ListObjectVersionsCommand(params))
+ const res = await $client.send(new ListObjectVersionsCommand(params))
+
+ const Versions = (res.Versions ?? []).filter(v => v.Key === key)
+ const DeleteMarkers = (res.DeleteMarkers ?? []).filter(m => m.Key === key)
+
+ // Sort by LastModified desc
+ Versions.sort((a, b) => +new Date(b.LastModified!) - +new Date(a.LastModified!))
+ DeleteMarkers.sort((a, b) => +new Date(b.LastModified!) - +new Date(a.LastModified!))
+
+ return { ...res, Versions, DeleteMarkers }
}
async function deleteAllVersions(key: string) {
try {
// Get all versions of the object
- const versions = await getObjectVersions(key)
+ const versions = await listObjectVersions(key)
const versionsToDelete = versions.Versions || []
const deleteMarkers = versions.DeleteMarkers || []
@@ -258,7 +268,7 @@ export function useObject({ bucket, region }: { bucket: string; region?: string
getObjectLegalHold,
putObjectLegalHold,
setLegalHold: (key: string, enabled: boolean) => putObjectLegalHold(key, { Status: enabled ? 'ON' : 'OFF' }),
- getObjectVersions,
+ listObjectVersions,
deleteAllVersions,
}
}