Skip to content

Commit

Permalink
Merge pull request #12 from piximi/bugfix/issue-#8_improper_category_…
Browse files Browse the repository at this point in the history
…loading

[fix] fixes category import
  • Loading branch information
Andrea-Papaleo authored Jul 10, 2024
2 parents 87985aa + 7175b97 commit 7f8dae3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/utils/file-io/converters/dataConverter_v1v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
generateUnknownCategory,
generateUUID,
getPropertiesFromImageSync,
isUnknownCategory,
} from "utils/common/helpers";
import { logger } from "utils/common/helpers";
import { Partition } from "utils/models/enums";
Expand Down Expand Up @@ -71,29 +72,39 @@ export const dataConverter_v1v2 = (data: {
},
changes: {},
};
const nonUnknownCategoryMap: Record<string, string> = {};
for (const category of oldCategories) {
if (category.id === UNKNOWN_IMAGE_CATEGORY_ID) {
continue;
} else {
categories.ids.push(category.id);
categories.entities[category.id] = {
let catId: string = category.id;
if (isUnknownCategory(catId)) {
catId = "1" + category.id.slice(1);
nonUnknownCategoryMap[category.id] = catId;
}
categories.ids.push(catId);
categories.entities[catId] = {
saved: {
...category,
id: catId,
kind: "Image",
containing: [],
} as Category,
changes: {},
};
kinds.entities["Image"].saved.categories.push(category.id);
kinds.entities["Image"].saved.categories.push(catId);
}
}

for (const image of images) {
image.kind = "Image";
kinds.entities["Image"].saved.containing.push(image.id);
const cat =
image.categoryId === UNKNOWN_IMAGE_CATEGORY_ID
? unknownCategoryId
: image.categoryId;
let cat: string;
if (image.categoryId === UNKNOWN_IMAGE_CATEGORY_ID) {
cat = unknownCategoryId;
} else {
cat = nonUnknownCategoryMap[image.categoryId] ?? image.categoryId;
}
image.categoryId = cat;
image.containing = [];

Expand Down

0 comments on commit 7f8dae3

Please sign in to comment.