Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rename etc

Manav Rathi5fcb1de5401f
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsx
index d5ecb003b4..aff51460dd 100644
--- a/web/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx
@@ -11,13 +11,13 @@ import {
copyFileToClipboard,
downloadSingleFile,
getFileFromURL,
- isSupportedRawFormat,
} from "utils/file";
import { FILE_TYPE } from "@/media/file-type";
import { isNonWebImageFileExtension } from "@/media/formats";
import type { LoadedLivePhotoSourceURL } from "@/new/photos/types/file";
import { detectFileTypeInfo } from "@/new/photos/utils/detect-type";
+import { isNativeConvertibleToJPEG } from "@/new/photos/utils/file";
import { lowercaseExtension } from "@/next/file";
import { FlexWrapper } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner";
@@ -352,7 +352,9 @@ function PhotoViewer(props: Iprops) {
const extension = lowercaseExtension(file.metadata.title);
const isSupported =
!isNonWebImageFileExtension(extension) ||
- isSupportedRawFormat(extension);
+ // TODO: This condition doesn't sound correct when running in the
+ // web app?
+ isNativeConvertibleToJPEG(extension);
setShowEditButton(
file.metadata.fileType === FILE_TYPE.IMAGE && isSupported,
);
diff --git a/web/packages/new/photos/utils/file.ts b/web/packages/new/photos/utils/file.ts
index 9674b2f504..33d93242e2 100644
--- a/web/packages/new/photos/utils/file.ts
+++ b/web/packages/new/photos/utils/file.ts
@@ -7,19 +7,6 @@ import isElectron from "is-electron";
import type { EnteFile } from "../types/file";
import { detectFileTypeInfo } from "./detect-type";
-const SUPPORTED_RAW_FORMATS = [
- "heic",
- "rw2",
- "tiff",
- "arw",
- "cr3",
- "cr2",
- "nef",
- "psd",
- "dng",
- "tif",
-];
-
class ModuleState {
/**
* This will be set to true if we get an error from the Node.js side of our
@@ -95,7 +82,7 @@ export const getRenderableImage = async (fileName: string, imageBlob: Blob) => {
}
const available = !moduleState.isNativeJPEGConversionNotAvailable;
- if (isElectron() && available && isSupportedRawFormat(extension)) {
+ if (isElectron() && available && isNativeConvertibleToJPEG(extension)) {
// If we're running in our desktop app, see if our Node.js layer can
// convert this into a JPEG using native tools for us.
try {
@@ -124,6 +111,30 @@ export const getRenderableImage = async (fileName: string, imageBlob: Blob) => {
}
};
+/**
+ * File extensions which our native JPEG conversion code should be able to
+ * convert to a renderable image.
+ */
+const convertibleToJPEGExtensions = [
+ "heic",
+ "rw2",
+ "tiff",
+ "arw",
+ "cr3",
+ "cr2",
+ "nef",
+ "psd",
+ "dng",
+ "tif",
+];
+
+/**
+ * Return true if {@link extension} is amongst the file extensions which we
+ * expect our native JPEG conversion to be able to process.
+ */
+export const isNativeConvertibleToJPEG = (extension: string) =>
+ convertibleToJPEGExtensions.includes(extension.toLowerCase());
+
const nativeConvertToJPEG = async (imageBlob: Blob) => {
const startTime = Date.now();
const imageData = new Uint8Array(await imageBlob.arrayBuffer());
@@ -137,7 +148,3 @@ const nativeConvertToJPEG = async (imageBlob: Blob) => {
log.debug(() => `Native JPEG conversion took ${Date.now() - startTime} ms`);
return new Blob([jpegData], { type: "image/jpeg" });
};
-
-export function isSupportedRawFormat(exactType: string) {
- return SUPPORTED_RAW_FORMATS.includes(exactType.toLowerCase());
-}