Skip to content

Commit

Permalink
Improve project side & redistribution detection
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Feb 23, 2024
1 parent 4cd31e8 commit c863058
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/commonMain/kotlin/teksturepako/pakku/api/http/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ open class Http

suspend inline fun <reified T> HttpResponse.bodyIfOK(): T?
{
return if (this.status == HttpStatusCode.OK) this.body() else null
return if (this.status == HttpStatusCode.OK) this.body() else null.also {
println("Error: ${this::class.simpleName} HTTP request returned: ${this.status}")
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object CurseForge : Platform(
else -> return null.also { println("Project type $classId not found!") }
},
id = mutableMapOf(serialName to id.toString()),
redistributable = allowModDistribution ?: isAvailable,
files = mutableSetOf(),
)
}
Expand Down
17 changes: 11 additions & 6 deletions src/commonMain/kotlin/teksturepako/pakku/api/platforms/Modrinth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import teksturepako.pakku.api.data.json
import teksturepako.pakku.api.models.GetVersionsFromHashesRequest
import teksturepako.pakku.api.models.MrProjectModel
import teksturepako.pakku.api.models.MrVersionModel
import teksturepako.pakku.api.projects.Project
import teksturepako.pakku.api.projects.ProjectFile
import teksturepako.pakku.api.projects.ProjectType
import teksturepako.pakku.api.projects.assignFiles
import teksturepako.pakku.api.projects.*
import teksturepako.pakku.debugIfEmpty
import teksturepako.pakku.io.exitPakku
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -82,7 +79,15 @@ object Modrinth : Platform(

else -> return null.also { println("Project type $projectType not found!") }
},
side = when
{
serverSide == "required" && clientSide == "required" -> ProjectSide.BOTH
serverSide != "required" && clientSide == "required" -> ProjectSide.SERVER
serverSide == "required" && clientSide != "required" -> ProjectSide.CLIENT
else -> ProjectSide.BOTH
},
id = mutableMapOf(serialName to id),
redistributable = license.id != "ARR",
files = mutableSetOf(),
)
}
Expand Down Expand Up @@ -181,8 +186,8 @@ object Modrinth : Platform(
mcVersions: List<String>, loaders: List<String>, ids: List<String>
): MutableSet<ProjectFile>
{
/* Chunk requests if there are too many ids */
return ids.chunked(2_000).flatMap { list ->
/* Chunk requests if there is too many ids */
return ids.chunked(1_000).flatMap { list ->
val url = encode("versions?ids=${list.map { "\"$it\"" }}".filterNot { it.isWhitespace() }, allow = "?=")

json.decodeFromString<List<MrVersionModel>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ object Multiplatform : IProjectProvider

val listOfIds = projects.mapNotNull { it.id[platform.serialName] }

platform.requestMultipleProjectsWithFiles(mcVersions, loaders, listOfIds, numberOfFiles).forEach { project ->
acc.find { it.slug[platform.serialName] == project.slug[platform.serialName] }?.let {
acc -= it
acc += it + project
platform.requestMultipleProjectsWithFiles(mcVersions, loaders, listOfIds, numberOfFiles)
.forEach { newProject ->
acc.find { accProject ->
accProject.slug[platform.serialName] == newProject.slug[platform.serialName]
}?.let { accProject ->
acc -= accProject
acc += accProject + newProject
}
}
}

acc
}.filter { newProject ->
projects.none {
oldProject -> oldProject == newProject
projects.none { oldProject ->
oldProject == newProject
} && newProject.updateStrategy == UpdateStrategy.LATEST
}.toMutableSet()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ data class Project(
pakkuId = this.pakkuId,
pakkuLinks = this.pakkuLinks,
type = this.type,
side = this.side,
side = if (this.side != null) this.side else if (other.side != null) other.side else null,
// TODO: Maybe different approach to sides would be better

name = (this.name + other.name).toMutableMap(),
slug = (this.slug + other.slug).toMutableMap(),
Expand Down Expand Up @@ -137,7 +138,5 @@ data class Project(
{
// Init Pakku ID
if (pakkuId == null) pakkuId = generatePakkuId()
// Init ProjectSide
if (side == null) side = ProjectSide.BOTH
}
}
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Ls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Ls : CliktCommand("List projects")
else ->
{
if (project.hasNoFiles()) project.name.values.firstOrNull()?.let {
TextStyle(bgColor = gray, color = red)("$it")
TextStyle(bgColor = white, color = red)("$it")
} else project.name.values.firstOrNull()?.let {
TextStyle(bgColor = gray, color = black)("$it")
TextStyle(bgColor = white, color = black)("$it")
}
}
}
Expand Down

0 comments on commit c863058

Please sign in to comment.