From 128f2d2248005a060ae7a93040d3b8768f30a98d Mon Sep 17 00:00:00 2001 From: Om Gate Date: Fri, 7 Mar 2025 20:40:52 +0530 Subject: [PATCH 1/2] feat: generate url for image and audio --- src/constants.ts | 1 + src/core/audio.ts | 17 +++++++++++++++-- src/core/image.ts | 20 +++++++++++++++++++- src/interfaces/core.ts | 4 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) 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..b4a8c97 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,17 @@ export class Audio implements IAudio { this.meta.id, ]); }; + + 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..fc8f10f 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,19 @@ export class Image implements IImage { this.meta.id, ]); }; + + 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; +} From 6cfa046672f12cca518875000d7b216c3bb12871 Mon Sep 17 00:00:00 2001 From: Om Gate Date: Mon, 10 Mar 2025 15:03:20 +0530 Subject: [PATCH 2/2] feat: docstring --- src/core/audio.ts | 5 +++++ src/core/image.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/core/audio.ts b/src/core/audio.ts index b4a8c97..f49ece5 100644 --- a/src/core/audio.ts +++ b/src/core/audio.ts @@ -35,6 +35,11 @@ export class Audio implements IAudio { ]); }; + /** + * 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], diff --git a/src/core/image.ts b/src/core/image.ts index fc8f10f..8bbc556 100644 --- a/src/core/image.ts +++ b/src/core/image.ts @@ -38,6 +38,11 @@ export class Image implements IImage { ]); }; + /** + * 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],