Merge pull request #437 from ente-io/revert-435-skip-jpeg-type-detection
Revert "Skip jpeg type detection"
This commit is contained in:
commit
22cae92dde
|
@ -1,6 +1,14 @@
|
|||
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
|
||||
import { FILE_TYPE } from 'constants/file';
|
||||
import { Location, ParsedExtractedMetadata } from 'types/upload';
|
||||
|
||||
// list of format that were missed by type-detection for some files.
|
||||
export const FORMAT_MISSED_BY_FILE_TYPE_LIB = [
|
||||
{ fileType: FILE_TYPE.IMAGE, exactType: 'jpeg' },
|
||||
{ fileType: FILE_TYPE.IMAGE, exactType: 'jpg' },
|
||||
{ fileType: FILE_TYPE.VIDEO, exactType: 'webm' },
|
||||
];
|
||||
|
||||
// this is the chunk size of the un-encrypted file which is read and encrypted before uploading it as a single part.
|
||||
export const MULTIPART_PART_SIZE = 20 * 1024 * 1024;
|
||||
|
||||
|
|
|
@ -1,33 +1,21 @@
|
|||
import { FILE_TYPE } from 'constants/file';
|
||||
import { FORMAT_MISSED_BY_FILE_TYPE_LIB } from 'constants/upload';
|
||||
import { FileTypeInfo } from 'types/upload';
|
||||
import { CustomError } from 'utils/error';
|
||||
import { getFileExtension } from 'utils/file';
|
||||
import { logError } from 'utils/sentry';
|
||||
import { getUint8ArrayView } from './readerService';
|
||||
import FileType from 'file-type';
|
||||
import FileType from 'file-type/browser';
|
||||
|
||||
const TYPE_VIDEO = 'video';
|
||||
const TYPE_IMAGE = 'image';
|
||||
const CHUNK_SIZE_FOR_TYPE_DETECTION = 4100;
|
||||
|
||||
// list of format whose detection should be skipped
|
||||
export const FORMATS_TO_SKIP_TYPE_DETECTION = [
|
||||
{ fileType: FILE_TYPE.IMAGE, exactType: 'jpeg' },
|
||||
{ fileType: FILE_TYPE.IMAGE, exactType: 'jpg' },
|
||||
];
|
||||
|
||||
export async function getFileType(
|
||||
reader: FileReader,
|
||||
receivedFile: File
|
||||
): Promise<FileTypeInfo> {
|
||||
const fileExtension = getFileExtension(receivedFile.name);
|
||||
try {
|
||||
const formatToBeSkipped = FORMATS_TO_SKIP_TYPE_DETECTION.find(
|
||||
(a) => a.exactType === fileExtension
|
||||
);
|
||||
if (formatToBeSkipped) {
|
||||
return formatToBeSkipped;
|
||||
}
|
||||
let fileType: FILE_TYPE;
|
||||
const typeResult = await extractFileType(reader, receivedFile);
|
||||
const mimTypeParts = typeResult.mime?.split('/');
|
||||
|
@ -46,10 +34,17 @@ export async function getFileType(
|
|||
}
|
||||
return { fileType, exactType: typeResult.ext };
|
||||
} catch (e) {
|
||||
const fileFormat = getFileExtension(receivedFile.name);
|
||||
const formatMissedByTypeDetection = FORMAT_MISSED_BY_FILE_TYPE_LIB.find(
|
||||
(a) => a.exactType === fileFormat
|
||||
);
|
||||
if (formatMissedByTypeDetection) {
|
||||
return formatMissedByTypeDetection;
|
||||
}
|
||||
logError(e, CustomError.TYPE_DETECTION_FAILED, {
|
||||
fileExtension,
|
||||
fileFormat,
|
||||
});
|
||||
return { fileType: FILE_TYPE.OTHERS, exactType: fileExtension };
|
||||
return { fileType: FILE_TYPE.OTHERS, exactType: fileFormat };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { logError } from 'utils/sentry';
|
|||
import { BLACK_THUMBNAIL_BASE64 } from '../../../public/images/black-thumbnail-b64';
|
||||
import FFmpegService from 'services/ffmpeg/ffmpegService';
|
||||
import { convertToHumanReadable } from 'utils/billing';
|
||||
import { getFileExtension, isFileHEIC } from 'utils/file';
|
||||
import { isFileHEIC } from 'utils/file';
|
||||
import { FileTypeInfo } from 'types/upload';
|
||||
import { getUint8ArrayView } from '../readerService';
|
||||
import HEICConverter from 'services/HEICConverter';
|
||||
|
@ -35,7 +35,7 @@ export async function generateThumbnail(
|
|||
let thumbnail: Uint8Array;
|
||||
try {
|
||||
if (fileTypeInfo.fileType === FILE_TYPE.IMAGE) {
|
||||
const isHEIC = isFileHEIC(getFileExtension(file.name));
|
||||
const isHEIC = isFileHEIC(fileTypeInfo.exactType);
|
||||
canvas = await generateImageThumbnail(file, isHEIC);
|
||||
} else {
|
||||
try {
|
||||
|
|
|
@ -295,19 +295,19 @@ export const preservePhotoswipeProps =
|
|||
return fileWithPreservedProperty;
|
||||
};
|
||||
|
||||
export function fileNameWithoutExtension(filename: string) {
|
||||
export function fileNameWithoutExtension(filename) {
|
||||
const lastDotPosition = filename.lastIndexOf('.');
|
||||
if (lastDotPosition === -1) return filename;
|
||||
else return filename.substr(0, lastDotPosition);
|
||||
}
|
||||
|
||||
export function fileExtensionWithDot(filename: string) {
|
||||
export function fileExtensionWithDot(filename) {
|
||||
const lastDotPosition = filename.lastIndexOf('.');
|
||||
if (lastDotPosition === -1) return '';
|
||||
else return filename.substr(lastDotPosition);
|
||||
}
|
||||
|
||||
export function splitFilenameAndExtension(filename: string): [string, string] {
|
||||
export function splitFilenameAndExtension(filename): [string, string] {
|
||||
const lastDotPosition = filename.lastIndexOf('.');
|
||||
if (lastDotPosition === -1) return [filename, null];
|
||||
else
|
||||
|
@ -317,7 +317,7 @@ export function splitFilenameAndExtension(filename: string): [string, string] {
|
|||
];
|
||||
}
|
||||
|
||||
export function getFileExtension(filename: string) {
|
||||
export function getFileExtension(filename) {
|
||||
return splitFilenameAndExtension(filename)[1];
|
||||
}
|
||||
|
||||
|
|
30
yarn.lock
30
yarn.lock
|
@ -1335,7 +1335,7 @@
|
|||
|
||||
"@tokenizer/token@^0.3.0":
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@tokenizer/token/-/token-0.3.0.tgz#fe98a93fe789247e998c75e74e9c7c63217aa276"
|
||||
resolved "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz"
|
||||
integrity sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==
|
||||
|
||||
"@types/debounce-promise@^3.1.3":
|
||||
|
@ -2997,7 +2997,7 @@ file-selector@^0.2.2:
|
|||
|
||||
file-type@^16.5.3:
|
||||
version "16.5.3"
|
||||
resolved "https://registry.yarnpkg.com/file-type/-/file-type-16.5.3.tgz#474b7e88c74724046abb505e9b8ed4db30c4fc06"
|
||||
resolved "https://registry.npmjs.org/file-type/-/file-type-16.5.3.tgz"
|
||||
integrity sha512-uVsl7iFhHSOY4bEONLlTK47iAHtNsFHWP5YE4xJfZ4rnX7S1Q3wce09XgqSC7E/xh8Ncv/be1lNoyprlUH/x6A==
|
||||
dependencies:
|
||||
readable-web-to-node-stream "^3.0.0"
|
||||
|
@ -3379,7 +3379,7 @@ idb@^6.0.0:
|
|||
|
||||
ieee754@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
|
||||
resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz"
|
||||
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
|
||||
|
||||
ignore@^4.0.6:
|
||||
|
@ -4362,10 +4362,10 @@ pbkdf2@^3.0.9:
|
|||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
peek-readable@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/peek-readable/-/peek-readable-4.1.0.tgz#4ece1111bf5c2ad8867c314c81356847e8a62e72"
|
||||
integrity sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==
|
||||
peek-readable@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.npmjs.org/peek-readable/-/peek-readable-4.0.1.tgz"
|
||||
integrity sha512-7qmhptnR0WMSpxT5rMHG9bW/mYSR1uqaPFj2MHvT+y/aOUu6msJijpKt5SkTDKySwg65OWG2JwTMBlgcbwMHrQ==
|
||||
|
||||
"photoswipe@file:./thirdparty/photoswipe":
|
||||
version "4.1.4"
|
||||
|
@ -4777,7 +4777,7 @@ readable-stream@^3.6.0:
|
|||
|
||||
readable-web-to-node-stream@^3.0.0:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz#5d52bb5df7b54861fd48d015e93a2cb87b3ee0bb"
|
||||
resolved "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz"
|
||||
integrity sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==
|
||||
dependencies:
|
||||
readable-stream "^3.6.0"
|
||||
|
@ -5370,12 +5370,12 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
|
|||
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
|
||||
|
||||
strtok3@^6.2.4:
|
||||
version "6.3.0"
|
||||
resolved "https://registry.yarnpkg.com/strtok3/-/strtok3-6.3.0.tgz#358b80ffe6d5d5620e19a073aa78ce947a90f9a0"
|
||||
integrity sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==
|
||||
version "6.2.4"
|
||||
resolved "https://registry.npmjs.org/strtok3/-/strtok3-6.2.4.tgz"
|
||||
integrity sha512-GO8IcFF9GmFDvqduIspUBwCzCbqzegyVKIsSymcMgiZKeCfrN9SowtUoi8+b59WZMAjIzVZic/Ft97+pynR3Iw==
|
||||
dependencies:
|
||||
"@tokenizer/token" "^0.3.0"
|
||||
peek-readable "^4.1.0"
|
||||
peek-readable "^4.0.1"
|
||||
|
||||
styled-components@^5.2.0:
|
||||
version "5.3.1"
|
||||
|
@ -5497,9 +5497,9 @@ toidentifier@1.0.0:
|
|||
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
|
||||
|
||||
token-types@^4.1.1:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/token-types/-/token-types-4.2.0.tgz#b66bc3d67420c6873222a424eee64a744f4c2f13"
|
||||
integrity sha512-P0rrp4wUpefLncNamWIef62J0v0kQR/GfDVji9WKY7GDCWy5YbVSrKUTam07iWPZQGy0zWNOfstYTykMmPNR7w==
|
||||
version "4.1.1"
|
||||
resolved "https://registry.npmjs.org/token-types/-/token-types-4.1.1.tgz"
|
||||
integrity sha512-hD+QyuUAyI2spzsI0B7gf/jJ2ggR4RjkAo37j3StuePhApJUwcWDjnHDOFdIWYSwNR28H14hpwm4EI+V1Ted1w==
|
||||
dependencies:
|
||||
"@tokenizer/token" "^0.3.0"
|
||||
ieee754 "^1.2.1"
|
||||
|
|
Loading…
Reference in a new issue