Skip to content

armgit / ente

Public Imported from GitHub
0

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

Separate file

Manav Rathi761fd560a189
diff --git a/web/apps/photos/src/services/ffmpeg.ts b/web/apps/photos/src/services/ffmpeg.ts
index 00d9a97351..f637b5bd2f 100644
--- a/web/apps/photos/src/services/ffmpeg.ts
+++ b/web/apps/photos/src/services/ffmpeg.ts
@@ -10,6 +10,7 @@ import {
import { NULL_LOCATION } from "constants/upload";
import type { ParsedExtractedMetadata } from "types/metadata";
import type { DedicatedFFmpegWorker } from "worker/ffmpeg.worker";
+import type { UploadItem } from "./upload/types";
/**
* Generate a thumbnail for the given video using a wasm FFmpeg running in a web
@@ -92,18 +93,18 @@ const makeGenThumbnailCommand = (seekTime: number) => [
* This function is called during upload, when we need to extract the metadata
* of videos that the user is uploading.
*
- * @param fileOrPath A {@link File}, or the absolute path to a file on the
+ * @param uploadItem A {@link File}, or the absolute path to a file on the
* user's local filesytem. A path can only be provided when we're running in the
* context of our desktop app.
*/
export const extractVideoMetadata = async (
- fileOrPath: File | string,
+ uploadItem: UploadItem,
): Promise<ParsedExtractedMetadata> => {
const command = extractVideoMetadataCommand;
const outputData =
- fileOrPath instanceof File
- ? await ffmpegExecWeb(command, fileOrPath, "txt", 0)
- : await electron.ffmpegExec(command, fileOrPath, "txt", 0);
+ uploadItem instanceof File
+ ? await ffmpegExecWeb(command, uploadItem, "txt", 0)
+ : await electron.ffmpegExec(command, uploadItem, "txt", 0);
return parseFFmpegExtractedMetadata(outputData);
};
diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.ts
index 2a71e420a0..24c0a9d267 100644
--- a/web/apps/photos/src/services/upload/takeout.ts
+++ b/web/apps/photos/src/services/upload/takeout.ts
@@ -6,7 +6,7 @@ import log from "@/next/log";
import { NULL_LOCATION } from "constants/upload";
import type { Location } from "types/metadata";
import { readStream } from "utils/native-stream";
-import type { UploadItem } from "./uploadManager";
+import type { UploadItem } from "./types";
export interface ParsedMetadataJSON {
creationTime: number;
diff --git a/web/apps/photos/src/services/upload/types.ts b/web/apps/photos/src/services/upload/types.ts
new file mode 100644
index 0000000000..25a79de1a2
--- /dev/null
+++ b/web/apps/photos/src/services/upload/types.ts
@@ -0,0 +1,31 @@
+import type { FileAndPath } from "@/next/types/file";
+import type { ZipItem } from "@/next/types/ipc";
+
+/**
+ * An item to upload is one of the following:
+ *
+ * 1. A file drag-and-dropped or selected by the user when we are running in the
+ * web browser. These is the {@link File} case.
+ *
+ * 2. A file drag-and-dropped or selected by the user when we are running in the
+ * context of our desktop app. In such cases, we also have the absolute path
+ * of the file in the user's local file system. This is the
+ * {@link FileAndPath} case.
+ *
+ * 3. A file path programmatically requested by the desktop app. For example, we
+ * might be resuming a previously interrupted upload after an app restart
+ * (thus we no longer have access to the {@link File} from case 2). Or we
+ * could be uploading a file this is in one of the folders the user has asked
+ * us to watch for changes. This is the `string` case.
+ *
+ * 4. A file within a zip file on the user's local file system. This too is only
+ * possible when we are running in the context of our desktop app. The user
+ * might have drag-and-dropped or selected a zip file, or it might be a zip
+ * file that they'd previously selected but we now are resuming an
+ * interrupted upload of. Either ways, what we have is a tuple containing the
+ * (path to zip file, and the name of an entry within that zip file). This is
+ * the {@link ZipItem} case.
+ *
+ * Also see: [Note: Reading a UploadItem].
+ */
+export type UploadItem = File | FileAndPath | string | ZipItem;
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index bbf0f827ad..99fe6ced39 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -3,8 +3,7 @@ import { potentialFileTypeFromExtension } from "@/media/live-photo";
import { ensureElectron } from "@/next/electron";
import { lowercaseExtension, nameAndExtension } from "@/next/file";
import log from "@/next/log";
-import { type FileAndPath } from "@/next/types/file";
-import type { Electron, ZipItem } from "@/next/types/ipc";
+import type { Electron } from "@/next/types/ipc";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { ensure } from "@/utils/ensure";
import { getDedicatedCryptoWorker } from "@ente/shared/crypto";
@@ -36,6 +35,7 @@ import {
tryParseTakeoutMetadataJSON,
type ParsedMetadataJSON,
} from "./takeout";
+import type { UploadItem } from "./types";
import UploadService, { uploadItemFileName, uploader } from "./uploadService";
export type FileID = number;
@@ -83,35 +83,6 @@ export interface ProgressUpdater {
/** The number of uploads to process in parallel. */
const maxConcurrentUploads = 4;
-/**
- * An item to upload is one of the following:
- *
- * 1. A file drag-and-dropped or selected by the user when we are running in the
- * web browser. These is the {@link File} case.
- *
- * 2. A file drag-and-dropped or selected by the user when we are running in the
- * context of our desktop app. In such cases, we also have the absolute path
- * of the file in the user's local file system. This is the
- * {@link FileAndPath} case.
- *
- * 3. A file path programmatically requested by the desktop app. For example, we
- * might be resuming a previously interrupted upload after an app restart
- * (thus we no longer have access to the {@link File} from case 2). Or we
- * could be uploading a file this is in one of the folders the user has asked
- * us to watch for changes. This is the `string` case.
- *
- * 4. A file within a zip file on the user's local file system. This too is only
- * possible when we are running in the context of our desktop app. The user
- * might have drag-and-dropped or selected a zip file, or it might be a zip
- * file that they'd previously selected but we now are resuming an
- * interrupted upload of. Either ways, what we have is a tuple containing the
- * (path to zip file, and the name of an entry within that zip file). This is
- * the {@link ZipItem} case.
- *
- * Also see: [Note: Reading a UploadItem].
- */
-export type UploadItem = File | FileAndPath | string | ZipItem;
-
export interface UploadItemWithCollection {
localID: number;
collectionID: number;
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index 5aadb25644..8c042ccaf3 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -50,8 +50,9 @@ import {
generateThumbnailNative,
generateThumbnailWeb,
} from "./thumbnail";
+import type { UploadItem } from "./types";
import UploadHttpClient from "./uploadHttpClient";
-import type { UploadItem, UploadableUploadItem } from "./uploadManager";
+import type { UploadableUploadItem } from "./uploadManager";
/**
* A readable stream for a file, and its associated size and last modified time.