Skip to content

Commit

Permalink
Add caption support to UploadcareImage
Browse files Browse the repository at this point in the history
  • Loading branch information
e1himself committed May 10, 2022
1 parent 8e2e1be commit a5fce2e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib/UploadcareImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export const MAX_PREVIEW_SIZE = 3000;
export const DEFAULT_PREVIEW_SIZE = 2048;

export class UploadcareImage {
public static createFromUploadcareWidgetPayload(fileInfo: FileInfo): UploadcareImage {
public static createFromUploadcareWidgetPayload(
fileInfo: FileInfo,
caption?: string,
): UploadcareImage {
if (!fileInfo.originalImageInfo) {
throw new Error('UploadcareImage was given a non-image FileInfo object');
}
Expand All @@ -23,10 +26,14 @@ export class UploadcareImage {
originalWidth: fileInfo.originalImageInfo.width,
size: fileInfo.size,
uuid: fileInfo.uuid,
caption,
});
}

public static createFromPrezlyStoragePayload(payload: UploadedImage): UploadcareImage {
public static createFromPrezlyStoragePayload(
payload: UploadedImage,
caption?: string,
): UploadcareImage {
return new UploadcareImage({
effects: payload.effects || [],
filename: payload.filename,
Expand All @@ -35,6 +42,7 @@ export class UploadcareImage {
originalWidth: payload.original_width,
size: payload.size,
uuid: payload.uuid,
caption,
});
}

Expand Down Expand Up @@ -68,6 +76,7 @@ export class UploadcareImage {
originalWidth,
originalHeight,
effects = [],
caption,
}: {
uuid: string;
filename: string;
Expand All @@ -76,6 +85,7 @@ export class UploadcareImage {
originalWidth: number;
originalHeight: number;
effects: string[];
caption?: string;
}) {
this.uuid = uuid;
this.filename = filename;
Expand All @@ -84,6 +94,10 @@ export class UploadcareImage {
this.originalWidth = originalWidth;
this.originalHeight = originalHeight;
this.effects = effects;

if (caption !== undefined) {
this[UPLOADCARE_FILE_DATA_KEY] = { caption };
}
}

public get dimensions(): { width: number; height: number } {
Expand Down

0 comments on commit a5fce2e

Please sign in to comment.