Skip to content

armgit / ente

Public Imported from GitHub
0

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

cp

Manav Rathi76be5e37d52a
diff --git a/web/apps/photos/src/services/upload/thumbnail.ts b/web/apps/photos/src/services/upload/thumbnail.ts
index b64521497d..e2eccf9b89 100644
--- a/web/apps/photos/src/services/upload/thumbnail.ts
+++ b/web/apps/photos/src/services/upload/thumbnail.ts
@@ -180,11 +180,11 @@ const percentageSizeDiff = (
* app, and this dependency is enforced by the need to pass the {@link electron}
* object which we use to perform IPC with the Node.js side of our desktop app.
*
- * @param dataOrPath The image or video {@link File}, or the path to the image
- * or video file on the user's local filesystem, whose thumbnail we want to
- * generate.
+ * @param dataOrPath Contents of an image or video file, or the path to the
+ * image or video file on the user's local filesystem, whose thumbnail we want
+ * to generate.
*
- * @param fileTypeInfo The type information for {@link fileOrPath}.
+ * @param fileTypeInfo The type information for {@link dataOrPath}.
*
* @return The JPEG data of the generated thumbnail.
*
@@ -192,39 +192,16 @@ const percentageSizeDiff = (
*/
export const generateThumbnailNative = async (
electron: Electron,
- fileOrPath: File | string,
+ dataOrPath: Uint8Array | string,
fileTypeInfo: FileTypeInfo,
): Promise<Uint8Array> =>
fileTypeInfo.fileType === FILE_TYPE.IMAGE
- ? await generateImageThumbnailNative(electron, fileOrPath)
- : await generateVideoThumbnailNative(blob);
-
-const generateImageThumbnailNative = async (
- electron: Electron,
- fileOrPath: File | string,
-) => {
- const startTime = Date.now();
- const jpegData = await electron.generateImageThumbnail(
- fileOrPath instanceof File
- ? new Uint8Array(await fileOrPath.arrayBuffer())
- : fileOrPath,
- maxThumbnailDimension,
- maxThumbnailSize,
- );
- log.debug(
- () => `Native thumbnail generation took ${Date.now() - startTime} ms`,
- );
- return jpegData;
-};
-
-const dataOrPath = (fileOrPath) => {
- fileOrPath
-}
-const generateVideoThumbnailNative = async (
- electron: Electron,
- fileOrPath: File | string,
-) => ffmpeg.generateVideoThumbnailNative(electron, )
-
+ ? await electron.generateImageThumbnail(
+ dataOrPath,
+ maxThumbnailDimension,
+ maxThumbnailSize,
+ )
+ : ffmpeg.generateVideoThumbnailNative(electron, dataOrPath);
/**
* A fallback, black, thumbnail for use in cases where thumbnail generation
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index f531c22388..c0ec389743 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -364,13 +364,15 @@ const readAsset = async (
class ModuleState {
/**
* This will be set to true if we get an error from the Node.js side of our
- * desktop app telling us that native JPEG conversion is not available for
- * the current OS/arch combination. That way, we can stop pestering it again
- * and again (saving an IPC round-trip).
+ * desktop app telling us that native image thumbnail generation is not
+ * available for the current OS/arch combination.
+ *
+ * That way, we can stop pestering it again and again (saving an IPC
+ * round-trip).
*
* Note the double negative when it is used.
*/
- isNativeThumbnailCreationNotAvailable = false;
+ isNativeImageThumbnailCreationNotAvailable = false;
}
const moduleState = new ModuleState();
@@ -429,7 +431,8 @@ const readFileOrPath = async (
): Promise<FileInMemory> => {
log.info(`Reading file ${fopLabel(fileOrPath)} `);
- // If it's a file, read it into data
+ // If it's a file, read-in its data. We need to do it once anyway for
+ // generating the thumbnail.
const dataOrPath =
fileOrPath instanceof File
? new Uint8Array(await fileOrPath.arrayBuffer())
@@ -438,8 +441,8 @@ const readFileOrPath = async (
let thumbnail: Uint8Array;
const electron = globalThis.electron;
- const available = !moduleState.isNativeThumbnailCreationNotAvailable;
- if (electron && available) {
+ if (electron) {
+ if !moduleState.isNativeImageThumbnailCreationNotAvailable;
try {
return await generateImageThumbnailNative(electron, fileOrPath);
} catch (e) {
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index a6cb640b6a..c37644b700 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -62,8 +62,10 @@ class ModuleState {
/**
* This will be set to true if we get an error from the Node.js side of our
* desktop app telling us that native JPEG conversion is not available for
- * the current OS/arch combination. That way, we can stop pestering it again
- * and again (saving an IPC round-trip).
+ * the current OS/arch combination.
+ *
+ * That way, we can stop pestering it again and again (saving an IPC
+ * round-trip).
*
* Note the double negative when it is used.
*/