fix: when there are multiple compatible of same game version + loader, give latest

This commit is contained in:
tdgao
2026-07-03 11:29:33 -07:00
parent d85e6dcb3c
commit 7a22c44467
2 changed files with 76 additions and 12 deletions
@@ -194,28 +194,58 @@ const showAllVersionsModel = computed({
},
})
const currentGameVersion = computed<string | null>(() => {
const selectedPlatform = computed<string | null>(() => {
if (userSelectedPlatform.value) return userSelectedPlatform.value
return props.project.loaders.length === 1 ? props.project.loaders[0] : null
})
const selectedGameVersion = computed<string | null>(() => {
if (userSelectedGameVersion.value) return userSelectedGameVersion.value
return props.project.game_versions.length === 1 ? props.project.game_versions[0] : null
})
const compatiblePlatforms = computed<string[]>(() => {
return props.project.loaders.filter(
(platform) =>
props.versions.some(
(version) =>
version.loaders.includes(platform) &&
(!selectedGameVersion.value ||
version.game_versions.includes(selectedGameVersion.value)),
) && !incompatibleLoadersSet.value.has(platform),
)
})
const currentPlatform = computed<string | null>(() => {
if (selectedPlatform.value) return selectedPlatform.value
return compatiblePlatforms.value.length === 1 ? compatiblePlatforms.value[0] : null
})
const possibleGameVersions = computed<string[]>(() => {
return props.versions
.filter((x) => !currentPlatform.value || x.loaders.includes(currentPlatform.value))
.flatMap((x) => x.game_versions)
})
const compatibleGameVersions = computed<string[]>(() => {
return props.project.game_versions.filter(
(gameVersion) =>
possibleGameVersions.value.includes(gameVersion) &&
!incompatibleGameVersionsSet.value.has(gameVersion),
)
})
const currentGameVersion = computed<string | null>(() => {
if (selectedGameVersion.value) return selectedGameVersion.value
return compatibleGameVersions.value.length === 1 ? compatibleGameVersions.value[0] : null
})
const possiblePlatforms = computed<string[]>(() => {
return props.versions
.filter((x) => !currentGameVersion.value || x.game_versions.includes(currentGameVersion.value))
.flatMap((x) => x.loaders)
})
const currentPlatform = computed<string | null>(() => {
if (userSelectedPlatform.value) return userSelectedPlatform.value
return props.project.loaders.length === 1 ? props.project.loaders[0] : null
})
const currentPlatformText = computed(() => {
if (!currentPlatform.value) return ''
return loaderLabel(currentPlatform.value)
@@ -727,13 +727,20 @@ const { data: projectOnlyDependencyVersions } = useQuery({
game_versions: currentVersion.game_versions,
loaders: dependencyResolutionLoaders.value,
include_changelog: false,
limit: 1,
limit: 100,
})
} catch {
return [projectId, undefined] as const
}
return [projectId, versions[0]] as const
return [
projectId,
getOnlyCompatibleDependencyVersion(
versions,
currentVersion.game_versions,
dependencyResolutionLoaders.value,
),
] as const
}),
)
@@ -1090,11 +1097,38 @@ function getDependencyVersion(dependency: Labrinth.Versions.v3.Dependency) {
return undefined
}
return (
(Object.keys(projectOnlyDependencyVersions.value || {}).length === 1 &&
projectOnlyDependencyVersions.value?.[dependency.project_id]) ||
undefined
return projectOnlyDependencyVersions.value?.[dependency.project_id]
}
function getOnlyCompatibleDependencyVersion(
versions: Labrinth.Versions.v2.Version[],
gameVersions: string[],
loaders: string[],
) {
const compatibleVersions = versions
.filter(
(version) =>
version.game_versions.some((gameVersion) => gameVersions.includes(gameVersion)) &&
version.loaders.some((loader) => loaders.includes(loader)),
)
.slice()
.sort(
(a, b) =>
new Date(b.date_published).getTime() - new Date(a.date_published).getTime(),
)
const targetKeys = new Set(
compatibleVersions.flatMap((version) =>
version.game_versions.flatMap((gameVersion) =>
gameVersions.includes(gameVersion)
? version.loaders
.filter((loader) => loaders.includes(loader))
.map((loader) => `${gameVersion}:${loader}`)
: [],
),
),
)
return targetKeys.size === 1 ? compatibleVersions[0] : undefined
}
function getDependencyPrimaryFile(version?: Labrinth.Versions.v2.Version) {