Include exporting of shared files on desktop (#3319)

## Description
This PR adds a new switch on the ExportModal to include export of shared
files.
This should fix https://github.com/ente-io/ente/discussions/2322
This commit is contained in:
Trekky12
2024-09-21 14:44:09 +02:00
committed by GitHub
parent d86df11f15
commit 94a8ff2c6f

View File

@@ -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,
@@ -40,7 +39,6 @@ import {
constructCollectionNameMap,
getCollectionUserFacingName,
} from "utils/collection";
import { getPersonalFiles } from "utils/file";
import { getAllLocalCollections } from "../collectionService";
import { migrateExport } from "./migration";
@@ -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,
);
@@ -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,
@@ -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;