feat: object preview

This commit is contained in:
overtrue
2024-12-19 21:11:11 +08:00
parent 0fdbb1a6c2
commit f77eb2b8cf
6 changed files with 418 additions and 116 deletions
+26
View File
@@ -0,0 +1,26 @@
import { GetObjectCommand, HeadObjectCommand } 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
const headObject = async (key: string) => {
const params = {
Bucket: bucket,
Key: key
}
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 { headObject, getSignedUrl }
}