28 lines
706 B
TypeScript
28 lines
706 B
TypeScript
|
|
import api from './api';
|
||
|
|
|
||
|
|
class UploadService {
|
||
|
|
private basePath = '/upload';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get a presigned download URL for an S3 key
|
||
|
|
*/
|
||
|
|
async getPresignedDownloadUrl(key: string): Promise<string> {
|
||
|
|
const response = await api.get<{ data: { url: string } }>(
|
||
|
|
`${this.basePath}/presigned-download-url`,
|
||
|
|
{ params: { key } }
|
||
|
|
);
|
||
|
|
return response.data.data.url;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if a URL is an S3 key (not a full URL or local path)
|
||
|
|
*/
|
||
|
|
isS3Key(url: string | null | undefined): boolean {
|
||
|
|
if (!url) return false;
|
||
|
|
// S3 keys don't start with http or /
|
||
|
|
return !url.startsWith('http') && !url.startsWith('/');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export const uploadService = new UploadService();
|