mirror of
https://github.com/rustfs/console.git
synced 2026-09-19 09:52:25 +08:00
27 lines
720 B
TypeScript
27 lines
720 B
TypeScript
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 }
|
|
}
|