Skip to content

armgit / ente

Public Imported from GitHub
0

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

fop

Manav Rathi070d9e1a62a5
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index dc0ab45207..fa61ab68d7 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -47,7 +47,7 @@ import {
tryParseTakeoutMetadataJSON,
type ParsedMetadataJSON,
} from "./takeout";
-import UploadService, { fopSize, getFileName, uploader } from "./uploadService";
+import UploadService, { fopFileName, fopSize, uploader } from "./uploadService";
/** The number of uploads to process in parallel. */
const maxConcurrentUploads = 4;
@@ -706,8 +706,8 @@ const makeFileWithCollectionIDAndName = (
collectionID: ensure(f.collectionID),
fileName: ensure(
f.isLivePhoto
- ? getFileName(f.livePhotoAssets.image)
- : getFileName(fileOrPath),
+ ? fopFileName(f.livePhotoAssets.image)
+ : fopFileName(fileOrPath),
),
isLivePhoto: f.isLivePhoto,
/* TODO(MR): ElectronFile - alias */
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index aab9f4dea8..dfbd3a8473 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -4,7 +4,6 @@ import type { Metadata } from "@/media/types/file";
import { ensureElectron } from "@/next/electron";
import { basename } from "@/next/file";
import log from "@/next/log";
-import { ElectronFile } from "@/next/types/file";
import { CustomErrorMessage } from "@/next/types/ipc";
import { ensure } from "@/utils/ensure";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
@@ -39,7 +38,6 @@ import { EncryptedMagicMetadata } from "types/magicMetadata";
import {
ParsedExtractedMetadata,
PublicUploadProps,
- UploadAsset,
type LivePhotoAssets2,
} from "types/upload";
import {
@@ -145,6 +143,26 @@ const uploadService = new UploadService();
export default uploadService;
+/**
+ * Return the file name for the given {@link fileOrPath}.
+ *
+ * @param fileOrPath The {@link File}, or the path to it. Note that it is only
+ * valid to specify a path if we are running in the context of our desktop app.
+ */
+export const fopFileName = (file: File | string) =>
+ typeof file == "string" ? basename(file) : file.name;
+
+/**
+ * Return the size of the given {@link fileOrPath}.
+ *
+ * @param fileOrPath The {@link File}, or the path to it. Note that it is only
+ * valid to specify a path if we are running in the context of our desktop app.
+ */
+export const fopSize = async (fileOrPath: File | string): Promise<number> =>
+ fileOrPath instanceof File
+ ? fileOrPath.size
+ : await ensureElectron().fs.size(fileOrPath);
+
/* -- Various intermediate type used during upload -- */
interface UploadAsset2 {
@@ -382,27 +400,6 @@ export const uploader = async (
}
};
-/**
- * Return the size of the given file
- *
- * @param fileOrPath The {@link File}, or the path to it. Note that it is only
- * valid to specify a path if we are running in the context of our desktop app.
- */
-export const fopSize = async (fileOrPath: File | string): Promise<number> =>
- fileOrPath instanceof File
- ? fileOrPath.size
- : await ensureElectron().fs.size(fileOrPath);
-
-export const getFileName = (file: File | ElectronFile | string) =>
- typeof file == "string" ? basename(file) : file.name;
-
-export const getAssetName = ({
- isLivePhoto,
- file,
- livePhotoAssets,
-}: UploadAsset) =>
- isLivePhoto ? getFileName(livePhotoAssets.image) : getFileName(file);
-
/**
* Read the given file or path into an in-memory representation.
*
@@ -564,7 +561,7 @@ const readImageOrVideoDetails = async (fileOrPath: File | string) => {
await reader.cancel();
return chunk;
}
- }, getFileName(fileOrPath));
+ }, fopFileName(fileOrPath));
return { fileTypeInfo, fileSize, lastModifiedMs };
};
@@ -642,7 +639,7 @@ const extractLivePhotoMetadata = async (
return {
metadata: {
...imageMetadata,
- title: getFileName(livePhotoAssets.image),
+ title: fopFileName(livePhotoAssets.image),
fileType: FILE_TYPE.LIVE_PHOTO,
imageHash: imageMetadata.hash,
videoHash: videoHash,
@@ -660,7 +657,7 @@ const extractImageOrVideoMetadata = async (
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
worker: Remote<DedicatedCryptoWorker>,
) => {
- const fileName = getFileName(fileOrPath);
+ const fileName = fopFileName(fileOrPath);
const { fileType } = fileTypeInfo;
let extractedMetadata: ParsedExtractedMetadata;
@@ -870,9 +867,9 @@ const readLivePhoto = async (
return {
filedata: await encodeLivePhoto({
- imageFileName: getFileName(livePhotoAssets.image),
+ imageFileName: fopFileName(livePhotoAssets.image),
imageData: await toData(imageDataOrStream),
- videoFileName: getFileName(livePhotoAssets.video),
+ videoFileName: fopFileName(livePhotoAssets.video),
videoData: await toData(readVideo.dataOrStream),
}),
thumbnail,