Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const ApiPath = {
scenes: 'scenes',
timeline: 'timeline',
frame: 'frame',
generate_url: 'generate_url',
} as const;

export const ResponseStatus = {
Expand Down
22 changes: 20 additions & 2 deletions src/core/audio.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<GenerateUrlResponse, object>(
[audio, this.meta.id, generate_url],
{},
{
params: { collection_id: this.meta.collectionId },
}
);

const signedUrl = urlData.data.signed_url;
return signedUrl;
};
}
25 changes: 24 additions & 1 deletion src/core/image.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<GenerateUrlResponse, object>(
[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 {
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,7 @@ export interface ITimeline {
addOverlay(start: number, asset: AudioAsset): void;
generateStream(): Promise<string>;
}

export interface GenerateUrlResponse {
signed_url: string;
}