Separate file

This commit is contained in:
Manav Rathi 2024-04-30 10:43:12 +05:30
parent c1a3fb4896
commit 761fd560a1
No known key found for this signature in database
5 changed files with 42 additions and 38 deletions

View file

@ -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);
};

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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.