From 0d18c2b0402ae6b1b23064f90d0322d4f58b4ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E7=99=BB=E5=B1=B1?= Date: Wed, 4 Jun 2025 18:16:34 +0800 Subject: [PATCH] feat :ObjectLegalHold --- components/object/info.vue | 246 +++++++++++++++++++++++++------------ composables/useObject.ts | 129 ++++++++++++++----- i18n/locales/en-US.json | 3 +- i18n/locales/zh-CN.json | 3 +- 4 files changed, 268 insertions(+), 113 deletions(-) diff --git a/components/object/info.vue b/components/object/info.vue index c4fa369..780011a 100644 --- a/components/object/info.vue +++ b/components/object/info.vue @@ -1,45 +1,77 @@ diff --git a/composables/useObject.ts b/composables/useObject.ts index 87b56ad..8b32551 100644 --- a/composables/useObject.ts +++ b/composables/useObject.ts @@ -1,57 +1,69 @@ -import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand,GetObjectTaggingCommand, PutObjectTaggingCommand,DeleteObjectTaggingCommand} from '@aws-sdk/client-s3' -import { getSignedUrl as _getSignedUrl } from '@aws-sdk/s3-request-presigner' +import { + DeleteObjectCommand, + GetObjectCommand, + HeadObjectCommand, + ListObjectsV2Command, + PutObjectCommand, + GetObjectTaggingCommand, + PutObjectTaggingCommand, + DeleteObjectTaggingCommand, + GetObjectRetentionCommand, + PutObjectRetentionCommand, + GetObjectLegalHoldCommand, + PutObjectLegalHoldCommand, +} from "@aws-sdk/client-s3"; +import { getSignedUrl as _getSignedUrl } from "@aws-sdk/s3-request-presigner"; -export function useObject({ bucket, region }: { bucket: string, region?: string }) { - const $client = useNuxtApp().$s3Client +export function useObject({ bucket, region }: { bucket: string; region?: string }) { + const $client = useNuxtApp().$s3Client; const headObject = async (key: string) => { const params = { Bucket: bucket, - Key: key - } + Key: key, + }; - return await $client.send(new HeadObjectCommand(params)) - } + return await $client.send(new HeadObjectCommand(params)); + }; const getSignedUrl = async (key: string, expiresIn = 3600) => { const command = new GetObjectCommand({ Bucket: bucket, Key: key, - }) + }); - return await _getSignedUrl($client, command, { expiresIn }) - } + return await _getSignedUrl($client, command, { expiresIn }); + }; const putObject = async (key: string, body: Blob | string) => { const params = { Bucket: bucket, Key: key, - Body: body - } + Body: body, + }; - return await $client.send(new PutObjectCommand(params)) - } + return await $client.send(new PutObjectCommand(params)); + }; const deleteObject = async (key: string) => { const params = { Bucket: bucket, - Key: key - } + Key: key, + }; - return await $client.send(new DeleteObjectCommand(params)) - } + return await $client.send(new DeleteObjectCommand(params)); + }; - const listObject = async (bucket:string,prefix :string| undefined = undefined,pageSize :number = 25) => { + const listObject = async (bucket: string, prefix: string | undefined = undefined, pageSize: number = 25) => { const params = { Bucket: bucket, Prefix: prefix, - MaxKeys: pageSize , + MaxKeys: pageSize, Delimiter: "/", - } - - return await $client.send(new ListObjectsV2Command(params)) - } + }; + return await $client.send(new ListObjectsV2Command(params)); + }; async function mapAllFiles(bucketName: string, prefix: string, callback: (fileKey: string) => void) { let isTruncated = true; @@ -89,29 +101,80 @@ export function useObject({ bucket, region }: { bucket: string, region?: string const params = { Bucket: bucket, Key: key, - } + }; - return await $client.send(new GetObjectTaggingCommand(params)) + return await $client.send(new GetObjectTaggingCommand(params)); } async function putObjectTagging(key: string, tagging: any) { const params = { Bucket: bucket, Key: key, - Tagging: tagging - } + Tagging: tagging, + }; - return await $client.send(new PutObjectTaggingCommand(params)) + return await $client.send(new PutObjectTaggingCommand(params)); } async function deleteObjectTagging(key: string) { const params = { Bucket: bucket, Key: key, - } + }; - return await $client.send(new DeleteObjectTaggingCommand(params)) + return await $client.send(new DeleteObjectTaggingCommand(params)); } - return { headObject, putObject, deleteObject, getSignedUrl, mapAllFiles,listObject,getObjectTagging ,putObjectTagging,deleteObjectTagging} + async function getObjectRetention(key: string) { + const params = { + Bucket: bucket, + Key: key, + }; + + return await $client.send(new GetObjectRetentionCommand(params)); + } + + async function putObjectRetention(key: string, retention: any) { + const params = { + Bucket: bucket, + Key: key, + }; + return await $client.send(new PutObjectRetentionCommand(params)); + } + + async function getObjectLegalHold(key: string) { + const params = { + Bucket: bucket, + Key: key, + }; + console.log("🚀 ~ getObjectLegalHold ~ params:", params); + + return await $client.send(new GetObjectLegalHoldCommand(params)); + } + + async function putObjectLegalHold(key: string, legalHold: any) { + const params = { + Bucket: bucket, + Key: key, + LegalHold: legalHold, + }; + + return await $client.send(new PutObjectLegalHoldCommand(params)); + } + + return { + headObject, + putObject, + deleteObject, + getSignedUrl, + mapAllFiles, + listObject, + getObjectTagging, + putObjectTagging, + deleteObjectTagging, + getObjectRetention, + putObjectRetention, + getObjectLegalHold, + putObjectLegalHold, + }; } diff --git a/i18n/locales/en-US.json b/i18n/locales/en-US.json index 215ec78..7c61e0f 100644 --- a/i18n/locales/en-US.json +++ b/i18n/locales/en-US.json @@ -327,5 +327,6 @@ "Retention Period": "Retention Period", "Please enter retention period": "Please enter retention period", "Please select retention unit": "Please select retention unit", - "Set Retention": "Set Retention" + "Set Retention": "Set Retention", + "Legal Hold": "Legal Hold" } diff --git a/i18n/locales/zh-CN.json b/i18n/locales/zh-CN.json index 4824337..fa5b93e 100644 --- a/i18n/locales/zh-CN.json +++ b/i18n/locales/zh-CN.json @@ -519,5 +519,6 @@ "Retention Period": "保留期限", "Please enter retention period": "请输入保留期限", "Please select retention unit": "请选择保留单位", - "Set Retention": "设置保留" + "Set Retention": "设置保留", + "Legal Hold": "合法保留" }