Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include exporting of shared files on desktop #3319

Merged
merged 6 commits into from
Sep 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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