109 lines
2.6 KiB
TypeScript
109 lines
2.6 KiB
TypeScript
import { adminApiClient } from './client'
|
|
|
|
export interface UploadResponse {
|
|
objectId: string
|
|
url: string // Presigned URL for preview
|
|
}
|
|
|
|
export interface PresignedUrlResponse {
|
|
url: string
|
|
expiresAt: string
|
|
}
|
|
|
|
export const mediaApi = {
|
|
/**
|
|
* Upload card image to MinIO
|
|
* @param file Image file to upload
|
|
* @returns Object ID and presigned URL
|
|
*/
|
|
async uploadCardImage(file: File): Promise<UploadResponse> {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
|
|
const response = await adminApiClient.post<UploadResponse>(
|
|
'/api/v2/media/upload/card-image',
|
|
formData,
|
|
{
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
}
|
|
)
|
|
|
|
return response.data
|
|
},
|
|
|
|
/**
|
|
* Upload test image to MinIO
|
|
* @param file Image file to upload
|
|
* @returns Object ID and presigned URL
|
|
*/
|
|
async uploadTestImage(file: File): Promise<UploadResponse> {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
|
|
const response = await adminApiClient.post<UploadResponse>(
|
|
'/api/v2/media/upload/test-image',
|
|
formData,
|
|
{
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
}
|
|
)
|
|
|
|
return response.data
|
|
},
|
|
|
|
/**
|
|
* Upload voice audio file to MinIO
|
|
* @param file Audio file to upload
|
|
* @returns Object ID and presigned URL
|
|
*/
|
|
async uploadVoice(file: File): Promise<UploadResponse> {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
|
|
const response = await adminApiClient.post<UploadResponse>(
|
|
'/api/v2/media/upload/voice',
|
|
formData,
|
|
{
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
}
|
|
)
|
|
|
|
return response.data
|
|
},
|
|
|
|
/**
|
|
* Get presigned URL for an object
|
|
* @param bucket Bucket name (card-images, test-images, voice-audio)
|
|
* @param objectId Object ID (UUID)
|
|
* @param expirySeconds Optional expiry time in seconds
|
|
* @returns Presigned URL and expiration time
|
|
*/
|
|
async getPresignedUrl(
|
|
bucket: string,
|
|
objectId: string,
|
|
expirySeconds?: number
|
|
): Promise<PresignedUrlResponse> {
|
|
const params = expirySeconds ? { expirySeconds: expirySeconds.toString() } : {}
|
|
const response = await adminApiClient.get<PresignedUrlResponse>(
|
|
`/api/v2/media/${bucket}/${objectId}/url`,
|
|
{ params }
|
|
)
|
|
|
|
return response.data
|
|
},
|
|
|
|
/**
|
|
* Delete a file from MinIO
|
|
* @param bucket Bucket name
|
|
* @param objectId Object ID to delete
|
|
*/
|
|
async deleteFile(bucket: string, objectId: string): Promise<void> {
|
|
await adminApiClient.delete(`/api/v2/media/${bucket}/${objectId}`)
|
|
},
|
|
}
|