diff --git a/src/constants.ts b/src/constants.ts index a54fed9..e5e488d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -36,6 +36,7 @@ export const ApiPath = { scenes: 'scenes', timeline: 'timeline', frame: 'frame', + generate_url: 'generate_url', } as const; export const ResponseStatus = { diff --git a/src/core/audio.ts b/src/core/audio.ts index fd64fe9..f49ece5 100644 --- a/src/core/audio.ts +++ b/src/core/audio.ts @@ -1,8 +1,8 @@ import { ApiPath } from '@/constants'; -import type { AudioBase, IAudio } from '@/interfaces/core'; +import type { AudioBase, GenerateUrlResponse, IAudio } from '@/interfaces/core'; import { HttpClient } from '@/utils/httpClient'; -const { audio } = ApiPath; +const { audio, generate_url } = ApiPath; /** * The base Audio class @@ -34,4 +34,22 @@ export class Audio implements IAudio { this.meta.id, ]); }; + + /** + * Generates the signed URL of the audio. + * @returns A promise that resolves to the signed URL of the audio. + * @throws an InvalidRequestError if the request fails + */ + public generateUrl = async () => { + const urlData = await this.#vhttp.post( + [audio, this.meta.id, generate_url], + {}, + { + params: { collection_id: this.meta.collectionId }, + } + ); + + const signedUrl = urlData.data.signed_url; + return signedUrl; + }; } diff --git a/src/core/image.ts b/src/core/image.ts index 5bab378..8bbc556 100644 --- a/src/core/image.ts +++ b/src/core/image.ts @@ -1,5 +1,10 @@ import { ApiPath } from '@/constants'; -import type { FrameBase, ImageBase, IImage } from '@/interfaces/core'; +import type { + FrameBase, + ImageBase, + IImage, + GenerateUrlResponse, +} from '@/interfaces/core'; import { HttpClient } from '@/utils/httpClient'; /** @@ -32,6 +37,24 @@ export class Image implements IImage { this.meta.id, ]); }; + + /** + * Generates the signed URL of the image. + * @returns A promise that resolves to the signed URL of the image. + * @throws an InvalidRequestError if the request fails + */ + public generateUrl = async () => { + const urlData = await this.#vhttp.post( + [ApiPath.image, this.meta.id, ApiPath.generate_url], + {}, + { + params: { collection_id: this.meta.collectionId }, + } + ); + + const signedUrl = urlData.data.signed_url; + return signedUrl; + }; } export class Frame extends Image { diff --git a/src/interfaces/core.ts b/src/interfaces/core.ts index ecd93fc..d20b458 100644 --- a/src/interfaces/core.ts +++ b/src/interfaces/core.ts @@ -145,3 +145,7 @@ export interface ITimeline { addOverlay(start: number, asset: AudioAsset): void; generateStream(): Promise; } + +export interface GenerateUrlResponse { + signed_url: string; +}