π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Ref
Manav Rathi1b863005eae9
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsxindex 86dbf0195c..6b94315460 100644--- a/web/apps/photos/src/components/PhotoViewer/index.tsx+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx@@ -12,6 +12,7 @@ import {import { fileLogID, type EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import { isHEICExtension, needsJPEGConversion } from "@/media/formats";+import { moveToTrash } from "@/new/photos/services/collection";import { extractRawExif, parseExif } from "@/new/photos/services/exif";import { AppContext } from "@/new/photos/types/context";import { FlexWrapper } from "@ente/shared/components/Container";@@ -58,7 +59,6 @@ import {addToFavorites,removeFromFavorites,} from "services/collectionService";-import { trashFiles } from "services/fileService";import { SetFilesDownloadProgressAttributesCreator } from "types/gallery";import {copyFileToClipboard,@@ -550,7 +550,7 @@ function PhotoViewer(props: PhotoViewerProps) {try {showLoadingBar();try {- await trashFiles([file]);+ await moveToTrash([file]);} finally {hideLoadingBar();}diff --git a/web/apps/photos/src/pages/deduplicate.tsx b/web/apps/photos/src/pages/deduplicate.tsxindex a805151a7a..3b7b41bff6 100644--- a/web/apps/photos/src/pages/deduplicate.tsx+++ b/web/apps/photos/src/pages/deduplicate.tsx@@ -2,7 +2,7 @@ import { stashRedirect } from "@/accounts/services/redirect";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { errorDialogAttributes } from "@/base/components/utils/dialog";import log from "@/base/log";-import { ALL_SECTION } from "@/new/photos/services/collection";+import { ALL_SECTION, moveToTrash } from "@/new/photos/services/collection";import { getLocalCollections } from "@/new/photos/services/collections";import {createFileCollectionIDs,@@ -24,7 +24,7 @@ import { default as Router, default as router } from "next/router";import { createContext, useEffect, useState } from "react";import { getAllLatestCollections } from "services/collectionService";import { Duplicate, getDuplicates } from "services/deduplicationService";-import { syncFiles, trashFiles } from "services/fileService";+import { syncFiles } from "services/fileService";import { syncTrash } from "services/trashService";import { SelectedState } from "types/gallery";import { getSelectedFiles } from "utils/file";@@ -133,7 +133,7 @@ export default function Deduplicate() {try {showLoadingBar();const selectedFiles = getSelectedFiles(selected, duplicateFiles);- await trashFiles(selectedFiles);+ await moveToTrash(selectedFiles);// trashFiles above does an API request, we still need to update our// local state.diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.tsindex 81864d4c95..a26c684d30 100644--- a/web/apps/photos/src/services/collectionService.ts+++ b/web/apps/photos/src/services/collectionService.ts@@ -63,7 +63,7 @@ const UNCATEGORIZED_COLLECTION_NAME = "Uncategorized";export const HIDDEN_COLLECTION_NAME = ".hidden";const FAVORITE_COLLECTION_NAME = "Favorites";-export const REQUEST_BATCH_SIZE = 1000;+const REQUEST_BATCH_SIZE = 1000;export const getCollectionLastSyncTime = async (collection: Collection) =>(await localForage.getItem<number>(`${collection.id}-time`)) ?? 0;diff --git a/web/apps/photos/src/services/fileService.ts b/web/apps/photos/src/services/fileService.tsindex a450a3bcba..ffde9fd9a1 100644--- a/web/apps/photos/src/services/fileService.ts+++ b/web/apps/photos/src/services/fileService.ts@@ -8,7 +8,6 @@ import {EnteFile,FileWithUpdatedMagicMetadata,FileWithUpdatedPublicMagicMetadata,- TrashRequest,} from "@/media/file";import {clearCachedThumbnailsIfChanged,@@ -16,14 +15,12 @@ import {getLocalFiles,setLocalFiles,} from "@/new/photos/services/files";-import { batch } from "@/utils/array";import HTTPService from "@ente/shared/network/HTTPService";import { getToken } from "@ente/shared/storage/localStorage/helpers";import exportService from "services/export";import { decryptFile } from "utils/file";import {getCollectionLastSyncTime,- REQUEST_BATCH_SIZE,setCollectionLastSyncTime,} from "./collectionService";@@ -133,59 +130,6 @@ const removeDeletedCollectionFiles = async (return files;};-export const trashFiles = async (filesToTrash: EnteFile[]) => {- try {- const token = getToken();- if (!token) {- return;- }- const batchedFilesToTrash = batch(filesToTrash, REQUEST_BATCH_SIZE);- for (const batch of batchedFilesToTrash) {- const trashRequest: TrashRequest = {- items: batch.map((file) => ({- fileID: file.id,- collectionID: file.collectionID,- })),- };- await HTTPService.post(- await apiURL("/files/trash"),- trashRequest,- null,- {- "X-Auth-Token": token,- },- );- }- } catch (e) {- log.error("trash file failed", e);- throw e;- }-};--export const deleteFromTrash = async (filesToDelete: number[]) => {- try {- const token = getToken();- if (!token) {- return;- }- const batchedFilesToDelete = batch(filesToDelete, REQUEST_BATCH_SIZE);-- for (const batch of batchedFilesToDelete) {- await HTTPService.post(- await apiURL("/trash/delete"),- { fileIDs: batch },- null,- {- "X-Auth-Token": token,- },- );- }- } catch (e) {- log.error("deleteFromTrash failed", e);- throw e;- }-};-export interface UpdateMagicMetadataRequest {id: number;magicMetadata: EncryptedMagicMetadata;diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex 5223a38e26..85643640c7 100644--- a/web/apps/photos/src/utils/file/index.ts+++ b/web/apps/photos/src/utils/file/index.ts@@ -19,6 +19,7 @@ import {import { ItemVisibility } from "@/media/file-metadata";import { FileType } from "@/media/file-type";import { decodeLivePhoto } from "@/media/live-photo";+import { deleteFromTrash, moveToTrash } from "@/new/photos/services/collection";import {isArchivedFile,updateMagicMetadata,@@ -33,8 +34,6 @@ import {moveToHiddenCollection,} from "services/collectionService";import {- deleteFromTrash,- trashFiles,updateFileMagicMetadata,updateFilePublicMagicMetadata,} from "services/fileService";@@ -544,7 +543,7 @@ export const handleFileOps = async (case FILE_OPS_TYPE.TRASH:try {markTempDeleted(files);- await trashFiles(files);+ await moveToTrash(files);} catch (e) {clearTempDeleted();throw e;diff --git a/web/packages/media/file.ts b/web/packages/media/file.tsindex 92dee2b6e1..1082ca5280 100644--- a/web/packages/media/file.ts+++ b/web/packages/media/file.ts@@ -182,15 +182,6 @@ export interface EnteFilekey: string;}-export interface TrashRequest {- items: TrashRequestItems[];-}--export interface TrashRequestItems {- fileID: number;- collectionID: number;-}-export interface FileWithUpdatedMagicMetadata {file: EnteFile;updatedMagicMetadata: FileMagicMetadata;diff --git a/web/packages/new/photos/services/collection/index.ts b/web/packages/new/photos/services/collection/index.tsindex dd7c374155..33e602536c 100644--- a/web/packages/new/photos/services/collection/index.ts+++ b/web/packages/new/photos/services/collection/index.ts@@ -217,3 +217,44 @@ const encryptWithCollectionKey = async (};}),);++/**+ * Make a remote request to move the given {@link collectionFiles} to trash.+ *+ * Does not modify local state.+ */+export const moveToTrash = async (collectionFiles: EnteFile[]) => {+ for (const batchFiles of batch(collectionFiles, requestBatchSize)) {+ ensureOk(+ await fetch(await apiURL("/files/trash"), {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ body: JSON.stringify({+ items: batchFiles.map((file) => ({+ fileID: file.id,+ collectionID: file.collectionID,+ })),+ }),+ }),+ );+ }+};++/**+ * Make a remote request to delete the given {@link fileIDs} from trash.+ *+ * Does not modify local state.+ */+export const deleteFromTrash = async (fileIDs: number[]) => {+ for (const batchIDs of batch(fileIDs, requestBatchSize)) {+ ensureOk(+ await fetch(await apiURL("/trash/delete"), {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ body: JSON.stringify({+ fileIDs: batchIDs,+ }),+ }),+ );+ }+};