Skip to content

armgit / ente

Public Imported from GitHub
0

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

Spruce

Manav Rathi0566d2ee9338
diff --git a/web/apps/cast/src/constants/file.ts b/web/apps/cast/src/constants/file.ts
deleted file mode 100644
index 9be5746388..0000000000
--- a/web/apps/cast/src/constants/file.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-export enum FILE_TYPE {
- IMAGE,
- VIDEO,
- LIVE_PHOTO,
- OTHERS,
-}
-
-export const RAW_FORMATS = [
- "heic",
- "rw2",
- "tiff",
- "arw",
- "cr3",
- "cr2",
- "raf",
- "nef",
- "psd",
- "dng",
- "tif",
-];
diff --git a/web/apps/cast/src/constants/upload.ts b/web/apps/cast/src/constants/upload.ts
index 63d044fb49..801d8a6ab4 100644
--- a/web/apps/cast/src/constants/upload.ts
+++ b/web/apps/cast/src/constants/upload.ts
@@ -1,6 +1,20 @@
-import { FILE_TYPE } from "constants/file";
+import { FILE_TYPE } from "@/media/file";
import { FileTypeInfo } from "types/upload";
+export const RAW_FORMATS = [
+ "heic",
+ "rw2",
+ "tiff",
+ "arw",
+ "cr3",
+ "cr2",
+ "raf",
+ "nef",
+ "psd",
+ "dng",
+ "tif",
+];
+
// list of format that were missed by type-detection for some files.
export const WHITELISTED_FILE_FORMATS: FileTypeInfo[] = [
{ fileType: FILE_TYPE.IMAGE, exactType: "jpeg", mimeType: "image/jpeg" },
diff --git a/web/apps/cast/src/pages/slideshow.tsx b/web/apps/cast/src/pages/slideshow.tsx
index 774bbd4da9..000d18380b 100644
--- a/web/apps/cast/src/pages/slideshow.tsx
+++ b/web/apps/cast/src/pages/slideshow.tsx
@@ -1,7 +1,7 @@
import log from "@/next/log";
import PairedSuccessfullyOverlay from "components/PairedSuccessfullyOverlay";
import { PhotoAuditorium } from "components/PhotoAuditorium";
-import { FILE_TYPE } from "constants/file";
+import { FILE_TYPE } from "@/media/file";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import {
diff --git a/web/apps/cast/src/services/castDownloadManager.ts b/web/apps/cast/src/services/castDownloadManager.ts
index 76b37c082a..1b890fbbc1 100644
--- a/web/apps/cast/src/services/castDownloadManager.ts
+++ b/web/apps/cast/src/services/castDownloadManager.ts
@@ -2,7 +2,7 @@ import ComlinkCryptoWorker from "@ente/shared/crypto";
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
import { getCastFileURL } from "@ente/shared/network/api";
-import { FILE_TYPE } from "constants/file";
+import { FILE_TYPE } from "@/media/file";
import { EnteFile } from "types/file";
import { generateStreamFromArrayBuffer } from "utils/file";
diff --git a/web/apps/cast/src/services/readerService.ts b/web/apps/cast/src/services/readerService.ts
deleted file mode 100644
index 19f9bb9311..0000000000
--- a/web/apps/cast/src/services/readerService.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { convertBytesToHumanReadable } from "@/next/file";
-import log from "@/next/log";
-
-export async function getUint8ArrayView(file: Blob): Promise<Uint8Array> {
- try {
- return new Uint8Array(await file.arrayBuffer());
- } catch (e) {
- log.error(
- `Failed to read file blob of size ${convertBytesToHumanReadable(file.size)}`,
- e,
- );
- throw e;
- }
-}
diff --git a/web/apps/cast/src/services/typeDetectionService.ts b/web/apps/cast/src/services/typeDetectionService.ts
index 5acd3844dc..883d96b0e1 100644
--- a/web/apps/cast/src/services/typeDetectionService.ts
+++ b/web/apps/cast/src/services/typeDetectionService.ts
@@ -1,14 +1,13 @@
-import { nameAndExtension } from "@/next/file";
+import { FILE_TYPE } from "@/media/file";
+import { convertBytesToHumanReadable, nameAndExtension } from "@/next/file";
import log from "@/next/log";
import { CustomError } from "@ente/shared/error";
-import { FILE_TYPE } from "constants/file";
import {
KNOWN_NON_MEDIA_FORMATS,
WHITELISTED_FILE_FORMATS,
} from "constants/upload";
import FileType from "file-type";
import { FileTypeInfo } from "types/upload";
-import { getUint8ArrayView } from "./readerService";
const TYPE_VIDEO = "video";
const TYPE_IMAGE = "image";
@@ -66,6 +65,18 @@ async function extractFileType(file: File) {
return getFileTypeFromBuffer(fileDataChunk);
}
+export async function getUint8ArrayView(file: Blob): Promise<Uint8Array> {
+ try {
+ return new Uint8Array(await file.arrayBuffer());
+ } catch (e) {
+ log.error(
+ `Failed to read file blob of size ${convertBytesToHumanReadable(file.size)}`,
+ e,
+ );
+ throw e;
+ }
+}
+
async function getFileTypeFromBuffer(buffer: Uint8Array) {
const result = await FileType.fromBuffer(buffer);
if (!result?.mime) {
diff --git a/web/apps/cast/src/types/upload.ts b/web/apps/cast/src/types/upload.ts
index 6dc8818202..91b5c33851 100644
--- a/web/apps/cast/src/types/upload.ts
+++ b/web/apps/cast/src/types/upload.ts
@@ -1,4 +1,4 @@
-import { FILE_TYPE } from "constants/file";
+import { FILE_TYPE } from "@/media/file";
export interface Metadata {
title: string;
diff --git a/web/apps/cast/src/utils/file/index.ts b/web/apps/cast/src/utils/file.ts
similarity index 88%
rename from web/apps/cast/src/utils/file/index.ts
rename to web/apps/cast/src/utils/file.ts
index 60ec0e56e6..1f04a916df 100644
--- a/web/apps/cast/src/utils/file/index.ts
+++ b/web/apps/cast/src/utils/file.ts
@@ -1,7 +1,8 @@
+import { FILE_TYPE } from "@/media/file";
import { decodeLivePhoto } from "@/media/live-photo";
import log from "@/next/log";
import ComlinkCryptoWorker from "@ente/shared/crypto";
-import { FILE_TYPE, RAW_FORMATS } from "constants/file";
+import { RAW_FORMATS } from "constants/upload";
import CastDownloadManager from "services/castDownloadManager";
import { getFileType } from "services/typeDetectionService";
import {
@@ -103,18 +104,6 @@ export function isRawFileFromFileName(fileName: string) {
return false;
}
-/**
- * [Note: File name for local EnteFile objects]
- *
- * The title property in a file's metadata is the original file's name. The
- * metadata of a file cannot be edited. So if later on the file's name is
- * changed, then the edit is stored in the `editedName` property of the public
- * metadata of the file.
- *
- * This function merges these edits onto the file object that we use locally.
- * Effectively, post this step, the file's metadata.title can be used in lieu of
- * its filename.
- */
export function mergeMetadata(files: EnteFile[]): EnteFile[] {
return files.map((file) => {
if (file.pubMagicMetadata?.data.editedTime) {
diff --git a/web/apps/photos/src/services/upload/metadata.ts b/web/apps/photos/src/services/upload/metadata.ts
index 4cda767a03..dcd83c3e3a 100644
--- a/web/apps/photos/src/services/upload/metadata.ts
+++ b/web/apps/photos/src/services/upload/metadata.ts
@@ -8,6 +8,7 @@ import {
tryToParseDateTime,
validateAndGetCreationUnixTimeInMicroSeconds,
} from "@ente/shared/time";
+import type { DataStream } from "@ente/shared/utils/data-stream";
import { Remote } from "comlink";
import { FILE_TYPE } from "constants/file";
import { FILE_READER_CHUNK_SIZE, NULL_LOCATION } from "constants/upload";
@@ -29,7 +30,6 @@ import {
type ParsedMetadataJSON,
} from "./takeout";
import { getFileName } from "./uploadService";
-import type { DataStream } from "@ente/shared/utils/data-stream";
const EXIF_TAGS_NEEDED = [
"DateTimeOriginal",
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index b27843186f..9584b30ddc 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -7,6 +7,7 @@ import { CustomErrorMessage } from "@/next/types/ipc";
import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";
import { EncryptionResult } from "@ente/shared/crypto/types";
import { CustomError, handleUploadError } from "@ente/shared/error";
+import { isDataStream, type DataStream } from "@ente/shared/utils/data-stream";
import { Remote } from "comlink";
import { FILE_TYPE } from "constants/file";
import {
@@ -59,7 +60,6 @@ import {
} from "./thumbnail";
import uploadCancelService from "./uploadCancelService";
import UploadHttpClient from "./uploadHttpClient";
-import { isDataStream, type DataStream } from "@ente/shared/utils/data-stream";
/** Upload files to cloud storage */
class UploadService {
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index 03ef369826..29502213e3 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -441,6 +441,18 @@ export function isSharedFile(user: User, file: EnteFile) {
return file.ownerID !== user.id;
}
+/**
+ * [Note: File name for local EnteFile objects]
+ *
+ * The title property in a file's metadata is the original file's name. The
+ * metadata of a file cannot be edited. So if later on the file's name is
+ * changed, then the edit is stored in the `editedName` property of the public
+ * metadata of the file.
+ *
+ * This function merges these edits onto the file object that we use locally.
+ * Effectively, post this step, the file's metadata.title can be used in lieu of
+ * its filename.
+ */
export function mergeMetadata(files: EnteFile[]): EnteFile[] {
return files.map((file) => {
if (file.pubMagicMetadata?.data.editedTime) {