1 // Will include more rules in the future
2 import { hasPDFSupport } from './browser';
3 import { isAudio, isPDF, isSupportedImage, isSupportedText, isVideo, isWordDocument } from './mimetype';
5 // The reason to limit preview is because the file needs to be loaded
6 // in memory. At this moment we don't even have any progress bar so
7 // it is better to have reasonable lower limit.
8 // It could be dropped once we support video streaming or dynamic
9 // text loading and other tricks to avoid the need to load it all.
10 export const MAX_PREVIEW_FILE_SIZE = 1024 * 1024 * 100;
12 // Adding a lot of text to DOM crashes or slows down the browser.
13 // Even just 2 MB is enough to hang the browser for a short amount of time.
14 // Someday we'll do text windowing, but for now this will do.
15 export const MAX_PREVIEW_TEXT_SIZE = 1024 * 1024 * 2;
17 export const isPreviewTooLarge = (mimeType?: string, fileSize?: number) => {
18 if (!mimeType || !fileSize) {
22 const maxSize = isSupportedText(mimeType) ? MAX_PREVIEW_TEXT_SIZE : MAX_PREVIEW_FILE_SIZE;
23 return fileSize >= maxSize;
26 export const isPreviewAvailable = (mimeType: string, fileSize?: number) => {
28 (!fileSize || !isPreviewTooLarge(mimeType, fileSize)) &&
29 (isSupportedImage(mimeType) ||
32 isSupportedText(mimeType) ||
33 (hasPDFSupport() && isPDF(mimeType)) ||
34 isWordDocument(mimeType))