From 4aed69e39ac723ebde7db3155bc45ac8df135161 Mon Sep 17 00:00:00 2001 From: Jamalam360 <56727311+Jamalam360@users.noreply.github.com> Date: Mon, 4 Jul 2022 17:15:53 +0100 Subject: [PATCH 1/5] feat: description syncing --- .../CurseforgeAPI.kt | 14 ++++++++++---- .../p03w/modifold/modrinth_api/ModrinthAPI.kt | 2 +- .../modifold/modrinth_api/ModrinthProjectCreate.kt | 5 +++-- .../com/github/p03w/modifold/cli/ModifoldArgs.kt | 5 +++++ .../curseforge_schema/CurseforgeDescription.kt | 3 +++ .../p03w/modifold/core/CreateModrinthProjects.kt | 3 ++- 6 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 Schema-Curseforge/src/main/kotlin/com/github/p03w/modifold/curseforge_schema/CurseforgeDescription.kt diff --git a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt index 76fd717..5b5de3c 100644 --- a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt +++ b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt @@ -3,10 +3,7 @@ package com.github.p03w.modifold.curseforge_api import com.github.p03w.modifold.api_core.APIInterface import com.github.p03w.modifold.api_core.Ratelimit import com.github.p03w.modifold.cli.ModifoldArgs -import com.github.p03w.modifold.curseforge_schema.CurseforgeFile -import com.github.p03w.modifold.curseforge_schema.CurseforgeProject -import com.github.p03w.modifold.curseforge_schema.FilesWrapper -import com.github.p03w.modifold.curseforge_schema.ProjectWrapper +import com.github.p03w.modifold.curseforge_schema.* import java.io.InputStream import java.net.URL import kotlin.time.Duration.Companion.milliseconds @@ -37,6 +34,15 @@ object CurseforgeAPI : APIInterface() { } } + fun getProjectDescription(id: Int): String? { + return try { + getWithoutAuth("$root/mods/$id/description").data + } catch (ignored: Exception) { + ignored.printStackTrace() + null + } + } + fun getFileStream(file: CurseforgeFile): InputStream { waitUntilCanSend() return URL(file.downloadUrl).openStream() diff --git a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt index 3b9c564..98e5786 100644 --- a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt +++ b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt @@ -50,7 +50,7 @@ object ModrinthAPI : APIInterface() { } } - const val root = "https://api.modrinth.com/v2" + const val root = "https://staging-api.modrinth.com/v2" fun getPossibleLicenses(): List { val shortLicenses = getWithoutAuth>("$root/tag/license") diff --git a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthProjectCreate.kt b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthProjectCreate.kt index ed2c9b3..e524940 100644 --- a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthProjectCreate.kt +++ b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthProjectCreate.kt @@ -11,7 +11,7 @@ data class ModrinthProjectCreate private constructor( val slug: String, val title: String, val description: String, - val body: String = "Autogenerated project from modifold", + val body: String, val categories: List, @@ -33,12 +33,13 @@ data class ModrinthProjectCreate private constructor( val gallery_items: List? = null ) { companion object { - fun of(curseforgeProject: CurseforgeProject): ModrinthProjectCreate { + fun of(curseforgeProject: CurseforgeProject, description: String?): ModrinthProjectCreate { val copyLinks = ModifoldArgs.args.donts.contains(DONT.COPY_LINKS).not() return ModrinthProjectCreate( title = curseforgeProject.name, slug = curseforgeProject.slug, description = curseforgeProject.summary, + body = description ?: "Autogenerated project from modifold", license_id = ModifoldArgs.args.defaultLicense, categories = if (ModifoldArgs.args.donts.contains(DONT.MAP_CATEGORIES)) emptyList() else mapCategories( curseforgeProject.categories diff --git a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt index cd0a4f9..23f745a 100644 --- a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt +++ b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt @@ -18,6 +18,11 @@ class ModifoldArgsContainer(parser: ArgParser) { help = "Enable debug/verbose mode" ) + val migrateDescription by parser.flagging( + "--description", + help = "Enable migration of mod descriptions from curseforge to modrinth" + ) + val modrinthToken by parser.storing( "--token", help = "Sets the modrinth access token manually, bypassing the web-auth flow" diff --git a/Schema-Curseforge/src/main/kotlin/com/github/p03w/modifold/curseforge_schema/CurseforgeDescription.kt b/Schema-Curseforge/src/main/kotlin/com/github/p03w/modifold/curseforge_schema/CurseforgeDescription.kt new file mode 100644 index 0000000..fe6c186 --- /dev/null +++ b/Schema-Curseforge/src/main/kotlin/com/github/p03w/modifold/curseforge_schema/CurseforgeDescription.kt @@ -0,0 +1,3 @@ +package com.github.p03w.modifold.curseforge_schema + +data class CurseforgeDescription(val data: String) diff --git a/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt b/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt index 7459bc4..6d7cadb 100644 --- a/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt +++ b/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt @@ -2,6 +2,7 @@ package com.github.p03w.modifold.core import com.github.p03w.modifold.cli.log import com.github.p03w.modifold.cli.withSpinner +import com.github.p03w.modifold.curseforge_api.CurseforgeAPI import com.github.p03w.modifold.curseforge_schema.CurseforgeProject import com.github.p03w.modifold.modrinth_schema.ModrinthProject import com.github.p03w.modifold.modrinth_api.ModrinthAPI @@ -13,7 +14,7 @@ fun createModrinthProjects(curseforgeProjects: List): Mutable curseforgeProjects.forEach { project -> withSpinner("Making modrinth project for ${project.display()}") { - val mod = ModrinthAPI.makeProject(ModrinthProjectCreate.of(project), project) + val mod = ModrinthAPI.makeProject(ModrinthProjectCreate.of(project, CurseforgeAPI.getProjectDescription(project.id)), project) out[project] = mod } } From 463ee64bcbcc0a2adbfb1374e40b6c91672c9cd5 Mon Sep 17 00:00:00 2001 From: Jamalam360 <56727311+Jamalam360@users.noreply.github.com> Date: Mon, 4 Jul 2022 17:32:01 +0100 Subject: [PATCH 2/5] feat: make description migrating a 'dont' option --- .../github/p03w/modifold/cli/ModifoldArgs.kt | 11 ++++------- .../modifold/core/CreateModrinthProjects.kt | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt index 23f745a..e9748e2 100644 --- a/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt +++ b/CLITools/src/main/kotlin/com/github/p03w/modifold/cli/ModifoldArgs.kt @@ -18,11 +18,6 @@ class ModifoldArgsContainer(parser: ArgParser) { help = "Enable debug/verbose mode" ) - val migrateDescription by parser.flagging( - "--description", - help = "Enable migration of mod descriptions from curseforge to modrinth" - ) - val modrinthToken by parser.storing( "--token", help = "Sets the modrinth access token manually, bypassing the web-auth flow" @@ -36,7 +31,8 @@ class ModifoldArgsContainer(parser: ArgParser) { "1 to disable checking existing modrinth mods, " + "2 to change the mcreator->cursed mapping to mcreator->misc, " + "3 to disable category mapping entirely, " + - "4 to disable copying links", + "4 to disable copying links, " + + "5 to disable migration of project bodies", argName = "DONT_INDEX" ) { DONT.values()[toInt()] } @@ -93,6 +89,7 @@ class ModifoldArgsContainer(parser: ArgParser) { VERIFY_EXISTING, CURSE_MCREATOR, MAP_CATEGORIES, - COPY_LINKS + COPY_LINKS, + MIGRATE_DESCRIPTION } } diff --git a/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt b/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt index 6d7cadb..ca1df8d 100644 --- a/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt +++ b/src/main/kotlin/com/github/p03w/modifold/core/CreateModrinthProjects.kt @@ -1,12 +1,14 @@ package com.github.p03w.modifold.core +import com.github.p03w.modifold.cli.ModifoldArgs +import com.github.p03w.modifold.cli.ModifoldArgsContainer import com.github.p03w.modifold.cli.log import com.github.p03w.modifold.cli.withSpinner import com.github.p03w.modifold.curseforge_api.CurseforgeAPI import com.github.p03w.modifold.curseforge_schema.CurseforgeProject -import com.github.p03w.modifold.modrinth_schema.ModrinthProject import com.github.p03w.modifold.modrinth_api.ModrinthAPI import com.github.p03w.modifold.modrinth_api.ModrinthProjectCreate +import com.github.p03w.modifold.modrinth_schema.ModrinthProject fun createModrinthProjects(curseforgeProjects: List): MutableMap { log("Creating modrinth projects from curseforge projects") @@ -14,7 +16,18 @@ fun createModrinthProjects(curseforgeProjects: List): Mutable curseforgeProjects.forEach { project -> withSpinner("Making modrinth project for ${project.display()}") { - val mod = ModrinthAPI.makeProject(ModrinthProjectCreate.of(project, CurseforgeAPI.getProjectDescription(project.id)), project) + val description = if (ModifoldArgs.args.donts.contains(ModifoldArgsContainer.DONT.MIGRATE_DESCRIPTION)) { + null + } else { + CurseforgeAPI.getProjectDescription(project.id) + } + + val mod = ModrinthAPI.makeProject( + ModrinthProjectCreate.of( + project, + description + ), project + ) out[project] = mod } } From 290e495ba0ab9b7a7849b646975c0250e0a1da48 Mon Sep 17 00:00:00 2001 From: Jamalam360 <56727311+Jamalam360@users.noreply.github.com> Date: Tue, 5 Jul 2022 10:02:05 +0100 Subject: [PATCH 3/5] chore: revert back to normal api --- .../kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt index 98e5786..3b9c564 100644 --- a/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt +++ b/API-Modrinth/src/main/kotlin/com/github/p03w/modifold/modrinth_api/ModrinthAPI.kt @@ -50,7 +50,7 @@ object ModrinthAPI : APIInterface() { } } - const val root = "https://staging-api.modrinth.com/v2" + const val root = "https://api.modrinth.com/v2" fun getPossibleLicenses(): List { val shortLicenses = getWithoutAuth>("$root/tag/license") From 9bab7aed4ce672894ddf5a6e9999a329022b9ac4 Mon Sep 17 00:00:00 2001 From: Jamalam360 <56727311+Jamalam360@users.noreply.github.com> Date: Tue, 5 Jul 2022 10:03:05 +0100 Subject: [PATCH 4/5] fix: variable naming --- .../com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt index 5b5de3c..32650c0 100644 --- a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt +++ b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt @@ -37,7 +37,7 @@ object CurseforgeAPI : APIInterface() { fun getProjectDescription(id: Int): String? { return try { getWithoutAuth("$root/mods/$id/description").data - } catch (ignored: Exception) { + } catch (err: Exception) { ignored.printStackTrace() null } From ae5efa62d19e0a9de96efcbb34521169f5c9bf19 Mon Sep 17 00:00:00 2001 From: Jamalam360 <56727311+Jamalam360@users.noreply.github.com> Date: Tue, 5 Jul 2022 10:03:49 +0100 Subject: [PATCH 5/5] fix: typo --- .../com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt index 32650c0..d9f107f 100644 --- a/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt +++ b/API-Curseforge/src/main/kotlin/com.github.p03w.modifold.curseforge_api/CurseforgeAPI.kt @@ -38,7 +38,7 @@ object CurseforgeAPI : APIInterface() { return try { getWithoutAuth("$root/mods/$id/description").data } catch (err: Exception) { - ignored.printStackTrace() + err.printStackTrace() null } }