From 689f343a8c8c437fcc37673cb6692eab7f0bde1f Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 2 Jan 2024 12:45:39 +0000 Subject: [PATCH] Added filter for duplicate dependencies Fixes #72 --- src/platforms/curseforge/curseforge-uploader.ts | 9 +++++++-- src/platforms/modrinth/modrinth-uploader.ts | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/platforms/curseforge/curseforge-uploader.ts b/src/platforms/curseforge/curseforge-uploader.ts index 3b1b041..c17173c 100644 --- a/src/platforms/curseforge/curseforge-uploader.ts +++ b/src/platforms/curseforge/curseforge-uploader.ts @@ -3,6 +3,7 @@ import { Dependency } from "@/dependencies"; import { PlatformType } from "@/platforms/platform-type"; import { GenericPlatformUploader, GenericPlatformUploaderOptions } from "@/platforms/generic-platform-uploader"; import { ArgumentError } from "@/utils/errors"; +import { stringEquals } from "@/utils/string-utils"; import { CurseForgeDependency } from "./curseforge-dependency"; import { CurseForgeDependencyType } from "./curseforge-dependency-type"; import { CurseForgeEternalApiClient } from "./curseforge-eternal-api-client"; @@ -136,13 +137,17 @@ export class CurseForgeUploader extends GenericPlatformUploader { const simpleDependencies = this.convertToSimpleDependencies(dependencies, CurseForgeDependencyType.fromDependencyType); - const curseforgeDependencies = await Promise.all(simpleDependencies.map(async ([id, type]) => ({ + const curseForgeDependencies = await Promise.all(simpleDependencies.map(async ([id, type]) => ({ slug: isCurseForgeProjectId(id) ? await eternalApi.getProject(id).catch(() => undefined as CurseForgeProject).then(x => x?.slug) : id, type, }))); - return curseforgeDependencies.filter(x => x.slug && x.type); + const uniqueCurseForgeDependencies = curseForgeDependencies + .filter(x => x.slug && x.type) + .filter((x, i, self) => i === self.findIndex(y => stringEquals(x.slug, y.slug, { ignoreCase: true }))); + + return uniqueCurseForgeDependencies; } } diff --git a/src/platforms/modrinth/modrinth-uploader.ts b/src/platforms/modrinth/modrinth-uploader.ts index 0859bcd..caf62c1 100644 --- a/src/platforms/modrinth/modrinth-uploader.ts +++ b/src/platforms/modrinth/modrinth-uploader.ts @@ -127,7 +127,11 @@ export class ModrinthUploader extends GenericPlatformUploader undefined as string), dependency_type: type, }))); - return modrinthDependencies.filter(x => x.project_id && x.dependency_type); + const uniqueModrinthDependencies = modrinthDependencies + .filter(x => x.project_id && x.dependency_type) + .filter((x, i, self) => i === self.findIndex(y => x.project_id === y.project_id)); + + return uniqueModrinthDependencies; } /**