@@ -1069,19 +1069,6 @@ export const getFavCollection = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getNonEmptyCollections = (
|
||||
collections: Collection[],
|
||||
files: EnteFile[],
|
||||
) => {
|
||||
const nonEmptyCollectionsIds = new Set<number>();
|
||||
for (const file of files) {
|
||||
nonEmptyCollectionsIds.add(file.collectionID);
|
||||
}
|
||||
return collections.filter((collection) =>
|
||||
nonEmptyCollectionsIds.has(collection.id),
|
||||
);
|
||||
};
|
||||
|
||||
export function sortCollectionSummaries(
|
||||
collectionSummaries: CollectionSummary[],
|
||||
sortBy: COLLECTION_LIST_SORT_BY,
|
||||
@@ -1141,51 +1128,46 @@ export function getCollectionSummaries(
|
||||
) {
|
||||
hasUncategorizedCollection = true;
|
||||
}
|
||||
if (
|
||||
collectionFilesCount.get(collection.id) ||
|
||||
collection.type === CollectionType.uncategorized
|
||||
) {
|
||||
let type: CollectionSummaryType;
|
||||
if (isIncomingShare(collection, user)) {
|
||||
if (isIncomingCollabShare(collection, user)) {
|
||||
type = CollectionSummaryType.incomingShareCollaborator;
|
||||
} else {
|
||||
type = CollectionSummaryType.incomingShareViewer;
|
||||
}
|
||||
} else if (isOutgoingShare(collection, user)) {
|
||||
type = CollectionSummaryType.outgoingShare;
|
||||
} else if (isSharedOnlyViaLink(collection)) {
|
||||
type = CollectionSummaryType.sharedOnlyViaLink;
|
||||
} else if (isArchivedCollection(collection)) {
|
||||
type = CollectionSummaryType.archived;
|
||||
} else if (isDefaultHiddenCollection(collection)) {
|
||||
type = CollectionSummaryType.defaultHidden;
|
||||
} else if (isPinnedCollection(collection)) {
|
||||
type = CollectionSummaryType.pinned;
|
||||
let type: CollectionSummaryType;
|
||||
if (isIncomingShare(collection, user)) {
|
||||
if (isIncomingCollabShare(collection, user)) {
|
||||
type = CollectionSummaryType.incomingShareCollaborator;
|
||||
} else {
|
||||
type = CollectionSummaryType[collection.type];
|
||||
type = CollectionSummaryType.incomingShareViewer;
|
||||
}
|
||||
|
||||
let CollectionSummaryItemName: string;
|
||||
if (type === CollectionSummaryType.uncategorized) {
|
||||
CollectionSummaryItemName = t("UNCATEGORIZED");
|
||||
} else if (type === CollectionSummaryType.favorites) {
|
||||
CollectionSummaryItemName = t("FAVORITES");
|
||||
} else {
|
||||
CollectionSummaryItemName = collection.name;
|
||||
}
|
||||
|
||||
collectionSummaries.set(collection.id, {
|
||||
id: collection.id,
|
||||
name: CollectionSummaryItemName,
|
||||
latestFile: collectionLatestFiles.get(collection.id),
|
||||
coverFile: collectionCoverFiles.get(collection.id),
|
||||
fileCount: collectionFilesCount.get(collection.id) ?? 0,
|
||||
updationTime: collection.updationTime,
|
||||
type: type,
|
||||
order: collection.magicMetadata?.data?.order ?? 0,
|
||||
});
|
||||
} else if (isOutgoingShare(collection, user)) {
|
||||
type = CollectionSummaryType.outgoingShare;
|
||||
} else if (isSharedOnlyViaLink(collection)) {
|
||||
type = CollectionSummaryType.sharedOnlyViaLink;
|
||||
} else if (isArchivedCollection(collection)) {
|
||||
type = CollectionSummaryType.archived;
|
||||
} else if (isDefaultHiddenCollection(collection)) {
|
||||
type = CollectionSummaryType.defaultHidden;
|
||||
} else if (isPinnedCollection(collection)) {
|
||||
type = CollectionSummaryType.pinned;
|
||||
} else {
|
||||
type = CollectionSummaryType[collection.type];
|
||||
}
|
||||
|
||||
let CollectionSummaryItemName: string;
|
||||
if (type === CollectionSummaryType.uncategorized) {
|
||||
CollectionSummaryItemName = t("UNCATEGORIZED");
|
||||
} else if (type === CollectionSummaryType.favorites) {
|
||||
CollectionSummaryItemName = t("FAVORITES");
|
||||
} else {
|
||||
CollectionSummaryItemName = collection.name;
|
||||
}
|
||||
|
||||
collectionSummaries.set(collection.id, {
|
||||
id: collection.id,
|
||||
name: CollectionSummaryItemName,
|
||||
latestFile: collectionLatestFiles.get(collection.id),
|
||||
coverFile: collectionCoverFiles.get(collection.id),
|
||||
fileCount: collectionFilesCount.get(collection.id) ?? 0,
|
||||
updationTime: collection.updationTime,
|
||||
type: type,
|
||||
order: collection.magicMetadata?.data?.order ?? 0,
|
||||
});
|
||||
}
|
||||
if (!hasUncategorizedCollection) {
|
||||
collectionSummaries.set(
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
import {
|
||||
constructCollectionNameMap,
|
||||
getCollectionUserFacingName,
|
||||
getNonEmptyPersonalCollections,
|
||||
} from "utils/collection";
|
||||
import { getPersonalFiles } from "utils/file";
|
||||
import { getAllLocalCollections } from "../collectionService";
|
||||
@@ -354,10 +353,8 @@ class ExportService {
|
||||
collectionIdToOwnerIDMap,
|
||||
);
|
||||
|
||||
const nonEmptyPersonalCollections = getNonEmptyPersonalCollections(
|
||||
collections,
|
||||
personalFiles,
|
||||
user,
|
||||
const personalCollections = collections.filter(
|
||||
(collection) => collection.owner.id === user?.id,
|
||||
);
|
||||
|
||||
const exportRecord = await this.getExportRecord(exportFolder);
|
||||
@@ -365,12 +362,11 @@ class ExportService {
|
||||
convertCollectionIDExportNameObjectToMap(
|
||||
exportRecord.collectionExportNames,
|
||||
);
|
||||
const collectionIDNameMap = constructCollectionNameMap(
|
||||
nonEmptyPersonalCollections,
|
||||
);
|
||||
const collectionIDNameMap =
|
||||
constructCollectionNameMap(personalCollections);
|
||||
|
||||
const renamedCollections = getRenamedExportedCollections(
|
||||
nonEmptyPersonalCollections,
|
||||
personalCollections,
|
||||
exportRecord,
|
||||
);
|
||||
|
||||
@@ -396,7 +392,7 @@ class ExportService {
|
||||
);
|
||||
|
||||
const deletedExportedCollections = getDeletedExportedCollections(
|
||||
nonEmptyPersonalCollections,
|
||||
personalCollections,
|
||||
exportRecord,
|
||||
);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
ExportedCollectionPaths,
|
||||
FileExportNames,
|
||||
} from "types/export";
|
||||
import { getNonEmptyPersonalCollections } from "utils/collection";
|
||||
import { getIDBasedSortedFiles, getPersonalFiles } from "utils/file";
|
||||
import {
|
||||
getCollectionIDFromFileUID,
|
||||
@@ -111,13 +110,11 @@ async function migrationV0ToV1(
|
||||
const personalFiles = getIDBasedSortedFiles(
|
||||
getPersonalFiles(localFiles, user),
|
||||
);
|
||||
const nonEmptyPersonalCollections = getNonEmptyPersonalCollections(
|
||||
localCollections,
|
||||
personalFiles,
|
||||
user,
|
||||
const personalCollections = localCollections.filter(
|
||||
(collection) => collection.owner.id === user?.id,
|
||||
);
|
||||
await migrateCollectionFolders(
|
||||
nonEmptyPersonalCollections,
|
||||
personalCollections,
|
||||
exportDir,
|
||||
collectionIDPathMap,
|
||||
);
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
createAlbum,
|
||||
getAllLocalCollections,
|
||||
getLocalCollections,
|
||||
getNonEmptyCollections,
|
||||
moveToCollection,
|
||||
removeFromCollection,
|
||||
restoreToCollection,
|
||||
@@ -546,24 +545,6 @@ export function getCollectionNameMap(
|
||||
);
|
||||
}
|
||||
|
||||
export function getNonEmptyPersonalCollections(
|
||||
collections: Collection[],
|
||||
personalFiles: EnteFile[],
|
||||
user: User,
|
||||
): Collection[] {
|
||||
if (!user?.id) {
|
||||
throw Error("user missing");
|
||||
}
|
||||
const nonEmptyCollections = getNonEmptyCollections(
|
||||
collections,
|
||||
personalFiles,
|
||||
);
|
||||
const personalCollections = nonEmptyCollections.filter(
|
||||
(collection) => collection.owner.id === user?.id,
|
||||
);
|
||||
return personalCollections;
|
||||
}
|
||||
|
||||
export function getNonHiddenCollections(
|
||||
collections: Collection[],
|
||||
): Collection[] {
|
||||
|
||||
@@ -140,19 +140,12 @@ async function totalFileCountCheck(expectedState) {
|
||||
|
||||
async function totalCollectionCountCheck(expectedState) {
|
||||
const collections = await getLocalCollections();
|
||||
const files = await getLocalFiles();
|
||||
const nonEmptyCollectionIds = new Set(
|
||||
files.map((file) => file.collectionID),
|
||||
);
|
||||
const nonEmptyCollections = collections.filter((collection) =>
|
||||
nonEmptyCollectionIds.has(collection.id),
|
||||
);
|
||||
if (expectedState["collection_count"] === nonEmptyCollections.length) {
|
||||
if (expectedState["collection_count"] === collections.length) {
|
||||
console.log("collection count check passed ✅");
|
||||
} else {
|
||||
throw Error(
|
||||
`total Collection count check failed ❌
|
||||
expected : ${expectedState["collection_count"]}, got: ${nonEmptyCollections.length}`,
|
||||
expected : ${expectedState["collection_count"]}, got: ${collections.length}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user