Skip to content

Commit 3936d70

Browse files
author
William Gorge
committed
LKE-13676 fix: limit thumbnail size
1 parent 07b1c02 commit 3936d70

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/api/Visualization/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ export interface IVisualizationTimeline {
148148
}
149149

150150
export interface VisualizationThumbnailData {
151-
svg: string;
151+
svg: string; // Should not exceed a certain size, cf isThumbnailTooLarge
152+
}
153+
154+
export const MAX_VISUALIZATION_THUMBNAIL_SIZE_BYTES = 2_097_152; // 2MB
155+
156+
export function isThumbnailTooLarge(thumbnail: VisualizationThumbnailData | undefined): boolean {
157+
const thumbnailContent = thumbnail?.svg ?? '';
158+
const thumbnailSizeBytes = new TextEncoder().encode(thumbnailContent).byteLength;
159+
return thumbnailSizeBytes > MAX_VISUALIZATION_THUMBNAIL_SIZE_BYTES;
152160
}
153161

154162
export interface BaseVisualization {

0 commit comments

Comments
 (0)