fix: better handling of datapacks in frontend & desync issues between browse page impl in app and website

This commit is contained in:
Calum H. (IMB11)
2026-06-26 17:09:23 +01:00
parent 7618f9bc09
commit 32ca8d549b
7 changed files with 136 additions and 44 deletions
@@ -384,9 +384,26 @@ export function getLoaderFilterTypes(contentType: string) {
if (contentType === 'plugin') return ['plugin_loader', 'plugin_platform']
if (contentType === 'modpack') return ['modpack_loader']
if (contentType === 'shader') return ['shader_loader']
if (contentType === 'datapack') return ['datapack_loader']
return []
}
const SERVER_RUNTIME_INSTALL_FILTER_TYPES = new Set([
'game_version',
'mod_loader',
'plugin_loader',
'plugin_platform',
'datapack_loader',
])
export function stripServerRuntimeInstallFilters(filters: readonly FilterValue[]) {
return filters.filter((filter) => !SERVER_RUNTIME_INSTALL_FILTER_TYPES.has(filter.type))
}
export function stripServerRuntimeInstallOverrides(filterTypes: readonly string[]) {
return filterTypes.filter((type) => !SERVER_RUNTIME_INSTALL_FILTER_TYPES.has(type))
}
/**
* Merges user-selected filters with target-provided filters for install decisions.
*
@@ -454,7 +471,12 @@ export function getTargetInstallPreferences(
return normalizeInstallPreferences({
gameVersions: gameVersion && shouldUseTargetRuntime ? [gameVersion] : undefined,
loaders: loader && shouldUseTargetRuntime ? [loader] : undefined,
loaders:
contentType === 'datapack'
? ['datapack']
: loader && shouldUseTargetRuntime
? [loader]
: undefined,
})
}
@@ -515,10 +537,9 @@ export function mergeInstallPreferences(
export function getLatestMatchingInstallVersion(
versions: readonly Labrinth.Versions.v2.Version[],
preferences: BrowseInstallPreferences,
contentType: string,
) {
return [...versions]
.filter((version) => versionMatchesPreferences(version, preferences, contentType))
.filter((version) => versionMatchesPreferences(version, preferences))
.sort((a, b) => new Date(b.date_published).getTime() - new Date(a.date_published).getTime())[0]
}
@@ -543,11 +564,7 @@ export async function resolveInstallPlan<TProject extends BrowseInstallProject>(
let lastError: Error | null = null
for (const candidate of candidates) {
const version = getLatestMatchingInstallVersion(
versions,
candidate.preferences,
options.contentType,
)
const version = getLatestMatchingInstallVersion(versions, candidate.preferences)
if (version) {
const fileName =
@@ -747,13 +764,11 @@ function hasPreferences(preferences: BrowseInstallPreferences) {
function versionMatchesPreferences(
version: Labrinth.Versions.v2.Version,
preferences: BrowseInstallPreferences,
contentType: string,
) {
const gameVersionMatches =
!preferences.gameVersions?.length ||
version.game_versions.some((gameVersion) => preferences.gameVersions?.includes(gameVersion))
if (!gameVersionMatches) return false
if (contentType === 'datapack') return true
if (!preferences.loaders?.length) return true
const compatibleLoaders = getCompatibleLoaderAliasSet(preferences.loaders)
@@ -384,7 +384,11 @@ function toResolvePreferences(
async function resolveStoredServerAddonPlans(plans: BrowseInstallPlan[]) {
const existingProjectIds = getInstalledProjectIds()
const resolvedAddons: Array<{ project_id: string; version_id: string }> = []
const resolvedAddons: Array<{
project_id: string
version_id: string
kind: Archon.Content.v1.AddonKind
}> = []
for (const plan of plans) {
const target = getTargetInstallPreferences(
@@ -409,6 +413,7 @@ async function resolveStoredServerAddonPlans(plans: BrowseInstallPlan[]) {
resolvedAddons.push({
project_id: item.project_id,
version_id: item.version_id,
kind: plan.contentType as Archon.Content.v1.AddonKind,
})
}
}
@@ -1417,7 +1422,7 @@ provideContentManager({
: (updatingProject?.version?.id ?? '')
"
:is-app="false"
:project-type="updatingModpack ? 'modpack' : updatingProject?.project_type"
:project-type="updatingModpack ? 'modpack' : type"
:project-icon-url="
updatingModpack ? modpack?.project.icon_url : updatingProject?.project?.icon_url
"
@@ -47,12 +47,16 @@ export function versionMatchesCompatibilityTarget(
return false
}
const normalizedVersionLoaders = version.loaders.map(normalizeLoaderAlias)
if (target.projectType === 'datapack') {
return normalizedVersionLoaders.includes('datapack')
}
if (target.projectType && NON_MOD_PROJECT_TYPES.has(target.projectType)) {
return true
}
const normalizedVersionLoaders = version.loaders.map(normalizeLoaderAlias)
if (
target.projectType === 'modpack' &&
(normalizedVersionLoaders.length === 0 ||