Skip to content

Commit

Permalink
Include exporting of shared files on desktop (#3319)
Browse files Browse the repository at this point in the history
## Description
This PR adds a new switch on the ExportModal to include export of shared
files.
This should fix #2322
  • Loading branch information
Trekky12 authored Sep 21, 2024
1 parent d86df11 commit 94a8ff2
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions web/apps/photos/src/services/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { writeStream } from "@/new/photos/utils/native-stream";
import { wait } from "@/utils/promise";
import { CustomError } from "@ente/shared/error";
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
import type { User } from "@ente/shared/user/types";
import QueueProcessor, {
CancellationStatus,
RequestCanceller,
Expand All @@ -40,7 +39,6 @@ import {
constructCollectionNameMap,
getCollectionUserFacingName,
} from "utils/collection";
import { getPersonalFiles } from "utils/file";
import { getAllLocalCollections } from "../collectionService";
import { migrateExport } from "./migration";

Expand Down Expand Up @@ -212,23 +210,10 @@ class ExportService {
exportRecord: ExportRecord,
): Promise<EnteFile[]> => {
try {
const user: User = getData(LS_KEYS.USER);
const files = await getAllLocalFiles();
const collections = await getAllLocalCollections();
const collectionIdToOwnerIDMap = new Map<number, number>(
collections.map((collection) => [
collection.id,
collection.owner.id,
]),
);
const userPersonalFiles = getPersonalFiles(
files,
user,
collectionIdToOwnerIDMap,
);

const unExportedFiles = getUnExportedFiles(
userPersonalFiles,
files,
exportRecord,
undefined,
);
Expand Down Expand Up @@ -338,46 +323,29 @@ class ExportService {
{ resync }: ExportOpts,
) {
try {
const user: User = getData(LS_KEYS.USER);
const files = mergeMetadata(await getAllLocalFiles());
const collections = await getAllLocalCollections();
const collectionIdToOwnerIDMap = new Map<number, number>(
collections.map((collection) => [
collection.id,
collection.owner.id,
]),
);
const personalFiles = getPersonalFiles(
files,
user,
collectionIdToOwnerIDMap,
);

const personalCollections = collections.filter(
(collection) => collection.owner.id === user?.id,
);

const exportRecord = await this.getExportRecord(exportFolder);
const collectionIDExportNameMap =
convertCollectionIDExportNameObjectToMap(
exportRecord.collectionExportNames,
);
const collectionIDNameMap =
constructCollectionNameMap(personalCollections);
const collectionIDNameMap = constructCollectionNameMap(collections);

const renamedCollections = getRenamedExportedCollections(
personalCollections,
collections,
exportRecord,
);

const removedFileUIDs = getDeletedExportedFiles(
personalFiles,
files,
exportRecord,
);

const diskFileRecordIDs = resync
? await readOnDiskFileExportRecordIDs(
personalFiles,
files,
collectionIDExportNameMap,
exportFolder,
exportRecord,
Expand All @@ -386,18 +354,18 @@ class ExportService {
: undefined;

const filesToExport = getUnExportedFiles(
personalFiles,
files,
exportRecord,
diskFileRecordIDs,
);

const deletedExportedCollections = getDeletedExportedCollections(
personalCollections,
collections,
exportRecord,
);

log.info(
`personal files:${personalFiles.length} unexported files: ${filesToExport.length}, deleted exported files: ${removedFileUIDs.length}, renamed collections: ${renamedCollections.length}, deleted collections: ${deletedExportedCollections.length}`,
`files:${files.length} unexported files: ${filesToExport.length}, deleted exported files: ${removedFileUIDs.length}, renamed collections: ${renamedCollections.length}, deleted collections: ${deletedExportedCollections.length}`,
);
let success = 0;
let failed = 0;
Expand Down

0 comments on commit 94a8ff2

Please sign in to comment.