Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from Jamalam360/master
Browse files Browse the repository at this point in the history
feat: migrate project body
  • Loading branch information
SilverAndro authored Jul 10, 2022
2 parents c1a473d + ae5efa6 commit c2c623c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +34,15 @@ object CurseforgeAPI : APIInterface() {
}
}

fun getProjectDescription(id: Int): String? {
return try {
getWithoutAuth<CurseforgeDescription>("$root/mods/$id/description").data
} catch (err: Exception) {
err.printStackTrace()
null
}
}

fun getFileStream(file: CurseforgeFile): InputStream {
waitUntilCanSend()
return URL(file.downloadUrl).openStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

Expand All @@ -33,12 +33,13 @@ data class ModrinthProjectCreate private constructor(
val gallery_items: List<Any>? = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,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()] }

Expand Down Expand Up @@ -88,6 +89,7 @@ class ModifoldArgsContainer(parser: ArgParser) {
VERIFY_EXISTING,
CURSE_MCREATOR,
MAP_CATEGORIES,
COPY_LINKS
COPY_LINKS,
MIGRATE_DESCRIPTION
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.p03w.modifold.curseforge_schema

data class CurseforgeDescription(val data: String)
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
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<CurseforgeProject>): MutableMap<CurseforgeProject, ModrinthProject> {
log("Creating modrinth projects from curseforge projects")
val out = mutableMapOf<CurseforgeProject, ModrinthProject>()

curseforgeProjects.forEach { project ->
withSpinner("Making modrinth project for ${project.display()}") {
val mod = ModrinthAPI.makeProject(ModrinthProjectCreate.of(project), 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
}
}
Expand Down

0 comments on commit c2c623c

Please sign in to comment.