mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 21:26:40 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
428e13a6d3 | ||
|
|
9006dce2b0 | ||
|
|
efdfb51149 | ||
|
|
79cc5fef72 | ||
|
|
ddefc28ca6 | ||
|
|
654757f9fb | ||
|
|
407641ee7c | ||
|
|
96ab120cd0 | ||
|
|
3ed75a146a | ||
|
|
5a1c2a46bc | ||
|
|
df8ebbd3e0 | ||
|
|
517c3d2d72 | ||
|
|
7f15772f59 | ||
|
|
0905ea72f6 | ||
|
|
8d20fd82db | ||
|
|
c831e38e32 | ||
|
|
40b8fb3a4a | ||
|
|
977bb2ff58 | ||
|
|
732bdfc79b | ||
|
|
1cce1eb248 | ||
|
|
76320f227f | ||
|
|
34228a5b6c | ||
|
|
6d66aee4ec | ||
|
|
fc7be043c7 | ||
|
|
7fa88e5d4d | ||
|
|
21508e0637 |
@@ -94,10 +94,11 @@ jobs:
|
||||
uses: rui314/setup-mold@9c9c13bf4c3f1adef0cc596abc155580bcb04444 # v1 / Mold 2.41.0
|
||||
|
||||
- name: Install build dependencies
|
||||
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
|
||||
with:
|
||||
packages: cmake libcurl4-openssl-dev
|
||||
version: v2 # cache key
|
||||
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends cmake libcurl4-openssl-dev
|
||||
#uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
|
||||
#with:
|
||||
# packages: cmake libcurl4-openssl-dev
|
||||
# version: v2 # cache key
|
||||
|
||||
- name: Cache Cargo registry and index
|
||||
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Modrinth Monorepo
|
||||
|
||||
Welcome to the Modrinth Monorepo, the primary codebase for the Modrinth web interface and app. It contains  lines of code and has  contributors!
|
||||
Welcome to the Modrinth Monorepo, the primary codebase for the Modrinth web interface and app. It contains  lines of code and has  contributors!
|
||||
|
||||
If you're not a developer and you've stumbled upon this repository, you can access the web interface on the [Modrinth website](https://modrinth.com) and download the latest release of the app [here](https://modrinth.com/app).
|
||||
|
||||
|
||||
@@ -8,13 +8,18 @@ import type { ComputedRef, Ref } from 'vue'
|
||||
import { onUnmounted, ref, shallowRef } from 'vue'
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
import {
|
||||
fetchCachedServerStatus,
|
||||
getFreshCachedServerStatus,
|
||||
} from '@/composables/instances/use-server-status-query'
|
||||
import { process_listener } from '@/helpers/events'
|
||||
import { kill, list as listInstances } from '@/helpers/instance'
|
||||
import { get_by_instance_id } from '@/helpers/process'
|
||||
import type { GameInstance } from '@/helpers/types'
|
||||
import { add_server_to_instance, getServerAddress, getServerLatency } from '@/helpers/worlds'
|
||||
import { add_server_to_instance, getServerAddress } from '@/helpers/worlds'
|
||||
|
||||
interface BrowseServerInstance {
|
||||
id: string
|
||||
name: string
|
||||
path: string
|
||||
}
|
||||
@@ -68,12 +73,10 @@ export function useAppServerBrowse(options: UseAppServerBrowseOptions) {
|
||||
const queryClient = useQueryClient()
|
||||
const debugLog = useDebugLogger('BrowseServer')
|
||||
const serverPings = shallowRef<Record<string, number | undefined>>({})
|
||||
const serverPingCache = new Map<string, number | undefined>()
|
||||
const pendingServerPings = new Map<string, Promise<number | undefined>>()
|
||||
const runningServerProjects = ref<Record<string, string>>({})
|
||||
const lastServerHits = shallowRef<Labrinth.Search.v3.ResultSearchProject[]>([])
|
||||
const contextMenuRef = ref<ContextMenuHandle | null>(null)
|
||||
let serverPingCacheActive = true
|
||||
let serverPingsActive = true
|
||||
let unlistenProcesses: (() => void) | null = null
|
||||
|
||||
async function checkServerRunningStates(hits: Labrinth.Search.v3.ResultSearchProject[]) {
|
||||
@@ -146,37 +149,26 @@ export function useAppServerBrowse(options: UseAppServerBrowseOptions) {
|
||||
})
|
||||
const nextPings = { ...serverPings.value }
|
||||
for (const { hit, address } of pingsToFetch) {
|
||||
if (serverPingCache.has(address)) {
|
||||
nextPings[hit.project_id] = serverPingCache.get(address)
|
||||
const cachedStatus = getFreshCachedServerStatus(queryClient, address)
|
||||
if (cachedStatus) {
|
||||
nextPings[hit.project_id] = cachedStatus.ping
|
||||
}
|
||||
}
|
||||
serverPings.value = nextPings
|
||||
|
||||
await Promise.all(
|
||||
pingsToFetch.map(async ({ hit, address }) => {
|
||||
if (serverPingCache.has(address)) return
|
||||
if (getFreshCachedServerStatus(queryClient, address)) return
|
||||
|
||||
let pending = pendingServerPings.get(address)
|
||||
if (!pending) {
|
||||
pending = getServerLatency(address)
|
||||
.then((latency) => {
|
||||
if (serverPingCacheActive) serverPingCache.set(address, latency)
|
||||
return latency
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Failed to ping server ${address}:`, error)
|
||||
if (serverPingCacheActive) serverPingCache.set(address, undefined)
|
||||
return undefined
|
||||
})
|
||||
.finally(() => {
|
||||
pendingServerPings.delete(address)
|
||||
})
|
||||
pendingServerPings.set(address, pending)
|
||||
try {
|
||||
const status = await fetchCachedServerStatus(queryClient, address)
|
||||
if (!serverPingsActive) return
|
||||
serverPings.value = { ...serverPings.value, [hit.project_id]: status.ping }
|
||||
} catch (error) {
|
||||
console.error(`Failed to ping server ${address}:`, error)
|
||||
if (!serverPingsActive) return
|
||||
serverPings.value = { ...serverPings.value, [hit.project_id]: undefined }
|
||||
}
|
||||
|
||||
const latency = await pending
|
||||
if (!serverPingCacheActive) return
|
||||
serverPings.value = { ...serverPings.value, [hit.project_id]: latency }
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -308,10 +300,8 @@ export function useAppServerBrowse(options: UseAppServerBrowseOptions) {
|
||||
.catch(options.handleError)
|
||||
|
||||
onUnmounted(() => {
|
||||
serverPingCacheActive = false
|
||||
serverPingsActive = false
|
||||
unlistenProcesses?.()
|
||||
serverPingCache.clear()
|
||||
pendingServerPings.clear()
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { QueryClient } from '@tanstack/vue-query'
|
||||
|
||||
import {
|
||||
get_server_status,
|
||||
normalizeServerAddress,
|
||||
type ProtocolVersion,
|
||||
type ServerStatus,
|
||||
} from '@/helpers/worlds'
|
||||
|
||||
export const SERVER_STATUS_CACHE_MS = 10 * 60 * 1000
|
||||
|
||||
function getProtocolVersionKey(protocolVersion: ProtocolVersion | null) {
|
||||
if (!protocolVersion) return 'default'
|
||||
return `${protocolVersion.version}:${protocolVersion.legacy ? 'legacy' : 'modern'}`
|
||||
}
|
||||
|
||||
export function getServerStatusQueryKey(
|
||||
address: string,
|
||||
protocolVersion: ProtocolVersion | null = null,
|
||||
) {
|
||||
return [
|
||||
'minecraft-server-status',
|
||||
normalizeServerAddress(address) || address.trim().toLowerCase(),
|
||||
getProtocolVersionKey(protocolVersion),
|
||||
] as const
|
||||
}
|
||||
|
||||
export function getFreshCachedServerStatus(
|
||||
queryClient: QueryClient,
|
||||
address: string,
|
||||
protocolVersion: ProtocolVersion | null = null,
|
||||
) {
|
||||
const queryKey = getServerStatusQueryKey(address, protocolVersion)
|
||||
const updatedAt = queryClient.getQueryState(queryKey)?.dataUpdatedAt ?? 0
|
||||
if (!updatedAt || Date.now() - updatedAt >= SERVER_STATUS_CACHE_MS) return undefined
|
||||
return queryClient.getQueryData<ServerStatus>(queryKey)
|
||||
}
|
||||
|
||||
export async function fetchCachedServerStatus(
|
||||
queryClient: QueryClient,
|
||||
address: string,
|
||||
protocolVersion: ProtocolVersion | null = null,
|
||||
) {
|
||||
return await queryClient.fetchQuery({
|
||||
queryKey: getServerStatusQueryKey(address, protocolVersion),
|
||||
queryFn: () => get_server_status(address, protocolVersion),
|
||||
staleTime: SERVER_STATUS_CACHE_MS,
|
||||
gcTime: SERVER_STATUS_CACHE_MS,
|
||||
})
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
preferencesDiffer,
|
||||
provideBrowseManager,
|
||||
requestInstall,
|
||||
stripServerRuntimeInstallFilters,
|
||||
stripServerRuntimeInstallOverrides,
|
||||
useBrowseSearch,
|
||||
useDebugLogger,
|
||||
useVIntl,
|
||||
@@ -47,6 +49,7 @@ import {
|
||||
get_installed_project_ids as getInstalledProjectIds,
|
||||
} from '@/helpers/instance'
|
||||
import { get_loader_versions as getLoaderManifest } from '@/helpers/metadata'
|
||||
import { get as getSettings, set as setSettings } from '@/helpers/settings.ts'
|
||||
import { get_categories, get_game_versions, get_loaders } from '@/helpers/tags'
|
||||
import { get_instance_worlds } from '@/helpers/worlds'
|
||||
import { injectContentInstall } from '@/providers/content-install'
|
||||
@@ -680,7 +683,6 @@ async function chooseInstanceInstallVersion(
|
||||
const selectedVersion = getLatestMatchingInstallVersion(
|
||||
await getInstallProjectVersions(project.project_id),
|
||||
selectedPreferences,
|
||||
projectTypeValue,
|
||||
)
|
||||
|
||||
if (!selectedVersion) {
|
||||
@@ -763,11 +765,15 @@ function getCardActions(
|
||||
project: projectResult,
|
||||
contentType,
|
||||
mode: isModpack ? 'immediate' : 'queue',
|
||||
selectedFilters: isModpack ? [] : searchState.currentFilters.value,
|
||||
selectedFilters: isModpack
|
||||
? []
|
||||
: stripServerRuntimeInstallFilters(searchState.currentFilters.value),
|
||||
providedFilters: isModpack ? [] : combinedProvidedFilters.value,
|
||||
overriddenProvidedFilterTypes: isModpack
|
||||
? []
|
||||
: searchState.overriddenProvidedFilterTypes.value,
|
||||
: stripServerRuntimeInstallOverrides(
|
||||
searchState.overriddenProvidedFilterTypes.value,
|
||||
),
|
||||
targetPreferences: getServerInstallTargetPreferences(contentType),
|
||||
getProjectVersions: getInstallProjectVersions,
|
||||
queue: serverInstallQueue,
|
||||
@@ -1036,10 +1042,24 @@ function getProjectBrowseQuery() {
|
||||
}
|
||||
}
|
||||
|
||||
const advancedFiltersCollapsed = computed({
|
||||
get: () => themeStore.getFeatureFlag('advanced_filters_collapsed'),
|
||||
set: (value) => {
|
||||
themeStore.featureFlags['advanced_filters_collapsed'] = value
|
||||
getSettings()
|
||||
.then((settings) => {
|
||||
settings.feature_flags['advanced_filters_collapsed'] = value
|
||||
return setSettings(settings)
|
||||
})
|
||||
.catch(handleError)
|
||||
},
|
||||
})
|
||||
|
||||
provideBrowseManager({
|
||||
tags,
|
||||
projectType,
|
||||
...searchState,
|
||||
advancedFiltersCollapsed,
|
||||
getProjectLink: (result: Labrinth.Search.v2.ResultSearchProject) => ({
|
||||
path: `/project/${result.project_id ?? result.slug}`,
|
||||
query: getProjectBrowseQuery(),
|
||||
|
||||
@@ -317,6 +317,10 @@ import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||
import ExportModal from '@/components/ui/ExportModal.vue'
|
||||
import InstanceSettingsModal from '@/components/ui/modal/InstanceSettingsModal.vue'
|
||||
import UpdateToPlayModal from '@/components/ui/modal/UpdateToPlayModal.vue'
|
||||
import {
|
||||
fetchCachedServerStatus,
|
||||
getFreshCachedServerStatus,
|
||||
} from '@/composables/instances/use-server-status-query'
|
||||
import { useInstanceConsole } from '@/composables/useInstanceConsole'
|
||||
import { trackEvent } from '@/helpers/analytics'
|
||||
import { get_project_v3 } from '@/helpers/cache.js'
|
||||
@@ -327,7 +331,7 @@ import { type InstanceContentData, loadInstanceContentData } from '@/helpers/ins
|
||||
import { get_by_instance_id } from '@/helpers/process'
|
||||
import type { GameInstance } from '@/helpers/types'
|
||||
import { createInstanceShortcut, showInstanceInFolder } from '@/helpers/utils.js'
|
||||
import { get_server_status, refreshWorlds } from '@/helpers/worlds'
|
||||
import { refreshWorlds, type ServerStatus } from '@/helpers/worlds'
|
||||
import { injectServerInstall } from '@/providers/server-install'
|
||||
import { handleSevereError } from '@/store/error.js'
|
||||
import { useBreadcrumbs, useTheming } from '@/store/state'
|
||||
@@ -372,13 +376,15 @@ const selected = ref<unknown[]>([])
|
||||
|
||||
const minecraftServer = computed(() => linkedProjectV3.value?.minecraft_server)
|
||||
const javaServerPingData = computed(() => linkedProjectV3.value?.minecraft_java_server?.ping?.data)
|
||||
const statusOnline = computed(() => !!javaServerPingData.value)
|
||||
const liveServerStatusOnline = ref(false)
|
||||
const statusOnline = computed(() => liveServerStatusOnline.value || !!javaServerPingData.value)
|
||||
const recentPlays = computed(
|
||||
() => linkedProjectV3.value?.minecraft_java_server?.verified_plays_2w ?? undefined,
|
||||
)
|
||||
const playersOnline = ref<number | undefined>(undefined)
|
||||
const ping = ref<number | undefined>(undefined)
|
||||
const loadingServerPing = ref(false)
|
||||
const activeInstanceId = ref<string>()
|
||||
|
||||
watch(
|
||||
() => router.currentRoute.value,
|
||||
@@ -390,6 +396,20 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function applyServerStatus(status: ServerStatus) {
|
||||
playersOnline.value = status.players?.online
|
||||
ping.value = status.ping
|
||||
liveServerStatusOnline.value = true
|
||||
loadingServerPing.value = true
|
||||
}
|
||||
|
||||
function resetServerStatus() {
|
||||
ping.value = undefined
|
||||
playersOnline.value = undefined
|
||||
liveServerStatusOnline.value = false
|
||||
loadingServerPing.value = false
|
||||
}
|
||||
|
||||
function isContentSubpageRoute(routeName = displayedInstanceRoute.value.name) {
|
||||
return typeof routeName === 'string' && contentSubpageRouteNames.has(routeName)
|
||||
}
|
||||
@@ -398,9 +418,7 @@ async function fetchInstance() {
|
||||
isServerInstance.value = false
|
||||
linkedProjectV3.value = undefined
|
||||
preloadedContent.value = null
|
||||
ping.value = undefined
|
||||
playersOnline.value = undefined
|
||||
loadingServerPing.value = false
|
||||
resetServerStatus()
|
||||
|
||||
const nextInstance = await get(route.params.id as string).catch(handleError)
|
||||
let nextLinkedProjectV3: Labrinth.Projects.v3.Project | undefined
|
||||
@@ -429,8 +447,9 @@ async function fetchInstance() {
|
||||
linkedProjectV3.value = nextLinkedProjectV3
|
||||
isServerInstance.value = nextIsServerInstance
|
||||
preloadedContent.value = nextPreloadedContent
|
||||
activeInstanceId.value = nextInstance?.id
|
||||
|
||||
fetchDeferredData()
|
||||
fetchDeferredData(nextInstance?.id)
|
||||
|
||||
if (nextInstance) {
|
||||
queryClient.prefetchQuery({
|
||||
@@ -441,18 +460,32 @@ async function fetchInstance() {
|
||||
}
|
||||
}
|
||||
|
||||
function fetchDeferredData() {
|
||||
function fetchDeferredData(instanceId?: string) {
|
||||
const serverAddress = linkedProjectV3.value?.minecraft_java_server?.address
|
||||
if (isServerInstance.value && serverAddress) {
|
||||
get_server_status(serverAddress)
|
||||
const cachedStatus = getFreshCachedServerStatus(queryClient, serverAddress)
|
||||
if (cachedStatus) {
|
||||
applyServerStatus(cachedStatus)
|
||||
} else {
|
||||
playersOnline.value = undefined
|
||||
ping.value = undefined
|
||||
loadingServerPing.value = false
|
||||
}
|
||||
|
||||
fetchCachedServerStatus(queryClient, serverAddress)
|
||||
.then((status) => {
|
||||
playersOnline.value = status.players?.online
|
||||
ping.value = status.ping
|
||||
if (
|
||||
activeInstanceId.value !== instanceId ||
|
||||
linkedProjectV3.value?.minecraft_java_server?.address !== serverAddress
|
||||
)
|
||||
return
|
||||
applyServerStatus(status)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Failed to fetch server status for ${serverAddress}:`, error)
|
||||
})
|
||||
.finally(() => {
|
||||
if (activeInstanceId.value !== instanceId) return
|
||||
loadingServerPing.value = true
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -302,6 +302,7 @@ import {
|
||||
SelectedProjectsFloatingBar,
|
||||
useVIntl,
|
||||
} from '@modrinth/ui'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||
import dayjs from 'dayjs'
|
||||
@@ -312,6 +313,10 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import { SwapIcon } from '@/assets/icons/index.js'
|
||||
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||
import InstanceIndicator from '@/components/ui/InstanceIndicator.vue'
|
||||
import {
|
||||
fetchCachedServerStatus,
|
||||
getFreshCachedServerStatus,
|
||||
} from '@/composables/instances/use-server-status-query'
|
||||
import {
|
||||
get_organization,
|
||||
get_project,
|
||||
@@ -330,7 +335,7 @@ import {
|
||||
import { get_loader_versions as getLoaderManifest } from '@/helpers/metadata'
|
||||
import { get_by_instance_id } from '@/helpers/process'
|
||||
import { get_categories, get_game_versions, get_loaders } from '@/helpers/tags'
|
||||
import { getServerAddress, getServerLatency } from '@/helpers/worlds'
|
||||
import { getServerAddress } from '@/helpers/worlds'
|
||||
import { injectContentInstall } from '@/providers/content-install'
|
||||
import { injectServerInstall } from '@/providers/server-install'
|
||||
import { createServerInstallContent } from '@/providers/setup/server-install-content'
|
||||
@@ -343,6 +348,7 @@ const { handleError } = injectNotificationManager()
|
||||
const { install: installVersion } = injectContentInstall()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const breadcrumbs = useBreadcrumbs()
|
||||
const themeStore = useTheming()
|
||||
const { formatMessage } = useVIntl()
|
||||
@@ -628,10 +634,19 @@ async function fetchProjectData() {
|
||||
function fetchDeferredServerData(project) {
|
||||
const serverAddress = projectV3.value?.minecraft_java_server?.address
|
||||
if (serverAddress) {
|
||||
serverPing.value = undefined
|
||||
getServerLatency(serverAddress)
|
||||
.then((latency) => {
|
||||
serverPing.value = latency
|
||||
const cachedStatus = getFreshCachedServerStatus(queryClient, serverAddress)
|
||||
if (cachedStatus) {
|
||||
serverPing.value = cachedStatus.ping
|
||||
serverStatusOnline.value = true
|
||||
} else {
|
||||
serverPing.value = undefined
|
||||
}
|
||||
|
||||
fetchCachedServerStatus(queryClient, serverAddress)
|
||||
.then((status) => {
|
||||
if (projectV3.value?.minecraft_java_server?.address !== serverAddress) return
|
||||
serverPing.value = status.ping
|
||||
serverStatusOnline.value = true
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Failed to ping server ${serverAddress}:`, error)
|
||||
|
||||
@@ -16,6 +16,7 @@ export const DEFAULT_FEATURE_FLAGS = {
|
||||
pride_fundraiser: true,
|
||||
i18n_debug: false,
|
||||
show_instance_play_time: true,
|
||||
advanced_filters_collapsed: true,
|
||||
}
|
||||
|
||||
export const THEME_OPTIONS = ['dark', 'light', 'oled', 'system'] as const
|
||||
|
||||
@@ -27,6 +27,8 @@ pub enum ErrorKind {
|
||||
inner: Box<s3::error::S3Error>,
|
||||
file: String,
|
||||
},
|
||||
#[error("I/O error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error("Error acquiring semaphore: {0}")]
|
||||
Acquire(#[from] tokio::sync::AcquireError),
|
||||
#[error("Tracing error: {0}")]
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
//! Fetches Fabric-compatible loader metadata.
|
||||
//!
|
||||
//! Fabric and Quilt both expose loader profiles for a concrete Minecraft
|
||||
//! version, but Daedalus publishes templated profiles using
|
||||
//! `${modrinth.gameVersion}`. A group is a set of Minecraft versions whose
|
||||
//! upstream loader profiles have the same structure after the concrete
|
||||
//! Minecraft version is replaced with `${modrinth.gameVersion}`. Fabric uses
|
||||
//! one universal group, so its public profile paths stay as
|
||||
//! `versions/{loader}.json`. Quilt has more than one group: versions before
|
||||
//! 26.x include hashed/intermediary libraries, while 26.x versions do not. For
|
||||
//! Quilt, Daedalus writes one templated profile per group at
|
||||
//! `version-group/{group}/loader-version/{loader}`.
|
||||
|
||||
use crate::metadata_groups::{
|
||||
UNIVERSAL_METADATA_GROUP, metadata_group_for_game_version, metadata_groups,
|
||||
};
|
||||
use crate::util::{download_file, fetch_json, format_url};
|
||||
use crate::{
|
||||
Error, FetchResult, MirrorArtifact, UploadFile, insert_mirrored_artifact,
|
||||
@@ -64,7 +80,112 @@ async fn fetch(
|
||||
&semaphore,
|
||||
)
|
||||
.await?;
|
||||
let all_loader_versions = fabric_manifest.loader.clone();
|
||||
let all_game_versions = fabric_manifest.game.clone();
|
||||
let metadata_groups = metadata_groups(
|
||||
mod_loader,
|
||||
all_game_versions.iter().map(|x| x.version.as_str()),
|
||||
);
|
||||
|
||||
if metadata_groups
|
||||
.iter()
|
||||
.any(|group| group.id != UNIVERSAL_METADATA_GROUP)
|
||||
{
|
||||
let loaders = all_loader_versions
|
||||
.iter()
|
||||
.filter(|x| !skip_versions.contains(&&*x.version))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let profile_requests = metadata_groups
|
||||
.iter()
|
||||
.flat_map(|group| {
|
||||
loaders.iter().map(move |loader| ProfileRequest {
|
||||
group: group.id.to_string(),
|
||||
loader_profile_template_game_version: group
|
||||
.loader_profile_template_game_version
|
||||
.clone(),
|
||||
game_versions: group.game_versions.clone(),
|
||||
loader_version: loader.version.clone(),
|
||||
url: format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
meta_url,
|
||||
group.loader_profile_template_game_version,
|
||||
loader.version
|
||||
),
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
fetch_metadata_profiles(
|
||||
mod_loader,
|
||||
format_version,
|
||||
maven_url,
|
||||
profile_requests,
|
||||
&upload_files,
|
||||
&mirror_artifacts,
|
||||
&semaphore,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let version_groups = metadata_groups
|
||||
.iter()
|
||||
.map(|group| daedalus::modded::VersionGroup {
|
||||
id: group.id.to_string(),
|
||||
loaders: loaders
|
||||
.iter()
|
||||
.map(|loader| {
|
||||
let version_path = metadata_version_path(
|
||||
mod_loader,
|
||||
format_version,
|
||||
&loader.version,
|
||||
group.id,
|
||||
);
|
||||
|
||||
daedalus::modded::LoaderVersion {
|
||||
id: loader.version.clone(),
|
||||
url: format_url(&version_path),
|
||||
stable: loader.stable,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let manifest = daedalus::modded::Manifest {
|
||||
game_versions: all_game_versions
|
||||
.into_iter()
|
||||
.map(|game_version| {
|
||||
let group = metadata_group_for_game_version(
|
||||
&metadata_groups,
|
||||
mod_loader,
|
||||
&game_version.version,
|
||||
)
|
||||
.expect("game version should have a metadata group");
|
||||
|
||||
daedalus::modded::Version {
|
||||
id: game_version.version.clone(),
|
||||
stable: game_version.stable,
|
||||
version_group: Some(group.id.to_string()),
|
||||
loaders: Vec::new(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
version_groups,
|
||||
};
|
||||
|
||||
upload_files.insert(
|
||||
format!("{mod_loader}/v{format_version}/manifest.json"),
|
||||
UploadFile {
|
||||
file: bytes::Bytes::from(serde_json::to_vec(&manifest)?),
|
||||
content_type: Some("application/json".to_string()),
|
||||
},
|
||||
);
|
||||
|
||||
return Ok(FetchResult {
|
||||
upload_files,
|
||||
mirror_artifacts,
|
||||
});
|
||||
}
|
||||
// We check Modrinth's manifest to find newly added loader versions,
|
||||
// intermediary/mapping artifacts, and game versions.
|
||||
let (
|
||||
@@ -125,8 +246,6 @@ async fn fetch(
|
||||
)
|
||||
};
|
||||
|
||||
const DUMMY_GAME_VERSION: &str = "1.21";
|
||||
|
||||
if !fetch_intermediary_versions.is_empty() {
|
||||
for x in &fetch_intermediary_versions {
|
||||
insert_mirrored_artifact(
|
||||
@@ -140,94 +259,38 @@ async fn fetch(
|
||||
}
|
||||
|
||||
if !fetch_fabric_versions.is_empty() {
|
||||
let fabric_version_manifest_urls = fetch_fabric_versions
|
||||
let universal_group = metadata_groups
|
||||
.iter()
|
||||
.map(|x| {
|
||||
format!(
|
||||
.find(|group| group.id == UNIVERSAL_METADATA_GROUP)
|
||||
.expect("fabric metadata should have a universal group");
|
||||
let profile_requests = fetch_fabric_versions
|
||||
.iter()
|
||||
.map(|loader| ProfileRequest {
|
||||
group: universal_group.id.to_string(),
|
||||
loader_profile_template_game_version: universal_group
|
||||
.loader_profile_template_game_version
|
||||
.clone(),
|
||||
game_versions: universal_group.game_versions.clone(),
|
||||
loader_version: loader.version.clone(),
|
||||
url: format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
meta_url, DUMMY_GAME_VERSION, x.version
|
||||
)
|
||||
meta_url,
|
||||
universal_group.loader_profile_template_game_version,
|
||||
loader.version
|
||||
),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let fabric_version_manifests = futures::future::try_join_all(
|
||||
fabric_version_manifest_urls
|
||||
.iter()
|
||||
.map(|x| download_file(x, None, &semaphore)),
|
||||
|
||||
fetch_metadata_profiles(
|
||||
mod_loader,
|
||||
format_version,
|
||||
maven_url,
|
||||
profile_requests,
|
||||
&upload_files,
|
||||
&mirror_artifacts,
|
||||
&semaphore,
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|x| serde_json::from_slice(&x))
|
||||
.collect::<Result<Vec<PartialVersionInfo>, serde_json::Error>>()?;
|
||||
|
||||
let patched_version_manifests = fabric_version_manifests
|
||||
.into_iter()
|
||||
.map(|mut version_info| {
|
||||
for lib in &mut version_info.libraries {
|
||||
let new_name = lib
|
||||
.name
|
||||
.replace(DUMMY_GAME_VERSION, DUMMY_REPLACE_STRING);
|
||||
|
||||
// Hard-code: This library is not present on fabric's maven, so we fetch it from MC libraries
|
||||
if &*lib.name == "net.minecraft:launchwrapper:1.12" {
|
||||
lib.url = Some(
|
||||
"https://libraries.minecraft.net/".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
// If a library is not intermediary, we add it to mirror artifacts to be mirrored
|
||||
if lib.name == new_name {
|
||||
insert_mirrored_artifact(
|
||||
&new_name,
|
||||
None,
|
||||
vec![
|
||||
lib.url
|
||||
.clone()
|
||||
.unwrap_or_else(|| maven_url.to_string()),
|
||||
],
|
||||
false,
|
||||
&mirror_artifacts,
|
||||
)?;
|
||||
} else {
|
||||
lib.name = new_name;
|
||||
}
|
||||
|
||||
lib.url = Some(format_url("maven/"));
|
||||
}
|
||||
|
||||
version_info.id = version_info
|
||||
.id
|
||||
.replace(DUMMY_GAME_VERSION, DUMMY_REPLACE_STRING);
|
||||
version_info.inherits_from = version_info
|
||||
.inherits_from
|
||||
.replace(DUMMY_GAME_VERSION, DUMMY_REPLACE_STRING);
|
||||
|
||||
Ok(version_info)
|
||||
})
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
let serialized_version_manifests = patched_version_manifests
|
||||
.iter()
|
||||
.map(|x| serde_json::to_vec(x).map(bytes::Bytes::from))
|
||||
.collect::<Result<Vec<_>, serde_json::Error>>()?;
|
||||
|
||||
serialized_version_manifests
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.for_each(|(index, bytes)| {
|
||||
let loader = fetch_fabric_versions[index];
|
||||
|
||||
let version_path = format!(
|
||||
"{mod_loader}/v{format_version}/versions/{}.json",
|
||||
loader.version
|
||||
);
|
||||
|
||||
upload_files.insert(
|
||||
version_path,
|
||||
UploadFile {
|
||||
file: bytes,
|
||||
content_type: Some("application/json".to_string()),
|
||||
},
|
||||
);
|
||||
});
|
||||
.await?;
|
||||
}
|
||||
|
||||
if !fetch_fabric_versions.is_empty()
|
||||
@@ -240,17 +303,20 @@ async fn fetch(
|
||||
let loader_versions = daedalus::modded::Version {
|
||||
id: DUMMY_REPLACE_STRING.to_string(),
|
||||
stable: true,
|
||||
loaders: fabric_manifest
|
||||
.loader
|
||||
.into_iter()
|
||||
version_group: None,
|
||||
loaders: all_loader_versions
|
||||
.iter()
|
||||
.filter(|x| !skip_versions.contains(&&*x.version))
|
||||
.map(|x| {
|
||||
let version_path = format!(
|
||||
"{mod_loader}/v{format_version}/versions/{}.json",
|
||||
x.version,
|
||||
let version_path = metadata_version_path(
|
||||
mod_loader,
|
||||
format_version,
|
||||
&x.version,
|
||||
UNIVERSAL_METADATA_GROUP,
|
||||
);
|
||||
|
||||
daedalus::modded::LoaderVersion {
|
||||
id: x.version,
|
||||
id: x.version.clone(),
|
||||
url: format_url(&version_path),
|
||||
stable: x.stable,
|
||||
}
|
||||
@@ -260,14 +326,16 @@ async fn fetch(
|
||||
|
||||
let manifest = daedalus::modded::Manifest {
|
||||
game_versions: std::iter::once(loader_versions)
|
||||
.chain(fabric_manifest.game.into_iter().map(|x| {
|
||||
.chain(all_game_versions.into_iter().map(|x| {
|
||||
daedalus::modded::Version {
|
||||
id: x.version,
|
||||
stable: x.stable,
|
||||
version_group: None,
|
||||
loaders: vec![],
|
||||
}
|
||||
}))
|
||||
.collect(),
|
||||
version_groups: Vec::new(),
|
||||
};
|
||||
|
||||
upload_files.insert(
|
||||
@@ -285,6 +353,145 @@ async fn fetch(
|
||||
})
|
||||
}
|
||||
|
||||
struct ProfileRequest {
|
||||
group: String,
|
||||
loader_profile_template_game_version: String,
|
||||
game_versions: Vec<String>,
|
||||
loader_version: String,
|
||||
url: String,
|
||||
}
|
||||
|
||||
fn metadata_version_path(
|
||||
mod_loader: &str,
|
||||
format_version: usize,
|
||||
loader_version: &str,
|
||||
group: &str,
|
||||
) -> String {
|
||||
if group == UNIVERSAL_METADATA_GROUP {
|
||||
format!("{mod_loader}/v{format_version}/versions/{loader_version}.json")
|
||||
} else {
|
||||
format!(
|
||||
"{mod_loader}/v{format_version}/version-group/{group}/loader-version/{loader_version}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_metadata_profiles(
|
||||
mod_loader: &str,
|
||||
format_version: usize,
|
||||
maven_url: &str,
|
||||
profile_requests: Vec<ProfileRequest>,
|
||||
upload_files: &DashMap<String, UploadFile>,
|
||||
mirror_artifacts: &DashMap<String, MirrorArtifact>,
|
||||
semaphore: &Arc<Semaphore>,
|
||||
) -> Result<(), Error> {
|
||||
let version_manifests = futures::future::try_join_all(
|
||||
profile_requests
|
||||
.iter()
|
||||
.map(|x| download_file(&x.url, None, semaphore)),
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|x| serde_json::from_slice(&x))
|
||||
.collect::<Result<Vec<PartialVersionInfo>, serde_json::Error>>()?;
|
||||
|
||||
let patched_version_manifests = version_manifests
|
||||
.into_iter()
|
||||
.zip(profile_requests.iter())
|
||||
.map(|(mut version_info, request)| {
|
||||
patch_version_info(
|
||||
&mut version_info,
|
||||
&request.loader_profile_template_game_version,
|
||||
&request.game_versions,
|
||||
maven_url,
|
||||
mirror_artifacts,
|
||||
)?;
|
||||
|
||||
Ok(version_info)
|
||||
})
|
||||
.collect::<Result<Vec<_>, Error>>()?;
|
||||
let serialized_version_manifests = patched_version_manifests
|
||||
.iter()
|
||||
.map(|x| serde_json::to_vec(x).map(bytes::Bytes::from))
|
||||
.collect::<Result<Vec<_>, serde_json::Error>>()?;
|
||||
|
||||
serialized_version_manifests
|
||||
.into_iter()
|
||||
.zip(profile_requests)
|
||||
.for_each(|(bytes, request)| {
|
||||
let version_path = metadata_version_path(
|
||||
mod_loader,
|
||||
format_version,
|
||||
&request.loader_version,
|
||||
&request.group,
|
||||
);
|
||||
|
||||
upload_files.insert(
|
||||
version_path,
|
||||
UploadFile {
|
||||
file: bytes,
|
||||
content_type: Some("application/json".to_string()),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn patch_version_info(
|
||||
version_info: &mut PartialVersionInfo,
|
||||
game_version: &str,
|
||||
game_versions: &[String],
|
||||
maven_url: &str,
|
||||
mirror_artifacts: &DashMap<String, MirrorArtifact>,
|
||||
) -> Result<(), Error> {
|
||||
for lib in &mut version_info.libraries {
|
||||
let new_name = lib.name.replace(game_version, DUMMY_REPLACE_STRING);
|
||||
|
||||
// Hard-code: This library is not present on fabric's maven, so we fetch it from MC libraries
|
||||
if &*lib.name == "net.minecraft:launchwrapper:1.12" {
|
||||
lib.url = Some("https://libraries.minecraft.net/".to_string());
|
||||
}
|
||||
let source_url =
|
||||
lib.url.clone().unwrap_or_else(|| maven_url.to_string());
|
||||
|
||||
if lib.name == new_name {
|
||||
insert_mirrored_artifact(
|
||||
&new_name,
|
||||
None,
|
||||
vec![source_url],
|
||||
false,
|
||||
mirror_artifacts,
|
||||
)?;
|
||||
} else {
|
||||
for concrete_game_version in game_versions {
|
||||
let concrete_name =
|
||||
lib.name.replace(game_version, concrete_game_version);
|
||||
|
||||
insert_mirrored_artifact(
|
||||
&concrete_name,
|
||||
None,
|
||||
vec![source_url.clone()],
|
||||
false,
|
||||
mirror_artifacts,
|
||||
)?;
|
||||
}
|
||||
|
||||
lib.name = new_name;
|
||||
}
|
||||
|
||||
lib.url = Some(format_url("maven/"));
|
||||
}
|
||||
|
||||
version_info.id =
|
||||
version_info.id.replace(game_version, DUMMY_REPLACE_STRING);
|
||||
version_info.inherits_from = version_info
|
||||
.inherits_from
|
||||
.replace(game_version, DUMMY_REPLACE_STRING);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct FabricVersions {
|
||||
pub loader: Vec<FabricLoaderVersion>,
|
||||
|
||||
@@ -12,7 +12,10 @@ use itertools::Itertools;
|
||||
use serde::Deserialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
#[tracing::instrument(skip(semaphore))]
|
||||
@@ -243,12 +246,45 @@ async fn fetch(
|
||||
};
|
||||
|
||||
if !fetch_versions.is_empty() {
|
||||
let forge_installers = futures::future::try_join_all(
|
||||
fetch_versions
|
||||
.iter()
|
||||
.map(|x| download_file(&x.installer_url, None, &semaphore)),
|
||||
)
|
||||
.await?;
|
||||
let total_installers = fetch_versions.len();
|
||||
let downloaded_installers = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
tracing::info!(
|
||||
mod_loader,
|
||||
total_files = total_installers,
|
||||
"Downloading loader installers"
|
||||
);
|
||||
|
||||
let forge_installers =
|
||||
futures::future::try_join_all(fetch_versions.iter().map(|x| {
|
||||
let downloaded_installers = downloaded_installers.clone();
|
||||
let semaphore = semaphore.clone();
|
||||
|
||||
async move {
|
||||
let installer =
|
||||
download_file(&x.installer_url, None, &semaphore)
|
||||
.await?;
|
||||
let downloaded = downloaded_installers
|
||||
.fetch_add(1, Ordering::Relaxed)
|
||||
+ 1;
|
||||
|
||||
if downloaded.is_multiple_of(100)
|
||||
|| downloaded == total_installers
|
||||
{
|
||||
tracing::info!(
|
||||
mod_loader,
|
||||
downloaded_files = downloaded,
|
||||
remaining_files =
|
||||
total_installers.saturating_sub(downloaded),
|
||||
total_files = total_installers,
|
||||
"Downloaded loader installers"
|
||||
);
|
||||
}
|
||||
|
||||
Ok::<_, Error>(installer)
|
||||
}
|
||||
}))
|
||||
.await?;
|
||||
|
||||
#[tracing::instrument(skip(raw, upload_files, mirror_artifacts))]
|
||||
async fn read_forge_installer(
|
||||
@@ -761,21 +797,23 @@ async fn fetch(
|
||||
.into_iter()
|
||||
.map(|(game_version, loaders)| {
|
||||
daedalus::modded::Version {
|
||||
id: game_version,
|
||||
stable: true,
|
||||
loaders: loaders
|
||||
.map(|x| daedalus::modded::LoaderVersion {
|
||||
url: format_url(&format!(
|
||||
"{mod_loader}/v{format_version}/versions/{}.json",
|
||||
x.loader_version
|
||||
)),
|
||||
id: x.loader_version,
|
||||
stable: false,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
id: game_version,
|
||||
stable: true,
|
||||
version_group: None,
|
||||
loaders: loaders
|
||||
.map(|x| daedalus::modded::LoaderVersion {
|
||||
url: format_url(&format!(
|
||||
"{mod_loader}/v{format_version}/versions/{}.json",
|
||||
x.loader_version
|
||||
)),
|
||||
id: x.loader_version,
|
||||
stable: false,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
version_groups: Vec::new(),
|
||||
};
|
||||
|
||||
upload_files.insert(
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use crate::util::{
|
||||
REQWEST_CLIENT, format_url, upload_file_to_bucket,
|
||||
upload_url_to_bucket_mirrors,
|
||||
upload_url_to_bucket_mirrors, write_file_to_local_output,
|
||||
write_url_to_local_output_mirrors,
|
||||
};
|
||||
use daedalus::get_path_from_artifact;
|
||||
use dashmap::{DashMap, DashSet};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
||||
@@ -12,6 +16,7 @@ use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
||||
mod error;
|
||||
mod fabric;
|
||||
mod forge;
|
||||
mod metadata_groups;
|
||||
mod minecraft;
|
||||
pub mod util;
|
||||
|
||||
@@ -44,51 +49,92 @@ async fn main() -> Result<()> {
|
||||
));
|
||||
|
||||
let mut fetch_result = FetchResult::default();
|
||||
let only_loader = dotenvy::var("DAEDALUS_ONLY").ok();
|
||||
|
||||
match minecraft::fetch(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Minecraft fetch failed"),
|
||||
if should_fetch(only_loader.as_deref(), "minecraft") {
|
||||
match minecraft::fetch(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Minecraft fetch failed"),
|
||||
}
|
||||
}
|
||||
|
||||
match fabric::fetch_fabric(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Fabric fetch failed"),
|
||||
if should_fetch(only_loader.as_deref(), "fabric") {
|
||||
match fabric::fetch_fabric(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Fabric fetch failed"),
|
||||
}
|
||||
}
|
||||
|
||||
match fabric::fetch_quilt(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Quilt fetch failed"),
|
||||
if should_fetch(only_loader.as_deref(), "quilt") {
|
||||
match fabric::fetch_quilt(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Quilt fetch failed"),
|
||||
}
|
||||
}
|
||||
|
||||
match forge::fetch_neo(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "NeoForge fetch failed"),
|
||||
if should_fetch(only_loader.as_deref(), "neo") {
|
||||
match forge::fetch_neo(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "NeoForge fetch failed"),
|
||||
}
|
||||
}
|
||||
|
||||
match forge::fetch_forge(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Forge fetch failed"),
|
||||
if should_fetch(only_loader.as_deref(), "forge") {
|
||||
match forge::fetch_forge(semaphore.clone()).await {
|
||||
Ok(fetched) => merge_fetch_result(&mut fetch_result, fetched),
|
||||
Err(err) => tracing::warn!(error = %err, "Forge fetch failed"),
|
||||
}
|
||||
}
|
||||
|
||||
let FetchResult {
|
||||
upload_files,
|
||||
mirror_artifacts,
|
||||
} = fetch_result;
|
||||
let upload_file_total = upload_files.len();
|
||||
let mirror_file_total = mirror_artifacts.len();
|
||||
|
||||
futures::future::try_join_all(upload_files.iter().map(|entry| {
|
||||
upload_file_to_bucket(
|
||||
entry.key().clone(),
|
||||
entry.value().file.clone(),
|
||||
entry.value().content_type.clone(),
|
||||
&semaphore,
|
||||
)
|
||||
}))
|
||||
.await?;
|
||||
if dotenvy::var("LOCAL_OUTPUT_DIR").is_ok() {
|
||||
let written_files = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
futures::future::try_join_all(mirror_artifacts.iter().map(|entry| {
|
||||
upload_url_to_bucket_mirrors(
|
||||
format!("maven/{}", entry.key()),
|
||||
entry
|
||||
tracing::info!(
|
||||
total_files = upload_file_total,
|
||||
"Writing local metadata files"
|
||||
);
|
||||
|
||||
futures::future::try_join_all(upload_files.iter().map(|entry| {
|
||||
let path = entry.key().clone();
|
||||
let file = entry.value().file.clone();
|
||||
let written_files = written_files.clone();
|
||||
|
||||
async move {
|
||||
write_file_to_local_output(&path, file).await?;
|
||||
let written = written_files.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
|
||||
if written.is_multiple_of(100) || written == upload_file_total {
|
||||
tracing::info!(
|
||||
written_files = written,
|
||||
remaining_files =
|
||||
upload_file_total.saturating_sub(written),
|
||||
total_files = upload_file_total,
|
||||
"Wrote local metadata files"
|
||||
);
|
||||
}
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let written_mirror_files = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
tracing::info!(
|
||||
total_files = mirror_file_total,
|
||||
"Writing local mirror files"
|
||||
);
|
||||
|
||||
futures::future::try_join_all(mirror_artifacts.iter().map(|entry| {
|
||||
let path = format!("maven/{}", entry.key());
|
||||
let mirrors = entry
|
||||
.value()
|
||||
.mirrors
|
||||
.iter()
|
||||
@@ -99,12 +145,117 @@ async fn main() -> Result<()> {
|
||||
format!("{}{}", mirror.path, entry.key())
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
entry.value().sha1.clone(),
|
||||
&semaphore,
|
||||
)
|
||||
}))
|
||||
.await?;
|
||||
.collect();
|
||||
let sha1 = entry.value().sha1.clone();
|
||||
let written_mirror_files = written_mirror_files.clone();
|
||||
let semaphore = semaphore.clone();
|
||||
|
||||
async move {
|
||||
write_url_to_local_output_mirrors(
|
||||
path, mirrors, sha1, &semaphore,
|
||||
)
|
||||
.await?;
|
||||
let written =
|
||||
written_mirror_files.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
|
||||
if written.is_multiple_of(100) || written == mirror_file_total {
|
||||
tracing::info!(
|
||||
written_files = written,
|
||||
remaining_files =
|
||||
mirror_file_total.saturating_sub(written),
|
||||
total_files = mirror_file_total,
|
||||
"Wrote local mirror files"
|
||||
);
|
||||
}
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}))
|
||||
.await?;
|
||||
} else {
|
||||
let uploaded_files = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
tracing::info!(
|
||||
total_files = upload_file_total,
|
||||
"Uploading metadata files"
|
||||
);
|
||||
|
||||
futures::future::try_join_all(upload_files.iter().map(|entry| {
|
||||
let path = entry.key().clone();
|
||||
let file = entry.value().file.clone();
|
||||
let content_type = entry.value().content_type.clone();
|
||||
let uploaded_files = uploaded_files.clone();
|
||||
let semaphore = semaphore.clone();
|
||||
|
||||
async move {
|
||||
upload_file_to_bucket(path, file, content_type, &semaphore)
|
||||
.await?;
|
||||
let uploaded =
|
||||
uploaded_files.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
|
||||
if uploaded.is_multiple_of(100) || uploaded == upload_file_total
|
||||
{
|
||||
tracing::info!(
|
||||
uploaded_files = uploaded,
|
||||
remaining_files =
|
||||
upload_file_total.saturating_sub(uploaded),
|
||||
total_files = upload_file_total,
|
||||
"Uploaded metadata files"
|
||||
);
|
||||
}
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let uploaded_mirror_files = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
tracing::info!(
|
||||
total_files = mirror_file_total,
|
||||
"Uploading mirror files"
|
||||
);
|
||||
|
||||
futures::future::try_join_all(mirror_artifacts.iter().map(|entry| {
|
||||
let path = format!("maven/{}", entry.key());
|
||||
let mirrors = entry
|
||||
.value()
|
||||
.mirrors
|
||||
.iter()
|
||||
.map(|mirror| {
|
||||
if mirror.entire_url {
|
||||
mirror.path.clone()
|
||||
} else {
|
||||
format!("{}{}", mirror.path, entry.key())
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let sha1 = entry.value().sha1.clone();
|
||||
let uploaded_mirror_files = uploaded_mirror_files.clone();
|
||||
let semaphore = semaphore.clone();
|
||||
|
||||
async move {
|
||||
upload_url_to_bucket_mirrors(path, mirrors, sha1, &semaphore)
|
||||
.await?;
|
||||
let uploaded =
|
||||
uploaded_mirror_files.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
|
||||
if uploaded.is_multiple_of(100) || uploaded == mirror_file_total
|
||||
{
|
||||
tracing::info!(
|
||||
uploaded_files = uploaded,
|
||||
remaining_files =
|
||||
mirror_file_total.saturating_sub(uploaded),
|
||||
total_files = mirror_file_total,
|
||||
"Uploaded mirror files"
|
||||
);
|
||||
}
|
||||
|
||||
Ok::<_, Error>(())
|
||||
}
|
||||
}))
|
||||
.await?;
|
||||
}
|
||||
|
||||
if dotenvy::var("CLOUDFLARE_INTEGRATION")
|
||||
.ok()
|
||||
@@ -151,6 +302,20 @@ async fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn should_fetch(only_loader: Option<&str>, loader: &str) -> bool {
|
||||
let Some(only_loader) = only_loader else {
|
||||
return true;
|
||||
};
|
||||
|
||||
only_loader.split(',').any(|entry| {
|
||||
let entry = entry.trim();
|
||||
|
||||
entry.eq_ignore_ascii_case("all")
|
||||
|| entry.eq_ignore_ascii_case(loader)
|
||||
|| (loader == "neo" && entry.eq_ignore_ascii_case("neoforge"))
|
||||
})
|
||||
}
|
||||
|
||||
pub struct UploadFile {
|
||||
file: bytes::Bytes,
|
||||
content_type: Option<String>,
|
||||
@@ -248,11 +413,13 @@ fn check_env_vars() -> bool {
|
||||
|
||||
failed |= check_var::<String>("BASE_URL");
|
||||
|
||||
failed |= check_var::<String>("S3_ACCESS_TOKEN");
|
||||
failed |= check_var::<String>("S3_SECRET");
|
||||
failed |= check_var::<String>("S3_URL");
|
||||
failed |= check_var::<String>("S3_REGION");
|
||||
failed |= check_var::<String>("S3_BUCKET_NAME");
|
||||
if dotenvy::var("LOCAL_OUTPUT_DIR").is_err() {
|
||||
failed |= check_var::<String>("S3_ACCESS_TOKEN");
|
||||
failed |= check_var::<String>("S3_SECRET");
|
||||
failed |= check_var::<String>("S3_URL");
|
||||
failed |= check_var::<String>("S3_REGION");
|
||||
failed |= check_var::<String>("S3_BUCKET_NAME");
|
||||
}
|
||||
|
||||
if dotenvy::var("CLOUDFLARE_INTEGRATION")
|
||||
.ok()
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
//! Determines how version info is generated for pairs of game and loader
|
||||
//! versions.
|
||||
//!
|
||||
//! When a user installs a version of the game, they install two things: the
|
||||
//! game (of some specific version), and a loader (of some other specific
|
||||
//! version). Each combination of game and loader version requires a specific
|
||||
//! configuration, like a specific set of libraries that must be downloaded and
|
||||
//! run along with the game. However, some versions of the game or loader may
|
||||
//! change configuration requirements without the other version being affected.
|
||||
//! For example, pre-26.x game versions with Quilt require the Quilt `hashed`
|
||||
//! libraries to also be downloaded. However, 26.x and later don't require the
|
||||
//! `hashed` libraries, and don't even have a download for them. The problem is
|
||||
//! that Quilt loader 0.30.0 can be used for both pre-26.x and 26.x - but our v0
|
||||
//! manifest files can't differentiate the two. The result is that you either
|
||||
//! break compatibility for 0.30.0 game versions pre-26.x, or break 0.30.0
|
||||
//! on 26.x and later.
|
||||
//!
|
||||
//! To fix this, v1 introduces the concept of *version groups*: game versions
|
||||
//! before 26.x are version group v1, and 26.x and later are v2. Then, we
|
||||
//! parameterize our version info on both version group and loader version,
|
||||
//! letting us specify the right configuration based on both game version and
|
||||
//! loader version.
|
||||
//!
|
||||
//! Why not parameterize on game version and loader version directly? Most game
|
||||
//! versions have the same configuration as their surrounding game versions, so
|
||||
//! we'd end up with many duplicate configurations: the number of game versions
|
||||
//! multiplied by the number of loader versions.
|
||||
//!
|
||||
//! This file lets you configure what game versions are grouped together.
|
||||
//!
|
||||
//! Each version group is templated from a specific game version - e.g. game
|
||||
//! version 1.21 is used as the template file for 1.20, 1.19, etc.
|
||||
|
||||
pub const UNIVERSAL_METADATA_GROUP: &str = "universal";
|
||||
pub const QUILT_LEGACY_METADATA_GROUP: &str = "v1";
|
||||
pub const QUILT_MODERN_METADATA_GROUP: &str = "v2";
|
||||
|
||||
pub struct MetadataGroup {
|
||||
pub id: &'static str,
|
||||
/// Minecraft version used to fetch and template this group's loader profiles.
|
||||
pub loader_profile_template_game_version: String,
|
||||
pub game_versions: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn metadata_groups<'a>(
|
||||
mod_loader: &str,
|
||||
game_versions: impl IntoIterator<Item = &'a str>,
|
||||
) -> Vec<MetadataGroup> {
|
||||
// Non-Quilt loaders don't need the concept of version groups, so we just
|
||||
// make one "universal" group, and template it on 1.21.
|
||||
if mod_loader != "quilt" {
|
||||
return vec![MetadataGroup {
|
||||
id: UNIVERSAL_METADATA_GROUP,
|
||||
loader_profile_template_game_version: "1.21".to_string(),
|
||||
game_versions: game_versions
|
||||
.into_iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect(),
|
||||
}];
|
||||
}
|
||||
|
||||
let game_versions = game_versions.into_iter().collect::<Vec<_>>();
|
||||
let legacy_game_versions = game_versions
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|game_version| {
|
||||
metadata_group_id_for_game_version(mod_loader, game_version)
|
||||
== QUILT_LEGACY_METADATA_GROUP
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let modern_game_versions = game_versions
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|game_version| {
|
||||
metadata_group_id_for_game_version(mod_loader, game_version)
|
||||
== QUILT_MODERN_METADATA_GROUP
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut groups = Vec::new();
|
||||
|
||||
if !legacy_game_versions.is_empty() {
|
||||
groups.push(MetadataGroup {
|
||||
id: QUILT_LEGACY_METADATA_GROUP,
|
||||
loader_profile_template_game_version: legacy_game_versions
|
||||
.iter()
|
||||
.find(|x| **x == "1.21")
|
||||
.copied()
|
||||
.unwrap_or(legacy_game_versions[0])
|
||||
.to_string(),
|
||||
game_versions: legacy_game_versions
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect(),
|
||||
});
|
||||
}
|
||||
|
||||
if !modern_game_versions.is_empty() {
|
||||
groups.push(MetadataGroup {
|
||||
id: QUILT_MODERN_METADATA_GROUP,
|
||||
loader_profile_template_game_version: modern_game_versions[0]
|
||||
.to_string(),
|
||||
game_versions: modern_game_versions
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect(),
|
||||
});
|
||||
}
|
||||
|
||||
groups
|
||||
}
|
||||
|
||||
pub fn metadata_group_for_game_version<'a>(
|
||||
groups: &'a [MetadataGroup],
|
||||
mod_loader: &str,
|
||||
game_version: &str,
|
||||
) -> Option<&'a MetadataGroup> {
|
||||
let group_id = metadata_group_id_for_game_version(mod_loader, game_version);
|
||||
|
||||
groups.iter().find(|group| group.id == group_id)
|
||||
}
|
||||
|
||||
fn metadata_group_id_for_game_version(
|
||||
mod_loader: &str,
|
||||
game_version: &str,
|
||||
) -> &'static str {
|
||||
if mod_loader == "quilt" && is_modern_quilt_game_version(game_version) {
|
||||
QUILT_MODERN_METADATA_GROUP
|
||||
} else if mod_loader == "quilt" {
|
||||
QUILT_LEGACY_METADATA_GROUP
|
||||
} else {
|
||||
UNIVERSAL_METADATA_GROUP
|
||||
}
|
||||
}
|
||||
|
||||
// Update these Quilt group boundaries if upstream loader profiles gain another
|
||||
// structural incompatibility between Minecraft versions.
|
||||
fn is_modern_quilt_game_version(game_version: &str) -> bool {
|
||||
let major = game_version
|
||||
.split(['.', 'w'])
|
||||
.next()
|
||||
.and_then(|x| x.parse::<usize>().ok());
|
||||
|
||||
major.is_some_and(|x| x >= 26)
|
||||
}
|
||||
@@ -3,7 +3,11 @@ use bytes::Bytes;
|
||||
use s3::creds::Credentials;
|
||||
use s3::{Bucket, Region};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{
|
||||
Arc, LazyLock,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
static BUCKET: LazyLock<Bucket> = LazyLock::new(|| {
|
||||
@@ -55,6 +59,8 @@ pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
static DOWNLOADED_FILE_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
#[tracing::instrument(skip(bytes, semaphore))]
|
||||
pub async fn upload_file_to_bucket(
|
||||
path: String,
|
||||
@@ -135,6 +141,74 @@ pub async fn upload_url_to_bucket(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write_file_to_local_output(
|
||||
path: &str,
|
||||
bytes: Bytes,
|
||||
) -> Result<(), Error> {
|
||||
let output_path = local_output_path(path)?;
|
||||
|
||||
if let Some(parent) = output_path.parent() {
|
||||
tokio::fs::create_dir_all(parent).await?;
|
||||
}
|
||||
|
||||
tokio::fs::write(output_path, bytes).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write_url_to_local_output_mirrors(
|
||||
output_path: String,
|
||||
mirrors: Vec<String>,
|
||||
sha1: Option<String>,
|
||||
semaphore: &Arc<Semaphore>,
|
||||
) -> Result<(), Error> {
|
||||
if mirrors.is_empty() {
|
||||
return Err(ErrorKind::InvalidInput(
|
||||
"No mirrors provided!".to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
for (index, mirror) in mirrors.iter().enumerate() {
|
||||
let result = write_url_to_local_output(
|
||||
output_path.clone(),
|
||||
mirror.clone(),
|
||||
sha1.clone(),
|
||||
semaphore,
|
||||
)
|
||||
.await;
|
||||
|
||||
if result.is_ok() || (result.is_err() && index == (mirrors.len() - 1)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
async fn write_url_to_local_output(
|
||||
path: String,
|
||||
url: String,
|
||||
sha1: Option<String>,
|
||||
semaphore: &Arc<Semaphore>,
|
||||
) -> Result<(), Error> {
|
||||
let data = download_file(&url, sha1.as_deref(), semaphore).await?;
|
||||
|
||||
write_file_to_local_output(&path, data).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn local_output_path(path: &str) -> Result<PathBuf, Error> {
|
||||
let output_dir = dotenvy::var("LOCAL_OUTPUT_DIR").map_err(|_| {
|
||||
ErrorKind::InvalidInput(
|
||||
"LOCAL_OUTPUT_DIR is required for local output".to_string(),
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(PathBuf::from(output_dir).join(path))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(bytes))]
|
||||
pub async fn sha1_async(bytes: Bytes) -> Result<String, Error> {
|
||||
let hash = tokio::task::spawn_blocking(move || {
|
||||
@@ -182,6 +256,16 @@ pub async fn download_file(
|
||||
}
|
||||
}
|
||||
|
||||
let downloaded = DOWNLOADED_FILE_COUNT
|
||||
.fetch_add(1, Ordering::Relaxed)
|
||||
+ 1;
|
||||
if downloaded.is_multiple_of(100) {
|
||||
tracing::info!(
|
||||
downloaded_files = downloaded,
|
||||
"Downloaded metadata files"
|
||||
);
|
||||
}
|
||||
|
||||
return Ok(bytes);
|
||||
} else if attempt <= RETRIES {
|
||||
continue;
|
||||
|
||||
@@ -692,6 +692,12 @@ components:
|
||||
type: string
|
||||
description: The ID of the project
|
||||
example: AABBCCDD
|
||||
all_project_types:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: All project types across every version of the project, unlike `project_type` which only reflects a version-specific type
|
||||
example: [mod, plugin, datapack]
|
||||
author:
|
||||
type: string
|
||||
description: The username of the project's author
|
||||
@@ -748,6 +754,7 @@ components:
|
||||
- client_side
|
||||
- server_side
|
||||
- project_id
|
||||
- all_project_types
|
||||
- author
|
||||
- versions
|
||||
- follows
|
||||
@@ -1948,6 +1955,7 @@ paths:
|
||||
|
||||
These are the most commonly used facet types:
|
||||
- `project_type`
|
||||
- `all_project_types` (matches against every project type across all of the project's versions, not just the primary/version-specific type)
|
||||
- `categories` (loaders are lumped in with categories in search)
|
||||
- `versions`
|
||||
- `client_side`
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
<div class="shadow-card rounded-2xl border border-solid border-surface-4 bg-surface-3 p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<NuxtLink
|
||||
:to="`/project/${queueEntry.project.slug}`"
|
||||
target="_blank"
|
||||
tabindex="-1"
|
||||
class="flex"
|
||||
>
|
||||
<NuxtLink :to="`/project/${projectRouteParam}`" target="_blank" tabindex="-1" class="flex">
|
||||
<Avatar
|
||||
:src="queueEntry.project.icon_url"
|
||||
size="4rem"
|
||||
@@ -17,7 +12,7 @@
|
||||
<div class="flex flex-col gap-1.5">
|
||||
<div class="flex items-center gap-2">
|
||||
<NuxtLink
|
||||
:to="`/project/${queueEntry.project.slug}`"
|
||||
:to="`/project/${projectRouteParam}`"
|
||||
target="_blank"
|
||||
class="text-lg font-semibold text-contrast hover:underline"
|
||||
>
|
||||
@@ -177,7 +172,7 @@ function getDaysQueued(date: Date): number {
|
||||
const queuedDate = computed(() => {
|
||||
return dayjs(
|
||||
props.queueEntry.project.queued ||
|
||||
props.queueEntry.project.created ||
|
||||
props.queueEntry.project.published ||
|
||||
props.queueEntry.project.updated,
|
||||
)
|
||||
})
|
||||
@@ -186,10 +181,14 @@ const daysInQueue = computed(() => {
|
||||
return getDaysQueued(queuedDate.value.toDate())
|
||||
})
|
||||
|
||||
const projectRouteParam = computed(
|
||||
() => props.queueEntry.project.slug || props.queueEntry.project.id,
|
||||
)
|
||||
|
||||
const formattedDate = computed(() => {
|
||||
const date =
|
||||
props.queueEntry.project.queued ||
|
||||
props.queueEntry.project.created ||
|
||||
props.queueEntry.project.published ||
|
||||
props.queueEntry.project.updated
|
||||
if (!date) return 'Unknown'
|
||||
|
||||
@@ -202,7 +201,7 @@ const formattedDate = computed(() => {
|
||||
|
||||
function copyLink() {
|
||||
const base = window.location.origin
|
||||
const projectUrl = `${base}/project/${props.queueEntry.project.slug}`
|
||||
const projectUrl = `${base}/project/${projectRouteParam.value}`
|
||||
navigator.clipboard.writeText(projectUrl).then(() => {
|
||||
addNotification({
|
||||
type: 'success',
|
||||
|
||||
@@ -10,9 +10,8 @@ import {
|
||||
CodeIcon,
|
||||
CopyIcon,
|
||||
DownloadIcon,
|
||||
EllipsisVerticalIcon,
|
||||
ExternalIcon,
|
||||
EyeOffIcon,
|
||||
LinkIcon,
|
||||
LoaderCircleIcon,
|
||||
ScaleIcon,
|
||||
ShieldCheckIcon,
|
||||
@@ -113,51 +112,6 @@ const isProjectApproved = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
const quickActions = computed<OverflowMenuOption[]>(() => {
|
||||
const actions: OverflowMenuOption[] = []
|
||||
|
||||
const sourceUrl = props.item.project.link_urls?.['source']?.url
|
||||
if (sourceUrl) {
|
||||
actions.push({
|
||||
id: 'view-source',
|
||||
action: () => {
|
||||
window.open(sourceUrl, '_blank', 'noopener,noreferrer')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
actions.push(
|
||||
{
|
||||
id: 'copy-link',
|
||||
action: () => {
|
||||
const base = window.location.origin
|
||||
const reportUrl = `${base}/moderation/technical-review/${props.item.project.id}`
|
||||
navigator.clipboard.writeText(reportUrl).then(() => {
|
||||
addNotification({
|
||||
type: 'success',
|
||||
title: 'Technical Review link copied',
|
||||
text: 'The link to this review has been copied to your clipboard.',
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'copy-id',
|
||||
action: () => {
|
||||
navigator.clipboard.writeText(props.item.project.id).then(() => {
|
||||
addNotification({
|
||||
type: 'success',
|
||||
title: 'Project ID copied',
|
||||
text: 'The ID of this project has been copied to your clipboard.',
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
return actions
|
||||
})
|
||||
|
||||
const isLoadingStatusAction = ref(false)
|
||||
const projectStatusActions = computed<OverflowMenuOption[]>(() => [
|
||||
{
|
||||
@@ -1020,6 +974,16 @@ async function handleSubmitReview(verdict: 'safe' | 'unsafe') {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copyId() {
|
||||
navigator.clipboard.writeText(props.item.project.id).then(() => {
|
||||
addNotification({
|
||||
type: 'success',
|
||||
title: 'Project ID copied',
|
||||
text: 'The ID of this project has been copied to your clipboard.',
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -1105,25 +1069,31 @@ async function handleSubmitReview(verdict: 'safe' | 'unsafe') {
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-base text-secondary">{{ formattedDate }}</span>
|
||||
<ButtonStyled circular>
|
||||
<OverflowMenu :options="quickActions" class="!shadow-none">
|
||||
<template #default>
|
||||
<EllipsisVerticalIcon class="size-4" />
|
||||
</template>
|
||||
<template #copy-id>
|
||||
<ClipboardCopyIcon />
|
||||
<span class="hidden sm:inline">Copy ID</span>
|
||||
</template>
|
||||
<template #copy-link>
|
||||
<LinkIcon />
|
||||
<span class="hidden sm:inline">Copy link</span>
|
||||
</template>
|
||||
<template #view-source>
|
||||
<div class="flex items-center gap-2">
|
||||
<ButtonStyled v-if="props.item.project.link_urls?.['source']?.url" circular>
|
||||
<a
|
||||
v-tooltip="'Open sources in new tab'"
|
||||
:href="props.item.project.link_urls?.['source']?.url"
|
||||
target="_blank"
|
||||
>
|
||||
<CodeIcon />
|
||||
<span class="hidden sm:inline">View source</span>
|
||||
</template>
|
||||
</OverflowMenu>
|
||||
</ButtonStyled>
|
||||
</a>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled circular>
|
||||
<button v-tooltip="'Copy ID'" @click="copyId">
|
||||
<ClipboardCopyIcon />
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled circular>
|
||||
<a
|
||||
v-tooltip="'Open in new tab'"
|
||||
:href="`/moderation/technical-review/${props.item.project.id}`"
|
||||
target="_blank"
|
||||
>
|
||||
<ExternalIcon />
|
||||
</a>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
<script setup lang="ts">
|
||||
import type { Labrinth } from '@modrinth/api-client'
|
||||
import { FolderSearchIcon, StarIcon } from '@modrinth/assets'
|
||||
import {
|
||||
ButtonStyled,
|
||||
defineMessages,
|
||||
injectModrinthClient,
|
||||
NewModal,
|
||||
Table,
|
||||
type TableColumn,
|
||||
useVIntl,
|
||||
} from '@modrinth/ui'
|
||||
import { computed, ref, useTemplateRef } from 'vue'
|
||||
|
||||
const messages = defineMessages({
|
||||
title: {
|
||||
id: 'modpack-scan-modal.title',
|
||||
defaultMessage: 'Modpack Scan ({scanned}/{total} Files)',
|
||||
},
|
||||
scanAllFiles: {
|
||||
id: 'modpack-scan-modal.scan-all-files',
|
||||
defaultMessage: 'Scan All Files',
|
||||
},
|
||||
packFileName: {
|
||||
id: 'modpack-scan-modal.pack-file-name',
|
||||
defaultMessage: 'Pack File Name',
|
||||
},
|
||||
newFiles: {
|
||||
id: 'modpack-scan-modal.new-files',
|
||||
defaultMessage: 'New Files',
|
||||
},
|
||||
newGroups: {
|
||||
id: 'modpack-scan-modal.new-groups',
|
||||
defaultMessage: 'New Groups',
|
||||
},
|
||||
loadingVersions: {
|
||||
id: 'modpack-scan-modal.loading-versions',
|
||||
defaultMessage: 'Loading versions...',
|
||||
},
|
||||
noFiles: {
|
||||
id: 'modpack-scan-modal.no-files',
|
||||
defaultMessage: 'No files found.',
|
||||
},
|
||||
notScanned: {
|
||||
id: 'modpack-scan-modal.not-scanned',
|
||||
defaultMessage: 'Not scanned',
|
||||
},
|
||||
scanning: {
|
||||
id: 'modpack-scan-modal.scanning',
|
||||
defaultMessage: 'Scanning...',
|
||||
},
|
||||
failed: {
|
||||
id: 'modpack-scan-modal.failed',
|
||||
defaultMessage: 'Failed',
|
||||
},
|
||||
overrideFiles: {
|
||||
id: 'modpack-scan-modal.override-files',
|
||||
defaultMessage: 'Override Files ({count})',
|
||||
},
|
||||
loadVersionsError: {
|
||||
id: 'modpack-scan-modal.load-versions-error',
|
||||
defaultMessage: 'Failed to load versions: {error}',
|
||||
},
|
||||
scanError: {
|
||||
id: 'modpack-scan-modal.scan-error',
|
||||
defaultMessage: 'Some files failed to scan: {error}',
|
||||
},
|
||||
})
|
||||
|
||||
type ScanTableColumn = 'filename' | 'newFiles' | 'newGroups'
|
||||
|
||||
type ScanRow = {
|
||||
id: string
|
||||
filename: string
|
||||
primary: boolean
|
||||
scan?: Labrinth.Attribution.Internal.FileScanResponse
|
||||
isScanning: boolean
|
||||
error?: string
|
||||
newFiles?: number
|
||||
newGroups?: number
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
project_id: string
|
||||
}>()
|
||||
|
||||
const client = injectModrinthClient()
|
||||
const modalRef = useTemplateRef<InstanceType<typeof NewModal>>('modalRef')
|
||||
const { formatMessage } = useVIntl()
|
||||
|
||||
const rows = ref<ScanRow[]>([])
|
||||
const isLoadingVersions = ref(false)
|
||||
const isScanning = ref(false)
|
||||
const versionLoadError = ref<string | null>(null)
|
||||
const scanError = ref<string | null>(null)
|
||||
const requestId = ref(0)
|
||||
const scanRequestId = ref(0)
|
||||
|
||||
const columns = computed<TableColumn<ScanTableColumn>[]>(() => [
|
||||
{ key: 'filename', label: formatMessage(messages.packFileName), width: '60%' },
|
||||
{ key: 'newFiles', label: formatMessage(messages.newFiles), align: 'center', width: '20%' },
|
||||
{ key: 'newGroups', label: formatMessage(messages.newGroups), align: 'center', width: '20%' },
|
||||
])
|
||||
|
||||
const scannedCount = computed(() => rows.value.filter((row) => row.scan || row.error).length)
|
||||
const isBusy = computed(() => isLoadingVersions.value || isScanning.value)
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return error.message
|
||||
}
|
||||
|
||||
if (typeof error === 'object' && error !== null && 'data' in error) {
|
||||
const data = (error as { data?: { description?: string } }).data
|
||||
if (data?.description) {
|
||||
return data.description
|
||||
}
|
||||
}
|
||||
|
||||
return String(error)
|
||||
}
|
||||
|
||||
async function fetchAllVersions() {
|
||||
const currentRequestId = ++requestId.value
|
||||
isLoadingVersions.value = true
|
||||
versionLoadError.value = null
|
||||
scanError.value = null
|
||||
rows.value = []
|
||||
|
||||
try {
|
||||
const versions = await client.labrinth.versions_v2.getProjectVersions(props.project_id)
|
||||
if (currentRequestId !== requestId.value) {
|
||||
return
|
||||
}
|
||||
|
||||
rows.value = versions
|
||||
.flatMap((version) => version.files)
|
||||
.filter((file): file is Labrinth.Versions.v2.VersionFile & { id: string } => Boolean(file.id))
|
||||
.map((file) => ({
|
||||
id: file.id,
|
||||
filename: file.filename,
|
||||
primary: file.primary,
|
||||
isScanning: false,
|
||||
newFiles: undefined,
|
||||
newGroups: undefined,
|
||||
}))
|
||||
} catch (error) {
|
||||
if (currentRequestId === requestId.value) {
|
||||
versionLoadError.value = formatMessage(messages.loadVersionsError, {
|
||||
error: getErrorMessage(error),
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
if (currentRequestId === requestId.value) {
|
||||
isLoadingVersions.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchAllScans() {
|
||||
if (isBusy.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentScanRequestId = ++scanRequestId.value
|
||||
isScanning.value = true
|
||||
scanError.value = null
|
||||
rows.value = rows.value.map((row) => ({
|
||||
...row,
|
||||
scan: undefined,
|
||||
isScanning: false,
|
||||
error: undefined,
|
||||
newFiles: undefined,
|
||||
newGroups: undefined,
|
||||
}))
|
||||
|
||||
try {
|
||||
for (const row of rows.value) {
|
||||
if (currentScanRequestId !== scanRequestId.value) {
|
||||
return
|
||||
}
|
||||
|
||||
row.isScanning = true
|
||||
try {
|
||||
const scan = await client.labrinth.attribution_internal.scanFile(row.id)
|
||||
if (currentScanRequestId !== scanRequestId.value) {
|
||||
return
|
||||
}
|
||||
|
||||
row.scan = scan
|
||||
row.newFiles = scan.new_attribution_files
|
||||
row.newGroups = scan.new_attribution_groups
|
||||
} catch (error) {
|
||||
if (currentScanRequestId !== scanRequestId.value) {
|
||||
return
|
||||
}
|
||||
|
||||
row.error = getErrorMessage(error)
|
||||
scanError.value = formatMessage(messages.scanError, { error: row.error })
|
||||
} finally {
|
||||
row.isScanning = false
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (currentScanRequestId === scanRequestId.value) {
|
||||
isScanning.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function show() {
|
||||
scanRequestId.value++
|
||||
isScanning.value = false
|
||||
rows.value = []
|
||||
void fetchAllVersions()
|
||||
modalRef.value?.show()
|
||||
}
|
||||
|
||||
function hide() {
|
||||
modalRef.value?.hide()
|
||||
}
|
||||
defineExpose({ show, hide })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NewModal
|
||||
ref="modalRef"
|
||||
width="60vw"
|
||||
:close-on-click-outside="false"
|
||||
:close-on-esc="false"
|
||||
:disable-close="isBusy"
|
||||
>
|
||||
<template #title>
|
||||
<div class="flex w-full items-center justify-between gap-2">
|
||||
<span class="text-2xl font-semibold text-contrast">
|
||||
{{
|
||||
formatMessage(messages.title, {
|
||||
scanned: scannedCount,
|
||||
total: rows.length,
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
<div>
|
||||
<ButtonStyled circular>
|
||||
<button
|
||||
v-tooltip="formatMessage(messages.scanAllFiles)"
|
||||
:disabled="isBusy || rows.length === 0"
|
||||
@click="fetchAllScans"
|
||||
>
|
||||
<FolderSearchIcon aria-hidden="true" />
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="w-full">
|
||||
<div
|
||||
v-if="versionLoadError || scanError"
|
||||
class="mb-3 rounded-xl bg-highlight-red p-3 text-red"
|
||||
>
|
||||
{{ versionLoadError || scanError }}
|
||||
</div>
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
:row-below-visible="
|
||||
(row) => Boolean(row.scan?.scanned_file_names && row.scan.scanned_file_names.length > 0)
|
||||
"
|
||||
table-min-width="42rem"
|
||||
>
|
||||
<template #cell-filename="{ row }">
|
||||
<div class="flex min-w-0 items-center gap-1 text-contrast">
|
||||
<StarIcon v-if="row.primary" class="size-4 shrink-0" aria-hidden="true" />
|
||||
<span class="min-w-0 truncate">{{ row.filename }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template #cell-newFiles="{ row }">
|
||||
<span v-if="row.isScanning">{{ formatMessage(messages.scanning) }}</span>
|
||||
<span v-else-if="row.error" v-tooltip="row.error" class="text-red">
|
||||
{{ formatMessage(messages.failed) }}
|
||||
</span>
|
||||
<span v-else-if="row.scan">{{ row.scan.new_attribution_files }}</span>
|
||||
<span v-else>{{ formatMessage(messages.notScanned) }}</span>
|
||||
</template>
|
||||
<template #cell-newGroups="{ row }">
|
||||
<span v-if="row.isScanning">{{ formatMessage(messages.scanning) }}</span>
|
||||
<span v-else-if="row.error" v-tooltip="row.error" class="text-red">
|
||||
{{ formatMessage(messages.failed) }}
|
||||
</span>
|
||||
<span v-else-if="row.scan">{{ row.scan.new_attribution_groups }}</span>
|
||||
<span v-else>{{ formatMessage(messages.notScanned) }}</span>
|
||||
</template>
|
||||
<template #row-below="{ row }">
|
||||
<div class="border-0 border-t border-solid border-surface-4 px-4 py-3">
|
||||
<details>
|
||||
<summary>
|
||||
{{
|
||||
formatMessage(messages.overrideFiles, {
|
||||
count: row.scan?.scanned_file_names.length ?? 0,
|
||||
})
|
||||
}}
|
||||
</summary>
|
||||
<div class="flex flex-wrap gap-1 pt-2">
|
||||
<span
|
||||
v-for="name of row.scan?.scanned_file_names ?? []"
|
||||
:key="name"
|
||||
v-tooltip="name"
|
||||
class="flex items-center gap-1 text-wrap rounded-full bg-button-bg px-2 py-0.5 text-xs font-medium text-contrast"
|
||||
>
|
||||
{{ name }}
|
||||
</span>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</template>
|
||||
<template #empty-state>
|
||||
<div class="flex h-64 items-center justify-center text-secondary">
|
||||
{{ formatMessage(isLoadingVersions ? messages.loadingVersions : messages.noFiles) }}
|
||||
</div>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
</NewModal>
|
||||
</template>
|
||||
@@ -1949,7 +1949,10 @@ function generateModpackMessage(allFiles: {
|
||||
|
||||
const hasNextProject = ref(false)
|
||||
async function refreshModerationCaches(threadId?: string) {
|
||||
const refreshes: Promise<unknown>[] = [invalidate(), refreshNuxtData('moderation-projects')]
|
||||
const refreshes: Promise<unknown>[] = [
|
||||
invalidate(),
|
||||
queryClient.invalidateQueries({ queryKey: ['moderation-projects'] }),
|
||||
]
|
||||
|
||||
if (threadId) {
|
||||
refreshes.push(queryClient.invalidateQueries({ queryKey: ['thread', threadId] }))
|
||||
|
||||
@@ -58,6 +58,7 @@ export const DEFAULT_FEATURE_FLAGS = validateValues({
|
||||
showHostingAccessInstanceAuditLog: false,
|
||||
versionDevInfoCollapsed: true,
|
||||
alwaysShowVersionDevInfo: false,
|
||||
advancedFiltersCollapsed: true,
|
||||
} as const)
|
||||
|
||||
export type FeatureFlag = keyof typeof DEFAULT_FEATURE_FLAGS
|
||||
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
readStoredServerInstallQueue,
|
||||
removePendingServerContentInstall,
|
||||
requestInstall,
|
||||
stripServerRuntimeInstallFilters,
|
||||
stripServerRuntimeInstallOverrides,
|
||||
useVIntl,
|
||||
writePendingServerContentInstallBaseline,
|
||||
writeStoredServerInstallQueue,
|
||||
@@ -604,11 +606,15 @@ export function useServerInstallContent({
|
||||
project,
|
||||
contentType,
|
||||
mode: isModpack ? 'immediate' : 'queue',
|
||||
selectedFilters: isModpack ? [] : browseSearchState.currentFilters.value,
|
||||
selectedFilters: isModpack
|
||||
? []
|
||||
: stripServerRuntimeInstallFilters(browseSearchState.currentFilters.value),
|
||||
providedFilters: isModpack ? [] : serverFilters.value,
|
||||
overriddenProvidedFilterTypes: isModpack
|
||||
? []
|
||||
: browseSearchState.overriddenProvidedFilterTypes.value,
|
||||
: stripServerRuntimeInstallOverrides(
|
||||
browseSearchState.overriddenProvidedFilterTypes.value,
|
||||
),
|
||||
targetPreferences: getServerInstallTargetPreferences(contentType),
|
||||
getProjectVersions: getInstallProjectVersions,
|
||||
queue: serverInstallQueue,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Labrinth } from '@modrinth/api-client'
|
||||
import type { ExtendedReport, OwnershipTarget } from '@modrinth/moderation'
|
||||
import type {
|
||||
Organization,
|
||||
@@ -197,14 +198,10 @@ export interface ModerationOwnershipOrganization {
|
||||
|
||||
export type ModerationOwnership = ModerationOwnershipUser | ModerationOwnershipOrganization
|
||||
|
||||
export interface ProjectWithOwnership {
|
||||
ownership: ModerationOwnership
|
||||
external_dependencies_count: number
|
||||
[key: string]: any
|
||||
}
|
||||
export type ProjectWithOwnership = Labrinth.Moderation.Internal.QueueProject
|
||||
|
||||
export interface ModerationProject {
|
||||
project: any
|
||||
project: Omit<ProjectWithOwnership, 'ownership' | 'external_dependencies_count'>
|
||||
ownership: ModerationOwnership | null
|
||||
external_dependencies_count: number
|
||||
}
|
||||
|
||||
@@ -2672,6 +2672,9 @@
|
||||
"layout.nav.upgrade-to-modrinth-plus": {
|
||||
"message": "Upgrade to Modrinth+"
|
||||
},
|
||||
"moderation.exclude-technical-review": {
|
||||
"message": "Exclude TR"
|
||||
},
|
||||
"moderation.moderate": {
|
||||
"message": "Moderate"
|
||||
},
|
||||
@@ -2687,6 +2690,45 @@
|
||||
"moderation.page.technicalReview": {
|
||||
"message": "Tech review"
|
||||
},
|
||||
"modpack-scan-modal.failed": {
|
||||
"message": "Failed"
|
||||
},
|
||||
"modpack-scan-modal.load-versions-error": {
|
||||
"message": "Failed to load versions: {error}"
|
||||
},
|
||||
"modpack-scan-modal.loading-versions": {
|
||||
"message": "Loading versions..."
|
||||
},
|
||||
"modpack-scan-modal.new-files": {
|
||||
"message": "New Files"
|
||||
},
|
||||
"modpack-scan-modal.new-groups": {
|
||||
"message": "New Groups"
|
||||
},
|
||||
"modpack-scan-modal.no-files": {
|
||||
"message": "No files found."
|
||||
},
|
||||
"modpack-scan-modal.not-scanned": {
|
||||
"message": "Not scanned"
|
||||
},
|
||||
"modpack-scan-modal.override-files": {
|
||||
"message": "Override Files ({count})"
|
||||
},
|
||||
"modpack-scan-modal.pack-file-name": {
|
||||
"message": "Pack File Name"
|
||||
},
|
||||
"modpack-scan-modal.scan-all-files": {
|
||||
"message": "Scan All Files"
|
||||
},
|
||||
"modpack-scan-modal.scan-error": {
|
||||
"message": "Some files failed to scan: {error}"
|
||||
},
|
||||
"modpack-scan-modal.scanning": {
|
||||
"message": "Scanning..."
|
||||
},
|
||||
"modpack-scan-modal.title": {
|
||||
"message": "Modpack Scan ({scanned}/{total} Files)"
|
||||
},
|
||||
"muralpay.account-type.checking": {
|
||||
"message": "Checking"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useGeneratedState } from '~/composables/generated'
|
||||
import { projectQueryOptions } from '~/composables/queries/project'
|
||||
import { useAppQueryClient } from '~/composables/query-client'
|
||||
import { createModrinthClient } from '~/helpers/api.ts'
|
||||
import { getProjectTypeForUrlShorthand } from '~/helpers/projects.js'
|
||||
import { useServerModrinthClient } from '~/server/utils/api-client'
|
||||
|
||||
@@ -18,9 +19,6 @@ const PROJECT_TYPES = [
|
||||
]
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
// Only run this middleware on the server - it relies on server-only runtime config
|
||||
if (import.meta.client) return
|
||||
|
||||
const routeProjectParam = to.params.project
|
||||
const projectId = Array.isArray(routeProjectParam) ? routeProjectParam[0] : routeProjectParam
|
||||
const routeType = Array.isArray(to.params.type) ? to.params.type[0] : to.params.type
|
||||
@@ -31,10 +29,11 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
}
|
||||
|
||||
const queryClient = useAppQueryClient()
|
||||
const authToken = useCookie('auth-token')
|
||||
const client = useServerModrinthClient({ authToken: authToken.value || undefined })
|
||||
const client = await getProjectMiddlewareClient()
|
||||
const tags = useGeneratedState()
|
||||
|
||||
if (import.meta.client) startLoading()
|
||||
|
||||
try {
|
||||
// Fetch v2 and v3 in parallel — cache both for the page's useQuery calls
|
||||
const [project, projectV3] = await Promise.all([
|
||||
@@ -48,9 +47,11 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
// Cache by slug if we looked up by ID (or vice versa)
|
||||
if (projectId !== project.slug) {
|
||||
queryClient.setQueryData(['project', 'v2', project.slug], project)
|
||||
queryClient.setQueryData(['project', 'v3', project.slug], projectV3)
|
||||
}
|
||||
if (projectId !== project.id) {
|
||||
queryClient.setQueryData(['project', 'v2', project.id], project)
|
||||
queryClient.setQueryData(['project', 'v3', project.id], projectV3)
|
||||
}
|
||||
|
||||
const projectType = projectV3.minecraft_server != null ? 'server' : project.project_type
|
||||
@@ -81,5 +82,23 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
}
|
||||
} catch {
|
||||
// Let the page handle 404s and other errors
|
||||
} finally {
|
||||
if (import.meta.client) stopLoading()
|
||||
}
|
||||
})
|
||||
|
||||
async function getProjectMiddlewareClient() {
|
||||
if (import.meta.server) {
|
||||
const authToken = useCookie('auth-token')
|
||||
return useServerModrinthClient({ authToken: authToken.value || undefined })
|
||||
}
|
||||
|
||||
const auth = await useAuth()
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
return createModrinthClient(auth, {
|
||||
apiBaseUrl: config.public.apiBaseUrl.replace('/v2/', '/'),
|
||||
archonBaseUrl: config.public.pyroBaseUrl.replace('/v2/', '/'),
|
||||
rateLimitKey: config.rateLimitKey,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@
|
||||
@download="triggerDownloadAnimation"
|
||||
/>
|
||||
<CollectionCreateModal ref="modal_collection" :project-ids="[project.id]" />
|
||||
<ModpackScanModal ref="scanModal" :project_id="project.id" />
|
||||
|
||||
<div
|
||||
class="new-page sidebar"
|
||||
:class="{
|
||||
@@ -424,13 +426,6 @@
|
||||
tags.staffRoles.includes(auth.user.role) &&
|
||||
!showModerationChecklist,
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
shown:
|
||||
auth.user &&
|
||||
tags.staffRoles.includes(auth.user.role) &&
|
||||
!showModerationChecklist,
|
||||
},
|
||||
{
|
||||
id: 'tech-review',
|
||||
link: `/moderation/technical-review/${project.id}`,
|
||||
@@ -438,6 +433,16 @@
|
||||
hoverOnly: true,
|
||||
shown: auth.user && tags.staffRoles.includes(auth.user.role),
|
||||
},
|
||||
{
|
||||
id: 'moderation-modpack-rescan',
|
||||
action: () => scanModal.show(),
|
||||
color: 'orange',
|
||||
hoverOnly: true,
|
||||
shown:
|
||||
auth.user &&
|
||||
tags.staffRoles.includes(auth.user.role) &&
|
||||
project.actualProjectType === 'modpack',
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
shown: auth.user && tags.staffRoles.includes(auth.user.role),
|
||||
@@ -469,6 +474,9 @@
|
||||
<ScaleIcon aria-hidden="true" /> {{ formatMessage(messages.reviewProject) }}
|
||||
</template>
|
||||
<template #tech-review> <ScanEyeIcon aria-hidden="true" /> Tech review </template>
|
||||
<template #moderation-modpack-rescan>
|
||||
<FolderSearchIcon aria-hidden="true" /> Rescan modpack
|
||||
</template>
|
||||
<template #report>
|
||||
<ReportIcon aria-hidden="true" />
|
||||
{{ formatMessage(commonMessages.reportButton) }}
|
||||
@@ -726,6 +734,7 @@ import {
|
||||
ClipboardCopyIcon,
|
||||
DownloadIcon,
|
||||
ExternalIcon,
|
||||
FolderSearchIcon,
|
||||
HeartIcon,
|
||||
ListIcon,
|
||||
MoreVerticalIcon,
|
||||
@@ -785,6 +794,7 @@ import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.
|
||||
import MessageBanner from '~/components/ui/MessageBanner.vue'
|
||||
import ModerationChecklist from '~/components/ui/moderation/checklist/ModerationChecklist.vue'
|
||||
import ModerationProjectNags from '~/components/ui/moderation/ModerationProjectNags.vue'
|
||||
import ModpackScanModal from '~/components/ui/moderation/ModpackScanModal.vue'
|
||||
import ProjectDownloadModal from '~/components/ui/ProjectDownloadModal/index.vue'
|
||||
import ProjectMemberHeader from '~/components/ui/ProjectMemberHeader.vue'
|
||||
import { getSignInRouteObj } from '~/composables/auth.ts'
|
||||
@@ -852,6 +862,7 @@ const debug = useDebugLogger('DownloadModal')
|
||||
const downloadModal = ref()
|
||||
const openInAppModal = ref()
|
||||
const overTheTopDownloadAnimation = ref()
|
||||
const scanModal = ref()
|
||||
|
||||
const projectV3Loaded = computed(() => !projectV3Pending.value || projectV3.value != null)
|
||||
const isServerProject = computed(() => projectV3.value?.minecraft_server != null)
|
||||
|
||||
@@ -372,6 +372,14 @@ const messages = defineMessages({
|
||||
},
|
||||
})
|
||||
|
||||
const advancedFiltersCollapsed = computed({
|
||||
get: () => flags.value.advancedFiltersCollapsed,
|
||||
set: (value) => {
|
||||
flags.value.advancedFiltersCollapsed = value
|
||||
saveFeatureFlags()
|
||||
},
|
||||
})
|
||||
|
||||
const projectTypeId = computed(() => projectType.value?.id ?? 'mod')
|
||||
|
||||
debug('projectTypeId:', projectTypeId.value)
|
||||
@@ -478,6 +486,7 @@ provideBrowseManager({
|
||||
showServerOnly: showServerOnlyToggle,
|
||||
serverOnlyLabel: computed(() => formatMessage(commonMessages.serverOnlyLabel)),
|
||||
hiddenFilterTypes: computed(() => (showServerOnlyToggle.value ? ['environment'] : [])),
|
||||
advancedFiltersCollapsed,
|
||||
displayMode: resultsDisplayMode,
|
||||
cycleDisplayMode: cycleSearchDisplayMode,
|
||||
maxResultsOptions: currentMaxResultsOptions,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<Combobox
|
||||
v-model="currentFilterType"
|
||||
class="!w-full flex-grow sm:!w-[280px] sm:flex-grow-0 lg:!w-[280px]"
|
||||
trigger-class="!h-10"
|
||||
:options="filterTypes"
|
||||
:placeholder="formatMessage(commonMessages.filterByLabel)"
|
||||
@select="goToPage(1)"
|
||||
@@ -26,7 +27,7 @@
|
||||
<span class="flex flex-row gap-2 align-middle font-semibold">
|
||||
<ListFilterIcon class="size-5 flex-shrink-0 text-secondary" />
|
||||
<span class="truncate text-contrast"
|
||||
>{{ currentFilterType }} ({{ filteredProjects.length }})</span
|
||||
>{{ currentFilterType }} ({{ totalProjects }})</span
|
||||
>
|
||||
</span>
|
||||
</template>
|
||||
@@ -35,6 +36,7 @@
|
||||
<Combobox
|
||||
v-model="currentSortType"
|
||||
class="!w-full flex-grow sm:!w-[240px] sm:flex-grow-0"
|
||||
trigger-class="!h-10"
|
||||
:options="sortTypes"
|
||||
:placeholder="formatMessage(commonMessages.sortByLabel)"
|
||||
@select="goToPage(1)"
|
||||
@@ -54,6 +56,7 @@
|
||||
<Combobox
|
||||
v-model="itemsPerPage"
|
||||
class="!w-full flex-grow sm:!w-[160px] sm:flex-grow-0 lg:!w-[140px]"
|
||||
trigger-class="!h-10"
|
||||
:options="itemsPerPageOptions"
|
||||
placeholder="Items per page"
|
||||
@select="goToPage(1)"
|
||||
@@ -69,7 +72,7 @@
|
||||
<ButtonStyled color="orange">
|
||||
<button
|
||||
class="flex !h-[40px] w-full items-center justify-center gap-2 sm:w-auto"
|
||||
:disabled="paginatedProjects?.length === 0"
|
||||
:disabled="pending || paginatedProjects?.length === 0"
|
||||
@click="moderateAllInFilter()"
|
||||
>
|
||||
<ScaleIcon class="flex-shrink-0" />
|
||||
@@ -80,17 +83,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="totalPages > 1" class="flex items-center justify-between">
|
||||
<div>
|
||||
Showing {{ itemsPerPage * (currentPage - 1) + 1 }}–{{
|
||||
itemsPerPage * (currentPage - 1) + Math.min(itemsPerPage, paginatedProjects.length)
|
||||
}}
|
||||
of {{ filteredProjects.length }}
|
||||
{{
|
||||
currentFilterType === DEFAULT_FILTER_TYPE ? 'projects' : currentFilterType.toLowerCase()
|
||||
}}
|
||||
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<div v-if="totalProjects > 0">
|
||||
Showing {{ pageStart }}–{{ pageEnd }} of {{ totalProjects }}
|
||||
{{
|
||||
currentFilterType === DEFAULT_FILTER_TYPE ? 'projects' : currentFilterType.toLowerCase()
|
||||
}}
|
||||
</div>
|
||||
<div class="flex items-center gap-2 text-sm font-semibold text-secondary">
|
||||
<Toggle id="moderation-exclude-technical-review" v-model="excludeTechnicalReview" small />
|
||||
<label class="cursor-pointer" for="moderation-exclude-technical-review">
|
||||
{{ formatMessage(messages.excludeTechnicalReview) }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<Pagination :page="currentPage" :count="totalPages" @switch-page="goToPage" />
|
||||
<Pagination
|
||||
v-if="totalPages > 1"
|
||||
:page="currentPage"
|
||||
:count="totalPages"
|
||||
@switch-page="goToPage"
|
||||
/>
|
||||
<ConfettiExplosion v-if="visible" />
|
||||
</div>
|
||||
|
||||
@@ -124,6 +137,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type { Labrinth } from '@modrinth/api-client'
|
||||
import { ListFilterIcon, ScaleIcon, SearchIcon, SortAscIcon, SortDescIcon } from '@modrinth/assets'
|
||||
import {
|
||||
ButtonStyled,
|
||||
@@ -132,20 +146,18 @@ import {
|
||||
commonMessages,
|
||||
defineMessages,
|
||||
EmptyState,
|
||||
injectModrinthClient,
|
||||
injectNotificationManager,
|
||||
Pagination,
|
||||
StyledInput,
|
||||
Toggle,
|
||||
useVIntl,
|
||||
} from '@modrinth/ui'
|
||||
import Fuse from 'fuse.js'
|
||||
import { useQuery } from '@tanstack/vue-query'
|
||||
import ConfettiExplosion from 'vue-confetti-explosion'
|
||||
|
||||
import ModerationQueueCard from '~/components/ui/moderation/ModerationQueueCard.vue'
|
||||
import {
|
||||
type ModerationProject,
|
||||
type ProjectWithOwnership,
|
||||
toModerationProjects,
|
||||
} from '~/helpers/moderation.ts'
|
||||
import { type ModerationProject, toModerationProjects } from '~/helpers/moderation.ts'
|
||||
import { useModerationQueue } from '~/services/moderation-queue.ts'
|
||||
|
||||
useHead({ title: 'Projects queue - Modrinth' })
|
||||
@@ -155,6 +167,7 @@ const { addNotification } = injectNotificationManager()
|
||||
const moderationQueue = useModerationQueue()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const client = injectModrinthClient()
|
||||
|
||||
const visible = ref(false)
|
||||
if (import.meta.client && history && history.state && history.state.confetti) {
|
||||
@@ -173,37 +186,14 @@ const messages = defineMessages({
|
||||
id: 'moderation.moderate',
|
||||
defaultMessage: 'Moderate',
|
||||
},
|
||||
})
|
||||
|
||||
const { data: allProjects, pending } = await useLazyAsyncData('moderation-projects', async () => {
|
||||
const startTime = performance.now()
|
||||
let currentOffset = 0
|
||||
const PROJECT_ENDPOINT_COUNT = 350
|
||||
const allProjects: ModerationProject[] = []
|
||||
|
||||
let projects: ProjectWithOwnership[] = []
|
||||
do {
|
||||
projects = (await useBaseFetch(
|
||||
`moderation/projects?count=${PROJECT_ENDPOINT_COUNT}&offset=${currentOffset}`,
|
||||
{ internal: true },
|
||||
)) as ProjectWithOwnership[]
|
||||
|
||||
if (projects.length === 0) break
|
||||
|
||||
allProjects.push(...toModerationProjects(projects))
|
||||
currentOffset += projects.length
|
||||
} while (projects.length === PROJECT_ENDPOINT_COUNT)
|
||||
|
||||
const duration = performance.now() - startTime
|
||||
|
||||
console.debug(
|
||||
`Projects fetched and processed in ${duration.toFixed(2)}ms (${(duration / 1000).toFixed(2)}s)`,
|
||||
)
|
||||
|
||||
return allProjects
|
||||
excludeTechnicalReview: {
|
||||
id: 'moderation.exclude-technical-review',
|
||||
defaultMessage: 'Exclude TR',
|
||||
},
|
||||
})
|
||||
|
||||
const query = ref(route.query.q?.toString() || '')
|
||||
const excludeTechnicalReview = ref(false)
|
||||
|
||||
watch(
|
||||
query,
|
||||
@@ -379,116 +369,106 @@ const itemsPerPage = computed({
|
||||
})
|
||||
|
||||
const currentPage = ref(1)
|
||||
const totalPages = computed(() =>
|
||||
Math.ceil((filteredProjects.value?.length || 0) / itemsPerPage.value),
|
||||
|
||||
function toApiProjectType(label: string): string | undefined {
|
||||
switch (label) {
|
||||
case 'Modpacks':
|
||||
return 'modpack'
|
||||
case 'Mods':
|
||||
return 'mod'
|
||||
case 'Resource Packs':
|
||||
return 'resourcepack'
|
||||
case 'Data Packs':
|
||||
return 'datapack'
|
||||
case 'Plugins':
|
||||
return 'plugin'
|
||||
case 'Shaders':
|
||||
return 'shader'
|
||||
case 'Servers':
|
||||
return 'minecraft_java_server'
|
||||
case 'Fucked up':
|
||||
return 'none'
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function toApiSort(label: string): Labrinth.Moderation.Internal.ProjectsSort {
|
||||
switch (label) {
|
||||
case 'Newest':
|
||||
return 'newest'
|
||||
case 'Most external deps':
|
||||
return 'most_external_deps'
|
||||
case 'Least external deps':
|
||||
return 'least_external_deps'
|
||||
default:
|
||||
return 'oldest'
|
||||
}
|
||||
}
|
||||
|
||||
const moderationProjectsRequest = computed<Labrinth.Moderation.Internal.ProjectsRequest>(() => ({
|
||||
count: itemsPerPage.value,
|
||||
offset: (currentPage.value - 1) * itemsPerPage.value,
|
||||
exclude_technical_review: excludeTechnicalReview.value,
|
||||
query: query.value || undefined,
|
||||
project_type: toApiProjectType(currentFilterType.value),
|
||||
sort: toApiSort(currentSortType.value),
|
||||
}))
|
||||
|
||||
const moderationProjectsQueryKey = computed(
|
||||
() => ['moderation-projects', moderationProjectsRequest.value] as const,
|
||||
)
|
||||
|
||||
const fuse = computed(() => {
|
||||
if (!allProjects.value || allProjects.value.length === 0) return null
|
||||
return new Fuse(allProjects.value, {
|
||||
keys: [
|
||||
{
|
||||
name: 'project.title',
|
||||
weight: 3,
|
||||
},
|
||||
{
|
||||
name: 'project.slug',
|
||||
weight: 2,
|
||||
},
|
||||
{
|
||||
name: 'project.description',
|
||||
weight: 2,
|
||||
},
|
||||
{
|
||||
name: 'project.project_type',
|
||||
weight: 1,
|
||||
},
|
||||
'ownership.name',
|
||||
],
|
||||
includeScore: true,
|
||||
threshold: 0.4,
|
||||
})
|
||||
const {
|
||||
data: moderationProjectsResponse,
|
||||
isPending: moderationProjectsPending,
|
||||
isPlaceholderData: moderationProjectsPlaceholder,
|
||||
} = useQuery({
|
||||
queryKey: moderationProjectsQueryKey,
|
||||
queryFn: ({ queryKey }) => client.labrinth.moderation_internal.getProjects(queryKey[1]),
|
||||
placeholderData: (previousData) => previousData,
|
||||
})
|
||||
|
||||
const searchResults = computed(() => {
|
||||
if (!query.value || !fuse.value) return null
|
||||
return fuse.value.search(query.value).map((result) => result.item)
|
||||
})
|
||||
|
||||
const baseFiltered = computed(() => {
|
||||
if (!allProjects.value) return []
|
||||
return query.value && searchResults.value ? searchResults.value : [...allProjects.value]
|
||||
})
|
||||
|
||||
const typeFiltered = computed(() => {
|
||||
if (currentFilterType.value === 'All projects') {
|
||||
return baseFiltered.value
|
||||
} else if (currentFilterType.value === 'Fucked up') {
|
||||
return baseFiltered.value.filter((queueItem) => queueItem.project.project_types.length === 0)
|
||||
const pending = computed(
|
||||
() => moderationProjectsPending.value || moderationProjectsPlaceholder.value,
|
||||
)
|
||||
const totalProjects = computed(() => moderationProjectsResponse.value?.total ?? 0)
|
||||
const totalPages = computed(() => Math.ceil(totalProjects.value / itemsPerPage.value))
|
||||
const filteredProjects = computed(() =>
|
||||
toModerationProjects(moderationProjectsResponse.value?.projects ?? []),
|
||||
)
|
||||
const paginatedProjects = computed(() => filteredProjects.value)
|
||||
const pageStart = computed(() =>
|
||||
totalProjects.value === 0 ? 0 : (currentPage.value - 1) * itemsPerPage.value + 1,
|
||||
)
|
||||
const pageEnd = computed(() =>
|
||||
Math.min(
|
||||
(currentPage.value - 1) * itemsPerPage.value + paginatedProjects.value.length,
|
||||
totalProjects.value,
|
||||
),
|
||||
)
|
||||
const projectsById = computed(() => {
|
||||
const projects = new Map<string, ModerationProject>()
|
||||
for (const project of filteredProjects.value) {
|
||||
projects.set(project.project.id, project)
|
||||
}
|
||||
|
||||
const filterMap: Record<string, string> = {
|
||||
Modpacks: 'modpack',
|
||||
Mods: 'mod',
|
||||
'Resource Packs': 'resourcepack',
|
||||
'Data Packs': 'datapack',
|
||||
Plugins: 'plugin',
|
||||
Shaders: 'shader',
|
||||
Servers: 'minecraft_java_server',
|
||||
}
|
||||
const projectType = filterMap[currentFilterType.value]
|
||||
if (!projectType) return baseFiltered.value
|
||||
|
||||
return baseFiltered.value.filter(
|
||||
(queueItem) =>
|
||||
(queueItem.project.project_types.length > 0 &&
|
||||
queueItem.project.project_types[0] === projectType) ||
|
||||
(projectType === 'minecraft_java_server' &&
|
||||
queueItem.project.project_types.includes('minecraft_java_server')),
|
||||
)
|
||||
return projects
|
||||
})
|
||||
|
||||
const filteredProjects = computed(() => {
|
||||
const filtered = [...typeFiltered.value]
|
||||
|
||||
if (currentSortType.value === 'Most external deps') {
|
||||
filtered.sort((a, b) => {
|
||||
const depsDiff = b.external_dependencies_count - a.external_dependencies_count
|
||||
if (depsDiff !== 0) return depsDiff
|
||||
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
||||
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
||||
return dateA - dateB
|
||||
})
|
||||
} else if (currentSortType.value === 'Least external deps') {
|
||||
filtered.sort((a, b) => {
|
||||
const depsDiff = a.external_dependencies_count - b.external_dependencies_count
|
||||
if (depsDiff !== 0) return depsDiff
|
||||
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
||||
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
||||
return dateA - dateB
|
||||
})
|
||||
} else if (currentSortType.value === 'Oldest') {
|
||||
filtered.sort((a, b) => {
|
||||
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
||||
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
||||
return dateA - dateB
|
||||
})
|
||||
} else {
|
||||
filtered.sort((a, b) => {
|
||||
const dateA = new Date(a.project.queued || a.project.published || 0).getTime()
|
||||
const dateB = new Date(b.project.queued || b.project.published || 0).getTime()
|
||||
return dateB - dateA
|
||||
})
|
||||
watch(totalPages, (pages) => {
|
||||
if (pages === 0 && currentPage.value !== 1) {
|
||||
currentPage.value = 1
|
||||
return
|
||||
}
|
||||
|
||||
return filtered
|
||||
if (pages > 0 && currentPage.value > pages) {
|
||||
currentPage.value = pages
|
||||
}
|
||||
})
|
||||
|
||||
const paginatedProjects = computed(() => {
|
||||
if (!filteredProjects.value) return []
|
||||
const start = (currentPage.value - 1) * itemsPerPage.value
|
||||
const end = start + itemsPerPage.value
|
||||
return filteredProjects.value.slice(start, end)
|
||||
watch(excludeTechnicalReview, () => {
|
||||
goToPage(1)
|
||||
})
|
||||
|
||||
const emptyStateHeading = computed(() => {
|
||||
@@ -525,21 +505,16 @@ function notifySkippedProjects(skippedCount: number) {
|
||||
})
|
||||
}
|
||||
|
||||
async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
||||
async function findFirstEligibleProject(): Promise<string | null> {
|
||||
let skippedCount = 0
|
||||
|
||||
while (moderationQueue.hasItems) {
|
||||
const currentId = moderationQueue.getCurrentProjectId()
|
||||
if (!currentId) return null
|
||||
|
||||
const project = filteredProjects.value.find((p) => p.project.id === currentId)
|
||||
if (!project) {
|
||||
await moderationQueue.completeCurrentProject(currentId, 'skipped')
|
||||
skippedCount++
|
||||
continue
|
||||
}
|
||||
const project = projectsById.value.get(currentId)
|
||||
|
||||
if (project.project.status !== 'processing') {
|
||||
if (project && project.project.status !== 'processing') {
|
||||
await moderationQueue.completeCurrentProject(currentId, 'skipped')
|
||||
skippedCount++
|
||||
continue
|
||||
@@ -550,13 +525,13 @@ async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
||||
|
||||
if (!lockStatus.locked || lockStatus.expired || lockStatus.is_own_lock) {
|
||||
notifySkippedProjects(skippedCount)
|
||||
return project
|
||||
return currentId
|
||||
}
|
||||
|
||||
await moderationQueue.completeCurrentProject(currentId, 'skipped')
|
||||
skippedCount++
|
||||
} catch {
|
||||
return project
|
||||
return currentId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,17 +540,42 @@ async function findFirstEligibleProject(): Promise<ModerationProject | null> {
|
||||
return null
|
||||
}
|
||||
|
||||
function getProjectRouteParam(projectId: string): string {
|
||||
return projectsById.value.get(projectId)?.project.slug || projectId
|
||||
}
|
||||
|
||||
async function navigateToModerationProject(projectId: string) {
|
||||
await navigateTo({
|
||||
name: 'type-project',
|
||||
params: {
|
||||
type: 'project',
|
||||
project: getProjectRouteParam(projectId),
|
||||
},
|
||||
state: {
|
||||
showChecklist: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function getFilteredProjectIds(): Promise<string[]> {
|
||||
const response = await client.labrinth.moderation_internal.getProjectIds({
|
||||
exclude_technical_review: excludeTechnicalReview.value,
|
||||
query: query.value || undefined,
|
||||
project_type: toApiProjectType(currentFilterType.value),
|
||||
sort: toApiSort(currentSortType.value),
|
||||
})
|
||||
|
||||
return response.ids
|
||||
}
|
||||
|
||||
async function moderateAllInFilter() {
|
||||
// Start from the current page - get projects from current page onwards
|
||||
const startIndex = (currentPage.value - 1) * itemsPerPage.value
|
||||
const projectsFromCurrentPage = filteredProjects.value.slice(startIndex)
|
||||
const projectIds = projectsFromCurrentPage.map((queueItem) => queueItem.project.id)
|
||||
const projectIds = (await getFilteredProjectIds()).slice(startIndex)
|
||||
await moderationQueue.setQueue(projectIds)
|
||||
|
||||
// Find first unlocked project
|
||||
const targetProject = await findFirstEligibleProject()
|
||||
const targetProjectId = await findFirstEligibleProject()
|
||||
|
||||
if (!targetProject) {
|
||||
if (!targetProjectId) {
|
||||
addNotification({
|
||||
title: 'No projects available',
|
||||
text: 'All projects in queue are already moderated or locked by others.',
|
||||
@@ -584,34 +584,22 @@ async function moderateAllInFilter() {
|
||||
return
|
||||
}
|
||||
|
||||
navigateTo({
|
||||
name: 'type-project',
|
||||
params: {
|
||||
type: 'project',
|
||||
project: targetProject.project.slug,
|
||||
},
|
||||
state: {
|
||||
showChecklist: true,
|
||||
},
|
||||
})
|
||||
await navigateToModerationProject(targetProjectId)
|
||||
}
|
||||
|
||||
async function startFromProject(projectId: string) {
|
||||
// Find the index of the clicked project in the filtered list
|
||||
const projectIndex = filteredProjects.value.findIndex((p) => p.project.id === projectId)
|
||||
const allFilteredProjectIds = await getFilteredProjectIds()
|
||||
const projectIndex = allFilteredProjectIds.indexOf(projectId)
|
||||
if (projectIndex === -1) {
|
||||
// Project not found in filtered list, just moderate it alone
|
||||
await moderationQueue.setSingleProject(projectId)
|
||||
} else {
|
||||
// Start queue from this project onwards
|
||||
const projectsFromHere = filteredProjects.value.slice(projectIndex)
|
||||
const projectIds = projectsFromHere.map((queueItem) => queueItem.project.id)
|
||||
const projectIds = allFilteredProjectIds.slice(projectIndex)
|
||||
await moderationQueue.setQueue(projectIds)
|
||||
}
|
||||
|
||||
const targetProject = await findFirstEligibleProject()
|
||||
const targetProjectId = await findFirstEligibleProject()
|
||||
|
||||
if (!targetProject) {
|
||||
if (!targetProjectId) {
|
||||
addNotification({
|
||||
title: 'No projects available',
|
||||
text: 'All projects in queue are already moderated or locked by others.',
|
||||
@@ -620,15 +608,6 @@ async function startFromProject(projectId: string) {
|
||||
return
|
||||
}
|
||||
|
||||
navigateTo({
|
||||
name: 'type-project',
|
||||
params: {
|
||||
type: 'project',
|
||||
project: targetProject.project.slug,
|
||||
},
|
||||
state: {
|
||||
showChecklist: true,
|
||||
},
|
||||
})
|
||||
await navigateToModerationProject(targetProjectId)
|
||||
}
|
||||
</script>
|
||||
|
||||
Generated
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n select id\n from mods\n where id = any($1)\n and status not in ('rejected', 'draft', 'withheld', 'withdrawn')\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8Array"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "079846a1e6a6b080e0e7f2e3efbb53b6526332433faf66de8716bc5cd2b12afd"
|
||||
}
|
||||
Generated
-31
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT\n id,\n external_dependencies_count as \"external_dependencies_count!\"\n FROM (\n SELECT DISTINCT ON (m.id)\n m.id,\n m.queued,\n (\n SELECT COUNT(*)\n FROM versions v\n INNER JOIN dependencies d ON d.dependent_id = v.id\n WHERE v.mod_id = m.id\n AND d.dependency_file_name IS NOT NULL\n ) external_dependencies_count\n FROM mods m\n\n /* -- Temporarily, don't exclude projects in tech rev q\n\n -- exclude projects in tech review queue\n LEFT JOIN delphi_issue_details_with_statuses didws\n ON didws.project_id = m.id AND didws.status = 'pending'\n */\n\n WHERE\n m.status = $1\n /* AND didws.status IS NULL */ -- Temporarily don't exclude\n\n GROUP BY m.id\n ) t\n WHERE\n ($4::boolean IS NULL OR (external_dependencies_count > 0) = $4)\n ORDER BY queued ASC\n OFFSET $3\n LIMIT $2\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "external_dependencies_count!",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "119a59fcf4bb2f19f89002c712a67c75d30056143c0bcabdbd74bb4c7b442082"
|
||||
}
|
||||
Generated
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id\n FROM mods\n WHERE\n status = $1\n AND (\n $3::boolean = false\n OR NOT EXISTS (\n SELECT 1\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.project_id = mods.id\n AND didws.status = 'pending'\n )\n )\n ORDER BY\n CASE WHEN $2 = 'newest' THEN COALESCE(queued, published) END DESC NULLS LAST,\n CASE WHEN $2 = 'oldest' THEN COALESCE(queued, published) END ASC NULLS LAST,\n id ASC\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "1bff1c5714dd039814d7a9d9f25f4ceca0e84a42b3a4c414210739fec6308e2d"
|
||||
}
|
||||
Generated
+28
File diff suppressed because one or more lines are too long
Generated
+135
File diff suppressed because one or more lines are too long
Generated
+138
File diff suppressed because one or more lines are too long
@@ -78,6 +78,8 @@ pub enum LegacyNotificationBody {
|
||||
SharedInstanceInvite {
|
||||
shared_instance_id: String,
|
||||
shared_instance_name: String,
|
||||
shared_instance_icon: Option<String>,
|
||||
invited_by: UserId,
|
||||
},
|
||||
StatusChange {
|
||||
project_id: ProjectId,
|
||||
@@ -306,9 +308,13 @@ impl LegacyNotification {
|
||||
NotificationBody::SharedInstanceInvite {
|
||||
shared_instance_id,
|
||||
shared_instance_name,
|
||||
shared_instance_icon,
|
||||
invited_by,
|
||||
} => LegacyNotificationBody::SharedInstanceInvite {
|
||||
shared_instance_id,
|
||||
shared_instance_name,
|
||||
shared_instance_icon,
|
||||
invited_by,
|
||||
},
|
||||
NotificationBody::StatusChange {
|
||||
project_id,
|
||||
|
||||
@@ -15,6 +15,8 @@ pub struct LegacySearchResults {
|
||||
pub struct LegacyResultSearchProject {
|
||||
pub project_id: String,
|
||||
pub project_type: String,
|
||||
#[serde(default)]
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
#[serde(default)]
|
||||
@@ -136,6 +138,7 @@ impl LegacyResultSearchProject {
|
||||
|
||||
Self {
|
||||
project_type,
|
||||
all_project_types: result_search_project.all_project_types,
|
||||
client_side,
|
||||
server_side,
|
||||
versions,
|
||||
|
||||
@@ -179,6 +179,8 @@ pub enum NotificationBody {
|
||||
SharedInstanceInvite {
|
||||
shared_instance_id: String,
|
||||
shared_instance_name: String,
|
||||
shared_instance_icon: Option<String>,
|
||||
invited_by: UserId,
|
||||
},
|
||||
StatusChange {
|
||||
project_id: ProjectId,
|
||||
|
||||
@@ -542,6 +542,26 @@ const OVERRIDE_PREFIXES: &[&str] = &[
|
||||
"client-overrides/resourcepacks",
|
||||
];
|
||||
|
||||
const OVERRIDE_ROOT_PREFIXES: &[&str] =
|
||||
&["overrides/", "client-overrides/", "server-overrides/"];
|
||||
|
||||
fn override_relative_name(name: &str) -> Option<&str> {
|
||||
// strip the root prefix
|
||||
let relative = OVERRIDE_ROOT_PREFIXES
|
||||
.iter()
|
||||
.find_map(|prefix| name.strip_prefix(prefix))?;
|
||||
|
||||
// check if it matches any of the whitelisted scan prefixes
|
||||
OVERRIDE_PREFIXES
|
||||
.iter()
|
||||
.any(|prefix| {
|
||||
name.strip_prefix(prefix)
|
||||
// check the stripped prefix is actually a full segment, not something weird like "overrides/modsabce/file.jar"
|
||||
.is_some_and(|suffix| suffix.starts_with('/'))
|
||||
})
|
||||
.then_some(relative)
|
||||
}
|
||||
|
||||
fn should_scan(name: &str) -> bool {
|
||||
let name = name.to_lowercase();
|
||||
let should_skip = name.starts_with("mods/.connector/")
|
||||
@@ -550,7 +570,7 @@ fn should_scan(name: &str) -> bool {
|
||||
|| name.starts_with("mods/mcef-libraries/")
|
||||
|| name.starts_with("mods/mcef-cache/")
|
||||
|| name.starts_with("config/super_resolution/libraries/")
|
||||
|| name.starts_with("config/Veinminer/update/")
|
||||
|| name.starts_with("config/veinminer/update/")
|
||||
|| name.starts_with("config/epicfight/native/")
|
||||
|| name.starts_with("essential/")
|
||||
|| name.ends_with(".rpo")
|
||||
@@ -579,14 +599,11 @@ fn extract_override_files(data: &[u8]) -> Result<Vec<OverrideFile>> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !OVERRIDE_PREFIXES
|
||||
.iter()
|
||||
.any(|prefix| name.starts_with(prefix))
|
||||
{
|
||||
let Some(relative_name) = override_relative_name(&name) else {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if !should_scan(&name) {
|
||||
if !should_scan(relative_name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -941,12 +958,31 @@ async fn resolve_overrides(
|
||||
.await
|
||||
.wrap_err("fetching files on platform by hash")?;
|
||||
|
||||
let matching_project_ids: Vec<_> =
|
||||
files.iter().map(|file| file.project_id.0).collect();
|
||||
let valid_project_ids = sqlx::query_scalar!(
|
||||
r#"
|
||||
select id
|
||||
from mods
|
||||
where id = any($1)
|
||||
and status not in ('rejected', 'draft', 'withheld', 'withdrawn')
|
||||
"#,
|
||||
&matching_project_ids,
|
||||
)
|
||||
.fetch_all(&mut *txn)
|
||||
.await
|
||||
.wrap_err("fetching matched file project statuses")?;
|
||||
|
||||
let version_ids: Vec<_> = files.iter().map(|x| x.version_id).collect();
|
||||
let versions_data = DBVersion::get_many(&version_ids, &mut *txn, redis)
|
||||
.await
|
||||
.wrap_err("fetching versions")?;
|
||||
|
||||
for file in &files {
|
||||
if !valid_project_ids.contains(&file.project_id.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !versions_data.iter().any(|v| v.inner.id == file.version_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use actix_web::{HttpResponse, get};
|
||||
use serde_json::json;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn index_get() -> HttpResponse {
|
||||
let data = json!({
|
||||
fn build_info() -> serde_json::Value {
|
||||
json!({
|
||||
"name": "modrinth-labrinth",
|
||||
"version": env!("CARGO_PKG_VERSION"),
|
||||
"documentation": "https://docs.modrinth.com",
|
||||
@@ -14,7 +13,15 @@ pub async fn index_get() -> HttpResponse {
|
||||
"git_hash": option_env!("GIT_HASH").unwrap_or("unknown"),
|
||||
"profile": env!("COMPILATION_PROFILE"),
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
HttpResponse::Ok().json(data)
|
||||
#[get("/")]
|
||||
pub async fn index_get() -> HttpResponse {
|
||||
HttpResponse::Ok().json(build_info())
|
||||
}
|
||||
|
||||
#[get("/build")]
|
||||
pub async fn build_get() -> HttpResponse {
|
||||
HttpResponse::Ok().json(build_info())
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
pats::edit_pat,
|
||||
pats::delete_pat,
|
||||
moderation::get_projects,
|
||||
moderation::get_project_ids,
|
||||
moderation::get_project_meta,
|
||||
moderation::set_project_meta,
|
||||
moderation::acquire_lock,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -138,6 +138,7 @@ pub fn root_config(cfg: &mut web::ServiceConfig) {
|
||||
web::scope("")
|
||||
.wrap(default_cors())
|
||||
.service(index::index_get)
|
||||
.service(index::build_get)
|
||||
.service(Files::new("/", "assets/")),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub(crate) mod moderation;
|
||||
mod notifications;
|
||||
mod openapi;
|
||||
pub(crate) mod project_creation;
|
||||
@@ -26,7 +25,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
.configure(super::internal::flows::config)
|
||||
.configure(super::internal::pats::config)
|
||||
.configure(super::internal::admin::config)
|
||||
.configure(moderation::config)
|
||||
.configure(notifications::config)
|
||||
.configure(project_creation::config)
|
||||
.configure(projects::config)
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
use super::ApiError;
|
||||
use crate::database::PgPool;
|
||||
use crate::models::projects::Project;
|
||||
use crate::models::v2::projects::LegacyProject;
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::internal;
|
||||
use crate::{database::redis::RedisPool, routes::v2_reroute};
|
||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(web::scope("/moderation").service(get_projects));
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ResultCount {
|
||||
#[serde(default = "default_count")]
|
||||
pub count: u16,
|
||||
}
|
||||
|
||||
fn default_count() -> u16 {
|
||||
100
|
||||
}
|
||||
|
||||
/// List projects in the moderation queue.
|
||||
#[utoipa::path(
|
||||
context_path = "/moderation",
|
||||
tag = "v2 moderation",
|
||||
get,
|
||||
operation_id = "getModerationProjects",
|
||||
params(
|
||||
("count" = Option<u16>, Query, description = "Maximum number of projects to return")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request", body = Vec<LegacyProject>),
|
||||
(
|
||||
status = 401,
|
||||
description = "Incorrect token scopes or no authorization to access the requested item(s)"
|
||||
),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
),
|
||||
security(("bearer_auth" = ["PROJECT_READ"]))
|
||||
)]
|
||||
#[get("/projects")]
|
||||
pub async fn get_projects(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
count: web::Query<ResultCount>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let response = internal::moderation::get_projects_internal(
|
||||
req,
|
||||
pool.clone(),
|
||||
redis.clone(),
|
||||
web::Query(internal::moderation::ProjectsRequestOptions {
|
||||
count: count.count,
|
||||
offset: 0,
|
||||
has_external_dependencies: None,
|
||||
}),
|
||||
session_queue,
|
||||
)
|
||||
.await
|
||||
.map(|resp| HttpResponse::Ok().json(resp))
|
||||
.or_else(v2_reroute::flatten_404_error)?;
|
||||
|
||||
// Convert to V2 projects
|
||||
match v2_reroute::extract_ok_json::<Vec<Project>>(response).await {
|
||||
Ok(project) => {
|
||||
let legacy_projects =
|
||||
LegacyProject::from_many(project, &**pool, &redis).await?;
|
||||
Ok(HttpResponse::Ok().json(legacy_projects))
|
||||
}
|
||||
Err(response) => Ok(response),
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,10 @@ const CONTENT_RESOLVE_CACHE_SCHEMA_VERSION: &str = "v1";
|
||||
const CONTENT_RESOLVE_CACHE_HEAT_WINDOW_SECONDS: i64 = 60 * 60 * 24;
|
||||
|
||||
pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(web::scope("/v3").service(resolve_content));
|
||||
cfg.service(resolve_content);
|
||||
}
|
||||
|
||||
/// Resolve content.
|
||||
/// Resolve content.
|
||||
#[utoipa::path(
|
||||
tag = "content",
|
||||
request_body = serde_json::Value,
|
||||
|
||||
@@ -69,9 +69,9 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
.configure(users::config)
|
||||
.configure(version_file::config)
|
||||
.configure(versions::config)
|
||||
.configure(friends::config),
|
||||
.configure(friends::config)
|
||||
.configure(content::config),
|
||||
);
|
||||
cfg.configure(content::config);
|
||||
}
|
||||
|
||||
#[derive(utoipa::OpenApi)]
|
||||
|
||||
@@ -405,6 +405,14 @@ impl SearchField {
|
||||
optional: true,
|
||||
token_separators: &["-"],
|
||||
},
|
||||
SearchField::AllProjectTypes => TypesenseFieldSpec {
|
||||
path: "all_project_types",
|
||||
ty: "string[]",
|
||||
facet: true,
|
||||
sort: false,
|
||||
optional: true,
|
||||
token_separators: &["-"],
|
||||
},
|
||||
SearchField::ProjectId => TypesenseFieldSpec {
|
||||
path: "project_id",
|
||||
ty: "string",
|
||||
@@ -563,6 +571,7 @@ impl Typesense {
|
||||
json!({"name": "indexed_name", "type": "string", "facet": false, "stem": true}),
|
||||
json!({"name": "indexed_author", "type": "string", "facet": false}),
|
||||
json!({"name": "log_downloads", "type": "float", "sort": true}),
|
||||
json!({"name": "downloads", "type": "int32", "sort": true}),
|
||||
json!({"name": "follows", "type": "int32", "facet": true, "sort": true}),
|
||||
json!({"name": "created_timestamp", "type": "int64", "sort": true}),
|
||||
json!({"name": "modified_timestamp", "type": "int64", "sort": true}),
|
||||
@@ -1255,9 +1264,12 @@ fn facets_to_typesense(facets_json: &str) -> Result<String> {
|
||||
/// Converts a single facet condition such as `"categories:mods"`,
|
||||
/// `"categories=mods"`, or `"downloads!=100"` into a Typesense filter clause.
|
||||
fn condition_to_typesense_filter(cond: &str) -> String {
|
||||
// Handle `!=` before `=` so we don't misfire on the equality arm.
|
||||
if let Some((field, value)) = cond.split_once("!=") {
|
||||
return format!("{}:!= {}", field.trim(), value.trim());
|
||||
// Match multi-character operators before their single-character prefixes,
|
||||
// and range/inequality operators before the plain `=` equality arm.
|
||||
for op in ["!=", ">=", "<=", ">", "<"] {
|
||||
if let Some((field, value)) = cond.split_once(op) {
|
||||
return format!("{}:{} {}", field.trim(), op, value.trim());
|
||||
}
|
||||
}
|
||||
if let Some((field, value)) = cond.split_once(':') {
|
||||
return format!("{}:= {}", field.trim(), value.trim());
|
||||
|
||||
@@ -495,6 +495,20 @@ async fn build_search_documents(
|
||||
.flat_map(|x| x.loaders.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// all valid project types across every version of the project, so that
|
||||
// filters can exclude projects that have *any* version of a given
|
||||
// project type (unlike the version-specific `project_types` field).
|
||||
let mut all_project_types = versions
|
||||
.iter()
|
||||
.flat_map(|x| x.project_types.clone())
|
||||
.collect::<Vec<_>>();
|
||||
all_project_types.sort();
|
||||
all_project_types.dedup();
|
||||
exp::compat::correct_project_types(
|
||||
&project.components,
|
||||
&mut all_project_types,
|
||||
);
|
||||
|
||||
for version in versions {
|
||||
let version_fields = VersionField::from_query_json(
|
||||
version.version_fields,
|
||||
@@ -609,6 +623,7 @@ async fn build_search_documents(
|
||||
slug: project.slug.clone(),
|
||||
// TODO
|
||||
project_types,
|
||||
all_project_types: all_project_types.clone(),
|
||||
gallery: gallery.clone(),
|
||||
featured_gallery: featured_gallery.clone(),
|
||||
open_source,
|
||||
|
||||
@@ -202,6 +202,7 @@ pub enum SearchField {
|
||||
Author,
|
||||
License,
|
||||
ProjectTypes,
|
||||
AllProjectTypes,
|
||||
ProjectId,
|
||||
OpenSource,
|
||||
Environment,
|
||||
@@ -238,6 +239,8 @@ pub struct UploadSearchProject {
|
||||
pub project_id: String,
|
||||
//
|
||||
pub project_types: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
pub author_id: String,
|
||||
@@ -307,6 +310,8 @@ pub struct ResultSearchProject {
|
||||
pub version_id: String,
|
||||
pub project_id: String,
|
||||
pub project_types: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
#[serde(default)]
|
||||
@@ -355,6 +360,7 @@ impl From<UploadSearchProject> for ResultSearchProject {
|
||||
version_id: source.version_id,
|
||||
project_id: source.project_id,
|
||||
project_types: source.project_types,
|
||||
all_project_types: source.all_project_types,
|
||||
slug: source.slug,
|
||||
author: source.author,
|
||||
author_id: Some(source.author_id),
|
||||
|
||||
@@ -100,4 +100,21 @@ export class LabrinthAttributionInternalModule extends AbstractModule {
|
||||
body,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a file for attribution information.
|
||||
* POST /_internal/attribution/file/{file_id}/scan
|
||||
*
|
||||
* @param fileId - The file ID to scan.
|
||||
*/
|
||||
public async scanFile(fileId: string): Promise<Labrinth.Attribution.Internal.FileScanResponse> {
|
||||
return this.client.request<Labrinth.Attribution.Internal.FileScanResponse>(
|
||||
`/attribution/file/${fileId}/scan`,
|
||||
{
|
||||
api: 'labrinth',
|
||||
version: 'internal',
|
||||
method: 'POST',
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,34 @@ export class LabrinthModerationInternalModule extends AbstractModule {
|
||||
return 'labrinth_moderation_internal'
|
||||
}
|
||||
|
||||
public async getProjects(
|
||||
params: Labrinth.Moderation.Internal.ProjectsRequest = {},
|
||||
): Promise<Labrinth.Moderation.Internal.ProjectsResponse> {
|
||||
return this.client.request<Labrinth.Moderation.Internal.ProjectsResponse>(
|
||||
'/moderation/projects',
|
||||
{
|
||||
api: 'labrinth',
|
||||
version: 'internal',
|
||||
method: 'GET',
|
||||
params,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
public async getProjectIds(
|
||||
params: Omit<Labrinth.Moderation.Internal.ProjectsRequest, 'count' | 'offset'> = {},
|
||||
): Promise<Labrinth.Moderation.Internal.ProjectIdsResponse> {
|
||||
return this.client.request<Labrinth.Moderation.Internal.ProjectIdsResponse>(
|
||||
'/moderation/projects/ids',
|
||||
{
|
||||
api: 'labrinth',
|
||||
version: 'internal',
|
||||
method: 'GET',
|
||||
params,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
public async acquireLock(
|
||||
projectId: string,
|
||||
): Promise<Labrinth.Moderation.Internal.LockAcquireResponse> {
|
||||
|
||||
@@ -397,6 +397,12 @@ export namespace Labrinth {
|
||||
sha1: string
|
||||
project_id: string
|
||||
}
|
||||
|
||||
export type FileScanResponse = {
|
||||
new_attribution_groups: number
|
||||
new_attribution_files: number
|
||||
scanned_file_names: string[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1333,6 +1339,7 @@ export namespace Labrinth {
|
||||
}
|
||||
|
||||
export type VersionFile = {
|
||||
id?: string
|
||||
hashes: VersionFileHash
|
||||
url: string
|
||||
filename: string
|
||||
@@ -1454,6 +1461,7 @@ export namespace Labrinth {
|
||||
}
|
||||
|
||||
export interface VersionFile {
|
||||
id?: string
|
||||
hashes: VersionFileHash
|
||||
url: string
|
||||
filename: string
|
||||
@@ -1734,6 +1742,7 @@ export namespace Labrinth {
|
||||
export interface ResultSearchProject {
|
||||
project_id: string
|
||||
project_type: string
|
||||
all_project_types: string[]
|
||||
slug: string | null
|
||||
author: string
|
||||
author_id: string | null
|
||||
@@ -1771,6 +1780,7 @@ export namespace Labrinth {
|
||||
version_id: string
|
||||
project_id: string
|
||||
project_types: string[]
|
||||
all_project_types: string[]
|
||||
slug: string | null
|
||||
author: string
|
||||
author_id: string | null
|
||||
@@ -1906,6 +1916,57 @@ export namespace Labrinth {
|
||||
|
||||
export namespace Moderation {
|
||||
export namespace Internal {
|
||||
export type Ownership =
|
||||
| {
|
||||
kind: 'user'
|
||||
id: string
|
||||
name: string
|
||||
icon_url: string | null
|
||||
}
|
||||
| {
|
||||
kind: 'organization'
|
||||
id: string
|
||||
name: string
|
||||
icon_url: string | null
|
||||
}
|
||||
|
||||
export type ProjectsSort = 'oldest' | 'newest' | 'most_external_deps' | 'least_external_deps'
|
||||
|
||||
export type ProjectsRequest = {
|
||||
count?: number
|
||||
offset?: number
|
||||
has_external_dependencies?: boolean
|
||||
exclude_technical_review?: boolean
|
||||
query?: string
|
||||
project_type?: string
|
||||
sort?: ProjectsSort
|
||||
}
|
||||
|
||||
export type QueueProject = {
|
||||
id: string
|
||||
slug: string | null
|
||||
name: string
|
||||
summary: string
|
||||
icon_url: string | null
|
||||
status: Projects.v2.ProjectStatus
|
||||
requested_status: Projects.v2.ProjectStatus | null
|
||||
queued: string | null
|
||||
published: string
|
||||
updated: string
|
||||
project_types: string[]
|
||||
ownership: Ownership
|
||||
external_dependencies_count: number
|
||||
}
|
||||
|
||||
export type ProjectsResponse = {
|
||||
total: number
|
||||
projects: QueueProject[]
|
||||
}
|
||||
|
||||
export type ProjectIdsResponse = {
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export type LockedByUser = {
|
||||
id: string
|
||||
username: string
|
||||
|
||||
@@ -61,11 +61,16 @@ pub async fn edit(
|
||||
let state = State::get().await?;
|
||||
crate::state::edit_instance(instance_id, patch, &state.pool).await?;
|
||||
|
||||
crate::state::get_instance(instance_id, &state.pool)
|
||||
let instance = crate::state::get_instance(instance_id, &state.pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
crate::ErrorKind::InputError("Unknown instance".to_string()).into()
|
||||
})
|
||||
crate::ErrorKind::InputError("Unknown instance".to_string())
|
||||
.as_error()
|
||||
})?;
|
||||
|
||||
emit_instance(&instance.instance.id, InstancePayloadType::Edited).await?;
|
||||
|
||||
Ok(instance)
|
||||
}
|
||||
|
||||
pub async fn edit_icon(
|
||||
|
||||
@@ -64,6 +64,7 @@ pub enum FeatureFlag {
|
||||
I18nDebug,
|
||||
ShowInstancePlayTime,
|
||||
SkipNonEssentialWarnings,
|
||||
AdvancedFiltersCollapsed,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
||||
@@ -10,6 +10,44 @@ export type VersionEntry = {
|
||||
}
|
||||
|
||||
const VERSIONS: VersionEntry[] = [
|
||||
{
|
||||
date: `2026-07-08T15:05:35+00:00`,
|
||||
product: 'app',
|
||||
version: '0.15.9',
|
||||
body: `## Added
|
||||
- Added new advanced filter category to Discover content.
|
||||
- Added options to exclude plugins and data packs from mod search
|
||||
- Added options to exclude mods and plugins from data pack search
|
||||
|
||||
## Fixed
|
||||
- Instance edits not appearing to be immediately saved.`,
|
||||
},
|
||||
{
|
||||
date: `2026-07-08T15:05:35+00:00`,
|
||||
product: 'web',
|
||||
body: `## Added
|
||||
- Added new advanced filter category to Discover content.
|
||||
- Added options to exclude plugins and data packs from mod search
|
||||
- Added options to exclude mods and data packs from plugin search
|
||||
- Added options to exclude mods and plugins from data pack search`,
|
||||
},
|
||||
{
|
||||
date: `2026-07-06T22:19:13+00:00`,
|
||||
product: 'app',
|
||||
version: '0.15.8',
|
||||
body: `## Changed
|
||||
- Updated the version pages to use the new design.
|
||||
|
||||
## Fixed
|
||||
- Fixed project and version links from an instance not being aware of the instance you're coming from.
|
||||
- Fixed Files tab preloading files which weren't actually editable/viewable which caused a memory leak.`,
|
||||
},
|
||||
{
|
||||
date: `2026-07-06T22:19:13+00:00`,
|
||||
product: 'hosting',
|
||||
body: `## Fixed
|
||||
- Fixed Files tab preloading files which weren't actually editable/viewable which caused a memory leak.`,
|
||||
},
|
||||
{
|
||||
date: `2026-07-05T01:48:48+00:00`,
|
||||
product: 'app',
|
||||
|
||||
@@ -10,10 +10,73 @@ pub const CURRENT_FABRIC_FORMAT_VERSION: usize = 0;
|
||||
/// The latest version of the format the fabric model structs deserialize to
|
||||
pub const CURRENT_FORGE_FORMAT_VERSION: usize = 0;
|
||||
/// The latest version of the format the quilt model structs deserialize to
|
||||
pub const CURRENT_QUILT_FORMAT_VERSION: usize = 0;
|
||||
pub const CURRENT_QUILT_FORMAT_VERSION: usize = 1;
|
||||
/// The latest version of the format the neoforge model structs deserialize to
|
||||
pub const CURRENT_NEOFORGE_FORMAT_VERSION: usize = 0;
|
||||
|
||||
/// Metadata for locating and caching a loader manifest.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LoaderManifestMetadata {
|
||||
/// The canonical loader name used in launcher-meta paths.
|
||||
pub loader: String,
|
||||
/// The latest manifest format version for this loader.
|
||||
pub format_version: usize,
|
||||
/// The cache key that includes the loader format version.
|
||||
pub cache_key: String,
|
||||
/// The launcher-meta path to the manifest.
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
/// Returns metadata for the latest manifest format for the provided loader.
|
||||
pub fn loader_manifest_metadata(loader: &str) -> LoaderManifestMetadata {
|
||||
let format_version = current_loader_manifest_format_version(loader);
|
||||
let cache_key = format!("{loader}-v{format_version}");
|
||||
let path = format!("{loader}/v{format_version}/manifest.json");
|
||||
|
||||
LoaderManifestMetadata {
|
||||
loader: loader.to_string(),
|
||||
format_version,
|
||||
cache_key,
|
||||
path,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns loader manifest metadata from a versioned cache key.
|
||||
pub fn loader_manifest_metadata_from_cache_key(
|
||||
cache_key: &str,
|
||||
) -> LoaderManifestMetadata {
|
||||
if let Some((loader, format_version)) =
|
||||
cache_key.rsplit_once("-v").and_then(|(loader, version)| {
|
||||
version
|
||||
.parse::<usize>()
|
||||
.ok()
|
||||
.map(|version| (loader, version))
|
||||
})
|
||||
{
|
||||
let cache_key = format!("{loader}-v{format_version}");
|
||||
let path = format!("{loader}/v{format_version}/manifest.json");
|
||||
|
||||
LoaderManifestMetadata {
|
||||
loader: loader.to_string(),
|
||||
format_version,
|
||||
cache_key,
|
||||
path,
|
||||
}
|
||||
} else {
|
||||
loader_manifest_metadata(cache_key)
|
||||
}
|
||||
}
|
||||
|
||||
fn current_loader_manifest_format_version(loader: &str) -> usize {
|
||||
match loader {
|
||||
"fabric" => CURRENT_FABRIC_FORMAT_VERSION,
|
||||
"forge" => CURRENT_FORGE_FORMAT_VERSION,
|
||||
"quilt" => CURRENT_QUILT_FORMAT_VERSION,
|
||||
"neo" => CURRENT_NEOFORGE_FORMAT_VERSION,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// The dummy replace string library names, inheritsFrom, and version names should be replaced with
|
||||
pub const DUMMY_REPLACE_STRING: &str = "${modrinth.gameVersion}";
|
||||
|
||||
@@ -188,19 +251,36 @@ pub fn merge_partial_version(
|
||||
pub struct Manifest {
|
||||
/// The game versions the mod loader supports
|
||||
pub game_versions: Vec<Version>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
/// Groups of game versions that share compatible loader version profiles
|
||||
pub version_groups: Vec<VersionGroup>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
/// A game version of Minecraft
|
||||
pub struct Version {
|
||||
/// The minecraft version ID
|
||||
pub id: String,
|
||||
/// Whether the release is stable or not
|
||||
pub stable: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// The loader profile group for this Minecraft version
|
||||
pub version_group: Option<String>,
|
||||
/// A map that contains loader versions for the game version
|
||||
pub loaders: Vec<LoaderVersion>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
/// A group of Minecraft versions that share loader version profiles
|
||||
pub struct VersionGroup {
|
||||
/// The version group ID
|
||||
pub id: String,
|
||||
/// The loader versions for this version group
|
||||
pub loaders: Vec<LoaderVersion>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
/// A version of a Minecraft mod loader
|
||||
pub struct LoaderVersion {
|
||||
|
||||
@@ -71,83 +71,105 @@
|
||||
</template>
|
||||
<template v-else #default>
|
||||
<slot name="prefix" />
|
||||
<StyledInput
|
||||
v-if="filterType.searchable"
|
||||
:id="`search-${filterType.id}`"
|
||||
v-model="query"
|
||||
:icon="SearchIcon"
|
||||
type="text"
|
||||
:placeholder="formatMessage(messages.searchPlaceholder)"
|
||||
autocomplete="off"
|
||||
clearable
|
||||
size="small"
|
||||
input-class="!bg-button-bg"
|
||||
wrapper-class="mx-2 my-1 w-[calc(100%-1rem)]"
|
||||
/>
|
||||
|
||||
<ScrollablePanel :class="{ 'h-[16rem]': scrollable }" :disable-scrolling="!scrollable">
|
||||
<div :class="innerPanelClass ? innerPanelClass : ''" class="flex flex-col gap-1">
|
||||
<template v-if="groupedOptions">
|
||||
<SearchFilterGroup
|
||||
v-for="[groupName, options] in groupedOptions"
|
||||
:key="`${filterType.id}-group-${groupName}`"
|
||||
:group-name="groupName"
|
||||
:options="options"
|
||||
:supports-negative-filter="filterType.supports_negative_filter"
|
||||
:included="isIncluded"
|
||||
:excluded="isExcluded"
|
||||
@toggle="toggleFilter"
|
||||
@toggle-exclude="toggleNegativeFilter"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<SearchFilterOption
|
||||
v-for="option in visibleOptions"
|
||||
:key="`${filterType.id}-${option}`"
|
||||
:option="option"
|
||||
:included="isIncluded(option)"
|
||||
:excluded="isExcluded(option)"
|
||||
:supports-negative-filter="filterType.supports_negative_filter"
|
||||
:class="{
|
||||
'mr-3': scrollable,
|
||||
}"
|
||||
@toggle="toggleFilter"
|
||||
@toggle-exclude="toggleNegativeFilter"
|
||||
<div
|
||||
v-if="filterType.display === 'toggle'"
|
||||
:class="innerPanelClass ? innerPanelClass : ''"
|
||||
class="flex flex-col gap-3"
|
||||
>
|
||||
<label
|
||||
v-for="option in filterType.options"
|
||||
:key="`${filterType.id}-toggle-${option.id}`"
|
||||
class="flex cursor-pointer items-center justify-between text-secondary gap-3 font-semibold"
|
||||
>
|
||||
<span class="text-sm">{{ option.formatted_name ?? option.id }}</span>
|
||||
<Toggle
|
||||
:model-value="isExcluded(option)"
|
||||
small
|
||||
class="shrink-0"
|
||||
@update:model-value="toggleNegativeFilter(option)"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<template v-if="filterType.display !== 'toggle'">
|
||||
<StyledInput
|
||||
v-if="filterType.searchable"
|
||||
:id="`search-${filterType.id}`"
|
||||
v-model="query"
|
||||
:icon="SearchIcon"
|
||||
type="text"
|
||||
:placeholder="formatMessage(messages.searchPlaceholder)"
|
||||
autocomplete="off"
|
||||
clearable
|
||||
size="small"
|
||||
input-class="!bg-button-bg"
|
||||
wrapper-class="mx-2 my-1 w-[calc(100%-1rem)]"
|
||||
/>
|
||||
<ScrollablePanel :class="{ 'h-[16rem]': scrollable }" :disable-scrolling="!scrollable">
|
||||
<div :class="innerPanelClass ? innerPanelClass : ''" class="flex flex-col gap-1">
|
||||
<template v-if="groupedOptions">
|
||||
<SearchFilterGroup
|
||||
v-for="[groupName, options] in groupedOptions"
|
||||
:key="`${filterType.id}-group-${groupName}`"
|
||||
:group-name="groupName"
|
||||
:options="options"
|
||||
:supports-negative-filter="filterType.supports_negative_filter"
|
||||
:included="isIncluded"
|
||||
:excluded="isExcluded"
|
||||
@toggle="toggleFilter"
|
||||
@toggle-exclude="toggleNegativeFilter"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<SearchFilterOption
|
||||
v-for="option in visibleOptions"
|
||||
:key="`${filterType.id}-${option}`"
|
||||
:option="option"
|
||||
:included="isIncluded(option)"
|
||||
:excluded="isExcluded(option)"
|
||||
:supports-negative-filter="filterType.supports_negative_filter"
|
||||
:class="{
|
||||
'mr-3': scrollable,
|
||||
}"
|
||||
@toggle="toggleFilter"
|
||||
@toggle-exclude="toggleNegativeFilter"
|
||||
>
|
||||
<slot name="option" :filter="filterType" :option="option">
|
||||
<span
|
||||
v-if="option.icon"
|
||||
class="inline-flex items-center justify-center shrink-0 h-4 w-4"
|
||||
:style="iconStyle(option)"
|
||||
>
|
||||
<div
|
||||
v-if="typeof option.icon === 'string'"
|
||||
class="h-4 w-4"
|
||||
v-html="option.icon"
|
||||
/>
|
||||
<component :is="option.icon" v-else class="h-4 w-4" />
|
||||
</span>
|
||||
<span class="truncate text-sm" :style="iconStyle(option)">
|
||||
{{ option.formatted_name ?? option.id }}
|
||||
</span>
|
||||
</slot>
|
||||
</SearchFilterOption>
|
||||
</template>
|
||||
<button
|
||||
v-if="filterType.display === 'expandable'"
|
||||
class="flex bg-transparent text-secondary border-none cursor-pointer !w-full items-center gap-2 truncate rounded-xl px-2 py-1 text-sm font-semibold transition-all hover:text-contrast focus-visible:text-contrast active:scale-[0.98]"
|
||||
@click="showMore = !showMore"
|
||||
>
|
||||
<slot name="option" :filter="filterType" :option="option">
|
||||
<span
|
||||
v-if="option.icon"
|
||||
class="inline-flex items-center justify-center shrink-0 h-4 w-4"
|
||||
:style="iconStyle(option)"
|
||||
>
|
||||
<div
|
||||
v-if="typeof option.icon === 'string'"
|
||||
class="h-4 w-4"
|
||||
v-html="option.icon"
|
||||
/>
|
||||
<component :is="option.icon" v-else class="h-4 w-4" />
|
||||
</span>
|
||||
<span class="truncate text-sm" :style="iconStyle(option)">
|
||||
{{ option.formatted_name ?? option.id }}
|
||||
</span>
|
||||
</slot>
|
||||
</SearchFilterOption>
|
||||
</template>
|
||||
<button
|
||||
v-if="filterType.display === 'expandable'"
|
||||
class="flex bg-transparent text-secondary border-none cursor-pointer !w-full items-center gap-2 truncate rounded-xl px-2 py-1 text-sm font-semibold transition-all hover:text-contrast focus-visible:text-contrast active:scale-[0.98]"
|
||||
@click="showMore = !showMore"
|
||||
>
|
||||
<DropdownIcon
|
||||
class="h-4 w-4 transition-transform"
|
||||
:class="{ 'rotate-180': showMore }"
|
||||
/>
|
||||
<span class="truncate text-sm">
|
||||
{{ showMore ? formatMessage(messages.showFewer) : formatMessage(messages.showMore) }}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</ScrollablePanel>
|
||||
<DropdownIcon
|
||||
class="h-4 w-4 transition-transform"
|
||||
:class="{ 'rotate-180': showMore }"
|
||||
/>
|
||||
<span class="truncate text-sm">
|
||||
{{
|
||||
showMore ? formatMessage(messages.showFewer) : formatMessage(messages.showMore)
|
||||
}}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</ScrollablePanel>
|
||||
</template>
|
||||
<div :class="innerPanelClass ? innerPanelClass : ''" class="empty:hidden">
|
||||
<Checkbox
|
||||
v-for="group in filterType.toggle_groups"
|
||||
@@ -191,6 +213,7 @@ import { defineMessages, useVIntl } from '../../composables/i18n'
|
||||
import type { FilterOption, FilterType, FilterValue } from '../../utils/search'
|
||||
import Accordion from '../base/Accordion.vue'
|
||||
import ButtonStyled from '../base/ButtonStyled.vue'
|
||||
import Toggle from '../base/Toggle.vue'
|
||||
import { Checkbox, ScrollablePanel, StyledInput } from '../index'
|
||||
import SearchFilterGroup from './SearchFilterGroup.vue'
|
||||
import SearchFilterOption from './SearchFilterOption.vue'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -73,6 +73,7 @@ export interface BrowseManagerContext {
|
||||
showServerOnly?: ComputedRef<boolean>
|
||||
serverOnlyLabel?: ComputedRef<string>
|
||||
hiddenFilterTypes?: ComputedRef<string[]>
|
||||
advancedFiltersCollapsed?: Ref<boolean>
|
||||
onInstalled?: (projectId: string) => void
|
||||
|
||||
displayMode?: Ref<'list' | 'grid' | 'gallery'> | ComputedRef<'list' | 'grid' | 'gallery'>
|
||||
|
||||
@@ -17,6 +17,14 @@ const isApp = computed(() => ctx.variant === 'app')
|
||||
const lockedMessages = computed(() => toValue(ctx.lockedFilterMessages))
|
||||
const hiddenFilterTypes = computed(() => ctx.hiddenFilterTypes?.value ?? [])
|
||||
|
||||
const advancedFiltersCollapsed = computed(() => ctx.advancedFiltersCollapsed?.value ?? true)
|
||||
|
||||
function setAdvancedFiltersCollapsed(collapsed: boolean) {
|
||||
if (ctx.advancedFiltersCollapsed) {
|
||||
ctx.advancedFiltersCollapsed.value = collapsed
|
||||
}
|
||||
}
|
||||
|
||||
function closeFiltersMenu() {
|
||||
if (ctx.filtersMenuOpen) {
|
||||
ctx.filtersMenuOpen.value = false
|
||||
@@ -49,6 +57,9 @@ function hasProvidedFilter(filterId: string): boolean {
|
||||
}
|
||||
|
||||
function getFilterOpenByDefault(filterId: string): boolean {
|
||||
if (filterId === 'advanced') {
|
||||
return !advancedFiltersCollapsed.value
|
||||
}
|
||||
if (hasProvidedFilter(filterId)) {
|
||||
return true
|
||||
}
|
||||
@@ -188,6 +199,8 @@ function getFilterOpenByDefault(filterId: string): boolean {
|
||||
:content-class="contentClass"
|
||||
:inner-panel-class="innerPanelClass"
|
||||
:open-by-default="getFilterOpenByDefault(filter.id)"
|
||||
@on-open="() => filter.id === 'advanced' && setAdvancedFiltersCollapsed(false)"
|
||||
@on-close="() => filter.id === 'advanced' && setAdvancedFiltersCollapsed(true)"
|
||||
>
|
||||
<template #header>
|
||||
<h3 :class="isApp ? 'text-base m-0' : 'm-0 text-lg font-semibold'">
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
TextCursorInputIcon,
|
||||
TrashIcon,
|
||||
} from '@modrinth/assets'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
|
||||
import ButtonStyled from '#ui/components/base/ButtonStyled.vue'
|
||||
import EmptyState from '#ui/components/base/EmptyState.vue'
|
||||
@@ -389,10 +389,11 @@ async function promptDeleteItems(items: ContentItem[], event?: MouseEvent) {
|
||||
showDeletionConfirmation(event)
|
||||
}
|
||||
|
||||
function showDeletionConfirmation(event?: MouseEvent) {
|
||||
async function showDeletionConfirmation(event?: MouseEvent) {
|
||||
if ((event?.shiftKey || skipNonEssentialWarnings.value) && !ctx.isBusy.value) {
|
||||
confirmDelete()
|
||||
} else {
|
||||
await nextTick()
|
||||
confirmDeletionModal.value?.show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,11 +118,7 @@ import { defineMessages, useVIntl } from '#ui/composables/i18n'
|
||||
import { injectNotificationManager } from '#ui/providers/web-notifications'
|
||||
import { getFileExtensionIcon } from '#ui/utils/auto-icons'
|
||||
import { commonMessages } from '#ui/utils/common-messages'
|
||||
import {
|
||||
getFileExtension,
|
||||
isEditableFile as isEditableFileExt,
|
||||
isImageFile,
|
||||
} from '#ui/utils/file-extensions'
|
||||
import { canOpenInFileEditor, getFileExtension } from '#ui/utils/file-extensions'
|
||||
|
||||
import {
|
||||
fileDragActive,
|
||||
@@ -303,8 +299,7 @@ const formattedCreationDate = computed(() => {
|
||||
|
||||
const isEditableFile = computed(() => {
|
||||
if (props.type === 'file') {
|
||||
const ext = fileExtension.value
|
||||
return !props.name.includes('.') || isEditableFileExt(ext) || isImageFile(ext)
|
||||
return canOpenInFileEditor(props.name)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
@@ -225,7 +225,7 @@ import { useVirtualScroll } from '#ui/composables/virtual-scroll'
|
||||
import { injectFilePicker } from '#ui/providers/file-picker'
|
||||
import { injectNotificationManager } from '#ui/providers/web-notifications'
|
||||
import { commonMessages } from '#ui/utils/common-messages'
|
||||
import { getFileExtension } from '#ui/utils/file-extensions'
|
||||
import { canOpenInFileEditor, getFileExtension } from '#ui/utils/file-extensions'
|
||||
|
||||
import FileEditor from './components/editor/FileEditor.vue'
|
||||
import FileContextMenu from './components/FileContextMenu.vue'
|
||||
@@ -650,7 +650,7 @@ function handleItemHover(item: { type: string; path: string; name: string }) {
|
||||
: `${currentPath}/${item.name}`
|
||||
ctx.prefetchDirectory?.(navPath)
|
||||
}, 150)
|
||||
} else {
|
||||
} else if (canOpenInFileEditor(item.name)) {
|
||||
prefetchTimeout = setTimeout(() => {
|
||||
ctx.prefetchFile?.(item.path)
|
||||
}, 150)
|
||||
|
||||
@@ -3572,6 +3572,18 @@
|
||||
"search.filter.option.show_more": {
|
||||
"defaultMessage": "Show more"
|
||||
},
|
||||
"search.filter_type.advanced": {
|
||||
"defaultMessage": "Advanced"
|
||||
},
|
||||
"search.filter_type.advanced.exclude_datapack": {
|
||||
"defaultMessage": "Exclude data packs"
|
||||
},
|
||||
"search.filter_type.advanced.exclude_mod": {
|
||||
"defaultMessage": "Exclude mods"
|
||||
},
|
||||
"search.filter_type.advanced.exclude_plugin": {
|
||||
"defaultMessage": "Exclude plugins"
|
||||
},
|
||||
"search.filter_type.environment": {
|
||||
"defaultMessage": "Environment"
|
||||
},
|
||||
|
||||
@@ -89,6 +89,14 @@ export function isEditableFile(ext: string): boolean {
|
||||
return isCodeFile(ext) || isTextFile(ext)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file can be opened in the file editor
|
||||
*/
|
||||
export function canOpenInFileEditor(filename: string): boolean {
|
||||
const ext = getFileExtension(filename)
|
||||
return !filename.includes('.') || isEditableFile(ext) || isImageFile(ext)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ace editor language mode for a file extension
|
||||
*/
|
||||
|
||||
@@ -46,7 +46,7 @@ export type FilterType = {
|
||||
ordering?: number
|
||||
} & (
|
||||
| {
|
||||
display: 'all' | 'scrollable' | 'none'
|
||||
display: 'all' | 'scrollable' | 'none' | 'toggle'
|
||||
}
|
||||
| {
|
||||
display: 'expandable'
|
||||
@@ -112,6 +112,12 @@ export interface SortType {
|
||||
|
||||
const PLUGIN_PLATFORMS = ['bungeecord', 'waterfall', 'velocity', 'geyser']
|
||||
|
||||
const PROJECT_TYPE_EXCLUSION_FILTERS: Partial<Record<ProjectType, ProjectType[]>> = {
|
||||
mod: ['plugin', 'datapack'],
|
||||
plugin: ['mod', 'datapack'],
|
||||
datapack: ['mod', 'plugin'],
|
||||
}
|
||||
|
||||
export function useSearch(
|
||||
projectTypes: Ref<ProjectType[]>,
|
||||
tags: Ref<Tags>,
|
||||
@@ -143,6 +149,34 @@ export function useSearch(
|
||||
return formatCategory(formatMessage, categoryName)
|
||||
}
|
||||
|
||||
const formatExcludeProjectTypeLabel = (projectType: ProjectType): string => {
|
||||
switch (projectType) {
|
||||
case 'mod':
|
||||
return formatMessage(
|
||||
defineMessage({
|
||||
id: 'search.filter_type.advanced.exclude_mod',
|
||||
defaultMessage: 'Exclude mods',
|
||||
}),
|
||||
)
|
||||
case 'plugin':
|
||||
return formatMessage(
|
||||
defineMessage({
|
||||
id: 'search.filter_type.advanced.exclude_plugin',
|
||||
defaultMessage: 'Exclude plugins',
|
||||
}),
|
||||
)
|
||||
case 'datapack':
|
||||
return formatMessage(
|
||||
defineMessage({
|
||||
id: 'search.filter_type.advanced.exclude_datapack',
|
||||
defaultMessage: 'Exclude data packs',
|
||||
}),
|
||||
)
|
||||
default:
|
||||
return projectType
|
||||
}
|
||||
}
|
||||
|
||||
const filters = computed(() => {
|
||||
const categoryFilters: Record<string, FilterType> = {}
|
||||
for (const category of sortedCategories(tags.value, formatCategoryName, locale.value)) {
|
||||
@@ -171,6 +205,15 @@ export function useSearch(
|
||||
})
|
||||
}
|
||||
|
||||
const excludeableProjectTypes: ProjectType[] = []
|
||||
for (const projectType of projectTypes.value) {
|
||||
for (const target of PROJECT_TYPE_EXCLUSION_FILTERS[projectType] ?? []) {
|
||||
if (!excludeableProjectTypes.includes(target)) {
|
||||
excludeableProjectTypes.push(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const filterTypes: FilterType[] = [
|
||||
...Object.values(categoryFilters),
|
||||
{
|
||||
@@ -429,6 +472,26 @@ export function useSearch(
|
||||
options: [],
|
||||
allows_custom_options: 'and',
|
||||
},
|
||||
{
|
||||
id: 'advanced',
|
||||
formatted_name: formatMessage(
|
||||
defineMessage({
|
||||
id: 'search.filter_type.advanced',
|
||||
defaultMessage: 'Advanced',
|
||||
}),
|
||||
),
|
||||
supported_project_types: ['mod', 'plugin', 'datapack'],
|
||||
display: 'toggle',
|
||||
query_param: 'a',
|
||||
searchable: false,
|
||||
ordering: -1000,
|
||||
options: excludeableProjectTypes.map((target) => ({
|
||||
id: target,
|
||||
formatted_name: formatExcludeProjectTypeLabel(target),
|
||||
method: 'and',
|
||||
value: `all_project_types:${mapProjectTypeToSearch(target)}`,
|
||||
})),
|
||||
},
|
||||
]
|
||||
|
||||
return filterTypes
|
||||
@@ -460,6 +523,9 @@ export function useSearch(
|
||||
console.error(`Filter type ${filterValue.type} not found`)
|
||||
continue
|
||||
}
|
||||
if (type.id === 'advanced') {
|
||||
continue
|
||||
}
|
||||
let option = type?.options.find((option) => option.id === filterValue.option)
|
||||
if (!option && type.allows_custom_options) {
|
||||
option = {
|
||||
@@ -550,6 +616,15 @@ export function useSearch(
|
||||
parts.push(`project_types IN [${quoted}]`)
|
||||
}
|
||||
|
||||
const excludedProjectTypes = filterValues
|
||||
.filter((filterValue) => filterValue.type === 'advanced')
|
||||
.map((filterValue) =>
|
||||
formatSearchFilterValue(mapProjectTypeToSearch(filterValue.option as ProjectType)),
|
||||
)
|
||||
if (excludedProjectTypes.length > 0) {
|
||||
parts.push(`all_project_types NOT IN [${excludedProjectTypes.join(', ')}]`)
|
||||
}
|
||||
|
||||
return parts.join(' AND ')
|
||||
})
|
||||
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user