Dedup type

This commit is contained in:
Manav Rathi
2024-04-22 11:58:16 +05:30
parent b1e9f863d7
commit 2a647e3ddb
10 changed files with 29 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import type { CollectionMapping, Electron } from "@/next/types/ipc";
import { CustomError } from "@ente/shared/error";
import { isPromise } from "@ente/shared/utils";
@@ -32,11 +33,7 @@ import {
SetLoading,
UploadTypeSelectorIntent,
} from "types/gallery";
import {
ElectronFile,
FileWithCollection,
type FileWithCollection2,
} from "types/upload";
import { FileWithCollection, type FileWithCollection2 } from "types/upload";
import {
InProgressUpload,
SegregatedFinishedUploads,

View File

@@ -1,3 +1,4 @@
import { ElectronFile } from "@/next/types/file";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { validateAndGetCreationUnixTimeInMicroSeconds } from "@ente/shared/time";
import { Remote } from "comlink";
@@ -7,7 +8,7 @@ import {
outputPathPlaceholder,
} from "constants/ffmpeg";
import { NULL_LOCATION } from "constants/upload";
import { ElectronFile, ParsedExtractedMetadata } from "types/upload";
import { ParsedExtractedMetadata } from "types/upload";
import { type DedicatedFFmpegWorker } from "worker/ffmpeg.worker";
/** Called during upload */
@@ -30,7 +31,8 @@ export async function generateVideoThumbnail(
"scale=-1:720",
outputPathPlaceholder,
],
file,
/* TODO(MR): ElectronFile changes */
fileOrPath as File | ElectronFile,
"thumb.jpeg",
);
} catch (e) {
@@ -168,17 +170,23 @@ const ffmpegExec = async (
): Promise<File | ElectronFile> => {
const electron = globalThis.electron;
if (electron || false) {
return electron.ffmpegExec(
command,
inputDataOrPath,
outputFileName,
timeoutMS
)
// return electron.ffmpegExec(
// command,
// /* TODO(MR): ElectronFile changes */
// inputFile as unknown as string,
// outputFileName,
// timeoutMS,
// );
} else {
return workerFactory
.instance()
.then((worker) =>
worker.execute(command, inputFile, outputFileName, timeoutMS),
worker.execute(
command,
/* TODO(MR): ElectronFile changes */ inputFile as File,
outputFileName,
timeoutMS,
),
);
}
};

View File

@@ -1,6 +1,6 @@
import { convertBytesToHumanReadable } from "@/next/file";
import log from "@/next/log";
import { ElectronFile } from "types/upload";
import { ElectronFile } from "@/next/types/file";
export async function getUint8ArrayView(
file: Blob | ElectronFile,

View File

@@ -1,4 +1,5 @@
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import { CustomError } from "@ente/shared/error";
import { FILE_TYPE } from "constants/file";
import {
@@ -6,7 +7,7 @@ import {
WHITELISTED_FILE_FORMATS,
} from "constants/upload";
import FileType, { FileTypeResult } from "file-type";
import { ElectronFile, FileTypeInfo } from "types/upload";
import { FileTypeInfo } from "types/upload";
import { getFileExtension } from "utils/file";
import { getUint8ArrayView } from "./readerService";

View File

@@ -1,6 +1,7 @@
import { ensureElectron } from "@/next/electron";
import { basename, getFileNameSize } from "@/next/file";
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
import { CustomError } from "@ente/shared/error";
import {
@@ -17,7 +18,6 @@ import { getFileType } from "services/typeDetectionService";
import { FilePublicMagicMetadataProps } from "types/file";
import {
DataStream,
ElectronFile,
ExtractMetadataResult,
FileTypeInfo,
LivePhotoAssets,

View File

@@ -1,12 +1,13 @@
import { getFileNameSize } from "@/next/file";
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import { CustomErrorMessage, type Electron } from "@/next/types/ipc";
import { CustomError } from "@ente/shared/error";
import { FILE_TYPE } from "constants/file";
import { BLACK_THUMBNAIL_BASE64 } from "constants/upload";
import * as FFmpegService from "services/ffmpeg";
import { heicToJPEG } from "services/heic-convert";
import { ElectronFile, FileTypeInfo } from "types/upload";
import { FileTypeInfo } from "types/upload";
import { isFileHEIC } from "utils/file";
import { getUint8ArrayView } from "../readerService";
import { getFileName } from "./uploadService";

View File

@@ -1,5 +1,6 @@
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { getDedicatedCryptoWorker } from "@ente/shared/crypto";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
@@ -18,7 +19,6 @@ import { Collection } from "types/collection";
import { EncryptedEnteFile, EnteFile } from "types/file";
import { SetFiles } from "types/gallery";
import {
ElectronFile,
FileWithCollection,
ParsedMetadataJSON,
ParsedMetadataJSONMap,

View File

@@ -5,6 +5,7 @@ import {
getFileNameSize,
} from "@/next/file";
import log from "@/next/log";
import { ElectronFile } from "@/next/types/file";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
import {
B64EncryptionResult,
@@ -30,7 +31,6 @@ import { EncryptedMagicMetadata } from "types/magicMetadata";
import {
BackupedFile,
DataStream,
ElectronFile,
EncryptedFile,
ExtractMetadataResult,
FileInMemory,

View File

@@ -1,3 +1,4 @@
import type { ElectronFile } from "@/next/types/file";
import {
B64EncryptionResult,
LocalFileAttributes,
@@ -70,24 +71,6 @@ export interface FileTypeInfo {
videoType?: string;
}
/*
* ElectronFile is a custom interface that is used to represent
* any file on disk as a File-like object in the Electron desktop app.
*
* This was added to support the auto-resuming of failed uploads
* which needed absolute paths to the files which the
* normal File interface does not provide.
*/
export interface ElectronFile {
name: string;
path: string;
size: number;
lastModified: number;
stream: () => Promise<ReadableStream<Uint8Array>>;
blob: () => Promise<Blob>;
arrayBuffer: () => Promise<Uint8Array>;
}
export interface UploadAsset {
isLivePhoto?: boolean;
file?: File | ElectronFile;

View File

@@ -1,11 +1,11 @@
import { basename, dirname } from "@/next/file";
import { ElectronFile } from "@/next/types/file";
import { FILE_TYPE } from "constants/file";
import { PICKED_UPLOAD_TYPE } from "constants/upload";
import isElectron from "is-electron";
import { exportMetadataDirectoryName } from "services/export";
import { EnteFile } from "types/file";
import {
ElectronFile,
FileWithCollection,
Metadata,
type FileWithCollection2,