Skip to content

armgit / ente

Public Imported from GitHub
0

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

Ontology

Manav Rathibc874a229276
diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.ts
index 6d5eb2bd91..b5587b6ba1 100644
--- a/desktop/src/main/services/ffmpeg.ts
+++ b/desktop/src/main/services/ffmpeg.ts
@@ -299,7 +299,7 @@ export const ffmpegGenerateHLSPlaylistAndSegments = async (
// Generate a "key info":
//
// - the first line specifies the key URI that is written into the playlist.
- // - the second line specifies the path to the local filesystem file from
+ // - the second line specifies the path to the local file system file from
// where ffmpeg should read the key.
const keyInfo = [keyURI, keyPath].join("\n");
diff --git a/web/apps/photos/src/services/upload/thumbnail.ts b/web/apps/photos/src/services/upload/thumbnail.ts
index a6e0fee6f4..f000d64692 100644
--- a/web/apps/photos/src/services/upload/thumbnail.ts
+++ b/web/apps/photos/src/services/upload/thumbnail.ts
@@ -3,7 +3,7 @@ import { type Electron } from "ente-base/types/ipc";
import * as ffmpeg from "ente-gallery/services/ffmpeg";
import {
toDataOrPathOrZipEntry,
- type DesktopUploadItem,
+ type FileSystemUploadItem,
} from "ente-gallery/services/upload";
import { FileType, type FileTypeInfo } from "ente-media/file-type";
import { isHEICExtension } from "ente-media/formats";
@@ -178,11 +178,10 @@ export const generateVideoThumbnailUsingCanvas = async (blob: Blob) => {
* 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 Contents of an image or video file, or the path to the
- * image or video file on the user's local file system, whose thumbnail we want
- * to generate.
+ * @param fsUploadItem The image or video file on the user's file system whose
+ * thumbnail we want to generate.
*
- * @param fileTypeInfo The type information for {@link dataOrPath}.
+ * @param fileTypeInfo The type information for {@link fsUploadItem}.
*
* @return The JPEG data of the generated thumbnail.
*
@@ -190,16 +189,16 @@ export const generateVideoThumbnailUsingCanvas = async (blob: Blob) => {
*/
export const generateThumbnailNative = async (
electron: Electron,
- desktopUploadItem: DesktopUploadItem,
+ fsUploadItem: FileSystemUploadItem,
fileTypeInfo: FileTypeInfo,
): Promise<Uint8Array> =>
fileTypeInfo.fileType === FileType.image
? await electron.generateImageThumbnail(
- toDataOrPathOrZipEntry(desktopUploadItem),
+ toDataOrPathOrZipEntry(fsUploadItem),
maxThumbnailDimension,
maxThumbnailSize,
)
- : ffmpeg.generateVideoThumbnailNative(electron, desktopUploadItem);
+ : ffmpeg.generateVideoThumbnailNative(electron, fsUploadItem);
/**
* A fallback, black, thumbnail for use in cases where thumbnail generation
diff --git a/web/apps/photos/src/services/upload/upload-service.ts b/web/apps/photos/src/services/upload/upload-service.ts
index 4138d79d46..928332b9fa 100644
--- a/web/apps/photos/src/services/upload/upload-service.ts
+++ b/web/apps/photos/src/services/upload/upload-service.ts
@@ -14,6 +14,7 @@ import {
import type { UploadItem } from "ente-gallery/services/upload";
import {
RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,
+ type LivePhotoAssets,
type UploadResult,
} from "ente-gallery/services/upload";
import {
@@ -42,7 +43,6 @@ import { addToCollection } from "ente-new/photos/services/collection";
import { CustomError, handleUploadError } from "ente-shared/error";
import { mergeUint8Arrays } from "ente-utils/array";
import { ensureInteger, ensureNumber } from "ente-utils/ensure";
-import { type LivePhotoAssets } from "ente-gallery/services/upload-impl";
import * as convert from "xml-js";
import { tryParseEpochMicrosecondsFromFileName } from "./date";
import {
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index f06a66450b..9c0a24965d 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -6,11 +6,11 @@ import { lowercaseExtension, nameAndExtension } from "ente-base/file-name";
import type { PublicAlbumsCredentials } from "ente-base/http";
import log from "ente-base/log";
import { ComlinkWorker } from "ente-base/worker/comlink-worker";
-import { type ClusteredUploadItem, markUploaded } from "ente-gallery/services/upload-impl";
import {
RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,
+ markUploadedAndObtainProcessableItem,
shouldDisableCFUploadProxy,
- toTimestampedDesktopUploadItem,
+ type ClusteredUploadItem,
type UploadPhase,
type UploadResult,
} from "ente-gallery/services/upload";
@@ -97,7 +97,6 @@ export type UploadItemWithCollection = UploadAsset & {
collectionID: number;
};
-
interface UploadCancelStatus {
value: boolean;
}
@@ -598,8 +597,8 @@ class UploadManager {
) {
log.info(`Upload ${uploadableItem.fileName} | ${uploadResult}`);
try {
- const electron = globalThis.electron;
- if (electron) await markUploaded(electron, uploadableItem);
+ const procesableUploadItem =
+ await markUploadedAndObtainProcessableItem(uploadableItem);
let decryptedFile: EnteFile;
switch (uploadResult) {
@@ -643,16 +642,8 @@ class UploadManager {
(uploadResult == "uploaded" ||
uploadResult == "uploadedWithStaticThumbnail")
) {
- if (electron) {
- // Run the various desktop app specific indexing /
- // processing steps on the uploaded file.
- const tsUploadItem = toTimestampedDesktopUploadItem(
- electron,
- uploadItem,
- );
- indexNewUpload(decryptedFile, tsUploadItem);
- processVideoNewUpload(decryptedFile, tsUploadItem);
- }
+ indexNewUpload(decryptedFile, procesableUploadItem);
+ processVideoNewUpload(decryptedFile, procesableUploadItem);
}
this.updateExistingFiles(decryptedFile);
}
@@ -769,7 +760,6 @@ const makeUploadItemWithCollectionIDAndName = (
externalParsedMetadata: f.externalParsedMetadata,
});
-
/**
* The file that we hand off to the uploader. Essentially
* {@link ClusteredUploadItem} with the {@link collection} attached to it.
@@ -795,7 +785,6 @@ const splitMetadataAndMediaItems = (
[[], []],
);
-
/**
* Go through the given files, combining any sibling image + video assets into a
* single live photo when appropriate.
diff --git a/web/packages/gallery/services/ffmpeg/index.ts b/web/packages/gallery/services/ffmpeg/index.ts
index f2b7db15dc..1dd4f7f4b7 100644
--- a/web/packages/gallery/services/ffmpeg/index.ts
+++ b/web/packages/gallery/services/ffmpeg/index.ts
@@ -3,7 +3,7 @@ import log from "ente-base/log";
import type { Electron } from "ente-base/types/ipc";
import {
toDataOrPathOrZipEntry,
- type DesktopUploadItem,
+ type FileSystemUploadItem,
type UploadItem,
} from "ente-gallery/services/upload";
import {
@@ -77,12 +77,12 @@ const _generateVideoThumbnail = async (
*/
export const generateVideoThumbnailNative = async (
electron: Electron,
- desktopUploadItem: DesktopUploadItem,
+ fsUploadItem: FileSystemUploadItem,
) =>
_generateVideoThumbnail((seekTime: number) =>
electron.ffmpegExec(
makeGenThumbnailCommand(seekTime),
- toDataOrPathOrZipEntry(desktopUploadItem),
+ toDataOrPathOrZipEntry(fsUploadItem),
"jpeg",
),
);
diff --git a/web/packages/gallery/services/upload-impl.ts b/web/packages/gallery/services/upload-impl.ts
deleted file mode 100644
index 8f8a68c756..0000000000
--- a/web/packages/gallery/services/upload-impl.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import log from "ente-base/log";
-import type { Electron } from "ente-base/types/ipc";
-import type { UploadItem } from "./upload";
-
-export interface LivePhotoAssets {
- image: UploadItem;
- video: UploadItem;
-}
-
-/**
- * An upload item with both parts of a live photo clubbed together.
- *
- * See: [Note: Intermediate file types during upload].
- */
-export interface ClusteredUploadItem {
- localID: number;
- collectionID: number;
- fileName: string;
- isLivePhoto: boolean;
- uploadItem?: UploadItem;
- // TODO: Tie this to the isLivePhoto flag using a discriminated union.
- livePhotoAssets?: LivePhotoAssets;
-}
-
-export const markUploaded = async (
- electron: Electron,
- item: ClusteredUploadItem,
-) => {
- if (item.isLivePhoto) {
- const [p0, p1] = [
- item.livePhotoAssets!.image,
- item.livePhotoAssets!.video,
- ];
- if (Array.isArray(p0) && Array.isArray(p1)) {
- return electron.markUploadedZipItem(p0, p1);
- } else if (typeof p0 == "string" && typeof p1 == "string") {
- return electron.markUploadedFile(p0, p1);
- } else if (
- p0 &&
- typeof p0 == "object" &&
- "path" in p0 &&
- p1 &&
- typeof p1 == "object" &&
- "path" in p1
- ) {
- return electron.markUploadedFile(p0.path, p1.path);
- } else {
- throw new Error(
- "Attempting to mark upload completion of unexpected desktop upload items",
- );
- }
- } else {
- const p = item.uploadItem!;
- if (Array.isArray(p)) {
- return electron.markUploadedZipItem(p);
- } else if (typeof p == "string") {
- return electron.markUploadedFile(p);
- } else if (typeof p == "object" && "path" in p) {
- return electron.markUploadedFile(p.path);
- } else {
- // We can come here when the user saves an image they've edited, in
- // which case `item` will be a web File object which won't have a
- // path. Such a la carte uploads don't mark the file as pending
- // anyways, so there isn't anything to do also.
- //
- // Keeping a log here, though really the upper layers of the code
- // need to be reworked so that we don't even get here in such cases.
- log.info(
- "Ignoring attempt to mark upload completion of (likely edited) item",
- );
- return 0;
- }
- }
-};
diff --git a/web/packages/gallery/services/upload.ts b/web/packages/gallery/services/upload.ts
index e521df85de..01d56c6611 100644
--- a/web/packages/gallery/services/upload.ts
+++ b/web/packages/gallery/services/upload.ts
@@ -1,6 +1,6 @@
import log from "ente-base/log";
import { customAPIOrigin } from "ente-base/origins";
-import type { Electron, ZipItem } from "ente-base/types/ipc";
+import type { ZipItem } from "ente-base/types/ipc";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod";
@@ -79,14 +79,15 @@ export interface FileAndPath {
/**
* The cases of {@link UploadItem} that apply when we're running in the context
- * of our desktop app.
+ * of our desktop app, and the item that was uploaded has an associated file on
+ * the user's file system with a known path.
*
- * See also {@link TimestampedDesktopUploadItem}.
+ * See also {@link TimestampedFileSystemUploadItem}.
*/
-export type DesktopUploadItem = Exclude<UploadItem, File>;
+export type FileSystemUploadItem = Exclude<UploadItem, File>;
/**
- * A {@link DesktopUploadItem} augmented with the last modified time of the
+ * A {@link FileSystemUploadItem} augmented with the last modified time of the
* corresponding file on disk.
*
* By keeping the last modified time, we can use it as a test of whether or not
@@ -95,42 +96,125 @@ export type DesktopUploadItem = Exclude<UploadItem, File>;
* was uploaded and when the file gets processed.
*
* See {@link toTimestampedDesktopUploadItem} for converting a
- * {@link UploadItem} into a {@link TimestampedDesktopUploadItem} when running
- * in the context of the desktop app.
+ * {@link FileSystemUploadItem} into a {@link TimestampedFileSystemUploadItem}
+ * when running in the context of the desktop app.
*/
-export interface TimestampedDesktopUploadItem {
- uploadItem: DesktopUploadItem;
- lastModifiedTime: number;
+export interface TimestampedFileSystemUploadItem {
+ /**
+ * Information about the file system file which was uploaded to Ente.
+ */
+ fsUploadItem: FileSystemUploadItem;
+ /**
+ * The last modified time (epoch milliseconds) of the file system file.
+ */
+ lastModifiedMs: number;
+}
+
+export interface LivePhotoAssets {
+ image: UploadItem;
+ video: UploadItem;
+}
+
+/**
+ * An upload item with both parts of a live photo clubbed together.
+ *
+ * See: [Note: Intermediate file types during upload].
+ */
+export interface ClusteredUploadItem {
+ localID: number;
+ collectionID: number;
+ fileName: string;
+ isLivePhoto: boolean;
+ uploadItem?: UploadItem;
+ // TODO: Tie this to the isLivePhoto flag using a discriminated union.
+ livePhotoAssets?: LivePhotoAssets;
}
/**
- * Assert that the given {@link UploadItem} is, in fact, one of the cases that
- * can happen when we're running in the context of the desktop app, and attach
- * the last modified time of the corresponding file system file to it.
+ * Result of {@link markUploadedAndObtainPostProcessableItem}; see the
+ * documentation of that function for the meaning and cases of this type.
+ */
+export type ProcessableUploadItem = File | TimestampedFileSystemUploadItem;
+
+/**
+ * As the long name suggests, this function does a rather specific thing:
*
- * @param electron A witness to the fact that we're running in the context of
- * the desktop app. We also use it to find the last modified time of the file.
+ * - If we're running in the context of the web app, it will return the
+ * {@link File} object that best represents the newly uploaded item. For
+ * images and videos, this'll be the newly uploaded file itself. For live
+ * photos, this will be the {@link File} object for the image component of the
+ * live photo.
*
- * @param uploadItem The upload item we obtained from an arbitrary place in the
- * app.
+ * - If we're running in the context of the desktop app, it will first mark the
+ * item as having been uploaded in the persistent pending upload list that the
+ * desktop app keeps (so that they can be resumed on restarts). After this,
+ * it'll try to convert the item to a {@link TimestampedFileSystemUploadItem}
+ * if possible, otherwise will return the web {@link File}. As with the web
+ * case, in case of live photos the image component will be used in these
+ * transformations.
*
- * @returns The same {@link uploadItem}, but after excluding the cases that can
- * only happen when running in the web app, and with the last modified time of
- * the file attached to it.
+ * @param item An {@link ClusteredUploadItem} that was recently uploaded.
*/
-export const toTimestampedDesktopUploadItem = (
- electron: Electron,
- uploadItem: UploadItem,
-): TimestampedDesktopUploadItem => {
- if (uploadItem instanceof File) {
- log.info(`Invalid upload item (electron: ${!!electron})`, uploadItem);
- throw new Error(
- "Found a File upload item even though we're running in the desktop app",
- );
+export const markUploadedAndObtainProcessableItem = async (
+ item: ClusteredUploadItem,
+): Promise<ProcessableUploadItem> => {
+ const electron = globalThis.electron;
+ if (!electron) {
+ const resultItem = item.isLivePhoto
+ ? item.livePhotoAssets!.image
+ : item;
+ if (resultItem instanceof File) {
+ return resultItem;
+ } else {
+ throw new Error(
+ `Unexpected upload item of type "${typeof resultItem}"`,
+ );
+ }
+ }
+
+ const timestamped = async (
+ t: Promise<number>,
+ item: FileSystemUploadItem,
+ ): Promise<TimestampedFileSystemUploadItem> => ({
+ fsUploadItem: item,
+ lastModifiedMs: await t,
+ });
+
+ if (item.isLivePhoto) {
+ const [p0, p1] = [
+ item.livePhotoAssets!.image,
+ item.livePhotoAssets!.video,
+ ];
+ if (Array.isArray(p0) && Array.isArray(p1)) {
+ return timestamped(electron.markUploadedZipItem(p0, p1), p0);
+ } else if (typeof p0 == "string" && typeof p1 == "string") {
+ return timestamped(electron.markUploadedFile(p0, p1), p0);
+ } else if (
+ p0 &&
+ typeof p0 == "object" &&
+ "path" in p0 &&
+ p1 &&
+ typeof p1 == "object" &&
+ "path" in p1
+ ) {
+ return timestamped(electron.markUploadedFile(p0.path, p1.path), p0);
+ } else {
+ throw new Error(
+ "Attempting to mark upload completion of unexpected desktop upload items",
+ );
+ }
+ } else {
+ const p = item.uploadItem!;
+ if (Array.isArray(p)) {
+ return timestamped(electron.markUploadedZipItem(p), p);
+ } else if (typeof p == "string") {
+ return timestamped(electron.markUploadedFile(p), p);
+ } else if (typeof p == "object" && "path" in p) {
+ return timestamped(electron.markUploadedFile(p.path), p);
+ } else {
+ return p;
+ }
}
- // TODO(HLS):
- const lastModifiedTime = 0;
- return { uploadItem, lastModifiedTime };
};
/**
@@ -138,10 +222,10 @@ export const toTimestampedDesktopUploadItem = (
* context of our desktop app, return a value that can be passed to
* {@link Electron} functions over IPC.
*/
-export const toDataOrPathOrZipEntry = (desktopUploadItem: DesktopUploadItem) =>
- typeof desktopUploadItem == "string" || Array.isArray(desktopUploadItem)
- ? desktopUploadItem
- : desktopUploadItem.path;
+export const toDataOrPathOrZipEntry = (fsUploadItem: FileSystemUploadItem) =>
+ typeof fsUploadItem == "string" || Array.isArray(fsUploadItem)
+ ? fsUploadItem
+ : fsUploadItem.path;
export const RANDOM_PERCENTAGE_PROGRESS_FOR_PUT = () => 90 + 10 * Math.random();
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index b4361a43aa..7110944682 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -1,3 +1,5 @@
+import { isDesktop } from "ente-base/app";
+import { assertionFailed } from "ente-base/assert";
import { decryptBlob } from "ente-base/crypto";
import type { EncryptedBlob } from "ente-base/crypto/types";
import { ensureElectron } from "ente-base/electron";
@@ -21,7 +23,10 @@ import {
getFilePreviewDataUploadURL,
putVideoData,
} from "./file-data";
-import { type TimestampedDesktopUploadItem } from "./upload";
+import {
+ type ProcessableUploadItem,
+ type TimestampedFileSystemUploadItem,
+} from "./upload";
interface VideoProcessingQueueItem {
/**
@@ -30,14 +35,14 @@ interface VideoProcessingQueueItem {
*/
file: EnteFile;
/**
- * The {@link TimestampedDesktopUploadItem} when available for the newly
+ * The {@link TimestampedFileSystemUploadItem} when available for the newly
* uploaded {@link file}.
*
* It will be present when this queue item was enqueued during a upload from
* the current client. If present, this serves as an optimization allowing
- * us to directly read the file off the user's filesystem.
+ * us to directly read the file off the user's file system.
*/
- timestampedUploadItem: TimestampedDesktopUploadItem | undefined;
+ timestampedUploadItem: TimestampedFileSystemUploadItem | undefined;
}
/**
@@ -323,17 +328,27 @@ const blobToDataURL = (blob: Blob) =>
*
* @param file The {@link EnteFile} that got uploaded (video or otherwise).
*
- * @param timestampedUploadItem The item that was uploaded. This can be used to
+ * @param processableUploadItem The item that was uploaded. This can be used to
* read the contents of the file that got uploaded directly from disk instead of
* needing to download it again.
*/
export const processVideoNewUpload = (
file: EnteFile,
- timestampedUploadItem: TimestampedDesktopUploadItem,
+ processableUploadItem: ProcessableUploadItem,
) => {
// TODO(HLS):
if (!isVideoProcessingEnabled()) return;
+ if (!isDesktop) return;
if (file.metadata.fileType !== FileType.video) return;
+ if (processableUploadItem instanceof File) {
+ // While the types don't guarantee it, we really shouldn't be getting
+ // here. The only time a processableUploadItem can be File when we're
+ // running in the desktop app is when an edited image copy is being
+ // saved. But we've already checked above that the file which was
+ // uploaded was a video.
+ assertionFailed();
+ return;
+ }
if (_state.videoProcessingQueue.length > 50) {
// Drop new requests if the queue can't keep up to avoid the app running
@@ -344,7 +359,10 @@ export const processVideoNewUpload = (
}
// Enqueue the item.
- _state.videoProcessingQueue.push({ file, timestampedUploadItem });
+ _state.videoProcessingQueue.push({
+ file,
+ timestampedUploadItem: processableUploadItem,
+ });
// Tickle the processor if it isn't already running.
_state.queueProcessor ??= processQueue();
@@ -397,7 +415,7 @@ const processQueueItem = async ({
const electron = ensureElectron();
// TODO(HLS):
- const uploadItem = timestampedUploadItem?.uploadItem;
+ const uploadItem = timestampedUploadItem?.fsUploadItem;
log.debug(() => ["gen-hls", { file, uploadItem }]);
diff --git a/web/packages/gallery/utils/native-stream.ts b/web/packages/gallery/utils/native-stream.ts
index 87a1a66789..43e4523224 100644
--- a/web/packages/gallery/utils/native-stream.ts
+++ b/web/packages/gallery/utils/native-stream.ts
@@ -8,7 +8,7 @@
import type { Electron, ElectronMLWorker, ZipItem } from "ente-base/types/ipc";
import { z } from "zod";
-import type { DesktopUploadItem } from "../services/upload";
+import type { FileSystemUploadItem } from "../services/upload";
/**
* Stream the given file or zip entry from the user's local file system.
@@ -170,7 +170,7 @@ export type GenerateHLSResult = z.infer<typeof GenerateHLSResult>;
*
* This is a variant of {@link writeStream} tailored for the HLS generation. It
* is similar to {@link initiateConvertToMP4}, but also supports streaming
- * {@link DesktopUploadItem}s and {@link ReadableStream}s.
+ * {@link FileSystemUploadItem}s and {@link ReadableStream}s.
*
* @param _ An {@link Electron} instance, witness to the fact that we're running
* in the context of the desktop app. It is otherwise not used.
@@ -178,7 +178,7 @@ export type GenerateHLSResult = z.infer<typeof GenerateHLSResult>;
* @param video The video to convert.
*
* - If we're called during the upload process, then this will be set to the
- * {@link DesktopUploadItem} that was uploaded. This way, we can directly use
+ * {@link FileSystemUploadItem} that was uploaded. This way, we can directly use
* the on-disk file instead of needing to download the original from remote.
*
* - Otherwise it should be a {@link ReadableStream} of the video contents.
@@ -198,7 +198,7 @@ export type GenerateHLSResult = z.infer<typeof GenerateHLSResult>;
*/
export const initiateGenerateHLS = async (
_: Electron,
- video: DesktopUploadItem | ReadableStream,
+ video: FileSystemUploadItem | ReadableStream,
objectUploadURL: string,
): Promise<GenerateHLSResult | undefined> => {
const params = new URLSearchParams({ op: "generate-hls", objectUploadURL });
@@ -210,10 +210,10 @@ export const initiateGenerateHLS = async (
// video is a DesktopUploadItem
body = null;
if (typeof video == "string") {
- // Path to a regular file on the user's filesystem.
+ // Path to a regular file on the user's file system.
params.set("path", video);
} else if (Array.isArray(video)) {
- // Path within a zip file on the user's filesystem.
+ // Path within a zip file on the user's file system.
const [zipPath, entryName] = video;
params.set("zipPath", zipPath);
params.set("entryName", entryName);
diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.ts
index 77a2cd1b45..bf3c825a70 100644
--- a/web/packages/new/photos/services/ml/blob.ts
+++ b/web/packages/new/photos/services/ml/blob.ts
@@ -3,8 +3,8 @@ import type { ElectronMLWorker } from "ente-base/types/ipc";
import { renderableImageBlob } from "ente-gallery/services/convert";
import { downloadManager } from "ente-gallery/services/download";
import type {
- DesktopUploadItem,
- TimestampedDesktopUploadItem,
+ ProcessableUploadItem,
+ UploadItem,
} from "ente-gallery/services/upload";
import { readStream } from "ente-gallery/utils/native-stream";
import type { EnteFile } from "ente-media/file";
@@ -71,7 +71,7 @@ export const createImageBitmapAndData = async (
* @param file The {@link EnteFile} to index.
*
* @param uploadItem If we're called during the upload process, then this will
- * be set to the {@link DesktopUploadItem} that was uploaded so that we can
+ * be set to the {@link FilesystemUploadItem} that was uploaded so that we can
* directly use the on-disk file instead of needing to download the original.
*
* @param electron The {@link ElectronMLWorker} instance that stands as a
@@ -80,16 +80,16 @@ export const createImageBitmapAndData = async (
*/
export const fetchRenderableBlob = async (
file: EnteFile,
- tsUploadItem: TimestampedDesktopUploadItem | undefined,
+ puItem: ProcessableUploadItem | undefined,
electron: ElectronMLWorker,
): Promise<Blob> =>
- tsUploadItem
- ? await fetchRenderableUploadItemBlob(file, tsUploadItem, electron)
+ puItem
+ ? await fetchRenderableUploadItemBlob(file, puItem, electron)
: await fetchRenderableEnteFileBlob(file);
const fetchRenderableUploadItemBlob = async (
file: EnteFile,
- tsUploadItem: TimestampedDesktopUploadItem,
+ puItem: ProcessableUploadItem,
electron: ElectronMLWorker,
) => {
const fileType = file.metadata.fileType;
@@ -97,9 +97,8 @@ const fetchRenderableUploadItemBlob = async (
const thumbnailData = await downloadManager.thumbnailData(file);
return new Blob([thumbnailData!]);
} else {
- // TODO(HLS):
- const uploadItem = tsUploadItem.uploadItem;
-
+ const uploadItem =
+ puItem instanceof File ? puItem : puItem.fsUploadItem;
const blob = await readNonVideoUploadItem(uploadItem, electron);
return renderableImageBlob(blob, file.metadata.title);
}
@@ -110,15 +109,14 @@ const fetchRenderableUploadItemBlob = async (
*
* See: [Note: Reading a UploadItem]
*
- * @param uploadItem An {@link DesktopUploadItem} which we are trying to index.
- * The code calling us guarantees that this function will not be called for
- * videos.
+ * @param uploadItem An {@link UploadItem} which we are trying to index. The
+ * code calling us guarantees that this function will not be called for videos.
*
* @returns a web {@link File} that can be used to access the upload item's
* contents.
*/
const readNonVideoUploadItem = async (
- uploadItem: DesktopUploadItem,
+ uploadItem: UploadItem,
electron: ElectronMLWorker,
): Promise<File> => {
if (typeof uploadItem == "string" || Array.isArray(uploadItem)) {
@@ -133,7 +131,11 @@ const readNonVideoUploadItem = async (
lastModified: lastModifiedMs,
});
} else {
- return uploadItem.file;
+ if (uploadItem instanceof File) {
+ return uploadItem;
+ } else {
+ return uploadItem.file;
+ }
}
};
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index c4e85da1c6..d6bf07f330 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -10,7 +10,7 @@ import log from "ente-base/log";
import { masterKeyFromSession } from "ente-base/session";
import type { Electron } from "ente-base/types/ipc";
import { ComlinkWorker } from "ente-base/worker/comlink-worker";
-import { type TimestampedDesktopUploadItem } from "ente-gallery/services/upload";
+import { type ProcessableUploadItem } from "ente-gallery/services/upload";
import type { EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import { throttled } from "ente-utils/promise";
@@ -435,18 +435,19 @@ const workerDidUnawaitedIndex = () => void debounceUpdateClustersAndPeople();
*
* @param file The {@link EnteFile} that got uploaded.
*
- * @param timestampedUploadItem The item that was uploaded. This can be used to
- * get at the contents of the file that got uploaded. In case of live photos,
- * this is the image part of the live photo that was uploaded.
+ * @param processableItem The item that was uploaded. This can be used to get at
+ * the contents of the file that got uploaded. In case of live photos, this is
+ * the image part of the live photo that was uploaded.
*/
export const indexNewUpload = (
file: EnteFile,
- timestampedUploadItem: TimestampedDesktopUploadItem,
+ processableUploadItem: ProcessableUploadItem,
) => {
if (!isMLEnabled()) return;
+ if (!isDesktop) return;
if (file.metadata.fileType !== FileType.image) return;
- log.debug(() => ["ml/liveq", { file, timestampedUploadItem }]);
- void worker().then((w) => w.onUpload(file, timestampedUploadItem));
+ log.debug(() => ["ml/liveq", { file, processableUploadItem }]);
+ void worker().then((w) => w.onUpload(file, processableUploadItem));
};
export type MLStatus =
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index aec2ec62d2..adc996d642 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -6,7 +6,7 @@ import log from "ente-base/log";
import { logUnhandledErrorsAndRejectionsInWorker } from "ente-base/log-web";
import type { ElectronMLWorker } from "ente-base/types/ipc";
import { isNetworkDownloadError } from "ente-gallery/services/download";
-import type { TimestampedDesktopUploadItem } from "ente-gallery/services/upload";
+import type { ProcessableUploadItem } from "ente-gallery/services/upload";
import { fileLogID, type EnteFile } from "ente-media/file";
import { wait } from "ente-utils/promise";
import { getAllLocalFiles, getLocalTrashedFiles } from "../files";
@@ -71,7 +71,7 @@ interface IndexableItem {
/**
* If the file was uploaded from the current client, then its contents.
*/
- timestampedUploadItem: TimestampedDesktopUploadItem | undefined;
+ processableUploadItem: ProcessableUploadItem | undefined;
/**
* The existing ML data (if any) on remote corresponding to this file.
*/
@@ -182,10 +182,7 @@ export class MLWorker {
* This is a great opportunity to index since we already have the file with
* us and won't need to download the file from remote.
*/
- onUpload(
- file: EnteFile,
- timestampedUploadItem: TimestampedDesktopUploadItem,
- ) {
+ onUpload(file: EnteFile, processableUploadItem: ProcessableUploadItem) {
// Add the recently uploaded file to the live indexing queue.
//
// Limit the queue to some maximum so that we don't keep growing
@@ -201,7 +198,7 @@ export class MLWorker {
// pre-existing ML data on remote.
this.liveQ.push({
file,
- timestampedUploadItem,
+ processableUploadItem,
remoteMLData: undefined,
});
this.wakeUp();
@@ -319,7 +316,7 @@ export class MLWorker {
// Return files after annotating them with their existing ML data.
return Array.from(fileByID, ([id, file]) => ({
file,
- timestampedUploadItem: undefined,
+ processableUploadItem: undefined,
remoteMLData: mlDataByID.get(id),
}));
}
@@ -506,7 +503,7 @@ const syncWithLocalFilesAndGetFilesToIndex = async (
* then remote will return a 413 Request Entity Too Large).
*/
const index = async (
- { file, timestampedUploadItem, remoteMLData }: IndexableItem,
+ { file, processableUploadItem, remoteMLData }: IndexableItem,
electron: ElectronMLWorker,
) => {
const f = fileLogID(file);
@@ -558,7 +555,7 @@ const index = async (
try {
renderableBlob = await fetchRenderableBlob(
file,
- timestampedUploadItem,
+ processableUploadItem,
electron,
);
} catch (e) {