Compare commits

...
Author SHA1 Message Date
Gravy Boat fe64a15033 fix: keybind structuredClone only working the first time 2026-07-10 18:26:31 -02:30
ThatGravyBoatandGitHub 8680e61883 chore: misc moderation changes (#6690)
* fix: tech card not updating project status correctly

* feat: pull out quick actions into buttons for reports

* fix: reports duplicating in the reports queue

* feat: allow for moderation keybinds to be rebindable

* run prepr
2026-07-10 20:25:39 +00:00
Prospector ea86db450b changelog 2026-07-10 10:43:00 -07:00
ProspectorandGitHub bbdaa171e3 fix: remove unused facets from documentation (#6685) 2026-07-10 10:37:48 -07:00
ProspectorandGitHub af8daca059 fix: make search revalidate & change cache to be 10 minutes (#6682)
* fix: make search revalidate & change cache to be 10 minutes

* prepr
2026-07-10 16:58:45 +00:00
Truman GaoandGitHub 2434f0c45b fix: ads consent close button color (#6678)
* fix: ads consent close button

* update color
2026-07-10 16:57:56 +00:00
332dfe1074 Fix: fix passkey translation keys (#6512)
* fix: common message mentioning passkey

* devex: split title and header translation keys

* chore: rerun pnpm prepr:frontend

---------

Co-authored-by: Calum H. <calum@modrinth.com>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
2026-07-10 16:35:59 +00:00
Calum H.andGitHub c07727aa49 feat: install flow improvements (#6669)
* feat: better error handling + copy details btn for info

* refactor: clean up error handling into diagnostics

* feat: extra info for failure states + queuing properly

* fix: cleanup

* fix: lint

* fix: fmt

* fix: cleanup

* fix: cleanup

* fix: lint

* feat: use bon builder
2026-07-10 11:54:56 +00:00
aecsocketandGitHub 57a977f7f3 feat: use v1 version manifest for Quilt (#6650)
* wip: app-side logic

* lints

* fmt

* fmt

* Split Daedalus changes out of frontend branch

* Remove Daedalus changes from frontend branch
2026-07-10 11:17:41 +00:00
NitrrineandGitHub 323d088ebd fix: light mode icon shows in dark mode (#6614)
* fix: light mode icon shows in dark mode

* feat: use os icons from assets repo

* revert initial changes

* fix: lint
2026-07-09 21:43:13 +00:00
Truman GaoandGitHub 46f94bd067 fix: download modal no compatible empty state (#6680) 2026-07-09 21:37:09 +00:00
aecsocketandGitHub e877167db7 feat: global trace database frontend + improvements to tech review status sync (#6671)
* wip

* ui edits

* better logic for syncing tech review state in a single centralized place

* never automatically finish a tech review report

* fix css

* fix clippy

* prepr
2026-07-09 16:09:02 +00:00
Prospector 623b51e6ea update ads.txt 2026-07-09 08:37:23 -07:00
Prospector 5face9e56a changelog 2026-07-08 15:58:31 -07:00
40aff1e8bb feat: download modal changes (#6652)
* update download with modrinth app button

* feat: implement compatible version card and update download dependency buttons

* fix: download multiple files immediately triggers blocking

* refactor: implement download modal provider

* fix: duplicate dependencies and style update for dependecy section

* feat: improve loading flow when there are dependencies, to not show compatible version until all data is loaded

* fix: fallback to download compatible version if dependency lookup fails

* feat: implement selecting compatible versions when there are multiple

* fix: update dependencies version table to any compatible version

* fix: version showing before depedencies loaded

* feat: add platform options sort order

* pnpm prepr

* feat: keep previous result showing until new one loads in when change compatibility options

* feat: implement better handling for showing required/recommended resource packs with additional files

* pnpm prepr

* fix: required resource pack not showing footer actions

* fix: download with deps is downloading all files

* feat: add joined button for downloading with recommended

* feat: add admontion for dependency that has resource pack to download

* pnpm prepr

* fix: lint

* feat: append "-EXTRACT_ME.zip" to zipped project with dependencies

* fix: date published capitalization

* pnpm prepr

---------

Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
2026-07-08 22:54:23 +00:00
SychicandGitHub 5f8837604d feat(labrinth): shared instance icon (#6665) 2026-07-08 22:45:15 +00:00
ProspectorandGitHub 795dad040f feat: add complementary installer source support (#6667) 2026-07-08 15:44:59 -07:00
Truman GaoandGitHub 9ca181dc1a fix: privacy popup in app bounded to tiny webview (#6657) 2026-07-08 16:29:41 +00:00
aecsocketandGitHub c84b658e41 feat: tech review global trace database (#6648)
* global detail verdicts system

* global traces frontend

* split global routes into own mod

* tweak migration to only do no-key check at app level

* prepr
2026-07-08 16:06:45 +00:00
159 changed files with 8297 additions and 2265 deletions
Generated
+26
View File
@@ -1628,6 +1628,31 @@ dependencies = [
"serde_with",
]
[[package]]
name = "bon"
version = "3.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a602c73c7b0148ec6d12af6fd5cc7a46e2eacc8878271a999abac56eed12f561"
dependencies = [
"bon-macros",
"rustversion",
]
[[package]]
name = "bon-macros"
version = "3.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dee98b0db6a962de883bf5d20362dee4d7ca0d12fe39a7c6c73c844e1cd7c1f"
dependencies = [
"darling 0.23.0",
"ident_case",
"prettyplease",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.106",
]
[[package]]
name = "borsh"
version = "1.5.7"
@@ -10849,6 +10874,7 @@ dependencies = [
"async-walkdir",
"async_zip",
"base64 0.22.1",
"bon",
"bytemuck",
"bytes",
"chardetng",
+1
View File
@@ -51,6 +51,7 @@ aws-sdk-s3 = { version = "=1.122.0", default-features = false, features = [
] }
base64 = "0.22.1"
bitflags = "2.9.4"
bon = "3.9.3"
bytemuck = "1.24.0"
bytes = "1.10.1"
censor = "0.3.0"
@@ -269,16 +269,31 @@ provideInstallationSettings({
debug('resolveLoaderVersions: no manifest', { loader, gameVersion })
return []
}
if (loader === 'fabric' || loader === 'quilt') {
const result = manifest.gameVersions[0]?.loaders ?? []
debug('resolveLoaderVersions: fabric/quilt result', {
const entry = manifest.gameVersions?.find((item) => item.id === gameVersion)
if (entry?.versionGroup) {
const result =
manifest.versionGroups?.find((group) => group.id === entry.versionGroup)?.loaders ?? []
debug('resolveLoaderVersions: version group result', {
loader,
gameVersion,
versionGroup: entry.versionGroup,
count: result.length,
})
return result
}
const placeholder = manifest.gameVersions?.find((item) => item.id === '${modrinth.gameVersion}')
if (placeholder) {
const result = manifest.gameVersions?.some((item) => item.id === gameVersion)
? placeholder.loaders
: []
debug('resolveLoaderVersions: placeholder result', {
loader,
gameVersion,
count: result.length,
})
return result
}
const result = manifest.gameVersions?.find((item) => item.id === gameVersion)?.loaders ?? []
const result = entry?.loaders ?? []
debug('resolveLoaderVersions: result', { loader, gameVersion, count: result.length })
return result
},
@@ -1,4 +1,4 @@
import { UpdatedIcon } from '@modrinth/assets'
import { CheckIcon, CopyIcon, UpdatedIcon } from '@modrinth/assets'
import {
defineMessages,
type PopupNotificationButton,
@@ -15,9 +15,11 @@ import {
install_job_dismiss,
install_job_list,
install_job_retry,
install_job_support_details,
installJobInstanceId,
type InstallJobSnapshot,
type InstallJobStatus,
type InstallPhaseId,
type InstallProgress,
} from '@/helpers/install'
import { get_many as getInstances } from '@/helpers/instance'
@@ -31,6 +33,14 @@ const messages = defineMessages({
id: 'app.action-bar.install.retry',
defaultMessage: 'Retry',
},
copyDetails: {
id: 'app.action-bar.install.copy-details',
defaultMessage: 'Copy details',
},
copied: {
id: 'app.action-bar.install.copied-details',
defaultMessage: 'Copied',
},
dismiss: {
id: 'app.action-bar.install.dismiss',
defaultMessage: 'Dismiss',
@@ -39,22 +49,6 @@ const messages = defineMessages({
id: 'app.action-bar.install.open-instance',
defaultMessage: 'Open instance',
},
installFailed: {
id: 'app.action-bar.install.failed',
defaultMessage: 'Install failed',
},
installFailedAppClosed: {
id: 'app.action-bar.install.failed-app-closed',
defaultMessage: 'Installation failed due to app closing.',
},
installFailedNetwork: {
id: 'app.action-bar.install.failed-network',
defaultMessage: 'Installation failed due to a network error.',
},
installFailedUnknown: {
id: 'app.action-bar.install.failed-unknown',
defaultMessage: 'Installation failed due to an unknown error.',
},
unknownInstance: {
id: 'app.action-bar.install.unknown-instance',
defaultMessage: 'Unknown instance',
@@ -64,7 +58,7 @@ const messages = defineMessages({
const phaseMessages = defineMessages({
preparing_instance: {
id: 'app.install.phase.preparing_instance',
defaultMessage: 'Preparing instance',
defaultMessage: 'Queued to install',
},
resolving_pack: {
id: 'app.install.phase.resolving_pack',
@@ -139,7 +133,97 @@ const javaStepMessages = defineMessages({
},
})
const failureSummaryMessages = defineMessages({
canceled: {
id: 'app.action-bar.install.summary.canceled',
defaultMessage: 'Canceled',
},
appClosed: {
id: 'app.action-bar.install.summary.app-closing',
defaultMessage: 'Canceled due to app closing',
},
downloadFailed: {
id: 'app.action-bar.install.summary.download-failed',
defaultMessage: "Download couldn't finish",
},
modrinthUnreachable: {
id: 'app.action-bar.install.summary.modrinth-unreachable',
defaultMessage: "Couldn't reach Modrinth",
},
packDownloadFailed: {
id: 'app.action-bar.install.summary.pack-download-failed',
defaultMessage: "Couldn't download pack",
},
badModpackFile: {
id: 'app.action-bar.install.summary.bad-modpack-file',
defaultMessage: "Couldn't read modpack",
},
invalidModpack: {
id: 'app.action-bar.install.summary.invalid-modpack',
defaultMessage: 'Modpack data invalid',
},
contentDownloadFailed: {
id: 'app.action-bar.install.summary.content-download-failed',
defaultMessage: "Couldn't download files",
},
corruptDownload: {
id: 'app.action-bar.install.summary.corrupt-download',
defaultMessage: 'Downloaded file is corrupt',
},
invalidModpackFiles: {
id: 'app.action-bar.install.summary.invalid-modpack-files',
defaultMessage: 'Modpack files have invalid metadata',
},
noWritePermission: {
id: 'app.action-bar.install.summary.no-write-permission',
defaultMessage: 'No permission to write',
},
couldNotSaveFiles: {
id: 'app.action-bar.install.summary.could-not-save-files',
defaultMessage: "Couldn't save files",
},
invalidFilePath: {
id: 'app.action-bar.install.summary.invalid-file-path',
defaultMessage: 'File path is invalid',
},
instanceNotFound: {
id: 'app.action-bar.install.summary.instance-not-found',
defaultMessage: "Instance couldn't be found",
},
cleanupIncomplete: {
id: 'app.action-bar.install.summary.cleanup-incomplete',
defaultMessage: "Cleanup didn't finish",
},
javaSetupFailed: {
id: 'app.action-bar.install.summary.java-setup-failed',
defaultMessage: "Java setup couldn't finish",
},
minecraftSetupFailed: {
id: 'app.action-bar.install.summary.minecraft-setup-failed',
defaultMessage: 'Minecraft setup failed',
},
loaderSetupFailed: {
id: 'app.action-bar.install.summary.loader-setup-failed',
defaultMessage: 'Loader setup failed',
},
localDataError: {
id: 'app.action-bar.install.summary.local-data-error',
defaultMessage: "Couldn't update local data",
},
unexpectedError: {
id: 'app.action-bar.install.summary.unexpected-error',
defaultMessage: 'Something went wrong',
},
})
const visibleJobStatuses = new Set<InstallJobStatus>(['queued', 'running', 'failed', 'interrupted'])
const copyDetailsStallMs = 30_000
interface ProgressSnapshot {
signature: string
changedAt: number
timeout: number | null
}
function getDisplayIconUrl(icon: string | null | undefined): string | null {
if (!icon) return null
@@ -156,10 +240,13 @@ export async function useInstallJobNotifications(opts: {
const jobs = ref<InstallJobSnapshot[]>([])
const iconUrls = ref<Record<string, string | null>>({})
const instanceNames = ref<Record<string, string>>({})
const copiedJobIds = ref<Set<string>>(new Set())
const jobOrder = new Map<string, number>()
let refreshRequest = 0
let metadataRequest = 0
let nextJobOrder = 0
const copiedResetTimeouts = new Map<string, number>()
const progressSnapshots = new Map<string, ProgressSnapshot>()
function getTitle(job: InstallJobSnapshot): string {
if (job.display?.title) return job.display.title
@@ -174,13 +261,7 @@ export async function useInstallJobNotifications(opts: {
function getText(job: InstallJobSnapshot): string {
if (job.status === 'failed' || job.status === 'interrupted') {
if (job.error?.code === 'interrupted') {
return formatMessage(messages.installFailedAppClosed)
}
if (job.error?.code === 'network_error') {
return formatMessage(messages.installFailedNetwork)
}
return formatMessage(messages.installFailedUnknown)
return getFailureSummary(job)
}
if (job.phase === 'preparing_java' && job.details.type === 'java') {
return formatMessage(javaStepMessages[job.details.step], {
@@ -190,6 +271,104 @@ export async function useInstallJobNotifications(opts: {
return formatMessage(phaseMessages[job.phase])
}
function getFailureSummary(job: InstallJobSnapshot): string {
const code = job.error?.code
const phase = job.error?.phase ?? job.phase
if (code === 'app_closed' || (job.status === 'interrupted' && code === 'interrupted')) {
return formatMessage(failureSummaryMessages.appClosed)
}
if (code === 'canceled') {
return formatMessage(failureSummaryMessages.canceled)
}
if (job.rollback_error || code === 'rollback_error') {
return formatMessage(failureSummaryMessages.cleanupIncomplete)
}
if (hasPermissionError(job)) {
return formatMessage(failureSummaryMessages.noWritePermission)
}
switch (code) {
case 'network_error':
return formatMessage(
phase === 'downloading_pack_file'
? failureSummaryMessages.packDownloadFailed
: failureSummaryMessages.downloadFailed,
)
case 'api_error':
return formatMessage(failureSummaryMessages.modrinthUnreachable)
case 'pack_error':
return formatMessage(
phase === 'downloading_pack_file'
? failureSummaryMessages.packDownloadFailed
: failureSummaryMessages.invalidModpack,
)
case 'archive_error':
return formatMessage(failureSummaryMessages.badModpackFile)
case 'parse_error':
return formatMessage(failureSummaryMessages.invalidModpack)
case 'content_error':
return formatMessage(failureSummaryMessages.invalidModpackFiles)
case 'hash_error':
return formatMessage(failureSummaryMessages.corruptDownload)
case 'filesystem_error':
return formatMessage(failureSummaryMessages.couldNotSaveFiles)
case 'path_error':
return formatMessage(failureSummaryMessages.invalidFilePath)
case 'instance_error':
return formatMessage(failureSummaryMessages.instanceNotFound)
case 'java_error':
return formatMessage(failureSummaryMessages.javaSetupFailed)
case 'loader_error':
case 'processor_error':
return formatMessage(failureSummaryMessages.loaderSetupFailed)
case 'database_error':
return formatMessage(failureSummaryMessages.localDataError)
case 'launcher_error':
case 'metadata_error':
return getFailureSummaryForPhase(phase)
default:
return getFailureSummaryForPhase(phase)
}
}
function getFailureSummaryForPhase(phase: InstallPhaseId): string {
switch (phase) {
case 'downloading_pack_file':
return formatMessage(failureSummaryMessages.packDownloadFailed)
case 'resolving_pack':
case 'reading_pack_manifest':
return formatMessage(failureSummaryMessages.invalidModpack)
case 'downloading_content':
return formatMessage(failureSummaryMessages.contentDownloadFailed)
case 'extracting_overrides':
return formatMessage(failureSummaryMessages.couldNotSaveFiles)
case 'resolving_minecraft':
case 'downloading_minecraft':
return formatMessage(failureSummaryMessages.minecraftSetupFailed)
case 'resolving_loader':
case 'running_loader_processors':
return formatMessage(failureSummaryMessages.loaderSetupFailed)
case 'preparing_java':
return formatMessage(failureSummaryMessages.javaSetupFailed)
case 'preparing_instance':
return formatMessage(failureSummaryMessages.instanceNotFound)
case 'rolling_back':
return formatMessage(failureSummaryMessages.cleanupIncomplete)
default:
return formatMessage(failureSummaryMessages.unexpectedError)
}
}
function hasPermissionError(job: InstallJobSnapshot): boolean {
const message = job.error?.message.toLowerCase() ?? ''
return (
message.includes('permission denied') ||
message.includes('access is denied') ||
message.includes('operation not permitted')
)
}
function getProgressType(job: InstallJobSnapshot): PopupNotificationProgressType | undefined {
if (!getEffectiveProgress(job)) return undefined
if (
@@ -235,11 +414,165 @@ export async function useInstallJobNotifications(opts: {
return job.status === 'failed' || job.status === 'interrupted'
}
function getTerminalButtons(job: InstallJobSnapshot): PopupNotificationButton[] | undefined {
if (!isTerminalJob(job)) return undefined
function canShowStalledProgressDetails(job: InstallJobSnapshot): boolean {
return (
job.status === 'running' &&
job.phase !== 'preparing_instance' &&
job.phase !== 'finalizing' &&
job.phase !== 'rolling_back'
)
}
function getJobSortRank(job: InstallJobSnapshot): number {
if (isTerminalJob(job)) return 0
if (job.status === 'queued' || job.phase === 'preparing_instance') return 2
return 1
}
function progressSignature(job: InstallJobSnapshot): string {
const progress = job.progress
const secondary = progress?.secondary
return [
{
job.status,
job.phase,
JSON.stringify(job.details),
progress?.current ?? '',
progress?.total ?? '',
secondary?.current ?? '',
secondary?.total ?? '',
].join(':')
}
function clearCopied(jobId: string) {
if (!copiedJobIds.value.has(jobId)) {
return
}
const timeout = copiedResetTimeouts.get(jobId)
if (timeout != null) {
window.clearTimeout(timeout)
copiedResetTimeouts.delete(jobId)
}
const nextCopiedJobIds = new Set(copiedJobIds.value)
nextCopiedJobIds.delete(jobId)
copiedJobIds.value = nextCopiedJobIds
}
function clearProgressSnapshot(jobId: string) {
const snapshot = progressSnapshots.get(jobId)
if (snapshot?.timeout != null) {
window.clearTimeout(snapshot.timeout)
}
progressSnapshots.delete(jobId)
}
function scheduleStaleProgressRefresh(jobId: string) {
const snapshot = progressSnapshots.get(jobId)
if (!snapshot) {
return
}
snapshot.timeout = window.setTimeout(() => {
const snapshot = progressSnapshots.get(jobId)
if (!snapshot) {
return
}
snapshot.timeout = null
opts.onChange()
}, copyDetailsStallMs)
}
function syncProgressSnapshots(nextJobs: InstallJobSnapshot[]) {
const trackedJobIds = new Set<string>()
const now = Date.now()
for (const job of nextJobs) {
if (!canShowStalledProgressDetails(job)) {
continue
}
trackedJobIds.add(job.job_id)
const signature = progressSignature(job)
const snapshot = progressSnapshots.get(job.job_id)
if (snapshot?.signature === signature) {
continue
}
clearProgressSnapshot(job.job_id)
clearCopied(job.job_id)
progressSnapshots.set(job.job_id, {
signature,
changedAt: now,
timeout: null,
})
scheduleStaleProgressRefresh(job.job_id)
}
for (const jobId of progressSnapshots.keys()) {
if (!trackedJobIds.has(jobId)) {
clearProgressSnapshot(jobId)
}
}
}
function hasStalledProgress(job: InstallJobSnapshot): boolean {
const snapshot = progressSnapshots.get(job.job_id)
return !!snapshot && Date.now() - snapshot.changedAt >= copyDetailsStallMs
}
function shouldShowCopyDetails(job: InstallJobSnapshot): boolean {
return isTerminalJob(job) || (canShowStalledProgressDetails(job) && hasStalledProgress(job))
}
function isCopied(job: InstallJobSnapshot): boolean {
return copiedJobIds.value.has(job.job_id)
}
function setCopied(job: InstallJobSnapshot) {
copiedJobIds.value = new Set([...copiedJobIds.value, job.job_id])
const existingTimeout = copiedResetTimeouts.get(job.job_id)
if (existingTimeout != null) {
window.clearTimeout(existingTimeout)
}
copiedResetTimeouts.set(
job.job_id,
window.setTimeout(() => {
copiedResetTimeouts.delete(job.job_id)
if (!copiedJobIds.value.has(job.job_id)) {
return
}
const nextCopiedJobIds = new Set(copiedJobIds.value)
nextCopiedJobIds.delete(job.job_id)
copiedJobIds.value = nextCopiedJobIds
opts.onChange()
}, 1_000),
)
opts.onChange()
}
async function copyJobDetails(job: InstallJobSnapshot) {
const details = await install_job_support_details(job.job_id).catch((error) => {
opts.handleError(error)
return null
})
if (!details) {
return
}
try {
await navigator.clipboard.writeText(details)
setCopied(job)
} catch (error) {
opts.handleError(error)
}
}
function getButtons(job: InstallJobSnapshot): PopupNotificationButton[] {
const buttons: PopupNotificationButton[] = []
if (isTerminalJob(job)) {
buttons.push({
label: formatMessage(messages.retry),
icon: UpdatedIcon,
color: 'brand',
@@ -248,8 +581,23 @@ export async function useInstallJobNotifications(opts: {
await install_job_retry(job.job_id).catch(opts.handleError)
await refresh()
},
},
]
})
}
if (shouldShowCopyDetails(job)) {
const copied = isCopied(job)
buttons.push({
label: formatMessage(copied ? messages.copied : messages.copyDetails),
icon: copied ? CheckIcon : CopyIcon,
color: 'standard',
keepOpen: true,
action: async () => {
await copyJobDetails(job)
},
})
}
return buttons
}
function setJobs(nextJobs: InstallJobSnapshot[]) {
@@ -259,13 +607,15 @@ export async function useInstallJobNotifications(opts: {
}
}
jobs.value = nextJobs
.filter((job) => visibleJobStatuses.has(job.status))
.sort(
(a, b) =>
a.created.localeCompare(b.created) ||
(jobOrder.get(a.job_id) ?? 0) - (jobOrder.get(b.job_id) ?? 0),
)
const visibleJobs = nextJobs.filter((job) => visibleJobStatuses.has(job.status))
syncProgressSnapshots(visibleJobs)
jobs.value = visibleJobs.sort(
(a, b) =>
getJobSortRank(a) - getJobSortRank(b) ||
a.created.localeCompare(b.created) ||
(jobOrder.get(a.job_id) ?? 0) - (jobOrder.get(b.job_id) ?? 0),
)
}
const progressItems = computed<PopupNotificationProgressItem[]>(() =>
@@ -284,7 +634,7 @@ export async function useInstallJobNotifications(opts: {
progressType: isTerminalJob(job) ? undefined : getProgressType(job),
progressCurrent: isTerminalJob(job) ? undefined : progress?.current,
progressTotal: isTerminalJob(job) ? undefined : progress?.total,
buttons: getTerminalButtons(job),
buttons: getButtons(job),
onDismiss: isTerminalJob(job)
? async () => {
await install_job_dismiss(job.job_id).catch(opts.handleError)
@@ -382,6 +732,14 @@ export async function useInstallJobNotifications(opts: {
progressItems,
buttons,
refresh,
dispose: () => unlisten(),
dispose: () => {
for (const timeout of copiedResetTimeouts.values()) {
window.clearTimeout(timeout)
}
for (const jobId of progressSnapshots.keys()) {
clearProgressSnapshot(jobId)
}
unlisten()
},
}
}
+36 -1
View File
@@ -85,6 +85,36 @@ export type InstallJavaStep =
| 'extracting'
| 'validating'
export interface InstallErrorView {
code: string
phase?: InstallPhaseId | null
message: string
api?: {
error: string
status?: number | null
method?: string | null
url?: string | null
route?: string | null
} | null
context?: {
operation: string
source_path?: string | null
target_path?: string | null
file_path?: string | null
entry_path?: string | null
urls?: string[]
expected_hash?: string | null
expected_size?: number | null
project_id?: string | null
version_id?: string | null
minecraft_version?: string | null
loader?: string | null
java_version?: number | null
os?: string | null
arch?: string | null
} | null
}
export interface InstallJobSnapshot {
job_id: string
instance_id?: string | null
@@ -114,7 +144,8 @@ export interface InstallJobSnapshot {
}
| { type: 'import'; launcher_type: string; instance_folder: string }
display?: { title: string; icon?: string | null } | null
error?: { code: string; message: string } | null
error?: InstallErrorView | null
rollback_error?: InstallErrorView | null
created: string
modified: string
finished?: string | null
@@ -197,6 +228,10 @@ export async function install_job_dismiss(jobId: string) {
return await invoke<void>('plugin:install|install_job_dismiss', { jobId })
}
export async function install_job_support_details(jobId: string) {
return await invoke<string>('plugin:install|install_job_support_details', { jobId })
}
export function installJobInstanceId(job: InstallJobSnapshot): string | null {
return job.instance_id ?? job.target.instance_id ?? null
}
+7
View File
@@ -133,11 +133,18 @@ type Hooks = {
type Manifest = {
gameVersions: ManifestGameVersion[]
versionGroups?: ManifestVersionGroup[]
}
type ManifestGameVersion = {
id: string
stable: boolean
versionGroup?: string
loaders: ManifestLoaderVersion[]
}
type ManifestVersionGroup = {
id: string
loaders: ManifestLoaderVersion[]
}
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Zavřít"
},
"app.action-bar.install.failed": {
"message": "Instalace selhala"
},
"app.action-bar.install.failed-app-closed": {
"message": "Instalace selhala kvůli zavření aplikace."
},
"app.action-bar.install.failed-network": {
"message": "Instalace selhala kvůli chybě sítě."
},
"app.action-bar.install.failed-unknown": {
"message": "Instalace selhala kvůli neznámé chybě."
},
"app.action-bar.install.open-instance": {
"message": "Otevřít instanci"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Ignorieren"
},
"app.action-bar.install.failed": {
"message": "Installation fehlgeschlagen"
},
"app.action-bar.install.failed-app-closed": {
"message": "Installation aufgrund des Schließens der App fehlgeschlagen."
},
"app.action-bar.install.failed-network": {
"message": "Installation aufgrund eines Netzwerkfehlers fehlgeschlagen."
},
"app.action-bar.install.failed-unknown": {
"message": "Installation aufgrund eines unbekannten Fehlers fehlgeschlagen."
},
"app.action-bar.install.open-instance": {
"message": "Instanz öffnen"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Ausblenden"
},
"app.action-bar.install.failed": {
"message": "Installation fehlgeschlagen"
},
"app.action-bar.install.failed-app-closed": {
"message": "Installation aufgrund des Schließens der App fehlgeschlagen."
},
"app.action-bar.install.failed-network": {
"message": "Installation aufgrund eines Netzwerkfehlers fehlgeschlagen."
},
"app.action-bar.install.failed-unknown": {
"message": "Installation aufgrund eines unbekannten Fehlers fehlgeschlagen."
},
"app.action-bar.install.open-instance": {
"message": "Instanz öffnen"
},
+67 -13
View File
@@ -11,27 +11,81 @@
"app.action-bar.hide-more-running-instances": {
"message": "Hide more running instances"
},
"app.action-bar.install.copied-details": {
"message": "Copied"
},
"app.action-bar.install.copy-details": {
"message": "Copy details"
},
"app.action-bar.install.dismiss": {
"message": "Dismiss"
},
"app.action-bar.install.failed": {
"message": "Install failed"
},
"app.action-bar.install.failed-app-closed": {
"message": "Installation failed due to app closing."
},
"app.action-bar.install.failed-network": {
"message": "Installation failed due to a network error."
},
"app.action-bar.install.failed-unknown": {
"message": "Installation failed due to an unknown error."
},
"app.action-bar.install.open-instance": {
"message": "Open instance"
},
"app.action-bar.install.retry": {
"message": "Retry"
},
"app.action-bar.install.summary.app-closing": {
"message": "Canceled due to app closing"
},
"app.action-bar.install.summary.bad-modpack-file": {
"message": "Couldn't read modpack"
},
"app.action-bar.install.summary.canceled": {
"message": "Canceled"
},
"app.action-bar.install.summary.cleanup-incomplete": {
"message": "Cleanup didn't finish"
},
"app.action-bar.install.summary.content-download-failed": {
"message": "Couldn't download files"
},
"app.action-bar.install.summary.corrupt-download": {
"message": "Downloaded file is corrupt"
},
"app.action-bar.install.summary.could-not-save-files": {
"message": "Couldn't save files"
},
"app.action-bar.install.summary.download-failed": {
"message": "Download couldn't finish"
},
"app.action-bar.install.summary.instance-not-found": {
"message": "Instance couldn't be found"
},
"app.action-bar.install.summary.invalid-file-path": {
"message": "File path is invalid"
},
"app.action-bar.install.summary.invalid-modpack": {
"message": "Modpack data invalid"
},
"app.action-bar.install.summary.invalid-modpack-files": {
"message": "Modpack files have invalid metadata"
},
"app.action-bar.install.summary.java-setup-failed": {
"message": "Java setup couldn't finish"
},
"app.action-bar.install.summary.loader-setup-failed": {
"message": "Loader setup failed"
},
"app.action-bar.install.summary.local-data-error": {
"message": "Couldn't update local data"
},
"app.action-bar.install.summary.minecraft-setup-failed": {
"message": "Minecraft setup failed"
},
"app.action-bar.install.summary.modrinth-unreachable": {
"message": "Couldn't reach Modrinth"
},
"app.action-bar.install.summary.no-write-permission": {
"message": "No permission to write"
},
"app.action-bar.install.summary.pack-download-failed": {
"message": "Couldn't download pack"
},
"app.action-bar.install.summary.unexpected-error": {
"message": "Something went wrong"
},
"app.action-bar.install.unknown-instance": {
"message": "Unknown instance"
},
@@ -231,7 +285,7 @@
"message": "Finalizing"
},
"app.install.phase.preparing_instance": {
"message": "Preparing instance"
"message": "Queued to install"
},
"app.install.phase.preparing_java": {
"message": "Preparing Java"
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Descartar"
},
"app.action-bar.install.failed": {
"message": "La instalación falló"
},
"app.action-bar.install.failed-app-closed": {
"message": "La instalación falló porque la aplicación se cerró."
},
"app.action-bar.install.failed-network": {
"message": "La instalación falló debido a un error de red."
},
"app.action-bar.install.failed-unknown": {
"message": "La instalación falló debido a un error desconocido."
},
"app.action-bar.install.open-instance": {
"message": "Abrir instancia"
},
@@ -14,15 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Descartar"
},
"app.action-bar.install.failed": {
"message": "La instalación falló"
},
"app.action-bar.install.failed-app-closed": {
"message": "La instalación falló porque la aplicación se cerró."
},
"app.action-bar.install.failed-network": {
"message": "La instalación falló debido a un error de red."
},
"app.action-bar.make-primary-instance": {
"message": "Establecer como instancia principal"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Hylkää"
},
"app.action-bar.install.failed": {
"message": "Asennus epäonnistui"
},
"app.action-bar.install.failed-app-closed": {
"message": "Asennus epäonnistui sovelluksen sulkeutumisen vuoksi."
},
"app.action-bar.install.failed-network": {
"message": "Asennus epäonnistui verkkovirheen vuoksi."
},
"app.action-bar.install.failed-unknown": {
"message": "Asennus epäonnistui tuntemattoman virheen vuoksi."
},
"app.action-bar.install.open-instance": {
"message": "Avaa instanssi"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Rejeter"
},
"app.action-bar.install.failed": {
"message": "Échec de l'installation"
},
"app.action-bar.install.failed-app-closed": {
"message": "Échec de l'installation dû à la fermeture de l'app."
},
"app.action-bar.install.failed-network": {
"message": "Échec de l'installation dû à une erreur réseau."
},
"app.action-bar.install.failed-unknown": {
"message": "Échec de l'installation dû à une erreur inconnue."
},
"app.action-bar.install.open-instance": {
"message": "Ouvrir l'instance"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Ignora"
},
"app.action-bar.install.failed": {
"message": "Installazione fallita"
},
"app.action-bar.install.failed-app-closed": {
"message": "Installazione fallita: l'app è stata chiusa."
},
"app.action-bar.install.failed-network": {
"message": "Installazione fallita: errore di rete."
},
"app.action-bar.install.failed-unknown": {
"message": "Installazione fallita: errore sconosciuto."
},
"app.action-bar.install.open-instance": {
"message": "Apri istanza"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Odrzuć"
},
"app.action-bar.install.failed": {
"message": "Instalacja nie powiodła się"
},
"app.action-bar.install.failed-app-closed": {
"message": "Instalacja nie powiodła się z powodu zamknięcia aplikacji."
},
"app.action-bar.install.failed-network": {
"message": "Instalacja nie powiodła się z powodu problemów z połączeniem."
},
"app.action-bar.install.failed-unknown": {
"message": "Instalacja nie powiodła się z nieznanych przyczyn."
},
"app.action-bar.install.open-instance": {
"message": "Otwórz instancję"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Dispensar"
},
"app.action-bar.install.failed": {
"message": "Instalação falha"
},
"app.action-bar.install.failed-app-closed": {
"message": "A instalação falhou devido ao aplicativo ter fechado."
},
"app.action-bar.install.failed-network": {
"message": "A instalação falhou devido a um erro na rede."
},
"app.action-bar.install.failed-unknown": {
"message": "A instalação falhou devido a um erro desconhecido."
},
"app.action-bar.install.open-instance": {
"message": "Abrir instância"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Закрыть"
},
"app.action-bar.install.failed": {
"message": "Установка не удалась"
},
"app.action-bar.install.failed-app-closed": {
"message": "Установка не удалась из-за закрытия приложения."
},
"app.action-bar.install.failed-network": {
"message": "Установка не удалась из-за сетевой ошибки."
},
"app.action-bar.install.failed-unknown": {
"message": "Установка не удалась из-за неизвестной ошибки."
},
"app.action-bar.install.open-instance": {
"message": "Открыть сборку"
},
@@ -1,10 +1,4 @@
{
"app.action-bar.install.failed": {
"message": "Neuspešna instalacija"
},
"app.action-bar.install.failed-app-closed": {
"message": "Neuspešna instalacija zbog zatvaranja aplikacije."
},
"app.auth-servers.unreachable.body": {
"message": "Minecraft serveri za autentifikaciju su možda trenutno nedostupni. Molimo vas da proverite vašu internet vezu i pokušajte ponovo kasnije."
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Avvisa"
},
"app.action-bar.install.failed": {
"message": "Installationen misslyckades"
},
"app.action-bar.install.failed-app-closed": {
"message": "Installationen misslyckades för att appen stängdes."
},
"app.action-bar.install.failed-network": {
"message": "Installationen misslyckades av ett nätverksfel."
},
"app.action-bar.install.failed-unknown": {
"message": "Installationen misslyckades med ett okänt fel."
},
"app.action-bar.install.open-instance": {
"message": "Öppna instans"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "Reddet"
},
"app.action-bar.install.failed": {
"message": "Yükleme yapılamadı"
},
"app.action-bar.install.failed-app-closed": {
"message": "Yükleme uygulama kapandığından yapılamadı."
},
"app.action-bar.install.failed-network": {
"message": "Yükleme ağ hatasından dolayı yapılamadı."
},
"app.action-bar.install.failed-unknown": {
"message": "Yükleme bilinmeyen bir hatadan yapılamadı."
},
"app.action-bar.install.open-instance": {
"message": "Kurulumu aç"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "忽略"
},
"app.action-bar.install.failed": {
"message": "安装失败"
},
"app.action-bar.install.failed-app-closed": {
"message": "由于应用关闭,安装失败。"
},
"app.action-bar.install.failed-network": {
"message": "由于网络错误,安装失败。"
},
"app.action-bar.install.failed-unknown": {
"message": "由于未知错误,安装失败。"
},
"app.action-bar.install.open-instance": {
"message": "打开实例"
},
@@ -14,18 +14,6 @@
"app.action-bar.install.dismiss": {
"message": "忽略"
},
"app.action-bar.install.failed": {
"message": "無法安裝"
},
"app.action-bar.install.failed-app-closed": {
"message": "由於應用程式關閉,無法安裝。"
},
"app.action-bar.install.failed-network": {
"message": "由於網路錯誤,無法安裝。"
},
"app.action-bar.install.failed-unknown": {
"message": "由於未知錯誤,無法安裝。"
},
"app.action-bar.install.open-instance": {
"message": "開啟實例"
},
+1 -1
View File
@@ -884,7 +884,7 @@ async function search(requestParams: string) {
const rawResults = await queryClient.fetchQuery({
queryKey: ['search', 'v3', requestParams],
queryFn: () =>
get_search_results_v3(requestParams) as Promise<{
get_search_results_v3(requestParams, 'must_revalidate') as Promise<{
result: Labrinth.Search.v3.SearchResults & {
hits: (Labrinth.Search.v3.ResultSearchProject & { installed?: boolean })[]
}
+3
View File
@@ -157,6 +157,7 @@ fn main() {
"install_job_retry",
"install_job_cancel",
"install_job_dismiss",
"install_job_support_details",
])
.default_permission(
DefaultPermissionRule::AllowAllCommands,
@@ -276,6 +277,8 @@ fn main() {
"hide_ads_window",
"scroll_ads_window",
"show_ads_window",
"show_ads_consent_overlay",
"hide_ads_consent_overlay",
"record_ads_click",
"open_link",
"get_ads_personalization",
+99 -3
View File
@@ -1,14 +1,16 @@
const MODRINTH_ORIGIN = 'https://modrinth.com'
document.addEventListener(
'click',
function (e) {
window.top.postMessage({ modrinthAdClick: true }, 'https://modrinth.com')
window.top.postMessage({ modrinthAdClick: true }, MODRINTH_ORIGIN)
let target = e.target
while (target != null) {
if (target.matches('a')) {
e.preventDefault()
if (target.href) {
window.top.postMessage({ modrinthOpenUrl: target.href }, 'https://modrinth.com')
window.top.postMessage({ modrinthOpenUrl: target.href }, MODRINTH_ORIGIN)
}
break
}
@@ -19,7 +21,97 @@ document.addEventListener(
)
window.open = (url, target, features) => {
window.top.postMessage({ modrinthOpenUrl: url }, 'https://modrinth.com')
window.top.postMessage({ modrinthOpenUrl: url }, MODRINTH_ORIGIN)
}
let modrinthAdsConsentOverlayShown = false
let modrinthTcfListenerInstalled = false
let modrinthTcfListenerAttempts = 0
function installAdsConsentOverlayStyle() {
if (document.getElementById('modrinth-ads-consent-overlay-style')) {
return
}
const style = document.createElement('style')
style.id = 'modrinth-ads-consent-overlay-style'
style.textContent = `
html.modrinth-ads-consent-overlay #modrinth-rail-1 {
visibility: hidden !important;
}
.qc-cmp2-close-icon {
background: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M.5.5l23 23m0-23l-23 23' fill='none' stroke='%23b0bac5' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10'/%3E%3Cpath fill='none' d='M0 0h24v24H0z'/%3E%3C/svg%3E") 0% 0% / 66% auto no-repeat !important;
}
`
document.documentElement.appendChild(style)
}
function getTauriInvoke() {
return window.__TAURI__?.core?.invoke ?? window.__TAURI_INTERNALS__?.invoke
}
function invokeAdsConsentOverlayCommand(shown) {
const invoke = getTauriInvoke()
if (typeof invoke !== 'function') {
return
}
const command = shown ? 'show_ads_consent_overlay' : 'hide_ads_consent_overlay'
const args = shown ? {} : { dpr: window.devicePixelRatio }
invoke(`plugin:ads|${command}`, args).catch(() => {})
}
function setAdsConsentOverlay(shown) {
if (modrinthAdsConsentOverlayShown === shown) return
modrinthAdsConsentOverlayShown = shown
installAdsConsentOverlayStyle()
document.documentElement.classList.toggle('modrinth-ads-consent-overlay', shown)
if (window.top === window) {
invokeAdsConsentOverlayCommand(shown)
} else {
window.top.postMessage({ modrinthAdsConsentOverlay: shown }, MODRINTH_ORIGIN)
}
}
if (window.top === window) {
window.addEventListener('message', (event) => {
if (
event.origin === MODRINTH_ORIGIN &&
typeof event.data?.modrinthAdsConsentOverlay === 'boolean'
) {
setAdsConsentOverlay(event.data.modrinthAdsConsentOverlay)
}
})
}
function handleTcfConsentEvent(tcData, success) {
if (!success || !tcData) return
if (tcData.eventStatus === 'cmpuishown') {
setAdsConsentOverlay(true)
} else if (tcData.eventStatus === 'useractioncomplete' || tcData.eventStatus === 'tcloaded') {
setAdsConsentOverlay(false)
}
}
// polling to install listener on tcf api
function installTcfConsentListener() {
if (modrinthTcfListenerInstalled) return
if (typeof window.__tcfapi === 'function') {
modrinthTcfListenerInstalled = true
window.__tcfapi('addEventListener', 2, handleTcfConsentEvent)
return
}
if (modrinthTcfListenerAttempts < 60) {
modrinthTcfListenerAttempts += 1
setTimeout(installTcfConsentListener, 500)
}
}
function muteAudioContext() {
@@ -98,9 +190,13 @@ function muteVideos() {
}
document.addEventListener('DOMContentLoaded', () => {
installAdsConsentOverlayStyle()
muteVideos()
muteAudioContext()
installTcfConsentListener()
const observer = new MutationObserver(muteVideos)
observer.observe(document.body, { childList: true, subtree: true })
})
installTcfConsentListener()
+157 -18
View File
@@ -11,12 +11,14 @@ use tokio::sync::RwLock;
pub struct AdsState {
pub shown: bool,
pub modal_shown: bool,
pub consent_overlay_shown: bool,
pub occluded: bool,
pub last_click: Option<Instant>,
pub malicious_origins: HashSet<String>,
}
const AD_LINK: &str = "https://modrinth.com/wrapper/app-ads-cookie";
const APP_TITLE_BAR_HEIGHT: f32 = 48.0;
#[cfg(any(windows, target_os = "macos"))]
pub(super) const OCCLUDED_AREA_THRESHOLD: f64 = 0.5;
#[cfg(not(target_os = "linux"))]
@@ -131,13 +133,16 @@ fn set_webview_visible_for_window<R: Runtime>(
.and_then(|window| window.is_minimized().ok())
.unwrap_or(false);
let is_occluded = app
let (is_occluded, consent_overlay_shown) = app
.state::<RwLock<AdsState>>()
.try_read()
.map(|state| state.occluded)
.unwrap_or(false);
.map(|state| (state.occluded, state.consent_overlay_shown))
.unwrap_or((false, false));
set_webview_visible(webview, visible && !is_minimized && !is_occluded);
set_webview_visible(
webview,
visible && !is_minimized && (!is_occluded || consent_overlay_shown),
);
}
#[cfg(any(windows, target_os = "macos"))]
@@ -195,7 +200,8 @@ async fn sync_ads_occlusion<R: Runtime>(app: &tauri::AppHandle<R>) {
}
state.occluded = occluded;
let visible = state.shown && !state.modal_shown;
let visible =
state.shown && (!state.modal_shown || state.consent_overlay_shown);
drop(state);
if let Some(webview) = app.webviews().get("ads-window") {
@@ -211,21 +217,36 @@ fn sync_webview_visibility_for_main_window<R: Runtime>(
let is_minimized = main_window.is_minimized().unwrap_or(false);
let was = was_minimized.load(Ordering::SeqCst);
let ads_state = if is_minimized {
None
} else {
match app.state::<RwLock<AdsState>>().try_read() {
Ok(state) => Some((
state.shown
&& (!state.modal_shown || state.consent_overlay_shown)
&& (!state.occluded || state.consent_overlay_shown),
state.consent_overlay_shown,
)),
Err(_) => None,
}
};
let ads_visible = ads_state.map(|state| state.0).unwrap_or(false);
if ads_state.map(|state| state.1).unwrap_or(false)
&& let Some(webview) = app.webviews().get("ads-window")
&& let Ok((position, size)) =
get_overlay_webview_position_for_window(main_window)
{
webview.set_position(position).ok();
webview.set_size(size).ok();
}
if is_minimized == was {
return;
}
was_minimized.store(is_minimized, Ordering::SeqCst);
let ads_visible = if is_minimized {
false
} else {
match app.state::<RwLock<AdsState>>().try_read() {
Ok(state) => state.shown && !state.modal_shown && !state.occluded,
Err(_) => false,
}
};
let mut webviews = Vec::new();
let mut seen_webviews = HashSet::new();
@@ -254,6 +275,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
app.manage(RwLock::new(AdsState {
shown: true,
modal_shown: false,
consent_overlay_shown: false,
occluded: false,
last_click: None,
malicious_origins: HashSet::new(),
@@ -269,7 +291,10 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.state::<RwLock<AdsState>>()
.try_read()
.map(|state| {
state.shown && !state.modal_shown && !state.occluded
state.shown
&& !state.modal_shown
&& !state.consent_overlay_shown
&& !state.occluded
})
.unwrap_or(false);
@@ -332,6 +357,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
init_ads_window,
hide_ads_window,
show_ads_window,
show_ads_consent_overlay,
hide_ads_consent_overlay,
record_ads_click,
open_link,
get_ads_personalization,
@@ -358,6 +385,42 @@ fn get_webview_position<R: Runtime>(
))
}
fn get_overlay_webview_position_for_window<R: Runtime>(
main_window: &tauri::Window<R>,
) -> crate::api::Result<(PhysicalPosition<f32>, PhysicalSize<f32>)> {
let main_window_size = main_window.outer_size()?;
let title_bar_height =
APP_TITLE_BAR_HEIGHT * main_window.scale_factor()? as f32;
Ok((
PhysicalPosition::new(0.0, title_bar_height),
PhysicalSize::new(
main_window_size.width as f32,
(main_window_size.height as f32 - title_bar_height).max(0.0),
),
))
}
fn get_overlay_webview_position<R: Runtime>(
app: &tauri::AppHandle<R>,
) -> crate::api::Result<(PhysicalPosition<f32>, PhysicalSize<f32>)> {
let main_window = app.get_window("main").unwrap();
get_overlay_webview_position_for_window(&main_window)
}
fn get_device_pixel_ratio<R: Runtime>(
app: &tauri::AppHandle<R>,
dpr: Option<f32>,
) -> f32 {
dpr.unwrap_or_else(|| {
app.get_window("main")
.and_then(|window| window.scale_factor().ok())
.map(|scale_factor| scale_factor as f32)
.unwrap_or(1.0)
})
}
#[tauri::command]
#[cfg(not(target_os = "linux"))]
pub async fn init_ads_window<R: Runtime>(
@@ -374,11 +437,17 @@ pub async fn init_ads_window<R: Runtime>(
state.shown = true;
}
if state.modal_shown {
if state.modal_shown && !state.consent_overlay_shown {
return Ok(());
}
if let Ok((position, size)) = get_webview_position(&app, dpr) {
let layout = if state.consent_overlay_shown {
get_overlay_webview_position(&app)
} else {
get_webview_position(&app, dpr)
};
if let Ok((position, size)) = layout {
let webview = if let Some(webview) = app.webviews().get("ads-window") {
// set both the `hide`/`show` state and `position`,
// to ensure that the webview is actually shown/hidden
@@ -586,7 +655,11 @@ pub async fn show_ads_window<R: Runtime>(
state.modal_shown = false;
if state.shown {
let (position, size) = get_webview_position(&app, dpr)?;
let (position, size) = if state.consent_overlay_shown {
get_overlay_webview_position(&app)?
} else {
get_webview_position(&app, dpr)?
};
// set both the `hide`/`show` state and `position`,
// to ensure that the webview is actually shown/hidden
webview.set_size(size).ok();
@@ -610,8 +683,19 @@ pub async fn hide_ads_window<R: Runtime>(
if reset.unwrap_or(false) {
state.shown = false;
state.consent_overlay_shown = false;
} else {
state.modal_shown = true;
if state.consent_overlay_shown {
let (position, size) = get_overlay_webview_position(&app)?;
webview.set_size(size).ok();
webview.set_position(position).ok();
webview.show().ok();
set_webview_visible_for_window(&app, webview, true);
return Ok(());
}
}
// set both the `hide`/`show` state and `position`,
@@ -625,6 +709,61 @@ pub async fn hide_ads_window<R: Runtime>(
Ok(())
}
#[tauri::command]
pub async fn show_ads_consent_overlay<R: Runtime>(
app: tauri::AppHandle<R>,
) -> crate::api::Result<()> {
if let Some(webview) = app.webviews().get("ads-window") {
let state = app.state::<RwLock<AdsState>>();
let mut state = state.write().await;
// dont show for hidden ads so consent events cannot re-enable the webview.
if !state.shown {
return Ok(());
}
state.consent_overlay_shown = true;
let (position, size) = get_overlay_webview_position(&app)?;
webview.set_size(size).ok();
webview.set_position(position).ok();
webview.show().ok();
set_webview_visible_for_window(&app, webview, true);
}
Ok(())
}
#[tauri::command]
pub async fn hide_ads_consent_overlay<R: Runtime>(
app: tauri::AppHandle<R>,
dpr: Option<f32>,
) -> crate::api::Result<()> {
if let Some(webview) = app.webviews().get("ads-window") {
let state = app.state::<RwLock<AdsState>>();
let mut state = state.write().await;
state.consent_overlay_shown = false;
if state.shown && !state.modal_shown {
let dpr = get_device_pixel_ratio(&app, dpr);
let (position, size) = get_webview_position(&app, dpr)?;
webview.set_size(size).ok();
webview.set_position(position).ok();
webview.show().ok();
set_webview_visible_for_window(&app, webview, true);
} else {
webview
.set_position(PhysicalPosition::new(-1000, -1000))
.ok();
webview.hide().ok();
}
}
Ok(())
}
#[tauri::command]
pub async fn record_ads_click<R: Runtime>(
app: tauri::AppHandle<R>,
+6
View File
@@ -25,6 +25,7 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
install_job_retry,
install_job_cancel,
install_job_dismiss,
install_job_support_details,
])
.build()
}
@@ -169,3 +170,8 @@ pub async fn install_job_cancel(job_id: Uuid) -> Result<InstallJobSnapshot> {
pub async fn install_job_dismiss(job_id: Uuid) -> Result<()> {
Ok(theseus::install::dismiss_job(job_id).await?)
}
#[tauri::command]
pub async fn install_job_support_details(job_id: Uuid) -> Result<String> {
Ok(theseus::install::job_support_details(job_id).await?)
}
-3
View File
@@ -1969,11 +1969,8 @@ paths:
- `project_id`
- `license`
- `downloads`
- `color`
- `created_timestamp` (uses Unix timestamp)
- `modified_timestamp` (uses Unix timestamp)
- `date_created` (uses ISO-8601 timestamp)
- `date_modified` (uses ISO-8601 timestamp)
In order to then use these facets, you need a value to filter by, as well as an operation to perform on this value.
The most common operation is `:` (same as `=`), though you can also use `!=`, `>=`, `>`, `<=`, and `<`.
@@ -482,3 +482,8 @@ input {
.button-transparent {
box-shadow: none;
}
.qc-cmp2-close-tooltip {
background-color: transparent;
color: hsl(145, 78%, 28%);
}
@@ -0,0 +1,184 @@
<template>
<div
:role="selectable ? 'radio' : undefined"
:aria-checked="selectable ? selected : undefined"
:tabindex="selectable ? 0 : undefined"
class="grid items-center gap-3 rounded-2xl border border-solid px-3 py-3 transition-all"
:class="{
'grid-cols-[min-content_minmax(0,1fr)_min-content]': selectable,
'grid-cols-[minmax(0,1fr)_min-content]': !selectable,
'cursor-pointer border-brand bg-surface-4 text-contrast': selectable && selected,
'cursor-pointer border-surface-5 bg-surface-4 hover:brightness-[115%]':
selectable && !selected,
'border-transparent bg-surface-2': !selectable,
}"
@click="select"
@keydown.enter.self.prevent="select"
@keydown.space.self.prevent="select"
>
<template v-if="selectable">
<RadioButtonCheckedIcon v-if="selected" aria-hidden="true" class="size-5 text-brand" />
<RadioButtonIcon v-else aria-hidden="true" class="size-5 text-secondary" />
</template>
<div class="flex min-w-0 flex-col gap-1">
<div class="flex min-w-0 items-center gap-2">
<nuxt-link
v-tooltip="truncatedTooltip(versionNumberRef, version.version_number)"
:to="`/${project.project_type}/${project.slug || project.id}/version/${version.id}`"
target="_blank"
rel="noopener noreferrer"
class="block min-w-0 text-contrast no-underline hover:underline"
>
<span ref="versionNumberRef" class="block truncate font-semibold">
{{ version.version_number }}
</span>
</nuxt-link>
<VersionChannelTag :channel="version.version_type" class="relative -top-px !py-1" />
</div>
<div class="flex min-w-0 items-center gap-1.5 text-sm text-secondary">
<span v-tooltip="publishedTooltip" class="min-w-0 truncate">
{{ publishedLabel }}
</span>
<div
v-if="primaryFile"
class="h-1.5 w-1.5 flex-shrink-0 rounded-full bg-primary opacity-30"
></div>
<span v-if="primaryFile" class="flex-shrink-0">
{{ primaryFileSizeLabel }}
</span>
</div>
</div>
<ButtonStyled
v-if="primaryFile && showDownload"
:color="color"
:type="type"
:circular="circular"
>
<a
v-tooltip="circular ? formatMessage(messages.download) : null"
:href="primaryFileDownloadUrl"
:download="primaryFile.filename"
:aria-label="
formatMessage(messages.downloadVersion, {
version: version.version_number,
})
"
@click="emit('download')"
>
<DownloadIcon aria-hidden="true" />
<template v-if="!circular">
{{ formatMessage(messages.download) }}
</template>
</a>
</ButtonStyled>
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { DownloadIcon, RadioButtonCheckedIcon, RadioButtonIcon } from '@modrinth/assets'
import {
ButtonStyled,
type CdnDownloadReason,
defineMessages,
truncatedTooltip,
useFormatBytes,
useFormatDateTime,
useRelativeTime,
useVIntl,
} from '@modrinth/ui'
import VersionChannelTag from '@modrinth/ui/src/components/version/VersionChannelTag.vue'
import { capitalizeString, type DisplayProjectType } from '@modrinth/utils'
import { computed, ref } from 'vue'
defineOptions({
name: 'CompatibleVersionCard',
})
type DownloadModalProject = Omit<Labrinth.Projects.v2.Project, 'project_type'> & {
project_type: DisplayProjectType
actualProjectType: Labrinth.Projects.v2.ProjectType
}
const props = withDefaults(
defineProps<{
project: DownloadModalProject
version: Labrinth.Versions.v3.Version
downloadReason?: CdnDownloadReason
currentGameVersion?: string | null
currentPlatform?: string | null
color?: 'brand' | 'standard'
type?: 'standard' | 'transparent'
circular?: boolean
selectable?: boolean
selected?: boolean
showDownload?: boolean
}>(),
{
downloadReason: 'standalone',
currentGameVersion: null,
currentPlatform: null,
color: 'brand',
type: 'standard',
circular: false,
selectable: false,
selected: false,
showDownload: true,
},
)
const emit = defineEmits<{
download: []
select: []
}>()
const { createProjectDownloadUrl } = useCdnDownloadContext()
const { formatMessage } = useVIntl()
const formatBytes = useFormatBytes()
const formatDateTime = useFormatDateTime({
timeStyle: 'short',
dateStyle: 'long',
})
const formatRelativeTime = useRelativeTime()
const versionNumberRef = ref<HTMLElement | null>(null)
const primaryFile = computed<Labrinth.Versions.v3.VersionFile | null>(() => {
return props.version.files?.find((file) => file.primary) || props.version.files?.[0] || null
})
const primaryFileDownloadUrl = computed(() => {
if (!primaryFile.value) return '#'
return createProjectDownloadUrl(primaryFile.value.url, {
reason: props.downloadReason,
gameVersion: props.currentGameVersion ?? undefined,
loader: props.currentPlatform ?? undefined,
})
})
const publishedLabel = computed(() =>
capitalizeString(formatRelativeTime(props.version.date_published)),
)
const publishedTooltip = computed(() => formatDateTime(props.version.date_published))
const primaryFileSizeLabel = computed(() => {
if (!primaryFile.value) return ''
return formatBytes(primaryFile.value.size)
})
function select() {
if (!props.selectable) return
emit('select')
}
const messages = defineMessages({
downloadVersion: {
id: 'project.download.download-version',
defaultMessage: 'Download {version}',
},
download: {
id: 'project.download.download',
defaultMessage: 'Download',
},
})
</script>
@@ -1,494 +1,111 @@
<template>
<div v-if="downloadRows.length > 0" class="flex flex-col gap-1">
<div v-if="showTitle" class="flex flex-wrap items-center justify-between gap-2">
<h3 class="m-0 flex items-center gap-1.5 text-base font-semibold text-contrast">
{{ sectionTitle }}
<InfoIcon
v-if="duplicateDependencyRowsHidden"
v-tooltip="formatMessage(messages.duplicateDependenciesHidden)"
aria-hidden="true"
class="size-4 text-secondary"
<div v-if="downloadRows.length > 0 || recommendedRows.length > 0" class="flex flex-col gap-4">
<div v-if="downloadRows.length > 0" class="flex flex-col gap-2.5">
<div v-if="showTitle" class="flex flex-wrap items-center justify-between gap-2">
<h3 class="m-0 flex items-center gap-1.5 text-base font-semibold text-contrast">
{{ formatMessage(messages.dependenciesTitle) }}
<InfoIcon
v-if="duplicateDependencyRowsHidden"
v-tooltip="formatMessage(messages.duplicateDependenciesHidden)"
aria-hidden="true"
class="size-4 text-secondary"
/>
</h3>
</div>
<Admonition v-if="requiredResourcePackAdmonitionVisible" type="info">
<IntlFormatted :message-id="messages.requiredResourcePackAdmonition">
<template #folder>
<code class="text-sm">resourcepacks</code>
</template>
</IntlFormatted>
</Admonition>
<Admonition v-if="dependencyResourcePackAdmonitionVisible" type="info">
<IntlFormatted :message-id="messages.dependencyResourcePackAdmonition">
<template #folder>
<code class="text-sm">resourcepacks</code>
</template>
</IntlFormatted>
</Admonition>
<div class="rounded-2xl bg-surface-2 p-2 pl-4 pr-3">
<DownloadDependency
v-for="dependency in downloadRows"
:key="dependency.key"
:dependency="dependency"
@download="emit('download')"
/>
</h3>
</div>
</div>
<div class="flex flex-col gap-2">
<DownloadDependency
v-for="dependency in downloadRows"
:key="dependency.key"
:dependency="dependency"
@download="emit('download')"
/>
<div v-if="recommendedRows.length > 0" class="flex flex-col gap-2.5">
<h3 class="m-0 text-base font-semibold text-contrast">
{{ formatMessage(messages.recommendedTitle) }}
</h3>
<div class="rounded-2xl bg-surface-2 p-2 pl-4 pr-3">
<DownloadDependency
v-for="dependency in recommendedRows"
:key="dependency.key"
:dependency="dependency"
@download="emit('download')"
/>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { FileIcon, InfoIcon } from '@modrinth/assets'
import {
type CdnDownloadReason,
defineMessages,
fileTypeMessages,
injectModrinthClient,
useVIntl,
} from '@modrinth/ui'
import type { DisplayProjectType } from '@modrinth/utils'
import { useQuery } from '@tanstack/vue-query'
import { type Component, computed, watch } from 'vue'
import { InfoIcon } from '@modrinth/assets'
import { Admonition, defineMessages, IntlFormatted, useVIntl } from '@modrinth/ui'
import { injectDownloadModalProvider } from './download-modal-provider'
import DownloadDependency from './DownloadDependency.vue'
defineOptions({
name: 'DownloadDependencies',
})
type DownloadModalProject = Omit<Labrinth.Projects.v2.Project, 'project_type'> & {
project_type: DisplayProjectType
actualProjectType: Labrinth.Projects.v2.ProjectType
}
type ResolvedContent = Labrinth.Content.v3.ResolvedContent | Labrinth.Content.v3.SkippedContent
interface DownloadDependencyRow {
key: string
name: string
icon?: string
fallbackIcon?: Component
projectHref?: string
downloadHref?: string
filename?: string
fileSize?: number
typeLabel: string
unavailableTooltip: string
dependencies: DownloadDependencyRow[]
}
interface DownloadableDependencyFile {
href: string
filename: string
name: string
}
const props = withDefaults(
withDefaults(
defineProps<{
dependencies?: DownloadDependencyRow[] | null
project?: DownloadModalProject | null
selectedVersion?: Labrinth.Versions.v3.Version | null
currentGameVersion?: string | null
currentPlatform?: string | null
downloadReason?: CdnDownloadReason
additionalFiles?: Labrinth.Versions.v3.VersionFile[]
showTitle?: boolean
}>(),
{
dependencies: null,
project: null,
selectedVersion: null,
currentGameVersion: null,
currentPlatform: null,
downloadReason: 'standalone',
additionalFiles: () => [],
showTitle: true,
},
)
const emit = defineEmits<{
download: []
'update:downloadable-files': [files: DownloadableDependencyFile[]]
}>()
const client = injectModrinthClient()
const { createProjectDownloadUrl } = useCdnDownloadContext()
const { formatMessage } = useVIntl()
const shouldResolveDependencies = computed(
() => !props.dependencies && !!props.project && !!props.selectedVersion,
)
const dependencyResolutionPreferences = computed<Labrinth.Content.v3.ResolutionPreferences>(() => ({
game_versions: props.selectedVersion?.game_versions || [],
loaders: props.currentPlatform ? [props.currentPlatform] : props.selectedVersion?.loaders || [],
}))
const { data: dependencyResolution } = useQuery({
queryKey: computed(() => [
'project-download-modal',
'content-resolve',
props.project?.id,
props.selectedVersion?.id,
props.project?.project_type,
dependencyResolutionPreferences.value,
]),
queryFn: () =>
client.labrinth.content_v3.resolve({
project_id: props.project!.id,
version_id: props.selectedVersion!.id,
content_type: resolveContentType(props.project!.project_type),
selected: dependencyResolutionPreferences.value,
target: dependencyResolutionPreferences.value,
}),
enabled: shouldResolveDependencies,
})
const visibleResolvedDependencies = computed<ResolvedContent[]>(() => {
return [
...(dependencyResolution.value?.dependencies || []),
...(dependencyResolution.value?.skipped || []),
].filter(shouldShowDependency)
})
const dependencyVersionIds = computed<string[]>(() => {
return [
...new Set(
visibleResolvedDependencies.value
.filter((dependency) => !('reason' in dependency))
.map((dependency) => dependency.version_id)
.filter((versionId): versionId is string => !!versionId),
),
]
})
const { data: dependencyVersions } = useQuery({
queryKey: computed(() => [
'project-download-modal',
'resolved-versions',
dependencyVersionIds.value,
]),
queryFn: () => client.labrinth.versions_v3.getVersions(dependencyVersionIds.value),
enabled: computed(() => shouldResolveDependencies.value && dependencyVersionIds.value.length > 0),
})
const dependencyVersionById = computed(() => {
const map = new Map<string, Labrinth.Versions.v3.Version>()
for (const version of dependencyVersions.value || []) {
if (!version) continue
map.set(version.id, version)
}
return map
})
const dependencyProjectIds = computed<string[]>(() => {
return [
...new Set(
visibleResolvedDependencies.value
.map((dependency) => dependency.project_id)
.filter((projectId): projectId is string => !!projectId),
),
]
})
const { data: dependencyProjects } = useQuery({
queryKey: computed(() => [
'project-download-modal',
'resolved-projects',
dependencyProjectIds.value,
]),
queryFn: () => client.labrinth.projects_v2.getMultiple(dependencyProjectIds.value),
enabled: computed(() => shouldResolveDependencies.value && dependencyProjectIds.value.length > 0),
})
const dependencyProjectById = computed(() => {
const map = new Map<string, Labrinth.Projects.v2.Project>()
for (const project of dependencyProjects.value || []) {
map.set(project.id, project)
}
return map
})
const dependenciesByParentVersionId = computed(() => {
const map = new Map<string, ResolvedContent[]>()
for (const dependency of visibleResolvedDependencies.value) {
if (!dependency.dependent_on_version_id) continue
const dependencies = map.get(dependency.dependent_on_version_id) || []
dependencies.push(dependency)
map.set(dependency.dependent_on_version_id, dependencies)
}
return map
})
const dependenciesLoaded = computed(() => {
if (!shouldResolveDependencies.value) return false
if (!dependencyResolution.value) return false
if (
dependencyResolution.value.primary.version_id &&
dependencyResolution.value.primary.version_id !== props.selectedVersion?.id
) {
return false
}
if (
!dependencyVersionIds.value.every((versionId) => dependencyVersionById.value.has(versionId))
) {
return false
}
if (
!dependencyProjectIds.value.every((projectId) => dependencyProjectById.value.has(projectId))
) {
return false
}
return true
})
const resolvedDependencyRows = computed<DownloadDependencyRow[]>(() => {
if (!dependenciesLoaded.value) return []
const primaryVersionId =
dependencyResolution.value?.primary.version_id || props.selectedVersion?.id
if (!primaryVersionId) return []
const dependencies = dependenciesByParentVersionId.value.get(primaryVersionId) || []
return dependencies.flatMap((dependency) => {
const row = createDependencyRow(dependency)
return row ? [row] : []
})
})
const dependencyRows = computed<DownloadDependencyRow[]>(
() => props.dependencies || resolvedDependencyRows.value,
)
const visibleDependencyRows = computed<DownloadDependencyRow[]>(() =>
dedupeDependencyRows(dependencyRows.value),
)
const duplicateDependencyRowsHidden = computed(() =>
hasDuplicateDependencyRows(dependencyRows.value),
)
const additionalFileRows = computed<DownloadDependencyRow[]>(() =>
props.additionalFiles.map((file) => ({
key: `additional-file-${additionalFileKey(file)}`,
name: file.filename,
fallbackIcon: FileIcon,
downloadHref: getDownloadUrl(file.url),
filename: file.filename,
fileSize: file.size,
typeLabel: fileTypeLabel(file.file_type),
unavailableTooltip: formatMessage(messages.unavailableFile),
dependencies: [],
})),
)
const downloadRows = computed<DownloadDependencyRow[]>(() => [
...visibleDependencyRows.value,
...additionalFileRows.value,
])
const sectionTitle = computed(() =>
formatMessage(
visibleDependencyRows.value.length > 0
? messages.dependenciesTitle
: messages.additionalFilesTitle,
),
)
const downloadableDependencyFiles = computed<DownloadableDependencyFile[]>(() =>
collectDownloadableDependencyFiles(visibleDependencyRows.value),
)
watch(
downloadableDependencyFiles,
(files) => {
emit('update:downloadable-files', files)
},
{ immediate: true },
)
function primaryFileForVersion(version?: Labrinth.Versions.v3.Version) {
return version?.files?.find((file) => file.primary) || version?.files?.[0]
}
function shouldShowDependency(dependency: ResolvedContent) {
return !(
'reason' in dependency && ['duplicate_project', 'quilt_fabric_api'].includes(dependency.reason)
)
}
function createDependencyRow(dependency: ResolvedContent): DownloadDependencyRow | null {
const versionId = dependency.version_id ?? undefined
const version = versionId ? dependencyVersionById.value.get(versionId) : undefined
const project = dependencyProjectById.value.get(dependency.project_id)
if (!project) return null
const primaryFile = primaryFileForVersion(version)
const unavailableTooltip =
'reason' in dependency && dependency.reason
? skippedReasonLabel(dependency.reason)
: formatMessage(messages.unavailableDependency)
const name = project.title
return {
key: `${dependency.project_id}-${versionId ?? 'unresolved'}-${
'reason' in dependency ? dependency.reason : 'resolved'
}`,
name,
icon: project.icon_url ?? undefined,
projectHref: `/${project.project_type}/${project.slug || project.id}`,
downloadHref:
'reason' in dependency || !primaryFile ? undefined : getDownloadUrl(primaryFile.url),
filename: primaryFile?.filename,
fileSize: primaryFile?.size,
typeLabel: 'Required',
unavailableTooltip,
dependencies: (versionId && dependenciesByParentVersionId.value.get(versionId)
? dependenciesByParentVersionId.value.get(versionId)!
: []
).flatMap((subDependency) => {
const row = createDependencyRow(subDependency)
return row ? [row] : []
}),
}
}
function skippedReasonLabel(reason: Labrinth.Content.v3.SkippedContent['reason']) {
return (
{
already_installed: formatMessage(messages.alreadyInstalledDependency),
duplicate_project: formatMessage(messages.duplicateDependency),
conflicting_dependency: formatMessage(messages.conflictingDependency),
no_compatible_version: formatMessage(messages.noCompatibleDependency),
missing_version: formatMessage(messages.missingDependencyVersion),
quilt_fabric_api: formatMessage(messages.quiltFabricApiDependency),
}[reason] || formatMessage(messages.unavailableDependency)
)
}
function resolveContentType(projectType: DisplayProjectType): Labrinth.Content.v3.ContentType {
return ['mod', 'plugin', 'datapack', 'resourcepack', 'shader', 'modpack'].includes(projectType)
? (projectType as Labrinth.Content.v3.ContentType)
: 'mod'
}
function getDownloadUrl(url: string) {
return createProjectDownloadUrl(url, {
reason: props.downloadReason,
gameVersion: props.currentGameVersion ?? undefined,
loader: props.currentPlatform ?? undefined,
})
}
function fileTypeLabel(type?: Labrinth.Versions.v3.FileType | null) {
return formatMessage(fileTypeMessages[type ?? 'unknown'] ?? fileTypeMessages.unknown)
}
function additionalFileKey(file: Labrinth.Versions.v3.VersionFile) {
return file.hashes?.sha1 ?? file.filename
}
function dedupeDependencyRows(
rows: DownloadDependencyRow[],
seenDependencies = new Set<string>(),
): DownloadDependencyRow[] {
return rows.flatMap((row) => {
const identity = dependencyRowIdentity(row)
if (seenDependencies.has(identity)) return []
seenDependencies.add(identity)
return [
{
...row,
dependencies: dedupeDependencyRows(row.dependencies, seenDependencies),
},
]
})
}
function dependencyRowIdentity(row: DownloadDependencyRow) {
return row.projectHref ?? row.downloadHref ?? row.key
}
function hasDuplicateDependencyRows(
rows: DownloadDependencyRow[],
seenDependencies = new Set<string>(),
): boolean {
for (const row of rows) {
const rowId = dependencyRowIdentity(row)
if (seenDependencies.has(rowId)) return true
seenDependencies.add(rowId)
if (hasDuplicateDependencyRows(row.dependencies, seenDependencies)) return true
}
return false
}
function collectDownloadableDependencyFiles(
rows: DownloadDependencyRow[],
seenHrefs = new Set<string>(),
): DownloadableDependencyFile[] {
const files: DownloadableDependencyFile[] = []
for (const row of rows) {
if (row.downloadHref && !seenHrefs.has(row.downloadHref)) {
seenHrefs.add(row.downloadHref)
files.push({
href: row.downloadHref,
filename: row.filename || filenameFromUrl(row.downloadHref),
name: row.name,
})
}
files.push(...collectDownloadableDependencyFiles(row.dependencies, seenHrefs))
}
return files
}
function filenameFromUrl(url: string) {
try {
const filename = new URL(url).pathname.split('/').pop()
return filename ? decodeURIComponent(filename) : 'dependency.jar'
} catch {
return 'dependency.jar'
}
}
const {
dependencyResourcePackAdmonitionVisible,
duplicateDependencyRowsHidden,
downloadRows,
recommendedRows,
requiredResourcePackAdmonitionVisible,
} = injectDownloadModalProvider()
const messages = defineMessages({
dependenciesTitle: {
id: 'project.download.dependencies-title',
defaultMessage: 'Dependencies',
},
recommendedTitle: {
id: 'project.download.recommended-title',
defaultMessage: 'Recommended',
},
duplicateDependenciesHidden: {
id: 'project.download.duplicate-dependencies-hidden',
defaultMessage: 'Duplicate dependencies are hidden',
},
additionalFilesTitle: {
id: 'project.download.additional-files-title',
defaultMessage: 'Additional files',
requiredResourcePackAdmonition: {
id: 'project.download.required-resource-pack-admonition',
defaultMessage:
'This data pack also requires a resource pack. Download it and place it in your {folder} folder.',
},
alreadyInstalledDependency: {
id: 'project.download.dependency-already-installed',
defaultMessage: 'This dependency is already installed',
},
conflictingDependency: {
id: 'project.download.dependency-conflicting',
defaultMessage: 'This dependency conflicts with another dependency',
},
duplicateDependency: {
id: 'project.download.dependency-duplicate',
defaultMessage: 'This dependency is already included',
},
missingDependencyVersion: {
id: 'project.download.dependency-missing-version',
defaultMessage: 'This dependency version is unavailable',
},
noCompatibleDependency: {
id: 'project.download.dependency-no-compatible-version',
defaultMessage: 'No compatible version is available for this dependency',
},
quiltFabricApiDependency: {
id: 'project.download.dependency-quilt-fabric-api',
defaultMessage: 'Fabric API is skipped for Quilt',
},
unavailableDependency: {
id: 'project.download.dependency-unavailable',
defaultMessage: 'This dependency cannot be downloaded',
},
unavailableFile: {
id: 'project.download.file-unavailable',
defaultMessage: 'This file cannot be downloaded',
dependencyResourcePackAdmonition: {
id: 'project.download.dependency-resource-pack-admonition',
defaultMessage:
'This project has a dependency with a required resource pack. Download it and place it in your {folder} folder.',
},
})
</script>
@@ -1,24 +1,24 @@
<template>
<div class="flex min-w-0 flex-col gap-2">
<div class="flex min-w-0 flex-col">
<div
class="grid min-h-10 grid-cols-[minmax(0,1fr)_min-content] items-center gap-3 rounded-xl bg-button-bg py-0 pl-3.5 pr-2 text-primary"
class="z-10 grid h-11 grid-cols-[minmax(0,1fr)_min-content] items-center gap-1 text-primary"
>
<span class="flex min-w-0 items-center gap-3">
<span class="flex min-w-0 items-center gap-2">
<Avatar
v-if="dependency.icon"
v-if="dependency.icon && !dependency.hideIcon"
:src="dependency.icon"
:alt="dependency.name"
size="24px"
class="!rounded-lg !shadow-none"
/>
<span
v-else
class="flex size-4 flex-shrink-0 items-center justify-center rounded-lg border border-solid border-surface-5 text-secondary"
v-else-if="!dependency.hideIcon"
class="flex size-6 flex-shrink-0 items-center justify-center rounded-lg border border-solid border-surface-5 text-secondary"
>
<component
:is="dependency.fallbackIcon ?? PackageIcon"
aria-hidden="true"
class="size-5"
class="size-4"
/>
</span>
<a
@@ -28,7 +28,7 @@
:href="dependency.projectHref"
target="_blank"
rel="noopener noreferrer"
class="min-w-0 truncate text-base font-semibold text-contrast no-underline hover:underline"
class="min-w-0 truncate bg-surface-2 text-base font-semibold text-contrast hover:underline"
>
{{ dependency.name }}
</a>
@@ -36,13 +36,25 @@
v-else
ref="dependencyNameRef"
v-tooltip="truncatedTooltip(dependencyNameRef, dependency.name)"
class="min-w-0 truncate text-base font-semibold text-contrast"
class="min-w-0 truncate bg-surface-2 text-base text-contrast"
:class="dependency.isAdditionalFile ? 'font-medium' : 'font-semibold'"
>
{{ dependency.name }}
</span>
<TagItem class="shrink-0 border !border-solid border-surface-5 !px-3 !py-1 text-base">
{{ dependency.typeLabel }}
<TagItem
v-if="dependency.isAdditionalFile"
v-tooltip="metadataTooltip"
class="min-w-0 max-w-[50%] shrink-0 truncate border !border-solid border-surface-5"
>
{{ metadataLabel }}
</TagItem>
<span
v-else
v-tooltip="metadataTooltip"
class="min-w-0 max-w-[50%] truncate text-sm text-secondary"
>
{{ metadataLabel }}
</span>
</span>
<ButtonStyled v-if="dependency.downloadHref" circular type="transparent">
<a
@@ -68,14 +80,18 @@
<div
v-for="childDependency in dependency.dependencies"
:key="childDependency.key"
class="group/dependency relative pl-10"
class="group/dependency relative pl-8"
>
<DownloadDependency :dependency="childDependency" class="z-1" @download="emit('download')" />
<DownloadDependency
:dependency="childDependency"
class="relative z-10"
@download="emit('download')"
/>
<div
aria-hidden="true"
class="absolute -top-2 left-6 z-0 h-[calc(100%+1rem)] w-0.5 bg-surface-5 group-first/dependency:-top-2 group-first/dependency:h-20 group-last/dependency:h-7"
class="absolute -top-2.5 left-3 z-0 h-full w-0.5 bg-surface-5 group-last/dependency:h-8"
/>
<div aria-hidden="true" class="absolute left-6 top-5 z-0 h-0.5 w-4 bg-surface-5" />
<div aria-hidden="true" class="absolute left-3 top-[21px] z-0 h-0.5 w-7 bg-surface-5" />
</div>
</div>
</template>
@@ -102,10 +118,13 @@ interface DownloadDependencyRow {
name: string
icon?: string
fallbackIcon?: Component
hideIcon?: boolean
isAdditionalFile?: boolean
projectHref?: string
downloadHref?: string
filename?: string
fileSize?: number
metadataLabel?: string
typeLabel: string
unavailableTooltip: string
dependencies: DownloadDependencyRow[]
@@ -123,6 +142,13 @@ const { formatMessage } = useVIntl()
const formatBytes = useFormatBytes()
const dependencyNameRef = ref<HTMLElement | null>(null)
const metadataLabel = computed(() => props.dependency.metadataLabel ?? props.dependency.typeLabel)
const metadataTooltip = computed(() => {
if (props.dependency.isAdditionalFile) return null
if (metadataLabel.value === props.dependency.typeLabel) return null
return metadataLabel.value
})
const downloadTooltip = computed(() => {
const filename = props.dependency.filename || props.dependency.name
@@ -80,107 +80,76 @@
</Combobox>
</div>
<div v-if="selectedVersion" class="flex flex-col gap-1">
<div class="flex flex-wrap items-center justify-between gap-2">
<h3 class="relative top-0.5 m-0 text-base font-semibold text-contrast">
{{ formatMessage(messages.compatibleVersionTitle) }}
</h3>
<ButtonStyled v-if="downloadAllFiles.length > 1" type="transparent">
<button :disabled="downloadingSelectedVersion" @click="downloadSelectedVersionFiles">
<SpinnerIcon v-if="downloadingSelectedVersion" aria-hidden="true" class="animate-spin" />
<DownloadIcon v-else aria-hidden="true" />
{{
formatMessage(
downloadingSelectedVersion
? messages.downloadingSelectedVersion
: messages.downloadAllSelectedVersion,
{
current: selectedVersionDownloadProgress.current,
total: selectedVersionDownloadProgress.total,
},
)
}}
</button>
</ButtonStyled>
</div>
<div
class="grid grid-cols-[1fr_min-content] items-center gap-3 rounded-2xl bg-surface-2 px-3 py-3"
<div
v-if="selectedVersion && downloadDataLoaded"
:role="compatibleVersions.length > 1 ? 'radiogroup' : undefined"
:aria-label="
compatibleVersions.length > 1 ? formatMessage(messages.compatibleVersionTitle) : undefined
"
class="flex flex-col gap-2.5"
>
<h3
v-if="compatibleVersions.length > 1"
class="relative top-0.5 m-0 text-base font-semibold text-contrast"
>
<div class="flex min-w-0 flex-col gap-1">
<div class="flex min-w-0 items-center gap-2">
<nuxt-link
v-tooltip="truncatedTooltip(versionNumberRef, selectedVersion.version_number)"
:to="`/${project.project_type}/${project.slug || project.id}/version/${selectedVersion.id}`"
target="_blank"
rel="noopener noreferrer"
class="block min-w-0 text-contrast no-underline hover:underline"
>
<span ref="versionNumberRef" class="block truncate font-semibold">
{{ selectedVersion.version_number }}
</span>
</nuxt-link>
<VersionChannelTag
:channel="selectedVersion.version_type"
class="relative -top-px !py-0.5"
/>
</div>
<p
ref="versionNameRef"
v-tooltip="truncatedTooltip(versionNameRef, selectedVersion.name)"
class="m-0 w-fit max-w-full truncate text-sm text-secondary"
>
{{ selectedVersion.name }}
</p>
</div>
<ButtonStyled v-if="selectedPrimaryFile" color="brand" circular>
<a
v-tooltip="'Download'"
:href="selectedPrimaryFileDownloadUrl"
:download="selectedPrimaryFile.filename"
:aria-label="
formatMessage(messages.downloadVersion, {
version: selectedVersion.version_number,
})
"
@click="emit('download')"
>
<DownloadIcon aria-hidden="true" />
</a>
</ButtonStyled>
</div>
{{ formatMessage(messages.compatibleVersionTitle) }}
</h3>
<CompatibleVersionCard
v-for="compatibleVersion in compatibleVersions"
:key="compatibleVersion.id"
:project="project"
:version="compatibleVersion"
:download-reason="downloadReason"
:current-game-version="currentGameVersion"
:current-platform="currentPlatform"
:selectable="compatibleVersions.length > 1"
:selected="compatibleVersion.id === selectedVersion.id"
:show-download="
compatibleVersions.length === 1 || compatibleVersion.id === selectedVersion.id
"
:color="
compatibleVersion.id === selectedVersion.id &&
compatibleVersions.length === 1 &&
!hasAdditionalDownloads
? 'brand'
: 'standard'
"
:type="
compatibleVersion.id === selectedVersion.id &&
compatibleVersions.length === 1 &&
!hasAdditionalDownloads
? 'standard'
: 'transparent'
"
:circular="hasAdditionalDownloads || compatibleVersions.length > 1"
@select="selectCompatibleVersion(compatibleVersion)"
@download="emit('download')"
/>
</div>
<div v-else-if="showNoCompatibleVersions" class="pl-1 text-base text-primary" role="status">
{{ noCompatibleVersionsDescription }}
</div>
<p v-else-if="currentPlatform && currentGameVersion && versions.length > 0">
{{
formatMessage(messages.noVersionsAvailable, {
gameVersion: currentGameVersion,
platform: currentPlatformText,
})
}}
</p>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { DownloadIcon, SpinnerIcon, TriangleAlertIcon } from '@modrinth/assets'
import { TriangleAlertIcon } from '@modrinth/assets'
import {
ButtonStyled,
type CdnDownloadReason,
Checkbox,
Combobox,
type ComboboxOption,
defineMessages,
getTagMessage,
injectNotificationManager,
truncatedTooltip,
useDebugLogger,
useVIntl,
} from '@modrinth/ui'
import VersionChannelTag from '@modrinth/ui/src/components/version/VersionChannelTag.vue'
import type { DisplayProjectType } from '@modrinth/utils'
import dayjs from 'dayjs'
import JSZip from 'jszip'
import { computed, ref, watch } from 'vue'
import CompatibleVersionCard from './CompatibleVersionCard.vue'
defineOptions({
name: 'DownloadProject',
})
@@ -207,6 +176,8 @@ const props = withDefaults(
project: DownloadModalProject
versions?: Labrinth.Versions.v3.Version[]
dependencyDownloadFiles?: DownloadableFile[]
downloadDataLoaded?: boolean
versionsLoaded?: boolean
downloadReason?: CdnDownloadReason
initialGameVersion?: string | null
initialPlatform?: string | null
@@ -217,6 +188,8 @@ const props = withDefaults(
{
versions: () => [],
dependencyDownloadFiles: () => [],
downloadDataLoaded: false,
versionsLoaded: false,
downloadReason: 'standalone',
initialGameVersion: null,
initialPlatform: null,
@@ -233,22 +206,19 @@ const emit = defineEmits<{
'update:selection': [selection: ProjectDownloadSelection]
}>()
const { formatMessage } = useVIntl()
const { createProjectDownloadUrl } = useCdnDownloadContext()
const { addNotification } = injectNotificationManager()
const debug = useDebugLogger('DownloadProject')
const tags = useGeneratedState()
const userSelectedGameVersion = ref<string | null>(props.initialGameVersion)
const userSelectedPlatform = ref<string | null>(props.initialPlatform)
const userSelectedCompatibleVersionId = ref<string | null>(null)
const showAllVersions = ref(defaultShowAllVersions())
const versionFilter = ref('')
const versionNumberRef = ref<HTMLElement | null>(null)
const versionNameRef = ref<HTMLElement | null>(null)
const downloadingSelectedVersion = ref(false)
const selectedVersionDownloadProgress = ref({
current: 0,
total: 0,
})
const preferredPlatformRanks = new Map([
['fabric', 0],
['forge', 1],
['neoforge', 2],
])
const incompatibleGameVersionsSet = computed(() => new Set(props.incompatibleGameVersions))
const incompatibleLoadersSet = computed(() => new Set(props.incompatibleLoaders))
@@ -376,13 +346,12 @@ const gameVersionOptions = computed<ComboboxOption<string>[]>(() => {
const platformOptions = computed<ComboboxOption<string>[]>(() => {
return props.project.loaders
.slice()
.reverse()
.map((platform) => ({
value: platform,
label: loaderLabel(platform),
class: '!px-0 !py-1',
}))
.sort(comparePlatformOptions)
})
const filteredVersions = computed<Labrinth.Versions.v3.Version[]>(() => {
@@ -407,31 +376,71 @@ const filteredVersions = computed<Labrinth.Versions.v3.Version[]>(() => {
})
const filteredRelease = computed<Labrinth.Versions.v3.Version | undefined>(() => {
return filteredVersions.value.find((x) => x.version_type === 'release')
return latestVersionByType('release')
})
const filteredBeta = computed<Labrinth.Versions.v3.Version | undefined>(() => {
return filteredVersions.value.find(
(x) =>
x.version_type === 'beta' &&
(!filteredRelease.value ||
dayjs(x.date_published).isAfter(dayjs(filteredRelease.value.date_published))),
)
return latestVersionByType('beta')
})
const filteredAlpha = computed<Labrinth.Versions.v3.Version | undefined>(() => {
return filteredVersions.value.find(
(x) =>
x.version_type === 'alpha' &&
(!filteredRelease.value ||
dayjs(x.date_published).isAfter(dayjs(filteredRelease.value.date_published))) &&
(!filteredBeta.value ||
dayjs(x.date_published).isAfter(dayjs(filteredBeta.value.date_published))),
return latestVersionByType('alpha')
})
const defaultSelectedVersion = computed<Labrinth.Versions.v3.Version | null>(() => {
return filteredRelease.value || filteredBeta.value || filteredAlpha.value || null
})
const suggestedPreReleaseVersions = computed<Labrinth.Versions.v3.Version[]>(() => {
if (!defaultSelectedVersion.value || defaultSelectedVersion.value.version_type !== 'release')
return []
const versions: Labrinth.Versions.v3.Version[] = []
const beta = filteredBeta.value
if (beta && isNewerThan(beta, defaultSelectedVersion.value)) {
versions.push(beta)
}
const alpha = filteredAlpha.value
if (alpha && isNewerThan(alpha, defaultSelectedVersion.value)) {
versions.push(alpha)
}
return versions
})
const compatibleVersions = computed<Labrinth.Versions.v3.Version[]>(() => {
if (!defaultSelectedVersion.value) return []
return [defaultSelectedVersion.value, ...suggestedPreReleaseVersions.value]
})
const showNoCompatibleVersions = computed(() => {
return (
props.versionsLoaded &&
compatibleVersions.value.length === 0 &&
!!currentGameVersion.value &&
!!currentPlatform.value
)
})
const noCompatibleVersionsDescription = computed(() => {
const gameVersion = currentGameVersion.value
if (!gameVersion || !currentPlatform.value) return ''
return formatMessage(messages.noVersionsAvailable, {
gameVersion,
platform: currentPlatformText.value,
})
})
const selectedVersion = computed<Labrinth.Versions.v3.Version | null>(() => {
return filteredRelease.value || filteredBeta.value || filteredAlpha.value || null
return (
compatibleVersions.value.find(
(version) => version.id === userSelectedCompatibleVersionId.value,
) ||
defaultSelectedVersion.value ||
null
)
})
const selectedPrimaryFile = computed<Labrinth.Versions.v3.VersionFile | null>(() => {
@@ -442,39 +451,47 @@ const selectedPrimaryFile = computed<Labrinth.Versions.v3.VersionFile | null>(()
)
})
const selectedPrimaryFileDownloadUrl = computed(() => {
if (!selectedPrimaryFile.value) return '#'
return getDownloadUrl(selectedPrimaryFile.value.url)
const requiredResourcePackFile = computed<Labrinth.Versions.v3.VersionFile | null>(() => {
if (props.project.project_type !== 'datapack') return null
return (
selectedVersion.value?.files?.find(
(file) => file !== selectedPrimaryFile.value && file.file_type === 'required-resource-pack',
) || null
)
})
const selectedVersionDownloadFiles = computed(() => {
if (!selectedVersion.value) return []
const recommendedResourcePackFiles = computed<Labrinth.Versions.v3.VersionFile[]>(() => {
if (props.project.project_type !== 'datapack') return []
return selectedVersion.value.files.map((file) => ({
href: getDownloadUrl(file.url),
filename: file.filename,
}))
return (
selectedVersion.value?.files?.filter(
(file) => file !== selectedPrimaryFile.value && file.file_type === 'optional-resource-pack',
) || []
)
})
const downloadAllFiles = computed(() => {
const files: DownloadableFile[] = []
const hasAdditionalDownloads = computed(() => {
const hrefs = new Set<string>()
for (const file of [...selectedVersionDownloadFiles.value, ...props.dependencyDownloadFiles]) {
if (hrefs.has(file.href)) continue
hrefs.add(file.href)
files.push(file)
if (selectedPrimaryFile.value) {
hrefs.add(selectedPrimaryFile.value.url)
}
return files
})
if (requiredResourcePackFile.value) {
hrefs.add(requiredResourcePackFile.value.url)
}
const selectedVersionZipFilename = computed(() => {
if (!selectedVersion.value) return `${sanitizeFilename(props.project.title)}.zip`
for (const file of recommendedResourcePackFiles.value) {
hrefs.add(file.url)
}
return `${sanitizeFilename(props.project.title)} ${sanitizeFilename(
selectedVersion.value.version_number,
)}.zip`
for (const file of props.dependencyDownloadFiles) {
if (hrefs.has(file.href)) continue
hrefs.add(file.href)
}
return hrefs.size > 1
})
watch(
@@ -490,11 +507,16 @@ watch(
{ immediate: true },
)
watch([currentGameVersion, currentPlatform], () => {
userSelectedCompatibleVersionId.value = null
})
watch(
() => props.resetKey,
() => {
userSelectedGameVersion.value = props.initialGameVersion
userSelectedPlatform.value = props.initialPlatform
userSelectedCompatibleVersionId.value = null
showAllVersions.value = defaultShowAllVersions()
versionFilter.value = ''
},
@@ -513,115 +535,39 @@ function selectPlatform(platform?: string) {
emit('selectPlatform', platform)
}
function getDownloadUrl(url: string) {
return createProjectDownloadUrl(url, {
reason: props.downloadReason,
gameVersion: currentGameVersion.value ?? undefined,
loader: currentPlatform.value ?? undefined,
})
function selectCompatibleVersion(version: Labrinth.Versions.v3.Version) {
userSelectedCompatibleVersionId.value = version.id
}
async function downloadSelectedVersionFiles() {
if (downloadingSelectedVersion.value || downloadAllFiles.value.length <= 1) return
downloadingSelectedVersion.value = true
const files = [...downloadAllFiles.value]
selectedVersionDownloadProgress.value = {
current: 0,
total: files.length,
}
try {
const zip = new JSZip()
const usedFilenames = new Set<string>()
for (const [index, file] of files.entries()) {
selectedVersionDownloadProgress.value = {
current: index + 1,
total: files.length,
}
const response = await fetch(file.href)
if (!response.ok) {
throw new Error(`Failed to download ${file.filename}`)
}
zip.file(uniqueFilename(file.filename, usedFilenames), await response.blob())
}
downloadBlob(
await zip.generateAsync({
type: 'blob',
mimeType: 'application/zip',
}),
selectedVersionZipFilename.value,
)
emit('download')
} catch (error) {
console.error('Failed to download selected version files:', error)
addNotification({
title: formatMessage(messages.downloadSelectedVersionFailedTitle),
text: formatMessage(messages.downloadSelectedVersionFailedText),
type: 'error',
})
} finally {
downloadingSelectedVersion.value = false
selectedVersionDownloadProgress.value = {
current: 0,
total: 0,
}
}
function latestVersionByType(type: Labrinth.Versions.v3.VersionChannel) {
return filteredVersions.value
.filter((version) => version.version_type === type)
.reduce<Labrinth.Versions.v3.Version | undefined>((latest, version) => {
if (!latest || isNewerThan(version, latest)) return version
return latest
}, undefined)
}
function downloadBlob(blob: Blob, filename: string) {
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
link.remove()
window.setTimeout(() => URL.revokeObjectURL(url), 0)
}
function sanitizeFilename(value: string) {
const sanitized = value
.replace(/[<>:"/\\|?*]/g, '')
.replace(/\s+/g, ' ')
.trim()
return sanitized || 'download'
}
function uniqueFilename(filename: string, usedFilenames: Set<string>) {
const sanitizedFilename = sanitizeFilename(filename)
if (!usedFilenames.has(sanitizedFilename)) {
usedFilenames.add(sanitizedFilename)
return sanitizedFilename
}
const extensionIndex = sanitizedFilename.lastIndexOf('.')
const basename =
extensionIndex > 0 ? sanitizedFilename.slice(0, extensionIndex) : sanitizedFilename
const extension = extensionIndex > 0 ? sanitizedFilename.slice(extensionIndex) : ''
let index = 2
let candidate = `${basename} (${index})${extension}`
while (usedFilenames.has(candidate)) {
index += 1
candidate = `${basename} (${index})${extension}`
}
usedFilenames.add(candidate)
return candidate
function isNewerThan(
version: Labrinth.Versions.v3.Version,
comparison: Labrinth.Versions.v3.Version,
) {
return dayjs(version.date_published).isAfter(dayjs(comparison.date_published))
}
function loaderLabel(loader: string) {
return formatMessage(getTagMessage(loader, 'loader') ?? messages.unknownLoader)
}
function comparePlatformOptions(a: ComboboxOption<string>, b: ComboboxOption<string>) {
const aRank = preferredPlatformRanks.get(a.value) ?? Number.MAX_SAFE_INTEGER
const bRank = preferredPlatformRanks.get(b.value) ?? Number.MAX_SAFE_INTEGER
if (aRank !== bRank) return aRank - bRank
return a.label.localeCompare(b.label)
}
function isReleaseGameVersion(version: string) {
if (releaseVersions.value.has(version)) return true
if (nonReleaseVersions.value.has(version)) return false
@@ -706,29 +652,9 @@ const messages = defineMessages({
id: 'project.download.game-version-unsupported-tooltip',
defaultMessage: '{title} does not support {gameVersion} for {platform}',
},
downloadVersion: {
id: 'project.download.download-version',
defaultMessage: 'Download {version}',
},
compatibleVersionTitle: {
id: 'project.download.compatible-version-title',
defaultMessage: 'Compatible version',
},
downloadAllSelectedVersion: {
id: 'project.download.selected-version-download-all',
defaultMessage: 'Download all (.zip)',
},
downloadingSelectedVersion: {
id: 'project.download.selected-version-downloading',
defaultMessage: 'Downloading... ({current}/{total})',
},
downloadSelectedVersionFailedTitle: {
id: 'project.download.selected-version-failed-title',
defaultMessage: 'Could not download version',
},
downloadSelectedVersionFailedText: {
id: 'project.download.selected-version-failed-text',
defaultMessage: 'One or more version files could not be downloaded. Please try again.',
defaultMessage: 'Compatible versions',
},
noGameVersionsFound: {
id: 'project.download.no-game-versions-found',
@@ -6,29 +6,19 @@
"
class="modrinth-app-section contents"
>
<div class="flex flex-col">
<a
class="modrinth-app-install-card flex items-center justify-between gap-3 rounded-2xl border border-solid border-brand-highlight bg-surface-1 px-4 py-3 text-primary no-underline transition-[filter] hover:brightness-110"
:href="`modrinth://mod/${project.slug}`"
@click="installWithApp"
>
<span class="flex w-full min-w-0 flex-col gap-1">
<div class="flex items-center justify-between">
<span class="flex min-w-0 items-center gap-1.5 font-medium text-contrast">
Install with
<span class="text-brand">Modrinth App</span>
<ModrinthIcon aria-hidden="true" class="size-4 flex-shrink-0 text-brand" />
</span>
<ExternalIcon
aria-hidden="true"
class="size-4 flex-shrink-0 text-contrast transition-colors"
/>
</div>
<span class="truncate text-base text-contrast opacity-80">
{{ formatMessage(messages.installWithModrinthAppDescription) }}
<div class="flex flex-col items-center">
<ButtonStyled color="brand">
<a
class="!min-h-10 w-fit no-underline"
:href="`modrinth://mod/${project.slug}`"
@click="installWithApp"
>
<ModrinthIcon aria-hidden="true" />
<span class="min-w-0 text-center">
{{ formatMessage(messages.installWithModrinthApp) }}
</span>
</span>
</a>
</a>
</ButtonStyled>
<Accordion ref="getModrinthAppAccordion">
<nuxt-link class="mt-2 flex justify-center text-brand-blue hover:underline" to="/app">
{{ formatMessage(messages.dontHaveModrinthApp) }}
@@ -48,8 +38,8 @@
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { ExternalIcon, ModrinthIcon } from '@modrinth/assets'
import { defineMessages, useVIntl } from '@modrinth/ui'
import { ModrinthIcon } from '@modrinth/assets'
import { ButtonStyled, defineMessages, useVIntl } from '@modrinth/ui'
import type { DisplayProjectType } from '@modrinth/utils'
import { ref } from 'vue'
@@ -73,6 +63,10 @@ const tags = useGeneratedState()
const getModrinthAppAccordion = ref<InstanceType<typeof Accordion> | null>(null)
const messages = defineMessages({
installWithModrinthApp: {
id: 'project.download.install-with-app',
defaultMessage: 'Install with Modrinth App',
},
dontHaveModrinthApp: {
id: 'project.download.no-app',
defaultMessage: "Don't have Modrinth App?",
@@ -81,10 +75,6 @@ const messages = defineMessages({
id: 'project.download.manually',
defaultMessage: 'Download manually',
},
installWithModrinthAppDescription: {
id: 'project.download.install-with-app-description',
defaultMessage: 'Automatically install the correct version and dependencies.',
},
})
function installWithApp() {
@@ -95,14 +85,6 @@ function installWithApp() {
</script>
<style lang="scss" scoped>
.modrinth-app-install-card {
background: radial-gradient(
ellipse 90% 250% at 50% 200%,
color-mix(in srgb, var(--color-brand-shadow) 50%, var(--surface-1)) -30%,
var(--surface-1) 72%
);
}
@media (hover: none) and (max-width: 767px) {
.modrinth-app-section {
display: none;
@@ -0,0 +1,728 @@
import type { AbstractModrinthClient, Labrinth } from '@modrinth/api-client'
import {
type CdnDownloadReason,
createContext,
defineMessages,
fileTypeMessages,
injectModrinthClient,
useVIntl,
} from '@modrinth/ui'
import type { DisplayProjectType } from '@modrinth/utils'
import { useQuery, useQueryClient } from '@tanstack/vue-query'
import { type Component, computed, type ComputedRef } from 'vue'
import { STALE_TIME } from '~/composables/queries/project'
type DownloadModalProject = Omit<Labrinth.Projects.v2.Project, 'project_type'> & {
project_type: DisplayProjectType
actualProjectType: Labrinth.Projects.v2.ProjectType
}
type ResolvedContent = Labrinth.Content.v3.ResolvedContent | Labrinth.Content.v3.SkippedContent
export interface DownloadDependencyRow {
key: string
name: string
icon?: string
fallbackIcon?: Component
hideIcon?: boolean
isAdditionalFile?: boolean
projectHref?: string
downloadHref?: string
filename?: string
fileSize?: number
metadataLabel?: string
typeLabel: string
unavailableTooltip: string
dependencies: DownloadDependencyRow[]
}
export interface DownloadableDependencyFile {
href: string
filename: string
name: string
}
export interface ProjectDownloadSelection {
currentGameVersion: string | null
currentPlatform: string | null
selectedVersion: Labrinth.Versions.v3.Version | null
selectedPrimaryFile: Labrinth.Versions.v3.VersionFile | null
}
interface DownloadModalProviderOptions {
project: ComputedRef<DownloadModalProject | null>
selectedVersion: ComputedRef<Labrinth.Versions.v3.Version | null>
selectedPrimaryFile: ComputedRef<Labrinth.Versions.v3.VersionFile | null>
currentGameVersion: ComputedRef<string | null>
currentPlatform: ComputedRef<string | null>
downloadReason: ComputedRef<CdnDownloadReason>
additionalFiles: ComputedRef<Labrinth.Versions.v3.VersionFile[]>
}
export interface DownloadModalProvider {
visibleDependencyRows: ComputedRef<DownloadDependencyRow[]>
duplicateDependencyRowsHidden: ComputedRef<boolean>
downloadRows: ComputedRef<DownloadDependencyRow[]>
recommendedRows: ComputedRef<DownloadDependencyRow[]>
downloadRowsLoaded: ComputedRef<boolean>
requiredResourcePackAdmonitionVisible: ComputedRef<boolean>
dependencyResourcePackAdmonitionVisible: ComputedRef<boolean>
downloadableDependencyFiles: ComputedRef<DownloadableDependencyFile[]>
downloadableDependencyFilesLoaded: ComputedRef<boolean>
preloadDependenciesForSelection: (selection: ProjectDownloadSelection) => Promise<void>
}
export const [injectDownloadModalProvider, provideDownloadModalContext] =
createContext<DownloadModalProvider>('DownloadModal')
export function provideDownloadModalProvider(
options: DownloadModalProviderOptions,
): DownloadModalProvider {
const client = injectModrinthClient()
const queryClient = useQueryClient()
const { createProjectDownloadUrl } = useCdnDownloadContext()
const { formatMessage } = useVIntl()
const tags = useGeneratedState()
const shouldResolveDependencies = computed(
() => !!options.project.value && !!options.selectedVersion.value,
)
const dependencyResolutionPreferences = computed(() =>
createResolutionPreferences(options.selectedVersion.value, options.currentPlatform.value),
)
const { data: dependencyResolution, isFetching: dependencyResolutionFetching } = useQuery({
...dependencyResolutionQueryOptions(
client,
options.project,
options.selectedVersion,
dependencyResolutionPreferences,
),
enabled: shouldResolveDependencies,
})
const visibleResolvedDependencies = computed<ResolvedContent[]>(() =>
visibleDependencies(dependencyResolution.value),
)
const dependencyVersionIds = computed(() =>
sortedUnique(
visibleResolvedDependencies.value
.filter((dependency) => !('reason' in dependency))
.map((dependency) => dependency.version_id)
.filter((versionId): versionId is string => !!versionId),
),
)
const { data: dependencyVersions, isFetching: dependencyVersionsFetching } = useQuery({
...dependencyVersionsQueryOptions(client, dependencyVersionIds),
enabled: computed(
() => shouldResolveDependencies.value && dependencyVersionIds.value.length > 0,
),
})
const dependencyVersionById = computed(() => {
const map = new Map<string, Labrinth.Versions.v3.Version>()
for (const version of dependencyVersions.value || []) {
if (!version) continue
map.set(version.id, version)
}
return map
})
const dependencyProjectIds = computed(() =>
sortedUnique(
visibleResolvedDependencies.value
.map((dependency) => dependency.project_id)
.filter((projectId): projectId is string => !!projectId),
),
)
const { data: dependencyProjects, isFetching: dependencyProjectsFetching } = useQuery({
...dependencyProjectsQueryOptions(client, dependencyProjectIds),
enabled: computed(
() => shouldResolveDependencies.value && dependencyProjectIds.value.length > 0,
),
})
const dependencyProjectById = computed(() => {
const map = new Map<string, Labrinth.Projects.v2.Project>()
for (const project of dependencyProjects.value || []) {
map.set(project.id, project)
}
return map
})
const dependenciesByParentVersionId = computed(() => {
const map = new Map<string, ResolvedContent[]>()
for (const dependency of visibleResolvedDependencies.value) {
if (!dependency.dependent_on_version_id) continue
const dependencies = map.get(dependency.dependent_on_version_id) || []
dependencies.push(dependency)
map.set(dependency.dependent_on_version_id, dependencies)
}
return map
})
const dependenciesLoaded = computed(() => {
if (!shouldResolveDependencies.value) return false
if (dependencyResolutionFetching.value) return false
if (!dependencyResolution.value) return false
if (
dependencyResolution.value.primary.version_id &&
dependencyResolution.value.primary.version_id !== options.selectedVersion.value?.id
) {
return false
}
if (
dependencyVersionsFetching.value ||
!dependencyVersionIds.value.every((versionId) => dependencyVersionById.value.has(versionId))
) {
return false
}
if (
dependencyProjectsFetching.value ||
!dependencyProjectIds.value.every((projectId) => dependencyProjectById.value.has(projectId))
) {
return false
}
return true
})
const selectedDownloadRowsLoaded = computed(() => {
if (!options.selectedPrimaryFile.value) return false
return dependenciesLoaded.value
})
const keepPreviousDownloadRows = computed(
() => shouldResolveDependencies.value && !!options.selectedPrimaryFile.value,
)
const resolvedDependencyRows = computed<DownloadDependencyRow[]>(() => {
if (!selectedDownloadRowsLoaded.value) return []
const primaryVersionId =
dependencyResolution.value?.primary.version_id || options.selectedVersion.value?.id
if (!primaryVersionId) return []
const dependencies = dependenciesByParentVersionId.value.get(primaryVersionId) || []
return dependencies.flatMap((dependency) => {
const row = createDependencyRow(dependency)
return row ? [row] : []
})
})
const visibleDependencyRows = computed<DownloadDependencyRow[]>((previous) => {
if (selectedDownloadRowsLoaded.value) {
return dedupeDependencyRows(resolvedDependencyRows.value)
}
return keepPreviousDownloadRows.value ? (previous ?? []) : []
})
const duplicateDependencyRowsHidden = computed<boolean>((previous) => {
if (selectedDownloadRowsLoaded.value) {
return (
hasSkippedDuplicateDependency(dependencyResolution.value) ||
hasDuplicateDependencyRows(resolvedDependencyRows.value)
)
}
return keepPreviousDownloadRows.value ? (previous ?? false) : false
})
const visibleRequiredResourcePackFiles = computed(() => {
if (options.project.value?.project_type !== 'datapack') return []
return options.additionalFiles.value.filter(
(file) => file.file_type === 'required-resource-pack',
)
})
const visibleRecommendedResourcePackFiles = computed(() => {
if (options.project.value?.project_type !== 'datapack') return []
return options.additionalFiles.value.filter(
(file) => file.file_type === 'optional-resource-pack',
)
})
const additionalFileRows = computed<DownloadDependencyRow[]>(() =>
selectedDownloadRowsLoaded.value
? visibleRequiredResourcePackFiles.value.map(createAdditionalFileRow)
: [],
)
const recommendedRows = computed<DownloadDependencyRow[]>(() =>
selectedDownloadRowsLoaded.value
? visibleRecommendedResourcePackFiles.value.map(createAdditionalFileRow)
: [],
)
function createAdditionalFileRow(file: Labrinth.Versions.v3.VersionFile): DownloadDependencyRow {
return {
key: `additional-file-${additionalFileKey(file)}`,
name: file.filename,
hideIcon: true,
isAdditionalFile: true,
downloadHref: getDownloadUrl(file.url),
filename: file.filename,
fileSize: file.size,
metadataLabel: fileTypeDisplayLabel(file.file_type),
typeLabel: fileTypeLabel(file.file_type),
unavailableTooltip: formatMessage(messages.unavailableFile),
dependencies: [],
}
}
const downloadRows = computed<DownloadDependencyRow[]>((previous) => {
if (selectedDownloadRowsLoaded.value) {
return [...visibleDependencyRows.value, ...additionalFileRows.value]
}
return keepPreviousDownloadRows.value ? (previous ?? []) : []
})
const downloadRowsLoaded = computed<boolean>((previous) => {
if (selectedDownloadRowsLoaded.value) return true
return keepPreviousDownloadRows.value ? (previous ?? false) : false
})
const requiredResourcePackAdmonitionVisible = computed(() => {
return selectedDownloadRowsLoaded.value && visibleRequiredResourcePackFiles.value.length > 0
})
const dependencyResourcePackAdmonitionVisible = computed(() => {
return selectedDownloadRowsLoaded.value && hasAdditionalFileRows(visibleDependencyRows.value)
})
const downloadableDependencyFiles = computed<DownloadableDependencyFile[]>(() =>
collectDownloadableDependencyFiles(visibleDependencyRows.value),
)
const downloadableDependencyFilesLoaded = computed(() => {
return selectedDownloadRowsLoaded.value
})
async function preloadDependenciesForSelection(selection: ProjectDownloadSelection) {
if (!options.project.value || !selection.selectedVersion) return
const preferences = createResolutionPreferences(
selection.selectedVersion,
selection.currentPlatform,
)
const resolution = await queryClient.ensureQueryData({
queryKey: [
'project-download-modal',
'content-resolve',
options.project.value.id,
selection.selectedVersion.id,
options.project.value.project_type,
preferences,
],
queryFn: () =>
client.labrinth.content_v3.resolve({
project_id: options.project.value!.id,
version_id: selection.selectedVersion!.id,
content_type: resolveContentType(options.project.value!.project_type),
selected: preferences,
target: preferences,
}),
staleTime: STALE_TIME,
})
const visible = visibleDependencies(resolution)
const versionIds = getDependencyVersionIds(visible)
const projectIds = getDependencyProjectIds(visible)
await Promise.all([
versionIds.length > 0
? queryClient.ensureQueryData({
queryKey: ['project-download-modal', 'resolved-versions', versionIds],
queryFn: () => client.labrinth.versions_v3.getVersions(versionIds),
staleTime: STALE_TIME,
})
: Promise.resolve(),
projectIds.length > 0
? queryClient.ensureQueryData({
queryKey: ['project-download-modal', 'resolved-projects', projectIds],
queryFn: () => client.labrinth.projects_v2.getMultiple(projectIds),
staleTime: STALE_TIME,
})
: Promise.resolve(),
])
}
function createDependencyRow(dependency: ResolvedContent): DownloadDependencyRow | null {
const versionId = dependency.version_id ?? undefined
const version = versionId ? dependencyVersionById.value.get(versionId) : undefined
const project = dependencyProjectById.value.get(dependency.project_id)
if (!project) return null
const primaryFile = primaryFileForVersion(version)
const unavailableTooltip =
'reason' in dependency && dependency.reason
? skippedReasonLabel(dependency.reason)
: formatMessage(messages.unavailableDependency)
const name = project.title
const metadataLabel = isProjectOnlyDependencyReference(dependency)
? formatMessage(messages.anyCompatibleDependency)
: (version?.version_number ?? formatMessage(messages.anyCompatibleDependency))
const childDependencies = (
versionId && dependenciesByParentVersionId.value.get(versionId)
? dependenciesByParentVersionId.value.get(versionId)!
: []
).flatMap((subDependency) => {
const row = createDependencyRow(subDependency)
return row ? [row] : []
})
return {
key: `${dependency.project_id}-${versionId ?? 'unresolved'}-${
'reason' in dependency ? dependency.reason : 'resolved'
}`,
name,
icon: project.icon_url ?? undefined,
projectHref: `/${project.project_type}/${project.slug || project.id}`,
downloadHref:
'reason' in dependency || !primaryFile ? undefined : getDownloadUrl(primaryFile.url),
filename: primaryFile?.filename,
fileSize: primaryFile?.size,
metadataLabel,
typeLabel: 'Required',
unavailableTooltip,
dependencies: [
...childDependencies,
...createRequiredResourcePackRowsForDependency(project, version, primaryFile),
],
}
}
function createRequiredResourcePackRowsForDependency(
project: Labrinth.Projects.v2.Project,
version: Labrinth.Versions.v3.Version | undefined,
primaryFile: Labrinth.Versions.v3.VersionFile | undefined,
): DownloadDependencyRow[] {
if (!version || !isDataPackProject(project)) return []
return version.files
.filter((file) => file !== primaryFile && file.file_type === 'required-resource-pack')
.map((file) => ({
key: `dependency-resource-pack-${version.id}-${additionalFileKey(file)}`,
name: file.filename,
hideIcon: true,
isAdditionalFile: true,
downloadHref: getDownloadUrl(file.url),
filename: file.filename,
fileSize: file.size,
metadataLabel: fileTypeDisplayLabel(file.file_type),
typeLabel: fileTypeLabel(file.file_type),
unavailableTooltip: formatMessage(messages.unavailableFile),
dependencies: [],
}))
}
function isDataPackProject(project: Labrinth.Projects.v2.Project) {
return (
project.project_type === 'datapack' ||
project.loaders.some((loader) => tags.value.loaderData.dataPackLoaders.includes(loader))
)
}
function isProjectOnlyDependencyReference(dependency: ResolvedContent) {
const parentVersionId = dependency.dependent_on_version_id
const parentVersion =
parentVersionId === options.selectedVersion.value?.id
? options.selectedVersion.value
: parentVersionId
? dependencyVersionById.value.get(parentVersionId)
: undefined
return !!parentVersion?.dependencies?.some(
(parentDependency) =>
parentDependency.project_id === dependency.project_id && !parentDependency.version_id,
)
}
function skippedReasonLabel(reason: Labrinth.Content.v3.SkippedContent['reason']) {
return (
{
already_installed: formatMessage(messages.alreadyInstalledDependency),
duplicate_project: formatMessage(messages.duplicateDependency),
conflicting_dependency: formatMessage(messages.conflictingDependency),
no_compatible_version: formatMessage(messages.noCompatibleDependency),
missing_version: formatMessage(messages.missingDependencyVersion),
quilt_fabric_api: formatMessage(messages.quiltFabricApiDependency),
}[reason] || formatMessage(messages.unavailableDependency)
)
}
function getDownloadUrl(url: string) {
return createProjectDownloadUrl(url, {
reason: options.downloadReason.value,
gameVersion: options.currentGameVersion.value ?? undefined,
loader: options.currentPlatform.value ?? undefined,
})
}
function fileTypeLabel(type?: Labrinth.Versions.v3.FileType | null) {
return formatMessage(fileTypeMessages[type ?? 'unknown'] ?? fileTypeMessages.unknown)
}
function fileTypeDisplayLabel(type?: Labrinth.Versions.v3.FileType | null) {
if (type === 'required-resource-pack') return formatMessage(messages.requiredResourcePackShort)
return fileTypeLabel(type)
}
const provider = {
visibleDependencyRows,
duplicateDependencyRowsHidden,
downloadRows,
recommendedRows,
downloadRowsLoaded,
requiredResourcePackAdmonitionVisible,
dependencyResourcePackAdmonitionVisible,
downloadableDependencyFiles,
downloadableDependencyFilesLoaded,
preloadDependenciesForSelection,
}
provideDownloadModalContext(provider)
return provider
}
function dependencyResolutionQueryOptions(
client: AbstractModrinthClient,
project: ComputedRef<DownloadModalProject | null>,
selectedVersion: ComputedRef<Labrinth.Versions.v3.Version | null>,
preferences: ComputedRef<Labrinth.Content.v3.ResolutionPreferences>,
) {
return {
queryKey: computed(() => [
'project-download-modal',
'content-resolve',
project.value?.id,
selectedVersion.value?.id,
project.value?.project_type,
preferences.value,
]),
queryFn: () =>
client.labrinth.content_v3.resolve({
project_id: project.value!.id,
version_id: selectedVersion.value!.id,
content_type: resolveContentType(project.value!.project_type),
selected: preferences.value,
target: preferences.value,
}),
staleTime: STALE_TIME,
}
}
function dependencyVersionsQueryOptions(
client: AbstractModrinthClient,
versionIds: ComputedRef<string[]>,
) {
return {
queryKey: computed(() => ['project-download-modal', 'resolved-versions', versionIds.value]),
queryFn: () => client.labrinth.versions_v3.getVersions(versionIds.value),
staleTime: STALE_TIME,
}
}
function dependencyProjectsQueryOptions(
client: AbstractModrinthClient,
projectIds: ComputedRef<string[]>,
) {
return {
queryKey: computed(() => ['project-download-modal', 'resolved-projects', projectIds.value]),
queryFn: () => client.labrinth.projects_v2.getMultiple(projectIds.value),
staleTime: STALE_TIME,
}
}
function createResolutionPreferences(
version: Labrinth.Versions.v3.Version | null,
currentPlatform: string | null,
): Labrinth.Content.v3.ResolutionPreferences {
return {
game_versions: version?.game_versions || [],
loaders: currentPlatform ? [currentPlatform] : version?.loaders || [],
}
}
function visibleDependencies(resolution?: Labrinth.Content.v3.ResolveContentPlan) {
return [...(resolution?.dependencies || []), ...(resolution?.skipped || [])].filter(
shouldShowDependency,
)
}
function getDependencyVersionIds(dependencies: ResolvedContent[]) {
return sortedUnique(
dependencies
.filter((dependency) => !('reason' in dependency))
.map((dependency) => dependency.version_id)
.filter((versionId): versionId is string => !!versionId),
)
}
function getDependencyProjectIds(dependencies: ResolvedContent[]) {
return sortedUnique(
dependencies
.map((dependency) => dependency.project_id)
.filter((projectId): projectId is string => !!projectId),
)
}
function primaryFileForVersion(version?: Labrinth.Versions.v3.Version) {
return version?.files?.find((file) => file.primary) || version?.files?.[0]
}
function shouldShowDependency(dependency: ResolvedContent) {
return !(
'reason' in dependency && ['duplicate_project', 'quilt_fabric_api'].includes(dependency.reason)
)
}
function hasSkippedDuplicateDependency(resolution?: Labrinth.Content.v3.ResolveContentPlan) {
return (resolution?.skipped || []).some((dependency) => dependency.reason === 'duplicate_project')
}
function resolveContentType(projectType: DisplayProjectType): Labrinth.Content.v3.ContentType {
return ['mod', 'plugin', 'datapack', 'resourcepack', 'shader', 'modpack'].includes(projectType)
? (projectType as Labrinth.Content.v3.ContentType)
: 'mod'
}
function additionalFileKey(file: Labrinth.Versions.v3.VersionFile) {
return file.hashes?.sha1 ?? file.filename
}
function dedupeDependencyRows(
rows: DownloadDependencyRow[],
seenDependencies = new Set<string>(),
): DownloadDependencyRow[] {
return rows.flatMap((row) => {
const identity = dependencyRowIdentity(row)
if (seenDependencies.has(identity)) return []
seenDependencies.add(identity)
return [
{
...row,
dependencies: dedupeDependencyRows(row.dependencies, seenDependencies),
},
]
})
}
function dependencyRowIdentity(row: DownloadDependencyRow) {
return row.projectHref ?? row.downloadHref ?? row.key
}
function hasDuplicateDependencyRows(
rows: DownloadDependencyRow[],
seenDependencies = new Set<string>(),
): boolean {
for (const row of rows) {
const rowId = dependencyRowIdentity(row)
if (seenDependencies.has(rowId)) return true
seenDependencies.add(rowId)
if (hasDuplicateDependencyRows(row.dependencies, seenDependencies)) return true
}
return false
}
function hasAdditionalFileRows(rows: DownloadDependencyRow[]): boolean {
for (const row of rows) {
if (row.isAdditionalFile) return true
if (hasAdditionalFileRows(row.dependencies)) return true
}
return false
}
function collectDownloadableDependencyFiles(
rows: DownloadDependencyRow[],
seenHrefs = new Set<string>(),
): DownloadableDependencyFile[] {
const files: DownloadableDependencyFile[] = []
for (const row of rows) {
if (row.downloadHref && !seenHrefs.has(row.downloadHref)) {
seenHrefs.add(row.downloadHref)
files.push({
href: row.downloadHref,
filename: row.filename || filenameFromUrl(row.downloadHref),
name: row.name,
})
}
files.push(...collectDownloadableDependencyFiles(row.dependencies, seenHrefs))
}
return files
}
function filenameFromUrl(url: string) {
try {
const filename = new URL(url).pathname.split('/').pop()
return filename ? decodeURIComponent(filename) : 'dependency.jar'
} catch {
return 'dependency.jar'
}
}
function sortedUnique(values: string[]) {
return [...new Set(values)].sort()
}
const messages = defineMessages({
anyCompatibleDependency: {
id: 'project.download.dependency-any-compatible',
defaultMessage: 'Any compatible',
},
alreadyInstalledDependency: {
id: 'project.download.dependency-already-installed',
defaultMessage: 'This dependency is already installed',
},
conflictingDependency: {
id: 'project.download.dependency-conflicting',
defaultMessage: 'This dependency conflicts with another dependency',
},
duplicateDependency: {
id: 'project.download.dependency-duplicate',
defaultMessage: 'This dependency is already included',
},
missingDependencyVersion: {
id: 'project.download.dependency-missing-version',
defaultMessage: 'This dependency version is unavailable',
},
noCompatibleDependency: {
id: 'project.download.dependency-no-compatible-version',
defaultMessage: 'No compatible version is available for this dependency',
},
quiltFabricApiDependency: {
id: 'project.download.dependency-quilt-fabric-api',
defaultMessage: 'Fabric API is skipped for Quilt',
},
unavailableDependency: {
id: 'project.download.dependency-unavailable',
defaultMessage: 'This dependency cannot be downloaded',
},
unavailableFile: {
id: 'project.download.file-unavailable',
defaultMessage: 'This file cannot be downloaded',
},
requiredResourcePackShort: {
id: 'project.download.required-resource-pack-short',
defaultMessage: 'Resource pack',
},
})
@@ -1,5 +1,5 @@
<template>
<NewModal ref="modal" :on-show="onShow" :on-hide="onHide" width="544px">
<NewModal ref="modal" :on-show="onShow" :on-hide="onHide" width="544px" actions-divider>
<template #title>
<template v-if="project">
<Avatar :src="project.icon_url" :alt="project.title" class="icon" size="32px" />
@@ -19,6 +19,8 @@
:project="project"
:versions="versions"
:dependency-download-files="dependencyDownloadFiles"
:download-data-loaded="downloadRowsLoaded"
:versions-loaded="versionsLoaded"
:download-reason="downloadReason"
:initial-game-version="initialGameVersion"
:initial-platform="initialPlatform"
@@ -27,20 +29,11 @@
:reset-key="downloadProjectResetKey"
@select-game-version="selectGameVersion"
@select-platform="selectPlatform"
@update:selection="projectDownloadSelection = $event"
@update:selection="updateProjectDownloadSelection"
@download="onDownload"
/>
<div class="flex flex-col gap-4">
<DownloadDependencies
:project="project"
:selected-version="selectedVersion"
:current-game-version="currentGameVersion"
:current-platform="currentPlatform"
:download-reason="downloadReason"
:additional-files="additionalFiles"
@update:downloadable-files="dependencyDownloadFiles = $event"
@download="onDownload"
/>
<DownloadDependencies @download="onDownload" />
</div>
<ServersPromo
v-if="flags.showProjectPageDownloadModalServersPromo"
@@ -54,16 +47,61 @@
/>
</div>
</template>
<template v-if="showDependencyDownloadActions" #actions>
<div class="flex flex-wrap justify-end gap-2 p-2">
<ButtonStyled>
<button
class="!shadow-none"
:disabled="!!downloadingActionType || !dependencyDownloadFilesLoaded"
@click="downloadSelectedVersionZip"
>
<SpinnerIcon
v-if="downloadingActionType === 'zip'"
aria-hidden="true"
class="animate-spin"
/>
<DownloadIcon v-else aria-hidden="true" />
{{ formatMessage(messages.downloadAsZip) }}
</button>
</ButtonStyled>
<JoinedButtons
v-if="hasRecommendedDownloadFiles"
color="brand"
:actions="downloadWithRecommendedActions"
:disabled="!!downloadingActionType || !dependencyDownloadFilesLoaded"
/>
<ButtonStyled v-else color="brand">
<button
class="!shadow-none"
:disabled="!!downloadingActionType || !dependencyDownloadFilesLoaded"
@click="downloadFilesWithDependencies"
>
<SpinnerIcon
v-if="downloadingActionType === 'dependencies'"
aria-hidden="true"
class="animate-spin"
/>
<DownloadIcon v-else aria-hidden="true" />
{{ formatMessage(messages.downloadWithDependencies) }}
</button>
</ButtonStyled>
</div>
</template>
</NewModal>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { DownloadIcon, SpinnerIcon } from '@modrinth/assets'
import {
Avatar,
ButtonStyled,
type CdnDownloadReason,
defineMessages,
injectModrinthClient,
injectNotificationManager,
type JoinedButtonAction,
JoinedButtons,
NewModal,
ServersPromo,
truncatedTooltip,
@@ -71,13 +109,16 @@ import {
useVIntl,
} from '@modrinth/ui'
import type { DisplayProjectType } from '@modrinth/utils'
import { useQuery } from '@tanstack/vue-query'
import { useQuery, useQueryClient } from '@tanstack/vue-query'
import dayjs from 'dayjs'
import JSZip from 'jszip'
import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
import { navigateTo } from '#app'
import { saveFeatureFlags } from '~/composables/featureFlags.ts'
import { STALE_TIME, STALE_TIME_LONG } from '~/composables/queries/project'
import { provideDownloadModalProvider } from './download-modal-provider'
import DownloadDependencies from './DownloadDependencies.vue'
import DownloadProject from './DownloadProject.vue'
import InstallWithModrinthApp from './InstallWithModrinthApp.vue'
@@ -99,6 +140,12 @@ type DownloadableFile = {
filename: string
}
type DownloadedFile = DownloadableFile & {
blob: Blob
}
type DownloadActionType = 'zip' | 'dependencies' | 'recommended'
type NewModalRef = {
show: (event?: MouseEvent) => void
hide: () => void
@@ -138,19 +185,31 @@ const route = useRoute()
const flags = useFeatureFlags()
const tags = useGeneratedState()
const client = injectModrinthClient()
const queryClient = useQueryClient()
const { createProjectDownloadUrl } = useCdnDownloadContext()
const { addNotification } = injectNotificationManager()
const { formatMessage } = useVIntl()
const debug = useDebugLogger('DownloadModal')
const modal = ref<NewModalRef | null>(null)
const downloadTitleRef = ref<HTMLElement | null>(null)
const modalOpening = ref(false)
const modalOpen = ref(false)
const showProjectId = ref<string | null>(null)
const showOptions = ref<ResolvedProjectDownloadModalShowOptions>(getDefaultShowOptions())
const downloadProjectResetKey = ref(0)
const projectDownloadSelection = ref<ProjectDownloadSelection>(getDefaultProjectDownloadSelection())
const dependencyDownloadFiles = ref<DownloadableFile[]>([])
const pendingRouteSelection = ref({
gameVersion: getStringQueryValue(route.query.version),
platform: getStringQueryValue(route.query.loader),
})
const downloadingActionType = ref<DownloadActionType | null>(null)
const MODAL_CLOSE_STATE_RESET_MS = 350
const DOWNLOAD_URL_REVOKE_MS = 60000
const DOWNLOAD_STAGGER_MS = 500
let closeStateResetTimeout: ReturnType<typeof setTimeout> | null = null
let modalShowRequestId = 0
let unmounted = false
const routeProjectId = computed(() => showProjectId.value ?? props.projectId ?? null)
@@ -183,11 +242,7 @@ const downloadTitle = computed(() => {
})
const versionsEnabled = ref(false)
const {
data: versionsV3,
error: _versionsV3Error,
isFetching: versionsV3Loading,
} = useQuery({
const { data: versionsV3, isFetching: versionsV3Loading } = useQuery({
queryKey: computed(() => ['project', resolvedProjectId.value, 'versions', 'v3']),
queryFn: () =>
client.labrinth.versions_v3.getProjectVersions(resolvedProjectId.value!, {
@@ -198,24 +253,12 @@ const {
enabled: computed(() => !!resolvedProjectId.value && versionsEnabled.value),
})
const versions = computed<Labrinth.Versions.v3.Version[]>(() => {
const isModpack =
project.value?.actualProjectType === 'modpack' || project.value?.project_type === 'modpack'
return (versionsV3.value ?? []).map((version) => {
const files = Array.isArray(version.files) ? version.files : []
const gameVersions = Array.isArray(version.game_versions) ? version.game_versions : []
const loaders = Array.isArray(version.loaders) ? version.loaders : []
const mrpackLoaders = Array.isArray(version.mrpack_loaders) ? version.mrpack_loaders : []
return {
...version,
files,
game_versions: gameVersions,
loaders: isModpack && mrpackLoaders.length ? mrpackLoaders : loaders,
}
})
})
const versions = computed<Labrinth.Versions.v3.Version[]>(() =>
normalizeVersionsForDownload(versionsV3.value ?? []),
)
const versionsLoaded = computed(
() => versionsEnabled.value && !versionsV3Loading.value && Array.isArray(versionsV3.value),
)
const initialGameVersion = computed(() => {
const version = route.query.version
@@ -238,6 +281,88 @@ const additionalFiles = computed(() => {
return selectedVersion.value.files.filter((file) => file !== selectedPrimaryFile.value)
})
const hasRequiredResourcePackAdditionalFile = computed(() =>
additionalFiles.value.some((file) => file.file_type === 'required-resource-pack'),
)
const downloadModalProvider = provideDownloadModalProvider({
project,
selectedVersion,
selectedPrimaryFile,
currentGameVersion,
currentPlatform,
downloadReason: computed(() => props.downloadReason),
additionalFiles,
})
const dependencyDownloadFiles = downloadModalProvider.downloadableDependencyFiles
const dependencyDownloadFilesLoaded = downloadModalProvider.downloadableDependencyFilesLoaded
const downloadRowsLoaded = downloadModalProvider.downloadRowsLoaded
const selectedVersionDownloadFiles = computed<DownloadableFile[]>(() => {
if (!selectedVersion.value) return []
return selectedVersion.value.files
.filter(
(file) => file === selectedPrimaryFile.value || file.file_type === 'required-resource-pack',
)
.map((file) => ({
href: createProjectDownloadUrl(file.url, {
reason: props.downloadReason,
gameVersion: currentGameVersion.value ?? undefined,
loader: currentPlatform.value ?? undefined,
}),
filename: file.filename,
}))
})
const recommendedDownloadFiles = computed<DownloadableFile[]>(() => {
if (project.value?.project_type !== 'datapack' || !selectedVersion.value) return []
return selectedVersion.value.files
.filter(
(file) => file !== selectedPrimaryFile.value && file.file_type === 'optional-resource-pack',
)
.map((file) => ({
href: createProjectDownloadUrl(file.url, {
reason: props.downloadReason,
gameVersion: currentGameVersion.value ?? undefined,
loader: currentPlatform.value ?? undefined,
}),
filename: file.filename,
}))
})
const hasRecommendedDownloadFiles = computed(() => recommendedDownloadFiles.value.length > 0)
const showDependencyDownloadActions = computed(
() =>
selectedVersionDownloadFiles.value.length > 0 &&
(dependencyDownloadFiles.value.length > 0 ||
hasRequiredResourcePackAdditionalFile.value ||
hasRecommendedDownloadFiles.value),
)
const downloadWithRecommendedActions = computed<JoinedButtonAction[]>(() => [
{
id: 'download-with-dependencies',
label: formatMessage(messages.downloadWithDependencies),
icon: downloadingActionType.value === 'dependencies' ? SpinnerIcon : DownloadIcon,
action: () => void downloadFilesWithDependencies(),
},
{
id: 'download-with-recommended',
label: formatMessage(messages.downloadWithRecommended),
icon: DownloadIcon,
action: () => void downloadFilesWithRecommended(),
},
{
id: 'download-with-recommended-zip',
label: formatMessage(messages.downloadWithRecommendedAsZip),
icon: DownloadIcon,
action: () => void downloadSelectedVersionZip(),
},
])
watch(projectV2Error, (error) => {
if (error) {
debug('project query failed', error)
@@ -249,6 +374,30 @@ const messages = defineMessages({
id: 'project.download.title',
defaultMessage: 'Download {title}',
},
downloadAsZip: {
id: 'project.download.download-as-zip',
defaultMessage: 'Download as .zip',
},
downloadWithDependencies: {
id: 'project.download.download-with-dependencies',
defaultMessage: 'Download with deps',
},
downloadWithRecommended: {
id: 'project.download.download-with-recommended',
defaultMessage: 'Download with recommended',
},
downloadWithRecommendedAsZip: {
id: 'project.download.download-with-recommended-as-zip',
defaultMessage: 'Download with recommended as .zip',
},
downloadZipFailedTitle: {
id: 'project.download.zip-failed-title',
defaultMessage: 'Could not download files',
},
downloadZipFailedText: {
id: 'project.download.zip-failed-text',
defaultMessage: 'One or more files could not be downloaded. Please try again.',
},
})
function getProjectTypeForUrl(
@@ -278,15 +427,27 @@ function updateDownloadQuery({
platform: string | null
}) {
if (!props.updateRouteSelection) return
const nextGameVersion =
gameVersion ??
pendingRouteSelection.value.gameVersion ??
getStringQueryValue(route.query.version)
const nextPlatform =
platform ?? pendingRouteSelection.value.platform ?? getStringQueryValue(route.query.loader)
pendingRouteSelection.value = {
gameVersion: nextGameVersion,
platform: nextPlatform,
}
navigateTo(
{
query: {
...route.query,
...(gameVersion && {
version: gameVersion,
...(nextGameVersion && {
version: nextGameVersion,
}),
...(platform && {
loader: platform,
...(nextPlatform && {
loader: nextPlatform,
}),
},
hash: route.hash,
@@ -298,17 +459,25 @@ function updateDownloadQuery({
function selectGameVersion(gameVersion: string) {
updateDownloadQuery({
gameVersion,
platform: currentPlatform.value,
platform: null,
})
}
function selectPlatform(platform: string) {
updateDownloadQuery({
gameVersion: currentGameVersion.value,
gameVersion: null,
platform,
})
}
function updateProjectDownloadSelection(selection: ProjectDownloadSelection) {
projectDownloadSelection.value = selection
pendingRouteSelection.value = {
gameVersion: selection.currentGameVersion,
platform: selection.currentPlatform,
}
}
function onShow() {
clearCloseStateResetTimeout()
modalOpen.value = true
@@ -337,22 +506,37 @@ async function show(
event?: MouseEvent,
options: ProjectDownloadModalShowOptions = {},
): Promise<void> {
if (!modal.value || modalOpen.value) return
await waitForCloseStateReset()
if (!modal.value || modalOpen.value) return
showOptions.value = {
...getDefaultShowOptions(),
...options,
if (!modal.value || modalOpening.value || modalOpen.value) return
const showRequestId = ++modalShowRequestId
modalOpening.value = true
try {
await waitForCloseStateReset()
if (!isActiveShowRequest(showRequestId)) return
showOptions.value = {
...getDefaultShowOptions(),
...options,
}
showProjectId.value = showOptions.value.projectId ?? null
await nextTick()
if (!isActiveShowRequest(showRequestId)) return
if (!(await loadProjectForModal(!!showOptions.value.projectId))) return
if (!isActiveShowRequest(showRequestId)) return
resetDownloadState()
await preloadRouteSelectedDownload()
if (!isActiveShowRequest(showRequestId)) return
modalOpen.value = true
modal.value.show(event)
} finally {
if (modalShowRequestId === showRequestId) {
modalOpening.value = false
}
}
showProjectId.value = showOptions.value.projectId ?? null
await nextTick()
if (!(await loadProjectForModal(!!showOptions.value.projectId))) return
resetDownloadState()
modalOpen.value = true
modal.value.show(event)
}
function hide() {
modalShowRequestId += 1
modalOpening.value = false
if (!modal.value || !modalOpen.value) return
modal.value?.hide()
}
@@ -361,6 +545,199 @@ function onDownload() {
emit('download')
}
async function downloadSelectedVersionZip() {
if (downloadingActionType.value || !dependencyDownloadFilesLoaded.value) return
downloadingActionType.value = 'zip'
const files = dedupeDownloadFiles([
...selectedVersionDownloadFiles.value,
...dependencyDownloadFiles.value,
...recommendedDownloadFiles.value,
])
try {
const zip = new JSZip()
const usedFilenames = new Set<string>()
const downloadedFiles = await downloadFileBlobs(files)
for (const file of downloadedFiles) {
zip.file(uniqueFilename(file.filename, usedFilenames), file.blob)
}
downloadBlob(
await zip.generateAsync({
type: 'blob',
mimeType: 'application/zip',
}),
selectedVersionZipFilename(),
)
emit('download')
} catch (error) {
console.error('Failed to download selected version files:', error)
addNotification({
title: formatMessage(messages.downloadZipFailedTitle),
text: formatMessage(messages.downloadZipFailedText),
type: 'error',
})
} finally {
downloadingActionType.value = null
}
}
async function downloadFilesWithDependencies() {
if (downloadingActionType.value || !dependencyDownloadFilesLoaded.value) return
downloadingActionType.value = 'dependencies'
try {
const files = dedupeDownloadFiles([
...selectedVersionDownloadFiles.value,
...dependencyDownloadFiles.value,
])
await downloadFiles(files)
emit('download')
} catch (error) {
console.error('Failed to download selected version files:', error)
addNotification({
title: formatMessage(messages.downloadZipFailedTitle),
text: formatMessage(messages.downloadZipFailedText),
type: 'error',
})
} finally {
downloadingActionType.value = null
}
}
async function downloadFilesWithRecommended() {
if (downloadingActionType.value || !dependencyDownloadFilesLoaded.value) return
downloadingActionType.value = 'recommended'
try {
const files = dedupeDownloadFiles([
...selectedVersionDownloadFiles.value,
...dependencyDownloadFiles.value,
...recommendedDownloadFiles.value,
])
await downloadFiles(files)
emit('download')
} catch (error) {
console.error('Failed to download selected version files:', error)
addNotification({
title: formatMessage(messages.downloadZipFailedTitle),
text: formatMessage(messages.downloadZipFailedText),
type: 'error',
})
} finally {
downloadingActionType.value = null
}
}
async function downloadFileBlobs(files: DownloadableFile[]): Promise<DownloadedFile[]> {
return Promise.all(files.map((file) => downloadFileBlob(file)))
}
async function downloadFileBlob(file: DownloadableFile): Promise<DownloadedFile> {
const response = await fetch(file.href)
if (!response.ok) {
throw new Error(`Failed to download ${file.filename}`)
}
return {
...file,
blob: await response.blob(),
}
}
async function downloadFiles(files: DownloadableFile[]) {
await Promise.all(
files.map(async (file, index) => {
await delay(DOWNLOAD_STAGGER_MS * index)
downloadFileLink(file)
}),
)
}
function dedupeDownloadFiles(files: DownloadableFile[]) {
const result: DownloadableFile[] = []
const hrefs = new Set<string>()
for (const file of files) {
if (hrefs.has(file.href)) continue
hrefs.add(file.href)
result.push(file)
}
return result
}
function downloadBlob(blob: Blob, filename: string) {
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
link.remove()
window.setTimeout(() => URL.revokeObjectURL(url), DOWNLOAD_URL_REVOKE_MS)
}
function downloadFileLink(file: DownloadableFile) {
const link = document.createElement('a')
link.href = file.href
link.download = file.filename
document.body.appendChild(link)
link.click()
link.remove()
}
function selectedVersionZipFilename() {
if (!project.value || !selectedVersion.value) return 'download.zip'
return `${sanitizeFilename(project.value.title)} ${sanitizeFilename(
selectedVersion.value.version_number,
)}-EXTRACT_ME.zip`
}
function sanitizeFilename(value: string) {
const sanitized = value
.replace(/[<>:"/\\|?*]/g, '')
.replace(/\s+/g, ' ')
.trim()
return sanitized || 'download'
}
function uniqueFilename(filename: string, usedFilenames: Set<string>) {
const sanitizedFilename = sanitizeFilename(filename)
if (!usedFilenames.has(sanitizedFilename)) {
usedFilenames.add(sanitizedFilename)
return sanitizedFilename
}
const extensionIndex = sanitizedFilename.lastIndexOf('.')
const basename =
extensionIndex > 0 ? sanitizedFilename.slice(0, extensionIndex) : sanitizedFilename
const extension = extensionIndex > 0 ? sanitizedFilename.slice(extensionIndex) : ''
let index = 2
let candidate = `${basename} (${index})${extension}`
while (usedFilenames.has(candidate)) {
index += 1
candidate = `${basename} (${index})${extension}`
}
usedFilenames.add(candidate)
return candidate
}
function getDefaultProjectDownloadSelection(): ProjectDownloadSelection {
return {
currentGameVersion: null,
@@ -378,6 +755,19 @@ function getDefaultShowOptions(): ResolvedProjectDownloadModalShowOptions {
}
}
function getStringQueryValue(value: unknown) {
return typeof value === 'string' ? value : null
}
function shouldPreloadRouteSelectedDownload() {
return (
props.useRouteHash &&
!showOptions.value.projectId &&
!!getStringQueryValue(route.query.version) &&
!!getStringQueryValue(route.query.loader)
)
}
function clearCloseStateResetTimeout() {
if (!closeStateResetTimeout) return
clearTimeout(closeStateResetTimeout)
@@ -386,7 +776,11 @@ function clearCloseStateResetTimeout() {
async function waitForCloseStateReset() {
if (!closeStateResetTimeout) return
await new Promise((resolve) => setTimeout(resolve, MODAL_CLOSE_STATE_RESET_MS))
await delay(MODAL_CLOSE_STATE_RESET_MS)
}
async function delay(ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms))
}
async function loadProjectForModal(forceRefetch: boolean) {
@@ -397,9 +791,127 @@ async function loadProjectForModal(forceRefetch: boolean) {
return !!data
}
async function loadVersionsForModal() {
if (!resolvedProjectId.value) return null
versionsEnabled.value = true
if (versionsV3.value) return versions.value
const data = await queryClient.ensureQueryData({
queryKey: ['project', resolvedProjectId.value, 'versions', 'v3'],
queryFn: () =>
client.labrinth.versions_v3.getProjectVersions(resolvedProjectId.value!, {
include_changelog: false,
apiVersion: 3,
}),
staleTime: STALE_TIME_LONG,
})
return Array.isArray(data) ? normalizeVersionsForDownload(data) : null
}
async function preloadRouteSelectedDownload() {
if (!shouldPreloadRouteSelectedDownload()) return
try {
const routeVersions = await loadVersionsForModal()
if (!routeVersions) return
const selection = getRouteSelectedDownloadSelection(routeVersions)
if (!selection) return
await preloadDependenciesForSelection(selection)
} catch (error) {
debug('failed to preload selected route download', error)
}
}
function getRouteSelectedDownloadSelection(
versionList: Labrinth.Versions.v3.Version[] = versions.value,
): ProjectDownloadSelection | null {
const gameVersion = initialGameVersion.value
const platform = initialPlatform.value
const version = getSelectedRouteVersion(gameVersion, platform, versionList)
const primaryFile = version?.files?.find((file) => file.primary) || version?.files?.[0] || null
if (!gameVersion || !platform || !version || !primaryFile) return null
return {
currentGameVersion: gameVersion,
currentPlatform: platform,
selectedVersion: version,
selectedPrimaryFile: primaryFile,
}
}
function getSelectedRouteVersion(
gameVersion: string | null,
platform: string | null,
versionList: Labrinth.Versions.v3.Version[],
) {
if (!gameVersion || !platform || !project.value) return null
const filteredVersions = versionList.filter((version) => {
const matchesPlatform =
project.value?.project_type === 'resourcepack' ||
(!!platform && version.loaders.includes(platform))
return version.game_versions.includes(gameVersion) && matchesPlatform
})
return (
latestVersionByType(filteredVersions, 'release') ||
latestVersionByType(filteredVersions, 'beta') ||
latestVersionByType(filteredVersions, 'alpha') ||
null
)
}
function normalizeVersionsForDownload(
versionList: Labrinth.Versions.v3.Version[],
): Labrinth.Versions.v3.Version[] {
const isModpack =
project.value?.actualProjectType === 'modpack' || project.value?.project_type === 'modpack'
return versionList.map((version) => {
const files = Array.isArray(version.files) ? version.files : []
const gameVersions = Array.isArray(version.game_versions) ? version.game_versions : []
const loaders = Array.isArray(version.loaders) ? version.loaders : []
const mrpackLoaders = Array.isArray(version.mrpack_loaders) ? version.mrpack_loaders : []
return {
...version,
files,
game_versions: gameVersions,
loaders: isModpack && mrpackLoaders.length ? mrpackLoaders : loaders,
}
})
}
function latestVersionByType(
versionList: Labrinth.Versions.v3.Version[],
type: Labrinth.Versions.v3.VersionChannel,
) {
return versionList
.filter((version) => version.version_type === type)
.reduce<Labrinth.Versions.v3.Version | undefined>((latest, version) => {
if (!latest || dayjs(version.date_published).isAfter(dayjs(latest.date_published))) {
return version
}
return latest
}, undefined)
}
async function preloadDependenciesForSelection(selection: ProjectDownloadSelection) {
await downloadModalProvider.preloadDependenciesForSelection(selection)
}
function isActiveShowRequest(showRequestId: number) {
return !unmounted && modalShowRequestId === showRequestId && !!modal.value && !modalOpen.value
}
function resetDownloadState() {
projectDownloadSelection.value = getDefaultProjectDownloadSelection()
dependencyDownloadFiles.value = []
downloadProjectResetKey.value += 1
}
@@ -407,6 +919,7 @@ function openFromHash() {
if (
!props.useRouteHash ||
!modal.value ||
modalOpening.value ||
modalOpen.value ||
showProjectId.value ||
route.hash !== '#download'
@@ -437,11 +950,14 @@ watch(modal, openFromHash)
watch(() => route.hash, openFromHash)
watch(routeProjectId, () => {
projectDownloadSelection.value = getDefaultProjectDownloadSelection()
dependencyDownloadFiles.value = []
downloadProjectResetKey.value += 1
})
onUnmounted(clearCloseStateResetTimeout)
onUnmounted(() => {
unmounted = true
modalShowRequestId += 1
clearCloseStateResetTimeout()
})
defineExpose({ show, hide })
</script>
@@ -6,7 +6,7 @@
:description="
formatMessage(messages.removePasskeyConfirmDescription, { name: passkeyToRemove?.name })
"
:proceed-label="formatMessage(commonMessages.removeButton)"
:proceed-label="formatMessage(messages.deletePasskeyButton)"
@proceed="removePasskey()"
/>
@@ -70,7 +70,7 @@
</ButtonStyled>
<ButtonStyled circular>
<button
v-tooltip="formatMessage(commonMessages.removeButton)"
v-tooltip="formatMessage(messages.deletePasskeyButton)"
@click="
() => {
passkeyToRemove = passkey
@@ -88,7 +88,7 @@
<ButtonStyled>
<button @click="registerPasskey()">
<PlusIcon />
{{ formatMessage(messages.managePasskeyAddPasskey) }}
{{ formatMessage(messages.managePasskeyAddPasskeyButton) }}
</button>
</ButtonStyled>
<ButtonStyled>
@@ -104,7 +104,7 @@
<NewModal
ref="addPasskeyModal"
width="500px"
:header="formatMessage(messages.managePasskeyAddPasskey)"
:header="formatMessage(messages.passkeyAddModalTitle)"
>
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2.5">
@@ -133,7 +133,7 @@
<ButtonStyled color="brand">
<button :disabled="!pendingPasskeyName" @click="finishRegisterPasskey()">
<PlusIcon />
{{ formatMessage(messages.managePasskeyAddPasskey) }}
{{ formatMessage(messages.managePasskeyAddPasskeyButton) }}
</button>
</ButtonStyled>
</div>
@@ -189,7 +189,7 @@
<div>
<ButtonStyled>
<button id="manage-passkeys" @click="showPasskeyModal">
<UserKeyIcon /> {{ formatMessage(messages.managePasskeyTitle) }}
<UserKeyIcon /> {{ formatMessage(messages.managePasskeyButton) }}
</button>
</ButtonStyled>
</div>
@@ -247,12 +247,16 @@ const messages = defineMessages({
id: 'settings.account.security.passkey.title',
defaultMessage: 'Manage passkeys',
},
managePasskeyButton: {
id: 'settings.account.security.passkey.button',
defaultMessage: 'Manage passkeys',
},
managePasskeyDescription: {
id: 'settings.account.security.passkey.description',
defaultMessage: 'Manage your registered passkeys, or add a new one.',
},
managePasskeyAddPasskey: {
id: 'settings.account.security.passkey.add',
managePasskeyAddPasskeyButton: {
id: 'settings.account.security.passkey.add.button',
defaultMessage: 'Add passkey',
},
managePasskeyModalLoading: {
@@ -275,6 +279,10 @@ const messages = defineMessages({
id: 'settings.account.security.passkey.modal.never-used',
defaultMessage: 'Never used',
},
passkeyAddModalTitle: {
id: 'settings.account.security.passkey.add-modal.title',
defaultMessage: 'Add passkey',
},
passkeyNameLabel: {
id: 'settings.account.security.passkey.add-modal.name.label',
defaultMessage: 'Name',
@@ -292,6 +300,10 @@ const messages = defineMessages({
id: 'settings.account.security.passkey.rename-modal.header',
defaultMessage: 'Rename passkey',
},
deletePasskeyButton: {
id: 'settings.account.security.passkey.remove.button',
defaultMessage: 'Delete passkey',
},
removePasskeyConfirmTitle: {
id: 'settings.account.security.passkey.remove.title',
defaultMessage: 'Are you sure you want to remove this passkey?',
@@ -0,0 +1,63 @@
<template>
<div class="rounded-lg border border-divider bg-bg-raised p-3">
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="min-w-0">
<p class="m-0 break-words font-semibold text-contrast">
{{ trace.project_name }}
</p>
<p class="m-0 mt-1 break-all text-sm text-secondary">
Project {{ trace.project_slug ?? trace.project_id }} / Version
{{ trace.version_number }} / File {{ trace.file_name }}
</p>
</div>
<div class="flex flex-wrap items-center gap-2">
<span class="text-sm text-secondary">Local</span>
<Badge :type="trace.local_status" />
<span class="text-sm text-secondary">Effective</span>
<Badge :type="trace.effective_status" />
<ButtonStyled>
<NuxtLink :to="localTraceLink">
<ExternalIcon aria-hidden="true" />
View
</NuxtLink>
</ButtonStyled>
</div>
</div>
<div class="mt-3 grid gap-2 text-sm text-secondary md:grid-cols-2">
<p class="m-0 break-all">
<span class="font-semibold text-contrast">Issue</span>
{{ trace.issue_type }}
</p>
<p class="m-0 break-all">
<span class="font-semibold text-contrast">Severity</span>
{{ trace.severity }}
</p>
<p class="m-0 break-all">
<span class="font-semibold text-contrast">Path</span>
{{ trace.file_path }}
</p>
<p v-if="trace.jar" class="m-0 break-all">
<span class="font-semibold text-contrast">JAR</span>
{{ trace.jar }}
</p>
</div>
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { ExternalIcon } from '@modrinth/assets'
import { Badge, ButtonStyled } from '@modrinth/ui'
const props = defineProps<{
trace: Labrinth.TechReview.Internal.GlobalIssueDetailTrace
}>()
const localTraceLink = computed(
() =>
`/moderation/technical-review/${props.trace.project_id}?detail=${encodeURIComponent(
props.trace.detail_id,
)}`,
)
</script>
@@ -0,0 +1,226 @@
<template>
<div>
<form class="flex flex-col gap-2 sm:flex-row" @submit.prevent="executeSearch">
<StyledInput
v-model="query"
:icon="SearchIcon"
type="text"
autocomplete="off"
placeholder="Search global trace keys..."
clearable
wrapper-class="flex-1 w-full"
/>
<ButtonStyled color="brand">
<button type="submit" :disabled="isLoading">
<SearchIcon aria-hidden="true" />
Search
</button>
</ButtonStyled>
</form>
<div
v-if="!isLoading && !loadError && total > 0"
class="mt-4 flex flex-wrap items-center justify-between gap-3"
>
<p class="m-0 text-sm text-secondary">Showing {{ pageStart }}-{{ pageEnd }} of {{ total }}</p>
<Pagination :page="currentPage" :count="pageCount" @switch-page="switchPage" />
</div>
<EmptyState
v-if="isLoading"
type="no-search-result"
heading="Loading global detail traces..."
/>
<EmptyState
v-else-if="loadError"
type="no-search-result"
heading="Failed to load global detail traces"
/>
<div v-else-if="traces.length > 0" class="mt-4 flex flex-col gap-3">
<article
v-for="trace in traces"
:key="trace.detail_key"
class="universal-card flex flex-col gap-3"
>
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="min-w-0">
<div class="flex min-w-0 items-center gap-2">
<HashIcon class="shrink-0 text-secondary" aria-hidden="true" />
<h2 class="m-0 min-w-0 text-lg font-semibold text-contrast">
Trace
<span class="break-all font-mono text-base">{{ trace.detail_key }}</span>
</h2>
</div>
<p class="m-0 mt-1 text-sm text-secondary">
{{ formatTraceCount(trace.local_trace_count) }}
</p>
</div>
<div class="flex shrink-0 flex-wrap items-center gap-2">
<Badge :type="trace.verdict" />
<ButtonStyled color="red">
<button
:disabled="removingTraceKeys.has(trace.detail_key)"
@click="removeGlobalTrace(trace)"
>
<TrashIcon aria-hidden="true" />
Remove
</button>
</ButtonStyled>
</div>
</div>
<div v-if="getPreviewLocalTraces(trace).length > 0" class="flex flex-col gap-2">
<div
v-if="getVisibleLocalTraceTotal(trace) > getPreviewLocalTraces(trace).length"
class="flex flex-wrap items-center justify-between gap-2"
>
<p class="m-0 text-sm text-secondary">
Showing first {{ getPreviewLocalTraces(trace).length }} of
{{ getVisibleLocalTraceTotal(trace) }} local traces
</p>
<ButtonStyled>
<NuxtLink :to="getGlobalTraceLink(trace)">
<ListIcon aria-hidden="true" />
View all
</NuxtLink>
</ButtonStyled>
</div>
<GlobalDetailLocalTraceCard
v-for="localTrace in getPreviewLocalTraces(trace)"
:key="localTrace.detail_id"
:trace="localTrace"
/>
</div>
<EmptyState
v-else
type="no-search-result"
heading="No local traces currently match this key"
/>
</article>
</div>
<EmptyState v-else type="no-search-result" heading="No global detail traces found" />
<div v-if="!isLoading && !loadError && total > 0" class="mt-4 flex justify-end">
<Pagination :page="currentPage" :count="pageCount" @switch-page="switchPage" />
</div>
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { HashIcon, ListIcon, SearchIcon, TrashIcon } from '@modrinth/assets'
import {
Badge,
ButtonStyled,
EmptyState,
injectModrinthClient,
injectNotificationManager,
Pagination,
StyledInput,
} from '@modrinth/ui'
import GlobalDetailLocalTraceCard from '~/components/ui/moderation/GlobalDetailLocalTraceCard.vue'
const client = injectModrinthClient()
const { addNotification } = injectNotificationManager()
const query = ref('')
const activeQuery = ref<string | null>(null)
const isLoading = ref(false)
const loadError = ref(false)
const currentPage = ref(1)
const itemsPerPage = 20
const localTracePreviewLimit = 10
const total = ref(0)
const traces = ref<Labrinth.TechReview.Internal.GlobalIssueDetail[]>([])
const removingTraceKeys = reactive<Set<string>>(new Set())
const pageCount = computed(() => Math.max(Math.ceil(total.value / itemsPerPage), 1))
const pageStart = computed(() =>
total.value === 0 ? 0 : (currentPage.value - 1) * itemsPerPage + 1,
)
const pageEnd = computed(() => Math.min(currentPage.value * itemsPerPage, total.value))
function formatTraceCount(count: number) {
return `${count} local ${count === 1 ? 'trace' : 'traces'}`
}
function getPreviewLocalTraces(trace: Labrinth.TechReview.Internal.GlobalIssueDetail) {
return trace.local_traces.slice(0, localTracePreviewLimit)
}
function getVisibleLocalTraceTotal(trace: Labrinth.TechReview.Internal.GlobalIssueDetail) {
return Math.max(trace.local_trace_count, trace.local_traces.length)
}
function getGlobalTraceLink(trace: Labrinth.TechReview.Internal.GlobalIssueDetail) {
return `/moderation/global-traces/${encodeURIComponent(trace.detail_key)}`
}
async function loadTraces() {
isLoading.value = true
loadError.value = false
try {
const response = await client.labrinth.tech_review_internal.searchGlobalIssueDetails({
query: activeQuery.value,
limit: itemsPerPage,
page: currentPage.value - 1,
})
traces.value = response.traces
total.value = response.total
} catch (error) {
console.error('Failed to load global detail traces', error)
traces.value = []
total.value = 0
loadError.value = true
} finally {
isLoading.value = false
}
}
async function executeSearch() {
activeQuery.value = query.value.trim() || null
currentPage.value = 1
await loadTraces()
}
async function switchPage(page: number) {
currentPage.value = page
await loadTraces()
}
async function removeGlobalTrace(trace: Labrinth.TechReview.Internal.GlobalIssueDetail) {
if (removingTraceKeys.has(trace.detail_key)) return
removingTraceKeys.add(trace.detail_key)
try {
await client.labrinth.tech_review_internal.updateGlobalIssueDetails([
{ detail_key: trace.detail_key, verdict: 'pending' },
])
addNotification({
type: 'success',
title: 'Global trace removed',
text: 'The global verdict for this trace key has been removed.',
})
if (traces.value.length === 1 && currentPage.value > 1) {
currentPage.value--
}
await loadTraces()
} catch (error) {
console.error('Failed to remove global trace', error)
addNotification({
type: 'error',
title: 'Failed to remove global trace',
text: 'An error occurred while removing the global trace verdict.',
})
} finally {
removingTraceKeys.delete(trace.detail_key)
}
}
onMounted(loadTraces)
</script>
@@ -37,21 +37,22 @@
>
{{ formatRelativeTime(report.created) }}
</span>
<ButtonStyled circular>
<OverflowMenu :options="quickActions">
<template #default>
<EllipsisVerticalIcon class="size-4" />
</template>
<template #copy-id>
<div class="flex items-center gap-2">
<ButtonStyled circular>
<button v-tooltip="'Copy ID'" @click="copyId">
<ClipboardCopyIcon />
<span class="hidden sm:inline">Copy ID</span>
</template>
<template #copy-link>
<LinkIcon />
<span class="hidden sm:inline">Copy link</span>
</template>
</OverflowMenu>
</ButtonStyled>
</button>
</ButtonStyled>
<ButtonStyled circular>
<a
v-tooltip="'Open in new tab'"
:href="`/moderation/reports/${props.report.id}`"
target="_blank"
>
<ExternalIcon />
</a>
</ButtonStyled>
</div>
</div>
</div>
@@ -183,12 +184,7 @@
</div>
</template>
<script setup lang="ts">
import {
CheckCircleIcon,
ClipboardCopyIcon,
EllipsisVerticalIcon,
LinkIcon,
} from '@modrinth/assets'
import { CheckCircleIcon, ClipboardCopyIcon, ExternalIcon } from '@modrinth/assets'
import { type ExtendedReport, reportQuickReplies } from '@modrinth/moderation'
import {
Avatar,
@@ -196,8 +192,6 @@ import {
CollapsibleRegion,
getProjectTypeIcon,
injectNotificationManager,
OverflowMenu,
type OverflowMenuOption,
useFormatDateTime,
useRelativeTime,
} from '@modrinth/ui'
@@ -328,35 +322,6 @@ function updateThread(newThread: any) {
}
}
const quickActions: OverflowMenuOption[] = [
{
id: 'copy-link',
action: () => {
const base = window.location.origin
const reportUrl = `${base}/moderation/reports/${props.report.id}`
navigator.clipboard.writeText(reportUrl).then(() => {
addNotification({
type: 'success',
title: 'Report link copied',
text: 'The link to this report has been copied to your clipboard.',
})
})
},
},
{
id: 'copy-id',
action: () => {
navigator.clipboard.writeText(props.report.id).then(() => {
addNotification({
type: 'success',
title: 'Report ID copied',
text: 'The ID of this report has been copied to your clipboard.',
})
})
},
},
]
const reportItemAvatarUrl = computed(() => {
switch (props.report.item_type) {
case 'project':
@@ -395,4 +360,14 @@ const formattedReportType = computed(() => {
const words = reportType.includes('-') ? reportType.split('-') : reportType.split(' ')
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
})
function copyId() {
navigator.clipboard.writeText(props.report.id).then(() => {
addNotification({
type: 'success',
title: 'Report ID copied',
text: 'The ID of this report has been copied to your clipboard.',
})
})
}
</script>
@@ -1,7 +1,9 @@
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import {
BanIcon,
BugIcon,
CheckCheckIcon,
CheckCircleIcon,
CheckIcon,
ChevronDownIcon,
@@ -14,6 +16,7 @@ import {
EyeOffIcon,
LoaderCircleIcon,
ScaleIcon,
ShieldAlertIcon,
ShieldCheckIcon,
SpinnerIcon,
TimerIcon,
@@ -45,7 +48,7 @@ import {
type User,
} from '@modrinth/utils'
import dayjs from 'dayjs'
import { computed, reactive, ref, watch } from 'vue'
import { computed, nextTick, reactive, ref, watch } from 'vue'
import type { UnsafeFile } from '~/components/ui/moderation/MaliciousSummaryModal.vue'
import ThreadView from '~/components/ui/thread/ThreadView.vue'
@@ -89,6 +92,7 @@ const props = defineProps<{
thread: Labrinth.TechReview.Internal.Thread
reports: FlattenedFileReport[]
}
focusedDetailId?: string | null
loadingIssues: Set<string>
decompiledSources: Map<string, string>
}>()
@@ -119,30 +123,36 @@ const projectStatusActions = computed<OverflowMenuOption[]>(() => [
color: 'green',
action: () => setStatus('approved'),
hoverFilled: true,
disabled: isProjectApproved.value || isLoadingStatusAction.value,
disabled: isStatusActionDisabled('approved'),
},
{
id: 'withhold',
color: 'orange',
action: () => setStatus('withheld'),
hoverFilled: true,
disabled: projectStatus.value === 'withheld' || isLoadingStatusAction.value,
disabled: isStatusActionDisabled('withheld'),
},
{
id: 'send-to-review',
action: () => setStatus('processing'),
hoverFilled: true,
disabled: projectStatus.value === 'processing' || isLoadingStatusAction.value,
disabled: isStatusActionDisabled('processing'),
},
{
id: 'reject',
color: 'red',
action: () => setStatus('rejected'),
hoverFilled: true,
disabled: projectStatus.value === 'rejected' || isLoadingStatusAction.value,
disabled: isStatusActionDisabled('rejected'),
},
])
function isStatusActionDisabled(status: Labrinth.Projects.v2.ProjectStatus): boolean {
const currentStatus = projectStatus.value
const isLoading = isLoadingStatusAction.value
return currentStatus === status || isLoading
}
async function setStatus(status: Labrinth.Projects.v2.ProjectStatus) {
isLoadingStatusAction.value = true
try {
@@ -192,7 +202,12 @@ watch(selectedFile, (newFile) => {
const client = injectModrinthClient()
async function updateIssueDetails(data: { detail_id: string; verdict: 'safe' | 'unsafe' }[]) {
async function updateIssueDetails(
data: {
detail_id: string
verdict: Labrinth.TechReview.Internal.DelphiReportIssueStatus
}[],
) {
await client.request('/moderation/tech-review/issue-detail', {
api: 'labrinth',
version: 'internal',
@@ -201,15 +216,31 @@ async function updateIssueDetails(data: { detail_id: string; verdict: 'safe' | '
})
}
async function updateGlobalIssueDetail(
detailKey: string,
verdict: Labrinth.TechReview.Internal.DelphiReportIssueStatus,
) {
await client.labrinth.tech_review_internal.updateGlobalIssueDetails([
{ detail_key: detailKey, verdict },
])
}
const severityOrder = { severe: 3, high: 2, medium: 1, low: 0 } as Record<string, number>
type DetailDecision = 'safe' | 'malware'
type DetailDecision = 'safe' | 'malware' | 'pending'
type DetailDecisionScope = 'local' | 'global'
const detailDecisions = reactive<Map<string, DetailDecision>>(new Map())
const detailDecisionScopes = reactive<Map<string, DetailDecisionScope>>(new Map())
const updatingDetails = reactive<Set<string>>(new Set())
const updatingGlobalDetailKeys = reactive<Set<string>>(new Set())
function verdictToDecision(verdict: 'safe' | 'unsafe'): DetailDecision {
return verdict === 'safe' ? 'safe' : 'malware'
function verdictToDecision(
verdict: Labrinth.TechReview.Internal.DelphiReportIssueStatus,
): DetailDecision {
if (verdict === 'safe') return 'safe'
if (verdict === 'unsafe') return 'malware'
return 'pending'
}
function getAllDetails(): Labrinth.TechReview.Internal.ReportIssueDetail[] {
@@ -219,6 +250,7 @@ function getAllDetails(): Labrinth.TechReview.Internal.ReportIssueDetail[] {
function applyDecisionToRelatedDetails(
detailIds: string[],
decision: DetailDecision,
scope: DetailDecisionScope,
): { otherMatchedCount: number } {
const allDetails = getAllDetails()
const selectedDetailIds = new Set(detailIds)
@@ -236,12 +268,14 @@ function applyDecisionToRelatedDetails(
if (matchingDetails.length === 0) {
detailDecisions.set(detailId, decision)
detailDecisionScopes.set(detailId, scope)
updatedDetailIds.add(detailId)
continue
}
for (const matchingDetail of matchingDetails) {
detailDecisions.set(matchingDetail.id, decision)
detailDecisionScopes.set(matchingDetail.id, scope)
updatedDetailIds.add(matchingDetail.id)
}
}
@@ -252,6 +286,98 @@ function applyDecisionToRelatedDetails(
}
}
function statusMatchesDecision(
status: Labrinth.TechReview.Internal.DelphiReportIssueStatus | null,
decision: DetailDecision,
): boolean {
if (status === 'safe') return decision === 'safe'
if (status === 'unsafe') return decision === 'malware'
return false
}
function isDetailActionSelected(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
decision: DetailDecision,
scope: DetailDecisionScope,
): boolean {
const localDecision = detailDecisions.get(detail.id)
const localScope = detailDecisionScopes.get(detail.id)
if (localDecision && localScope) {
if (localDecision === 'pending') {
if (localScope === 'local') {
if (scope === 'local') return false
return statusMatchesDecision(detail.global_status, decision)
}
if (scope === 'global') return false
return statusMatchesDecision(detail.local_status, decision)
}
return localDecision === decision && localScope === scope
}
if (scope === 'global') {
return statusMatchesDecision(detail.global_status, decision)
}
if (detail.global_status) {
return false
}
return statusMatchesDecision(detail.local_status, decision)
}
function decisionToVerdict(
decision: Exclude<DetailDecision, 'pending'>,
): Labrinth.TechReview.Internal.DelphiReportIssueStatus {
return decision === 'safe' ? 'safe' : 'unsafe'
}
function getToggledDetailVerdict(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
decision: Exclude<DetailDecision, 'pending'>,
scope: DetailDecisionScope,
): Labrinth.TechReview.Internal.DelphiReportIssueStatus {
return isDetailActionSelected(detail, decision, scope) ? 'pending' : decisionToVerdict(decision)
}
function getDetailActionTooltip(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
decision: Exclude<DetailDecision, 'pending'>,
scope: DetailDecisionScope,
): string {
const action = decision === 'safe' ? 'pass' : 'fail'
const scopeLabel = scope === 'global' ? 'Global' : 'Local'
if (scope === 'global' && !canUpdateGlobalDetail(detail)) {
return 'Global verdict unavailable for generated trace keys'
}
if (isDetailActionSelected(detail, decision, scope)) {
return `Unset ${scopeLabel.toLowerCase()} ${action}`
}
return `${scopeLabel} ${action}`
}
function updateLocalDetailAction(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
decision: Exclude<DetailDecision, 'pending'>,
) {
return updateDetailStatus(detail.id, getToggledDetailVerdict(detail, decision, 'local'))
}
function updateGlobalDetailAction(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
decision: Exclude<DetailDecision, 'pending'>,
) {
return updateGlobalDetailStatus(detail, getToggledDetailVerdict(detail, decision, 'global'))
}
function canUpdateGlobalDetail(detail: Labrinth.TechReview.Internal.ReportIssueDetail): boolean {
return detail.key.length > 0 && !detail.key.startsWith('<no-key-')
}
function getFileHighestSeverity(
file: FlattenedFileReport,
): Labrinth.TechReview.Internal.DelphiSeverity {
@@ -381,6 +507,49 @@ function viewFileFlags(file: FlattenedFileReport) {
currentTab.value = 'File'
}
function getDetailElementId(detailId: string) {
return `tech-review-detail-${detailId}`
}
function findFileForDetail(detailId: string): FlattenedFileReport | null {
for (const report of props.item.reports) {
for (const issue of report.issues) {
if (issue.details.some((detail) => detail.id === detailId)) {
return report
}
}
}
return null
}
async function focusDetail(detailId: string) {
const file = findFileForDetail(detailId)
if (!file) return
viewFileFlags(file)
await nextTick()
const classItem = groupedByClass.value.find((group) =>
group.flags.some((flag) => flag.detail.id === detailId),
)
if (classItem) {
expandClass(classItem)
}
await nextTick()
if (!import.meta.client) return
window.requestAnimationFrame(() => {
document.getElementById(getDetailElementId(detailId))?.scrollIntoView({
behavior: 'smooth',
block: 'center',
})
})
}
function backToFileList() {
selectedFileId.value = null
if (currentTab.value === 'File') {
@@ -446,6 +615,18 @@ const remainingUnmarkedCount = computed(() => {
return getFileDetailCount(selectedFile.value) - getFileMarkedCount(selectedFile.value)
})
function getJarFlags(jarGroup: JarGroup): ClassGroup['flags'] {
return jarGroup.classes.flatMap((classItem) => classItem.flags)
}
function getJarMarkedCount(jarGroup: JarGroup): number {
return getMarkedFlagsCount(getJarFlags(jarGroup))
}
function getJarRemainingUnmarkedCount(jarGroup: JarGroup): number {
return getJarFlags(jarGroup).length - getJarMarkedCount(jarGroup)
}
const isBatchUpdating = ref(false)
async function batchMarkRemaining(verdict: 'safe' | 'unsafe') {
@@ -469,7 +650,7 @@ async function batchMarkRemaining(verdict: 'safe' | 'unsafe') {
try {
await updateIssueDetails(detailIds.map((detailId) => ({ detail_id: detailId, verdict })))
applyDecisionToRelatedDetails(detailIds, verdictToDecision(verdict))
applyDecisionToRelatedDetails(detailIds, verdictToDecision(verdict), 'local')
addNotification({
type: 'success',
@@ -499,7 +680,54 @@ async function batchMarkRemaining(verdict: 'safe' | 'unsafe') {
}
}
async function updateDetailStatus(detailId: string, verdict: 'safe' | 'unsafe') {
async function batchMarkRemainingInJar(jarGroup: JarGroup, verdict: 'safe' | 'unsafe') {
if (isBatchUpdating.value) return
const detailIds = getJarFlags(jarGroup)
.filter((flag) => getDetailDecision(flag.detail.id, flag.detail.status) === 'pending')
.map((flag) => flag.detail.id)
if (detailIds.length === 0) return
isBatchUpdating.value = true
try {
await updateIssueDetails(detailIds.map((detailId) => ({ detail_id: detailId, verdict })))
applyDecisionToRelatedDetails(detailIds, verdictToDecision(verdict), 'local')
addNotification({
type: 'success',
title: `Marked ${detailIds.length} traces as ${verdict}`,
text: `All remaining traces in this JAR have been marked as ${
verdict === 'safe' ? 'false positives' : 'malicious'
}.`,
})
if (selectedFile.value) {
const markedCount = getFileMarkedCount(selectedFile.value)
const totalCount = getFileDetailCount(selectedFile.value)
if (markedCount === totalCount) {
backToFileList()
}
}
emit('refetch')
} catch (error) {
console.error('Failed to batch update JAR traces:', error)
addNotification({
type: 'error',
title: 'Batch update failed',
text: 'An error occurred while updating JAR traces.',
})
} finally {
isBatchUpdating.value = false
}
}
async function updateDetailStatus(
detailId: string,
verdict: Labrinth.TechReview.Internal.DelphiReportIssueStatus,
) {
let priorDecision: 'safe' | 'malware' | 'pending' = 'pending'
outer: for (const report of props.item.reports) {
for (const issue of report.issues) {
@@ -519,10 +747,11 @@ async function updateDetailStatus(detailId: string, verdict: 'safe' | 'unsafe')
const { otherMatchedCount } = applyDecisionToRelatedDetails(
[detailId],
verdictToDecision(verdict),
'local',
)
// Only collapse if the prior state was 'pending' (new decision, not updating existing)
if (priorDecision === 'pending') {
if (verdict !== 'pending' && priorDecision === 'pending') {
for (const classGroup of groupedByClass.value) {
const hasThisDetail = classGroup.flags.some((f) => f.detail.id === detailId)
if (hasThisDetail && getMarkedFlagsCount(classGroup.flags) === classGroup.flags.length) {
@@ -533,7 +762,7 @@ async function updateDetailStatus(detailId: string, verdict: 'safe' | 'unsafe')
}
// Jump back to Files tab when all flags in the current file are marked
if (selectedFile.value) {
if (verdict !== 'pending' && selectedFile.value) {
const markedCount = getFileMarkedCount(selectedFile.value)
const totalCount = getFileDetailCount(selectedFile.value)
if (markedCount === totalCount) {
@@ -546,7 +775,13 @@ async function updateDetailStatus(detailId: string, verdict: 'safe' | 'unsafe')
? ` (${otherMatchedCount} other trace${otherMatchedCount === 1 ? '' : 's'} also marked)`
: ''
if (verdict === 'safe') {
if (verdict === 'pending') {
addNotification({
type: 'success',
title: 'Local trace verdict unset',
text: `The project-local verdict has been removed.${otherText}`,
})
} else if (verdict === 'safe') {
addNotification({
type: 'success',
title: 'Issue marked as pass',
@@ -573,6 +808,82 @@ async function updateDetailStatus(detailId: string, verdict: 'safe' | 'unsafe')
}
}
async function updateGlobalDetailStatus(
detail: Labrinth.TechReview.Internal.ReportIssueDetail,
verdict: Labrinth.TechReview.Internal.DelphiReportIssueStatus,
) {
if (!canUpdateGlobalDetail(detail)) {
addNotification({
type: 'error',
title: 'Global update unavailable',
text: 'Generated trace keys cannot be marked globally.',
})
return
}
updatingGlobalDetailKeys.add(detail.key)
try {
await updateGlobalIssueDetail(detail.key, verdict)
const { otherMatchedCount } = applyDecisionToRelatedDetails(
[detail.id],
verdictToDecision(verdict),
'global',
)
if (verdict !== 'pending') {
for (const classGroup of groupedByClass.value) {
if (getMarkedFlagsCount(classGroup.flags) === classGroup.flags.length) {
expandedClasses.delete(classGroup.key)
}
}
}
if (verdict !== 'pending' && selectedFile.value) {
const markedCount = getFileMarkedCount(selectedFile.value)
const totalCount = getFileDetailCount(selectedFile.value)
if (markedCount === totalCount) {
backToFileList()
}
}
const otherText =
otherMatchedCount > 0
? ` (${otherMatchedCount} other trace${otherMatchedCount === 1 ? '' : 's'} also marked in this project)`
: ''
if (verdict === 'pending') {
addNotification({
type: 'success',
title: 'Global trace verdict unset',
text: `The global verdict for this trace key has been removed.${otherText}`,
})
} else {
addNotification({
type: 'success',
title:
verdict === 'safe' ? 'Trace globally marked as pass' : 'Trace globally marked as fail',
text:
verdict === 'safe'
? `This trace key has been marked as a global false positive.${otherText}`
: `This trace key has been globally flagged as malicious.${otherText}`,
})
}
emit('refetch')
} catch (error) {
console.error('Failed to update global detail status:', error)
addNotification({
type: 'error',
title: 'Failed to update global trace',
text: 'An error occurred while updating the global trace status.',
})
} finally {
updatingGlobalDetailKeys.delete(detail.key)
}
}
const expandedClasses = reactive<Set<string>>(new Set())
const autoExpandedFileIds = reactive<Set<string>>(new Set())
const showCopyFeedback = reactive<Map<string, boolean>>(new Map())
@@ -691,6 +1002,16 @@ const groupedByJar = computed<JarGroup[]>(() => {
})
})
watch(
() => props.focusedDetailId,
(detailId) => {
if (detailId) {
focusDetail(detailId)
}
},
{ immediate: true },
)
// Auto-expand/load source for small files; keep larger files lazy.
watch(
[selectedFileId, groupedByClass],
@@ -1293,26 +1614,49 @@ function copyId() {
v-if="jarGroup.segments.length > 0"
class="border-b border-solid border-surface-1 px-4 py-3"
>
<div class="flex flex-wrap items-center gap-1">
<template
v-for="(segment, index) in jarGroup.segments"
:key="`${jarGroup.key}-${index}`"
>
<span
class="font-mono text-sm"
:class="
index === jarGroup.segments.length - 1
? 'font-semibold text-contrast'
: 'text-secondary'
"
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="flex flex-wrap items-center gap-1">
<template
v-for="(segment, index) in jarGroup.segments"
:key="`${jarGroup.key}-${index}`"
>
{{ segment }}
</span>
<ChevronRightIcon
v-if="index < jarGroup.segments.length - 1"
class="size-4 text-secondary"
/>
</template>
<span
class="font-mono text-sm"
:class="
index === jarGroup.segments.length - 1
? 'font-semibold text-contrast'
: 'text-secondary'
"
>
{{ segment }}
</span>
<ChevronRightIcon
v-if="index < jarGroup.segments.length - 1"
class="size-4 text-secondary"
/>
</template>
</div>
<div v-if="getJarRemainingUnmarkedCount(jarGroup) > 0" class="flex gap-2">
<ButtonStyled color="brand" size="small">
<button
:disabled="isBatchUpdating"
@click="batchMarkRemainingInJar(jarGroup, 'safe')"
>
<CheckCircleIcon class="size-4" />
Remaining safe ({{ getJarRemainingUnmarkedCount(jarGroup) }})
</button>
</ButtonStyled>
<ButtonStyled color="red" size="small">
<button
:disabled="isBatchUpdating"
@click="batchMarkRemainingInJar(jarGroup, 'unsafe')"
>
<TriangleAlertIcon class="size-4" />
Remaining malware ({{ getJarRemainingUnmarkedCount(jarGroup) }})
</button>
</ButtonStyled>
</div>
</div>
</div>
@@ -1384,8 +1728,12 @@ function copyId() {
>
<div
v-for="flag in classItem.flags"
:id="getDetailElementId(flag.detail.id)"
:key="`${flag.issueId}-${flag.detail.id}`"
class="flex flex-col gap-2 rounded-lg border-[1px] border-b border-solid border-surface-5 bg-surface-3 py-2 pl-4 last:border-b-0"
:class="{
'!border-brand bg-brand-highlight': props.focusedDetailId === flag.detail.id,
}"
>
<div class="grid grid-cols-[1fr_auto] items-center">
<div
@@ -1407,38 +1755,94 @@ function copyId() {
</div>
</div>
<div class="flex w-40 items-center justify-center gap-2">
<ButtonStyled
color="brand"
:type="
getDetailDecision(flag.detail.id, flag.detail.status) === 'safe'
? undefined
: 'outlined'
"
<div class="detail-verdict-action-groups">
<div
class="detail-verdict-buttons"
role="group"
aria-label="Trace verdict actions"
>
<button
:disabled="updatingDetails.has(flag.detail.id)"
@click="updateDetailStatus(flag.detail.id, 'safe')"
v-tooltip="getDetailActionTooltip(flag.detail, 'safe', 'global')"
class="detail-verdict-button detail-verdict-button--safe"
:class="{
'detail-verdict-button--selected': isDetailActionSelected(
flag.detail,
'safe',
'global',
),
}"
aria-label="Global pass"
:disabled="
!canUpdateGlobalDetail(flag.detail) ||
updatingGlobalDetailKeys.has(flag.detail.key) ||
updatingDetails.has(flag.detail.id)
"
@click="updateGlobalDetailAction(flag.detail, 'safe')"
>
Pass
<CheckCheckIcon aria-hidden="true" />
</button>
</ButtonStyled>
<ButtonStyled
color="red"
:type="
getDetailDecision(flag.detail.id, flag.detail.status) === 'malware'
? undefined
: 'outlined'
"
>
<button
:disabled="updatingDetails.has(flag.detail.id)"
@click="updateDetailStatus(flag.detail.id, 'unsafe')"
v-tooltip="getDetailActionTooltip(flag.detail, 'safe', 'local')"
class="detail-verdict-button detail-verdict-button--safe"
:class="{
'detail-verdict-button--selected': isDetailActionSelected(
flag.detail,
'safe',
'local',
),
}"
aria-label="Local pass"
:disabled="
updatingDetails.has(flag.detail.id) ||
updatingGlobalDetailKeys.has(flag.detail.key)
"
@click="updateLocalDetailAction(flag.detail, 'safe')"
>
Fail
<CheckIcon aria-hidden="true" />
</button>
</ButtonStyled>
<button
v-tooltip="getDetailActionTooltip(flag.detail, 'malware', 'local')"
class="detail-verdict-button detail-verdict-button--unsafe"
:class="{
'detail-verdict-button--selected': isDetailActionSelected(
flag.detail,
'malware',
'local',
),
}"
aria-label="Local fail"
:disabled="
updatingDetails.has(flag.detail.id) ||
updatingGlobalDetailKeys.has(flag.detail.key)
"
@click="updateLocalDetailAction(flag.detail, 'malware')"
>
<BanIcon aria-hidden="true" />
</button>
<button
v-tooltip="getDetailActionTooltip(flag.detail, 'malware', 'global')"
class="detail-verdict-button detail-verdict-button--unsafe"
:class="{
'detail-verdict-button--selected': isDetailActionSelected(
flag.detail,
'malware',
'global',
),
}"
aria-label="Global fail"
:disabled="
!canUpdateGlobalDetail(flag.detail) ||
updatingGlobalDetailKeys.has(flag.detail.key) ||
updatingDetails.has(flag.detail.id)
"
@click="updateGlobalDetailAction(flag.detail, 'malware')"
>
<ShieldAlertIcon aria-hidden="true" />
</button>
</div>
</div>
</div>
<div
@@ -1546,4 +1950,90 @@ pre {
.fade-leave-to {
opacity: 0;
}
.detail-verdict-action-groups {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 0.5rem;
margin-inline-end: 0.5rem;
}
.detail-verdict-buttons {
display: flex;
align-items: center;
overflow: hidden;
border: 1px solid var(--surface-5);
border-radius: var(--radius-md);
background: var(--surface-3);
}
.detail-verdict-button {
display: flex;
width: 2rem;
height: 2rem;
align-items: center;
justify-content: center;
border: 0;
border-left: 1px solid var(--surface-5);
background: transparent;
padding: 0;
cursor: pointer;
transition:
background-color 0.15s ease-in-out,
filter 0.15s ease-in-out;
}
.detail-verdict-button:first-child {
border-left: 0;
border-start-start-radius: calc(var(--radius-md) - 1px);
border-end-start-radius: calc(var(--radius-md) - 1px);
}
.detail-verdict-button:last-child {
border-start-end-radius: calc(var(--radius-md) - 1px);
border-end-end-radius: calc(var(--radius-md) - 1px);
}
.detail-verdict-button:hover,
.detail-verdict-button:focus-visible {
background: var(--surface-4);
}
.detail-verdict-button--selected {
background: var(--color-green-bg);
box-shadow: inset 0 0 0 1px var(--color-green);
}
.detail-verdict-button--selected:hover,
.detail-verdict-button--selected:focus-visible {
background: var(--color-green-bg);
}
.detail-verdict-button:focus-visible {
outline: none;
box-shadow: inset 0 0 0 2px var(--color-brand);
}
.detail-verdict-button--selected:focus-visible {
box-shadow: inset 0 0 0 2px var(--color-green);
}
.detail-verdict-button:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.detail-verdict-button svg {
width: 1rem;
height: 1rem;
}
.detail-verdict-button--safe {
color: var(--color-green);
}
.detail-verdict-button--unsafe {
color: var(--color-red);
}
</style>
@@ -0,0 +1,116 @@
<template>
<div class="flex flex-row items-center gap-2">
<kbd
v-for="(definition, index) in definitions"
:key="`keybind-${index}`"
ref="keybinding"
class="cursor-pointer border-2 !text-lg font-bold"
:class="{
editing: editing === index,
}"
@click="startEditing(index)"
>
{{ toDisplay(definition) }}
</kbd>
</div>
</template>
<script setup lang="ts">
import { type KeybindDefinition, toKeybindDefinition } from '@modrinth/moderation'
import { onUnmounted } from 'vue'
const props = defineProps<{
definitions: KeybindDefinition[]
onChange: (definitions: KeybindDefinition[]) => void
}>()
const keybinding = useTemplateRef('keybinding')
const definitions = ref(JSON.parse(JSON.stringify(props.definitions)))
const editing = ref(-1)
function startEditing(index: number) {
if (editing.value === index) {
stopEditing()
} else {
editing.value = index
window.addEventListener('keyup', handleKeybinds)
window.addEventListener('click', handleMouse)
}
}
function stopEditing() {
console.log('stop editing')
editing.value = -1
window.removeEventListener('keyup', handleKeybinds)
window.removeEventListener('click', handleMouse)
}
function handleMouse(event: MouseEvent) {
if (keybinding.value && event.target && editing.value != -1) {
const editingRef = keybinding.value[editing.value]
if (editingRef === event.target || editingRef.contains(event.target)) {
return
}
}
stopEditing()
}
function handleKeybinds(event: KeyboardEvent) {
definitions.value[editing.value] = toKeybindDefinition(event)
props.onChange(definitions.value)
stopEditing()
event.preventDefault()
event.stopPropagation()
}
function toDisplay(definition: KeybindDefinition): string {
const keys = []
if (definition.ctrl || definition.meta) {
keys.push(isMac() ? 'CMD' : 'CTRL')
}
if (definition.shift) keys.push('SHIFT')
if (definition.alt) keys.push('ALT')
const mainKey = definition.key
.toUpperCase()
.replace('ARROWLEFT', '←')
.replace('ARROWRIGHT', '→')
.replace('ARROWUP', '↑')
.replace('ARROWDOWN', '↓')
.replace('ENTER', '↵')
.replace('ESCAPE', 'ESC')
keys.push(mainKey)
return keys.join(' + ')
}
function isMac() {
return navigator.platform.toUpperCase().includes('MAC')
}
onUnmounted(stopEditing)
</script>
<style scoped lang="scss">
.editing {
animation: blink 1s step-end infinite;
}
@keyframes blink {
0%,
100% {
border-color: var(--color-red);
box-shadow: 0 0 10px 1px var(--color-red);
}
50% {
border-color: transparent;
box-shadow: none;
}
}
</style>
@@ -1,26 +1,32 @@
<template>
<NewModal ref="modal" header="Moderation shortcuts" :closable="true">
<div>
<div id="moderation-checklist-keybinds-modal">
<div class="keybinds-sections">
<div class="grid grid-cols-2 gap-x-12 gap-y-3">
<div
v-for="keybind in keybinds"
:key="keybind.id"
class="keybind-item flex items-center justify-between gap-4"
v-for="[id, keybind] in Object.entries(keybinds)"
:key="id"
class="keybind-item flex flex-wrap items-center justify-between gap-4"
:class="{
'col-span-2': keybinds.length % 2 === 1 && keybinds[keybinds.length - 1] === keybind,
'col-span-2':
Object.keys(keybinds).length % 2 === 1 &&
Object.keys(keybinds)[Object.keys(keybinds).length - 1] === id,
}"
>
<span class="text-sm text-secondary">{{ keybind.description }}</span>
<div class="flex items-center gap-1">
<kbd
v-for="(key, index) in parseKeybindDisplay(keybind.keybind)"
:key="`${keybind.id}-key-${index}`"
class="keybind-key"
>
{{ key }}
</kbd>
</div>
<ChecklistKeybind
:definitions="
(!Array.isArray(keybind.keybind) ? [keybind.keybind] : keybind.keybind).map(
normalizeKeybind,
)
"
:on-change="
(definitions) => {
keybinds[id].keybind = definitions
saveModerationKeybinds()
}
"
/>
</div>
</div>
</div>
@@ -29,43 +35,15 @@
</template>
<script setup lang="ts">
import { type KeybindListener, keybinds, normalizeKeybind } from '@modrinth/moderation'
import { normalizeKeybind } from '@modrinth/moderation'
import NewModal from '@modrinth/ui/src/components/modal/NewModal.vue'
import { ref } from 'vue'
import { saveModerationKeybinds } from '#imports'
import ChecklistKeybind from '~/components/ui/moderation/checklist/ChecklistKeybind.vue'
const modal = ref<InstanceType<typeof NewModal>>()
function parseKeybindDisplay(keybind: KeybindListener['keybind']): string[] {
const keybinds = Array.isArray(keybind) ? keybind : [keybind]
const normalized = keybinds[0]
const def = normalizeKeybind(normalized)
const keys = []
if (def.ctrl || def.meta) {
keys.push(isMac() ? 'CMD' : 'CTRL')
}
if (def.shift) keys.push('SHIFT')
if (def.alt) keys.push('ALT')
const mainKey = def.key
.replace('ArrowLeft', '←')
.replace('ArrowRight', '→')
.replace('ArrowUp', '↑')
.replace('ArrowDown', '↓')
.replace('Enter', '↵')
.replace('Space', 'SPACE')
.replace('Escape', 'ESC')
.toUpperCase()
keys.push(mainKey)
return keys
}
function isMac() {
return navigator.platform.toUpperCase().includes('MAC')
}
const keybinds = useModerationKeybinds()
function show(event?: MouseEvent) {
modal.value?.show(event)
@@ -82,29 +60,6 @@ defineExpose({
</script>
<style scoped lang="scss">
.keybind-key {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 2rem;
padding: 0.25rem 0.5rem;
background-color: var(--color-bg);
border: 1px solid var(--color-divider);
border-radius: 0.375rem;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
color: var(--color-contrast);
+ .keybind-key {
margin-left: 0.25rem;
}
}
.keybind-item {
min-height: 2rem;
}
@media (max-width: 768px) {
.keybinds-sections {
.grid {
@@ -478,7 +478,6 @@ import {
handleKeybind,
initializeActionState,
kebabToTitleCase,
keybinds,
type MultiSelectChipsAction,
processMessage,
type Stage,
@@ -533,6 +532,7 @@ import ModpackPermissionsFlow from './ModpackPermissionsFlow.vue'
const notifications = injectNotificationManager()
const { addNotification } = notifications
const debug = useDebugLogger('ModerationChecklist')
const keybinds = useModerationKeybinds()
const keybindsModal = ref<InstanceType<typeof KeybindsModal>>()
const takeOverModal = ref<InstanceType<typeof ConfirmModal>>()
@@ -1266,7 +1266,7 @@ function handleKeybinds(event: KeyboardEvent) {
},
},
},
keybinds,
Object.values(keybinds.value),
)
}
@@ -54,15 +54,21 @@
class="message__icon backed-svg circle moderation-color"
:class="{
raised: raised,
'system-message-icon': ['tech_review_entered', 'tech_review_exit_file_deleted'].includes(
message.body.type,
),
'system-message-icon': [
'tech_review_entered',
'tech_review_exited',
'tech_review_exit_file_deleted',
].includes(message.body.type),
}"
>
<ScaleIcon />
</div>
<span
v-if="!['tech_review_entered', 'tech_review_exit_file_deleted'].includes(message.body.type)"
v-if="
!['tech_review_entered', 'tech_review_exited', 'tech_review_exit_file_deleted'].includes(
message.body.type,
)
"
class="message__author moderation-color"
>
Moderator
@@ -100,6 +106,9 @@
<span v-else-if="message.body.type === 'tech_review_entered'">
The project has entered the technical review queue.
</span>
<span v-else-if="message.body.type === 'tech_review_exited'">
The project has left the technical review queue as all pending traces have been resolved.
</span>
<span v-else-if="message.body.type === 'tech_review_exit_file_deleted'">
The project has left the technical review queue as all files pending review were deleted by
the user.
@@ -214,9 +223,12 @@ const timeSincePosted = ref(formatRelativeTime(props.message.created))
const isPrivateMessage = computed(() => {
return (
props.message.body.private ||
['tech_review', 'tech_review_entered', 'tech_review_exit_file_deleted'].includes(
props.message.body.type,
)
[
'tech_review',
'tech_review_entered',
'tech_review_exited',
'tech_review_exit_file_deleted',
].includes(props.message.body.type)
)
})
@@ -0,0 +1,61 @@
import {
type KeybindDefinition,
type KeybindListener,
keybinds,
normalizeKeybind,
} from '@modrinth/moderation'
import type { CookieOptions } from '#app'
const moderationKeybindsId = 'moderation-keybinds'
type StoredKeybinds = { [id: string]: KeybindDefinition[] }
type PartialStoredKeybinds = Partial<StoredKeybinds>
const getCookieOptions = () =>
({
maxAge: 60 * 60 * 24 * 365 * 10,
sameSite: 'lax',
secure: useRuntimeConfig().public.cookieSecure,
httpOnly: false,
path: '/',
}) satisfies CookieOptions<PartialStoredKeybinds>
export const useModerationKeybinds = () =>
useState<{ [id: string]: KeybindListener }>(moderationKeybindsId, () => {
const storedKeybinds = useCookie<PartialStoredKeybinds>(
moderationKeybindsId,
getCookieOptions(),
)
if (!storedKeybinds.value) {
storedKeybinds.value = {}
}
const output: { [id: string]: KeybindListener } = {}
for (const [id, keybind] of Object.entries(keybinds)) {
const definitions = storedKeybinds.value[id]
output[id] = {
keybind: definitions !== undefined ? definitions : keybind.keybind,
description: keybind.description,
enabled: keybind.enabled,
action: keybind.action,
}
}
return output
})
export const saveModerationKeybinds = () => {
const keybinds = useModerationKeybinds()
const cookie = useCookie<PartialStoredKeybinds>(moderationKeybindsId, getCookieOptions())
const storedKeybinds: PartialStoredKeybinds = {}
for (const [id, keybind] of Object.entries(keybinds.value)) {
storedKeybinds[id] = (Array.isArray(keybind.keybind) ? keybind.keybind : [keybind.keybind]).map(
normalizeKeybind,
)
}
cookie.value = storedKeybinds
}
@@ -1766,9 +1766,6 @@
"project.download.no-app": {
"message": "Har ikke Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Ingen versioner tilgængelig til {gameVersion} og {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} understøtter ikke {platform} til {gameVersion}"
},
@@ -3227,9 +3227,6 @@
"project.download.no-app": {
"message": "Du hast die Modrinth App nicht?"
},
"project.download.no-versions-available": {
"message": "Keinen versionen verfügbar für {gameVersion} und {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} unterstützt {platform} für {gameVersion} nicht"
},
@@ -4055,9 +4052,6 @@
"settings.account.security.email.title": {
"message": "E-Mail"
},
"settings.account.security.passkey.add": {
"message": "Passkey hinzufügen"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Stell sicher, dass du etwas nimmst, was du dir gut merken kannst, damit du den Passkey später identifizieren kannst."
},
@@ -3227,9 +3227,6 @@
"project.download.no-app": {
"message": "Du hast die Modrinth App nicht?"
},
"project.download.no-versions-available": {
"message": "Keine Versionen für {gameVersion} und {platform} verfügbar."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} unterstützt {platform} für die {gameVersion} nicht"
},
@@ -4055,9 +4052,6 @@
"settings.account.security.email.title": {
"message": "E-Mail"
},
"settings.account.security.passkey.add": {
"message": "Passkey hinzufügen"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Stell sicher, dass du etwas nimmst, was du dir gut merken kannst, damit du den Passkey später identifizieren kannst."
},
+54 -21
View File
@@ -2681,6 +2681,9 @@
"moderation.page.external-projects": {
"message": "External projects"
},
"moderation.page.global-detail-traces": {
"message": "Global traces"
},
"moderation.page.projects": {
"message": "Projects"
},
@@ -3275,9 +3278,6 @@
"project.details.licensed": {
"message": "Licensed"
},
"project.download.additional-files-title": {
"message": "Additional files"
},
"project.download.base-game-version-incompatible-tooltip": {
"message": "This game version is incompatible with the base project."
},
@@ -3285,7 +3285,7 @@
"message": "This loader is incompatible with the base project."
},
"project.download.compatible-version-title": {
"message": "Compatible version"
"message": "Compatible versions"
},
"project.download.dependencies-title": {
"message": "Dependencies"
@@ -3293,6 +3293,9 @@
"project.download.dependency-already-installed": {
"message": "This dependency is already installed"
},
"project.download.dependency-any-compatible": {
"message": "Any compatible"
},
"project.download.dependency-conflicting": {
"message": "This dependency conflicts with another dependency"
},
@@ -3314,12 +3317,30 @@
"project.download.dependency-quilt-fabric-api": {
"message": "Fabric API is skipped for Quilt"
},
"project.download.dependency-resource-pack-admonition": {
"message": "This project has a dependency with a required resource pack. Download it and place it in your {folder} folder."
},
"project.download.dependency-unavailable": {
"message": "This dependency cannot be downloaded"
},
"project.download.download": {
"message": "Download"
},
"project.download.download-as-zip": {
"message": "Download as .zip"
},
"project.download.download-version": {
"message": "Download {version}"
},
"project.download.download-with-dependencies": {
"message": "Download with deps"
},
"project.download.download-with-recommended": {
"message": "Download with recommended"
},
"project.download.download-with-recommended-as-zip": {
"message": "Download with recommended as .zip"
},
"project.download.duplicate-dependencies-hidden": {
"message": "Duplicate dependencies are hidden"
},
@@ -3329,8 +3350,8 @@
"project.download.game-version-unsupported-tooltip": {
"message": "{title} does not support {gameVersion} for {platform}"
},
"project.download.install-with-app-description": {
"message": "Automatically install the correct version and dependencies."
"project.download.install-with-app": {
"message": "Install with Modrinth App"
},
"project.download.manually": {
"message": "Download manually"
@@ -3347,6 +3368,15 @@
"project.download.platform-unsupported-tooltip": {
"message": "{title} does not support {platform} for {gameVersion}"
},
"project.download.recommended-title": {
"message": "Recommended"
},
"project.download.required-resource-pack-admonition": {
"message": "This data pack also requires a resource pack. Download it and place it in your {folder} folder."
},
"project.download.required-resource-pack-short": {
"message": "Resource pack"
},
"project.download.search-game-versions": {
"message": "Select game version"
},
@@ -3356,18 +3386,6 @@
"project.download.select-platform": {
"message": "Select platform"
},
"project.download.selected-version-download-all": {
"message": "Download all (.zip)"
},
"project.download.selected-version-downloading": {
"message": "Downloading... ({current}/{total})"
},
"project.download.selected-version-failed-text": {
"message": "One or more version files could not be downloaded. Please try again."
},
"project.download.selected-version-failed-title": {
"message": "Could not download version"
},
"project.download.show-all-versions": {
"message": "Show all versions"
},
@@ -3377,6 +3395,12 @@
"project.download.unknown-loader": {
"message": "Unknown loader"
},
"project.download.zip-failed-text": {
"message": "One or more files could not be downloaded. Please try again."
},
"project.download.zip-failed-title": {
"message": "Could not download files"
},
"project.environment.migration-no-permission.message": {
"message": "We've just overhauled the Environments system on Modrinth and new options are now available. You don't have permission to modify these settings, but please let another member of the project know that the environment metadata needs to be verified."
},
@@ -4184,9 +4208,6 @@
"settings.account.security.email.title": {
"message": "Email"
},
"settings.account.security.passkey.add": {
"message": "Add passkey"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Make sure to pick something memorable, so you can identify this passkey later."
},
@@ -4196,6 +4217,15 @@
"settings.account.security.passkey.add-modal.name.placeholder": {
"message": "My passkey"
},
"settings.account.security.passkey.add-modal.title": {
"message": "Add passkey"
},
"settings.account.security.passkey.add.button": {
"message": "Add passkey"
},
"settings.account.security.passkey.button": {
"message": "Manage passkeys"
},
"settings.account.security.passkey.description": {
"message": "Manage your registered passkeys, or add a new one."
},
@@ -4214,6 +4244,9 @@
"settings.account.security.passkey.modal.no-passkeys": {
"message": "You do not have any passkeys registered."
},
"settings.account.security.passkey.remove.button": {
"message": "Delete passkey"
},
"settings.account.security.passkey.remove.description": {
"message": "This will permanently remove the passkey \"{name}\". You will no longer be able to sign in with it."
},
@@ -3227,9 +3227,6 @@
"project.download.no-app": {
"message": "¿No tienes la Modrinth App?"
},
"project.download.no-versions-available": {
"message": "No hay versiones disponibles para {gameVersion} y {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} no soporta {platform} para {gameVersion}"
},
@@ -4055,9 +4052,6 @@
"settings.account.security.email.title": {
"message": "Correo electrónico"
},
"settings.account.security.passkey.add": {
"message": "Agregar clave de acceso"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Asegúrate de elegir algo fácil de recordar, para que puedas identificar esta contraseña más adelante."
},
@@ -3107,9 +3107,6 @@
"project.download.no-app": {
"message": "¿No tienes la aplicación Modrinth?"
},
"project.download.no-versions-available": {
"message": "No hay versiones disponibles para {gameVersion} y {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} no está soportado para {platform} en la {gameVersion}"
},
@@ -2414,9 +2414,6 @@
"project.download.no-app": {
"message": "Wala kang Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Walang bersiyong magagamit para sa {gameVersion} at {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "Hindi masuport ng {title} ang {platform} para sa {gameVersion}"
},
@@ -3227,9 +3227,6 @@
"project.download.no-app": {
"message": "Vous n'avez pas Modrinth App ?"
},
"project.download.no-versions-available": {
"message": "Aucune version disponible pour {gameVersion} et {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} ne supporte pas {platform} pour {gameVersion}"
},
@@ -4055,9 +4052,6 @@
"settings.account.security.email.title": {
"message": "E-mail"
},
"settings.account.security.passkey.add": {
"message": "Ajouter une clé d'accès"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Veillez à choisir un nom facile à retenir, afin de pouvoir identifier tę klucz d'accès plus tard."
},
@@ -2033,9 +2033,6 @@
"project.download.no-app": {
"message": "אין לכם את אפליקציית Modrinth?"
},
"project.download.no-versions-available": {
"message": "אין גרסאות זמינות עבור {gameVersion} ו-{platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} אינו תומך ב-{platform} עבור {gameVersion}"
},
@@ -2924,9 +2924,6 @@
"project.download.no-app": {
"message": "Nincs meg a Modrinth App? "
},
"project.download.no-versions-available": {
"message": "Nem érhető el verzió ehhez: {platform} {gameVersion}"
},
"project.download.platform-unsupported-tooltip": {
"message": "A(z) {title} nem támogatja ezt a verziót: {platform} {gameVersion}"
},
@@ -2429,9 +2429,6 @@
"project.download.no-app": {
"message": "Tidak memiliki Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Tidak ada versi tersedia untuk {gameVersion} dan {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} tidak mendukung {platform} untuk {gameVersion}"
},
@@ -3218,9 +3218,6 @@
"project.download.no-app": {
"message": "Non hai Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Nessuna versione disponibile per {gameVersion} e {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} non supporta {platform} per {gameVersion}"
},
@@ -4028,9 +4025,6 @@
"settings.account.security.email.title": {
"message": "Email"
},
"settings.account.security.passkey.add": {
"message": "Aggiungi passkey"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Assicurati di scegliere un nome facile da ricordare, così da poter identificare la passkey più tardi."
},
@@ -2735,9 +2735,6 @@
"project.download.no-app": {
"message": "Modrinth Appをお持ちでないですか?"
},
"project.download.no-versions-available": {
"message": "{gameVersion}および{platform}向けのバージョンは利用できません。"
},
"project.download.platform-unsupported-tooltip": {
"message": "{title}は{gameVersion}の{platform}に対応していません"
},
@@ -2549,9 +2549,6 @@
"project.download.no-app": {
"message": "Modrinth 앱을 설치하지 않으셨나요?"
},
"project.download.no-versions-available": {
"message": "{gameVersion} 및 {platform}용 버전이 없습니다."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} 은(는) {gameVersion} 용 {platform} 을(를) 지원하지 않습니다."
},
@@ -2924,9 +2924,6 @@
"project.download.no-app": {
"message": "Tidak ada Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Tiada versi tersedia untuk {gameVersion} dan {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} tidak menyokong {platform} untuk {gameVersion}"
},
@@ -2798,9 +2798,6 @@
"project.download.no-app": {
"message": "Heb je de Modrinth App niet?"
},
"project.download.no-versions-available": {
"message": "Geen versies beschikbaar voor {gameVersion} en {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} steunt niet {platform} voor {gameVersion}"
},
@@ -2255,9 +2255,6 @@
"project.download.no-app": {
"message": "Har du ikke en Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Ingen versjoner tilgjengelige for {gameVersion} og {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} støtter ikke {platform} for {gameVersion}"
},
@@ -3221,9 +3221,6 @@
"project.download.no-app": {
"message": "Nie masz Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Brak dostępnych wersji dla {gameVersion} i {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} nie obsługuje {platform} dla {gameVersion}"
},
@@ -4049,9 +4046,6 @@
"settings.account.security.email.title": {
"message": "E-mail"
},
"settings.account.security.passkey.add": {
"message": "Dodaj klucz logowania"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Wybierz coś, co zapamiętasz, by móć później rozpoznać ten klucz logowania."
},
@@ -3218,9 +3218,6 @@
"project.download.no-app": {
"message": "Não tem o Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Nenhuma versão disponível para {gameVersion} e {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} não suporta {platform} para {gameVersion}"
},
@@ -4046,9 +4043,6 @@
"settings.account.security.email.title": {
"message": "E-mail"
},
"settings.account.security.passkey.add": {
"message": "Adicionar chave de acesso"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Certifique-se de adicionar algo memorável, para poder identificar mais tarde."
},
@@ -2228,9 +2228,6 @@
"project.download.no-app": {
"message": "Não tens a Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Nenhuma versão disponível para {gameVersion} e {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} não suporta {platform} para {gameVersion}"
},
@@ -1421,9 +1421,6 @@
"project.download.no-app": {
"message": "Nu ai Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Nu există versiuni disponibile pentru {gameVersion} și {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} nu este compatibil cu {platform} pentru {gameVersion}"
},
@@ -3221,9 +3221,6 @@
"project.download.no-app": {
"message": "У вас нет Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Нет версий, доступных для {gameVersion} и {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} не поддерживает {platform} для {gameVersion}"
},
@@ -4025,9 +4022,6 @@
"settings.account.security.email.title": {
"message": "Почта"
},
"settings.account.security.passkey.add": {
"message": "Добавить ключ доступа"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Выберите что-то запоминающееся, чтобы потом опознать этот ключ доступа."
},
@@ -2810,9 +2810,6 @@
"project.download.no-app": {
"message": "Har du inte Modrinth appen?"
},
"project.download.no-versions-available": {
"message": "Inga versioner finns tillgängliga för {gameVersion} och {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} stöttar inte {platform} för {gameVersion}"
},
@@ -3167,9 +3167,6 @@
"project.download.no-app": {
"message": "Modrinth App Yok Mu?"
},
"project.download.no-versions-available": {
"message": "{gameVersion} ve {platform} için sürüm mevcut değil."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title}, {gameVersion} sürümünde {platform} desteklemiyor"
},
@@ -3941,9 +3938,6 @@
"settings.account.security.email.title": {
"message": "Eposta"
},
"settings.account.security.passkey.add": {
"message": "Giriş anahtarı ekle"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "Giriş anahtarınızı hatırlamanız için akılda kalıcı bir şey seçin."
},
@@ -2855,9 +2855,6 @@
"project.download.no-app": {
"message": "Не маєте Modrinth App?"
},
"project.download.no-versions-available": {
"message": "Немає доступних версій для {gameVersion} та {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} не підтримує {platform} для {gameVersion}"
},
@@ -3071,9 +3071,6 @@
"project.download.no-app": {
"message": "Chưa có Ứng dụng Modrinth?"
},
"project.download.no-versions-available": {
"message": "Không có phiên bản khả dụng cho {gameVersion} và {platform}."
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} không hỗ trợ {platform} cho {gameVersion}"
},
@@ -3221,9 +3221,6 @@
"project.download.no-app": {
"message": "还没有 Modrinth App 吗?"
},
"project.download.no-versions-available": {
"message": "没有支持 {platform} {gameVersion} 的版本。"
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} 不支持 {gameVersion} 的 {platform}"
},
@@ -4049,9 +4046,6 @@
"settings.account.security.email.title": {
"message": "电子邮箱"
},
"settings.account.security.passkey.add": {
"message": "添加通行密钥"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "请确保你选择的名称易于记忆,方便你日后辨认出该通行密钥。"
},
@@ -3227,9 +3227,6 @@
"project.download.no-app": {
"message": "還沒有 Modrinth App 嗎?"
},
"project.download.no-versions-available": {
"message": "{platform} {gameVersion} 沒有可用的版本。"
},
"project.download.platform-unsupported-tooltip": {
"message": "{title} 不支援 {platform} {gameVersion}"
},
@@ -4055,9 +4052,6 @@
"settings.account.security.email.title": {
"message": "電子郵件"
},
"settings.account.security.passkey.add": {
"message": "新增通行金鑰"
},
"settings.account.security.passkey.add-modal.name.description": {
"message": "請務必選擇容易記住的名稱,以便日後能辨識出這個通行金鑰。"
},
File diff suppressed because one or more lines are too long
+21 -3
View File
@@ -15,7 +15,7 @@
</template>
<script setup lang="ts">
import { FolderIcon, GlobeIcon, ReportIcon, ShieldCheckIcon } from '@modrinth/assets'
import { FolderIcon, GlobeIcon, HashIcon, ReportIcon, ShieldCheckIcon } from '@modrinth/assets'
import { Chips, defineMessages, NavTabs, useVIntl } from '@modrinth/ui'
definePageMeta({
@@ -47,6 +47,10 @@ const messages = defineMessages({
id: 'moderation.page.external-projects',
defaultMessage: 'External projects',
},
globalDetailTracesTitle: {
id: 'moderation.page.global-detail-traces',
defaultMessage: 'Global traces',
},
})
const moderationLinks = [
@@ -62,6 +66,11 @@ const moderationLinks = [
href: '/moderation/external-projects',
icon: GlobeIcon,
},
{
label: formatMessage(messages.globalDetailTracesTitle),
href: '/moderation/global-traces',
icon: HashIcon,
},
]
const mobileNavOptions = [
@@ -69,15 +78,20 @@ const mobileNavOptions = [
formatMessage(messages.technicalReviewTitle),
formatMessage(messages.reportsTitle),
formatMessage(messages.externalFilesTitle),
formatMessage(messages.globalDetailTracesTitle),
]
const selectedChip = computed({
get() {
const path = route.path
if (path === '/moderation/technical-review') {
if (path.startsWith('/moderation/technical-review')) {
return formatMessage(messages.technicalReviewTitle)
} else if (path.startsWith('/moderation/reports/')) {
} else if (path.startsWith('/moderation/reports')) {
return formatMessage(messages.reportsTitle)
} else if (path.startsWith('/moderation/external-projects')) {
return formatMessage(messages.externalFilesTitle)
} else if (path.startsWith('/moderation/global-traces')) {
return formatMessage(messages.globalDetailTracesTitle)
} else {
return formatMessage(messages.projectsTitle)
}
@@ -92,6 +106,10 @@ function navigateToPage(selectedOption: string) {
router.push('/moderation/technical-review')
} else if (selectedOption === formatMessage(messages.reportsTitle)) {
router.push('/moderation/reports')
} else if (selectedOption === formatMessage(messages.externalFilesTitle)) {
router.push('/moderation/external-projects')
} else if (selectedOption === formatMessage(messages.globalDetailTracesTitle)) {
router.push('/moderation/global-traces')
} else {
router.push('/moderation')
}
@@ -0,0 +1,199 @@
<template>
<div class="flex flex-col gap-4">
<div>
<ButtonStyled>
<NuxtLink to="/moderation/global-traces">
<ArrowLeftIcon aria-hidden="true" />
Back to global traces
</NuxtLink>
</ButtonStyled>
</div>
<EmptyState
v-if="isLoading && !trace"
type="no-search-result"
heading="Loading global detail trace..."
/>
<EmptyState
v-else-if="loadError"
type="no-search-result"
heading="Failed to load global detail trace"
/>
<article v-else-if="trace" class="universal-card flex flex-col gap-3">
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="min-w-0">
<div class="flex min-w-0 items-center gap-2">
<HashIcon class="shrink-0 text-secondary" aria-hidden="true" />
<h2 class="m-0 min-w-0 text-lg font-semibold text-contrast">
Trace
<span class="break-all font-mono text-base">{{ trace.detail_key }}</span>
</h2>
</div>
<p class="m-0 mt-1 text-sm text-secondary">
{{ pageStart }}-{{ pageEnd }} of {{ trace.local_trace_count }} local traces
</p>
</div>
<div class="flex shrink-0 flex-wrap items-center gap-2">
<Badge :type="trace.verdict" />
<ButtonStyled color="red">
<button :disabled="isRemoving" @click="removeGlobalTrace">
<TrashIcon aria-hidden="true" />
Remove
</button>
</ButtonStyled>
</div>
</div>
<div
v-if="trace.local_trace_count > localTracePageSize"
class="flex flex-wrap items-center justify-between gap-3"
>
<Pagination :page="currentPage" :count="pageCount" @switch-page="switchPage" />
<p v-if="isLoading" class="m-0 text-sm text-secondary">Loading page...</p>
</div>
<div v-if="trace.local_traces.length > 0" class="flex flex-col gap-2">
<GlobalDetailLocalTraceCard
v-for="localTrace in trace.local_traces"
:key="localTrace.detail_id"
:trace="localTrace"
/>
</div>
<EmptyState v-else type="no-search-result" heading="No local traces match this key" />
<div v-if="trace.local_trace_count > localTracePageSize" class="mt-1 flex justify-end">
<Pagination :page="currentPage" :count="pageCount" @switch-page="switchPage" />
</div>
</article>
<EmptyState v-else type="no-search-result" heading="Global detail trace not found" />
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { ArrowLeftIcon, HashIcon, TrashIcon } from '@modrinth/assets'
import {
Badge,
ButtonStyled,
EmptyState,
injectModrinthClient,
injectNotificationManager,
Pagination,
} from '@modrinth/ui'
import GlobalDetailLocalTraceCard from '~/components/ui/moderation/GlobalDetailLocalTraceCard.vue'
const client = injectModrinthClient()
const { addNotification } = injectNotificationManager()
const route = useRoute()
const router = useRouter()
const detailKey = computed(() => {
const key = route.params.key
return Array.isArray(key) ? key.join('/') : String(key)
})
useHead({ title: () => `Global trace - ${detailKey.value} - Modrinth` })
const localTracePageSize = 20
const isLoading = ref(false)
const isRemoving = ref(false)
const loadError = ref(false)
const currentPage = ref(1)
const pageStartCursors = ref<(string | null)[]>([null])
const trace = ref<Labrinth.TechReview.Internal.GlobalIssueDetail | null>(null)
const pageCount = computed(() =>
Math.max(Math.ceil((trace.value?.local_trace_count ?? 0) / localTracePageSize), 1),
)
const pageStart = computed(() =>
trace.value && trace.value.local_trace_count > 0
? (currentPage.value - 1) * localTracePageSize + 1
: 0,
)
const pageEnd = computed(() =>
Math.min(currentPage.value * localTracePageSize, trace.value?.local_trace_count ?? 0),
)
async function fetchTracePage(afterDetailId: string | null) {
return await client.labrinth.tech_review_internal.getGlobalIssueDetail({
detail_key: detailKey.value,
limit: localTracePageSize,
after_detail_id: afterDetailId,
})
}
async function loadPage(page: number) {
if (page < 1 || isLoading.value) return
isLoading.value = true
loadError.value = false
try {
while (pageStartCursors.value.length < page) {
const cursor = pageStartCursors.value[pageStartCursors.value.length - 1]
const response = await fetchTracePage(cursor)
if (!response.next_after_detail_id) {
trace.value = response.trace
currentPage.value = pageStartCursors.value.length
return
}
pageStartCursors.value.push(response.next_after_detail_id)
}
const response = await fetchTracePage(pageStartCursors.value[page - 1])
trace.value = response.trace
currentPage.value = page
} catch (error) {
console.error('Failed to load global detail trace', error)
loadError.value = true
} finally {
isLoading.value = false
}
}
async function switchPage(page: number) {
await loadPage(page)
}
async function removeGlobalTrace() {
if (isRemoving.value) return
isRemoving.value = true
try {
await client.labrinth.tech_review_internal.updateGlobalIssueDetails([
{ detail_key: detailKey.value, verdict: 'pending' },
])
addNotification({
type: 'success',
title: 'Global trace removed',
text: 'The global verdict for this trace key has been removed.',
})
await router.push('/moderation/global-traces')
} catch (error) {
console.error('Failed to remove global detail trace', error)
addNotification({
type: 'error',
title: 'Failed to remove global trace',
text: 'An error occurred while removing the global trace verdict.',
})
} finally {
isRemoving.value = false
}
}
watch(
detailKey,
() => {
currentPage.value = 1
pageStartCursors.value = [null]
trace.value = null
loadPage(1)
},
{ immediate: true },
)
</script>
@@ -0,0 +1,9 @@
<template>
<GlobalDetailTracesList />
</template>
<script setup lang="ts">
import GlobalDetailTracesList from '~/components/ui/moderation/GlobalDetailTracesList.vue'
useHead({ title: 'Global detail traces - Modrinth' })
</script>
@@ -246,7 +246,9 @@ const { data: allReports } = await useLazyAsyncData('new-moderation-reports', as
const enrichmentPromise = enrichReportBatch(reports)
enrichmentPromises.push(enrichmentPromise)
currentOffset += reports.length
// this is explicitly not the length of the reports array, because the API may return fewer reports due to a report in the middle not being
// serializable if the offset is set to the reports array you can get the same report from the end multiple times.
currentOffset += REPORT_ENDPOINT_COUNT
if (enrichmentPromises.length >= 3) {
const completed = await Promise.all(enrichmentPromises.splice(0, 2))
@@ -11,6 +11,7 @@ import ModerationTechRevCard from '~/components/ui/moderation/ModerationTechRevC
const client = injectModrinthClient()
const queryClient = useQueryClient()
const route = useRoute()
const projectId = String(useRouteId('project'))
@@ -245,6 +246,8 @@ const reviewItem = computed(() => {
}
})
const focusedDetailId = computed(() => route.query.detail?.toString() ?? null)
async function handleMarkComplete(projectId: string) {
await Promise.all([
queryClient.invalidateQueries({ queryKey: ['tech-reviews'] }),
@@ -299,6 +302,7 @@ function refetch() {
<ModerationTechRevCard
v-else
:item="reviewItem"
:focused-detail-id="focusedDetailId"
:loading-issues="loadingIssues"
:decompiled-sources="decompiledSources"
@refetch="refetch"
+4
View File
@@ -534,3 +534,7 @@ Xandr.com, 2398, DIRECT
#Rubicon
rubiconproject.com, 24584, DIRECT, 0bfd66d529a55807
rubiconproject.com, 24586, DIRECT, 0bfd66d529a55807
copper6.com, 916020, Reseller
openx.com, 563905670, RESELLER, 6a698e2ec38604c6
xandr.com, 16546, RESELLER
@@ -1,34 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n m.id AS \"project_id: DBProjectId\",\n MIN(t.id) AS \"thread_id!: DBThreadId\"\n FROM mods m\n INNER JOIN threads t ON t.mod_id = m.id\n INNER JOIN versions v ON v.mod_id = m.id\n INNER JOIN files f ON f.version_id = v.id\n INNER JOIN delphi_reports dr ON dr.file_id = f.id\n INNER JOIN delphi_report_issues dri ON dri.report_id = dr.id\n INNER JOIN delphi_report_issue_details drid\n ON drid.issue_id = dri.id\n LEFT JOIN delphi_issue_detail_verdicts didv\n ON m.id = didv.project_id AND drid.key = didv.detail_key\n LEFT JOIN threads_messages tm_last\n ON tm_last.thread_id = t.id\n AND tm_last.id = (\n SELECT id FROM threads_messages\n WHERE thread_id = t.id\n ORDER BY created DESC\n LIMIT 1\n )\n LEFT JOIN users u_last\n ON u_last.id = tm_last.author_id\n WHERE\n (\n cardinality($4::text[]) = 0\n OR (\n 'minecraft_java_server' = ANY($4::text[])\n AND (\n m.components ? 'minecraft_server'\n OR m.components ? 'minecraft_java_server'\n )\n )\n OR EXISTS (\n SELECT 1\n FROM versions type_v\n INNER JOIN loaders_versions type_lv\n ON type_lv.version_id = type_v.id\n INNER JOIN loaders_project_types type_lpt\n ON type_lpt.joining_loader_id = type_lv.loader_id\n INNER JOIN project_types type_pt\n ON type_pt.id = type_lpt.joining_project_type_id\n WHERE\n type_v.mod_id = m.id\n AND type_pt.name = ANY($4::text[])\n AND (\n type_pt.name != 'modpack'\n OR NOT (\n m.components ? 'minecraft_server'\n OR m.components ? 'minecraft_java_server'\n )\n )\n )\n )\n AND m.status NOT IN ('draft', 'rejected', 'withheld')\n AND (cardinality($6::text[]) = 0 OR m.status = ANY($6::text[]))\n AND (cardinality($7::text[]) = 0 OR dri.issue_type = ANY($7::text[]))\n AND (didv.verdict IS NULL OR didv.verdict = 'pending'::delphi_report_issue_status)\n AND (\n $5::text IS NULL\n OR ($5::text = 'unreplied' AND (tm_last.id IS NULL OR u_last.role IS NULL OR u_last.role NOT IN ('moderator', 'admin')))\n OR ($5::text = 'replied' AND tm_last.id IS NOT NULL AND u_last.role IS NOT NULL AND u_last.role IN ('moderator', 'admin'))\n )\n GROUP BY m.id\n ORDER BY\n CASE WHEN $3 = 'created_asc' THEN MIN(dr.created) ELSE TO_TIMESTAMP(0) END ASC,\n CASE WHEN $3 = 'created_desc' THEN MIN(dr.created) ELSE TO_TIMESTAMP(0) END DESC,\n CASE WHEN $3 = 'severity_asc' THEN MAX(dr.severity) ELSE 'low'::delphi_severity END ASC,\n CASE WHEN $3 = 'severity_desc' THEN MAX(dr.severity) ELSE 'low'::delphi_severity END DESC,\n -- tie-breaker: oldest reports\n MIN(dr.created) ASC\n LIMIT $1 OFFSET $2\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "project_id: DBProjectId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "thread_id!: DBThreadId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8",
"Text",
"TextArray",
"Text",
"TextArray",
"TextArray"
]
},
"nullable": [
false,
null
]
},
"hash": "0545adc0340800b9fb4c23eb5ec2b30d5bba824f80cd25dbf08ca9f86c32ea1f"
}
@@ -0,0 +1,148 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n didws.key AS \"detail_key!\",\n didws.id AS \"detail_id!: DelphiReportIssueDetailsId\",\n didws.issue_id AS \"issue_id!: DelphiReportIssueId\",\n dri.issue_type,\n m.id AS \"project_id!: DBProjectId\",\n m.slug AS \"project_slug?\",\n m.name AS \"project_name!\",\n v.id AS \"version_id!: DBVersionId\",\n v.version_number,\n f.id AS \"file_id!: DBFileId\",\n f.filename AS \"file_name!\",\n didws.jar AS \"jar?\",\n didws.file_path AS \"file_path!\",\n didws.severity AS \"severity!: DelphiSeverity\",\n COALESCE(didv.verdict, 'pending'::delphi_report_issue_status)\n AS \"local_status!: DelphiStatus\",\n didws.status AS \"effective_status!: DelphiStatus\"\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n INNER JOIN delphi_reports dr ON dr.id = dri.report_id\n INNER JOIN files f ON f.id = dr.file_id\n INNER JOIN versions v ON v.id = f.version_id\n INNER JOIN mods m ON m.id = v.mod_id\n LEFT JOIN delphi_issue_detail_verdicts didv\n ON didv.project_id = didws.project_id\n AND didv.detail_key = didws.key\n WHERE\n didws.key = $1\n AND ($2::bigint IS NULL OR didws.id > $2)\n AND dri.issue_type != '__dummy'\n ORDER BY didws.id\n LIMIT $3\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "detail_key!",
"type_info": "Text"
},
{
"ordinal": 1,
"name": "detail_id!: DelphiReportIssueDetailsId",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "issue_id!: DelphiReportIssueId",
"type_info": "Int8"
},
{
"ordinal": 3,
"name": "issue_type",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "project_id!: DBProjectId",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "project_slug?",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "project_name!",
"type_info": "Varchar"
},
{
"ordinal": 7,
"name": "version_id!: DBVersionId",
"type_info": "Int8"
},
{
"ordinal": 8,
"name": "version_number",
"type_info": "Varchar"
},
{
"ordinal": 9,
"name": "file_id!: DBFileId",
"type_info": "Int8"
},
{
"ordinal": 10,
"name": "file_name!",
"type_info": "Varchar"
},
{
"ordinal": 11,
"name": "jar?",
"type_info": "Text"
},
{
"ordinal": 12,
"name": "file_path!",
"type_info": "Text"
},
{
"ordinal": 13,
"name": "severity!: DelphiSeverity",
"type_info": {
"Custom": {
"name": "delphi_severity",
"kind": {
"Enum": [
"low",
"medium",
"high",
"severe"
]
}
}
}
},
{
"ordinal": 14,
"name": "local_status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 15,
"name": "effective_status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
}
],
"parameters": {
"Left": [
"Text",
"Int8",
"Int8"
]
},
"nullable": [
true,
true,
true,
false,
false,
true,
false,
false,
false,
false,
false,
true,
true,
true,
null,
true
]
},
"hash": "055f71ec6d193c5f5259cafc989a04f3f791205e6c2df15c5bf9d5afcf71a76a"
}
@@ -0,0 +1,29 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n (\n SELECT t.id\n FROM threads t\n WHERE t.mod_id = $1\n ORDER BY t.id\n LIMIT 1\n ) AS \"thread_id: DBThreadId\",\n (\n SELECT tm.body->>'type'\n FROM threads t\n INNER JOIN threads_messages tm ON tm.thread_id = t.id\n WHERE\n t.mod_id = $1\n AND tm.body->>'type' = ANY($2::text[])\n ORDER BY tm.created DESC, tm.id DESC\n LIMIT 1\n ) AS \"last_tech_review_message_type\"\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "thread_id: DBThreadId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "last_tech_review_message_type",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int8",
"TextArray"
]
},
"nullable": [
null,
null
]
},
"hash": "080e2f0068c0c1c248dcfacf39798aefed70d9a61610fc7f4f1c8f291706fa4a"
}
@@ -0,0 +1,34 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n m.id AS \"project_id: DBProjectId\",\n MIN(t.id) AS \"thread_id!: DBThreadId\"\n FROM mods m\n INNER JOIN threads t ON t.mod_id = m.id\n INNER JOIN versions v ON v.mod_id = m.id\n INNER JOIN files f ON f.version_id = v.id\n INNER JOIN delphi_reports dr ON dr.file_id = f.id\n INNER JOIN delphi_report_issues dri ON dri.report_id = dr.id\n INNER JOIN delphi_issue_details_with_statuses didws\n ON didws.issue_id = dri.id\n LEFT JOIN threads_messages tm_last\n ON tm_last.thread_id = t.id\n AND tm_last.id = (\n SELECT id FROM threads_messages\n WHERE thread_id = t.id\n ORDER BY created DESC\n LIMIT 1\n )\n LEFT JOIN users u_last\n ON u_last.id = tm_last.author_id\n WHERE\n (\n cardinality($4::text[]) = 0\n OR (\n 'minecraft_java_server' = ANY($4::text[])\n AND (\n m.components ? 'minecraft_server'\n OR m.components ? 'minecraft_java_server'\n )\n )\n OR EXISTS (\n SELECT 1\n FROM versions type_v\n INNER JOIN loaders_versions type_lv\n ON type_lv.version_id = type_v.id\n INNER JOIN loaders_project_types type_lpt\n ON type_lpt.joining_loader_id = type_lv.loader_id\n INNER JOIN project_types type_pt\n ON type_pt.id = type_lpt.joining_project_type_id\n WHERE\n type_v.mod_id = m.id\n AND type_pt.name = ANY($4::text[])\n AND (\n type_pt.name != 'modpack'\n OR NOT (\n m.components ? 'minecraft_server'\n OR m.components ? 'minecraft_java_server'\n )\n )\n )\n )\n AND m.status NOT IN ('draft', 'rejected', 'withheld')\n AND (cardinality($6::text[]) = 0 OR m.status = ANY($6::text[]))\n AND (cardinality($7::text[]) = 0 OR dri.issue_type = ANY($7::text[]))\n AND didws.status = 'pending'\n AND (\n $5::text IS NULL\n OR ($5::text = 'unreplied' AND (tm_last.id IS NULL OR u_last.role IS NULL OR u_last.role NOT IN ('moderator', 'admin')))\n OR ($5::text = 'replied' AND tm_last.id IS NOT NULL AND u_last.role IS NOT NULL AND u_last.role IN ('moderator', 'admin'))\n )\n GROUP BY m.id\n ORDER BY\n CASE WHEN $3 = 'created_asc' THEN MIN(dr.created) ELSE TO_TIMESTAMP(0) END ASC,\n CASE WHEN $3 = 'created_desc' THEN MIN(dr.created) ELSE TO_TIMESTAMP(0) END DESC,\n CASE WHEN $3 = 'severity_asc' THEN MAX(dr.severity) ELSE 'low'::delphi_severity END ASC,\n CASE WHEN $3 = 'severity_desc' THEN MAX(dr.severity) ELSE 'low'::delphi_severity END DESC,\n -- tie-breaker: oldest reports\n MIN(dr.created) ASC\n LIMIT $1 OFFSET $2\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "project_id: DBProjectId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "thread_id!: DBThreadId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
"Int8",
"Text",
"TextArray",
"Text",
"TextArray",
"TextArray"
]
},
"nullable": [
false,
null
]
},
"hash": "1a6d4ac11af078439cff5c772f4dc2392729f99ba1f8c7892831235f341fb276"
}
@@ -1,87 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n drid.id AS \"id!: DelphiReportIssueDetailsId\",\n drid.issue_id AS \"issue_id!: DelphiReportIssueId\",\n drid.key AS \"key!: String\",\n drid.jar AS \"jar?: String\",\n drid.file_path AS \"file_path!: String\",\n drid.data AS \"data!: sqlx::types::Json<HashMap<String, serde_json::Value>>\",\n drid.severity AS \"severity!: DelphiSeverity\",\n COALESCE(didv.verdict, 'pending'::delphi_report_issue_status) AS \"status!: DelphiStatus\"\n FROM delphi_report_issue_details drid\n INNER JOIN delphi_report_issues dri ON dri.id = drid.issue_id\n INNER JOIN delphi_reports dr ON dr.id = dri.report_id\n INNER JOIN files f ON f.id = dr.file_id\n INNER JOIN versions v ON v.id = f.version_id\n INNER JOIN mods m ON m.id = v.mod_id\n LEFT JOIN delphi_issue_detail_verdicts didv\n ON m.id = didv.project_id AND drid.key = didv.detail_key\n WHERE drid.issue_id = ANY($1::bigint[])\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id!: DelphiReportIssueDetailsId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "issue_id!: DelphiReportIssueId",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "key!: String",
"type_info": "Text"
},
{
"ordinal": 3,
"name": "jar?: String",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "file_path!: String",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "data!: sqlx::types::Json<HashMap<String, serde_json::Value>>",
"type_info": "Jsonb"
},
{
"ordinal": 6,
"name": "severity!: DelphiSeverity",
"type_info": {
"Custom": {
"name": "delphi_severity",
"kind": {
"Enum": [
"low",
"medium",
"high",
"severe"
]
}
}
}
},
{
"ordinal": 7,
"name": "status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
}
],
"parameters": {
"Left": [
"Int8Array"
]
},
"nullable": [
false,
false,
false,
true,
false,
false,
false,
null
]
},
"hash": "263ad3654f544ffb6061c839d49dada47fb382a76fdcabad2077fb1ef6d1010a"
}
@@ -1,28 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n EXISTS(\n SELECT 1 FROM delphi_issue_details_with_statuses didws\n WHERE didws.project_id = $1 AND didws.status = 'pending'\n ) AS \"pending_issue_details_exist!\",\n t.id AS \"thread_id: DBThreadId\"\n FROM mods m\n INNER JOIN threads t ON t.mod_id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "pending_issue_details_exist!",
"type_info": "Bool"
},
{
"ordinal": 1,
"name": "thread_id: DBThreadId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
null,
false
]
},
"hash": "2d9e36c76a1e214c53d9dc2aa3debe1d03998be169a306b63a0ca1beaa07397f"
}
@@ -0,0 +1,47 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n dgdv.detail_key,\n dgdv.verdict AS \"verdict!: DelphiStatus\",\n COUNT(dri.id) AS \"local_trace_count!\"\n FROM delphi_global_detail_verdicts dgdv\n LEFT JOIN delphi_issue_details_with_statuses didws\n ON didws.key = dgdv.detail_key\n LEFT JOIN delphi_report_issues dri\n ON dri.id = didws.issue_id\n AND dri.issue_type != '__dummy'\n WHERE (\n $1::text IS NULL\n OR dgdv.detail_key ILIKE '%' || $1 || '%'\n )\n GROUP BY dgdv.detail_key, dgdv.verdict\n ORDER BY dgdv.detail_key\n LIMIT $2 OFFSET $3\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "detail_key",
"type_info": "Text"
},
{
"ordinal": 1,
"name": "verdict!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 2,
"name": "local_trace_count!",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Text",
"Int8",
"Int8"
]
},
"nullable": [
false,
false,
null
]
},
"hash": "4680c4a59c6679f90e3b9e1a33ed1cb1fb60b93ffb79ba5b99e01ee0c14c991a"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT DISTINCT ON (dr.id)\n to_jsonb(dr)\n || jsonb_build_object(\n 'report_id', dr.id,\n 'file_id', to_base62(f.id),\n 'version_id', to_base62(v.id),\n 'project_id', to_base62(v.mod_id),\n 'file_name', f.filename,\n 'file_size', f.size,\n 'flag_reason', 'delphi',\n 'download_url', f.url,\n -- TODO: replace with `json_array` in Postgres 16\n\t\t\t\t'issues', (\n\t\t\t\t\tSELECT coalesce(json_agg(\n\t\t\t\t\t\tto_jsonb(dri)\n\t\t\t\t\t\t|| jsonb_build_object(\n\t\t\t\t\t\t\t-- TODO: replace with `json_array` in Postgres 16\n\t\t\t\t\t\t\t'details', (\n\t\t\t\t\t\t\t\tSELECT coalesce(jsonb_agg(\n jsonb_build_object(\n 'id', didws.id,\n 'issue_id', didws.issue_id,\n 'key', didws.key,\n 'file_path', didws.file_path,\n 'decompiled_source', didws.decompiled_source,\n 'data', didws.data,\n 'severity', didws.severity,\n 'status', didws.status\n )\n ), '[]'::jsonb)\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.issue_id = dri.id\n )\n\t\t\t\t\t\t)\n\t\t\t\t\t), '[]'::json)\n\t\t\t\t\tFROM delphi_report_issues dri\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tdri.report_id = dr.id\n -- see delphi.rs todo comment\n AND dri.issue_type != '__dummy'\n )\n ) AS \"data!: sqlx::types::Json<FileReport>\"\n FROM delphi_reports dr\n INNER JOIN files f ON f.id = dr.file_id\n INNER JOIN versions v ON v.id = f.version_id\n WHERE dr.id = $1\n ",
"query": "\n SELECT DISTINCT ON (dr.id)\n to_jsonb(dr)\n || jsonb_build_object(\n 'report_id', dr.id,\n 'file_id', to_base62(f.id),\n 'version_id', to_base62(v.id),\n 'project_id', to_base62(v.mod_id),\n 'file_name', f.filename,\n 'file_size', f.size,\n 'flag_reason', 'delphi',\n 'download_url', f.url,\n -- TODO: replace with `json_array` in Postgres 16\n\t\t\t\t'issues', (\n\t\t\t\t\tSELECT coalesce(json_agg(\n\t\t\t\t\t\tto_jsonb(dri)\n\t\t\t\t\t\t|| jsonb_build_object(\n\t\t\t\t\t\t\t-- TODO: replace with `json_array` in Postgres 16\n\t\t\t\t\t\t\t'details', (\n\t\t\t\t\t\t\t\tSELECT coalesce(jsonb_agg(\n jsonb_build_object(\n 'id', didws.id,\n 'issue_id', didws.issue_id,\n 'key', didws.key,\n 'file_path', didws.file_path,\n 'decompiled_source', didws.decompiled_source,\n 'data', didws.data,\n 'severity', didws.severity,\n 'local_status', didws.local_status,\n 'global_status', didws.global_status,\n 'status', didws.status\n )\n ), '[]'::jsonb)\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.issue_id = dri.id\n )\n\t\t\t\t\t\t)\n\t\t\t\t\t), '[]'::json)\n\t\t\t\t\tFROM delphi_report_issues dri\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tdri.report_id = dr.id\n -- see delphi.rs todo comment\n AND dri.issue_type != '__dummy'\n )\n ) AS \"data!: sqlx::types::Json<FileReport>\"\n FROM delphi_reports dr\n INNER JOIN files f ON f.id = dr.file_id\n INNER JOIN versions v ON v.id = f.version_id\n WHERE dr.id = $1\n ",
"describe": {
"columns": [
{
@@ -18,5 +18,5 @@
null
]
},
"hash": "fe4ff6ab40fe3dc3d474c0c23c9dba514c66ac30e573fc5f4e44ed7ff360d3d6"
"hash": "48dfc2f2bcf8917f110b7b2b142167f1525cdea2ace9e6165e5c5f596cbd9fb3"
}
@@ -1,22 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT id AS \"thread_id: DBThreadId\"\n FROM threads\n WHERE mod_id = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "thread_id: DBThreadId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false
]
},
"hash": "555342b0ec9fb808f05a18aaeaf06fb61e968fb3379c9d0c7ad82c8747bd4256"
}
@@ -0,0 +1,45 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n dgdv.detail_key,\n dgdv.verdict AS \"verdict!: DelphiStatus\",\n COUNT(dri.id) AS \"local_trace_count!\"\n FROM delphi_global_detail_verdicts dgdv\n LEFT JOIN delphi_issue_details_with_statuses didws\n ON didws.key = dgdv.detail_key\n LEFT JOIN delphi_report_issues dri\n ON dri.id = didws.issue_id\n AND dri.issue_type != '__dummy'\n WHERE dgdv.detail_key = $1\n GROUP BY dgdv.detail_key, dgdv.verdict\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "detail_key",
"type_info": "Text"
},
{
"ordinal": 1,
"name": "verdict!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 2,
"name": "local_trace_count!",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
null
]
},
"hash": "5e5fcfa6ac68f296ba5238e8211f8e206473f11fe1796fc2feda15f8d0ee7f41"
}
@@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "\n WITH incoming AS (\n SELECT *\n FROM unnest($1::text[], $2::text[]) WITH ORDINALITY\n AS u(detail_key, verdict, ord)\n ),\n latest AS (\n SELECT DISTINCT ON (detail_key)\n detail_key,\n verdict\n FROM incoming\n ORDER BY detail_key, ord DESC\n ),\n deleted AS (\n DELETE FROM delphi_global_detail_verdicts dgdv\n USING latest\n WHERE\n dgdv.detail_key = latest.detail_key\n AND latest.verdict = 'pending'\n RETURNING 1\n )\n INSERT INTO delphi_global_detail_verdicts (\n detail_key,\n verdict\n )\n SELECT\n detail_key,\n verdict::delphi_report_issue_status\n FROM latest\n WHERE verdict != 'pending'\n ON CONFLICT (detail_key)\n DO UPDATE SET verdict = EXCLUDED.verdict\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"TextArray",
"TextArray"
]
},
"nullable": []
},
"hash": "7ca85bcc45e7d53106ea75b606ce2219bd37be7bb33588179cca6f1a26e5bb23"
}
@@ -0,0 +1,147 @@
{
"db_name": "PostgreSQL",
"query": "\n WITH ranked_local_traces AS (\n SELECT\n didws.key AS detail_key,\n didws.id AS detail_id,\n didws.issue_id,\n dri.issue_type,\n m.id AS project_id,\n m.slug AS project_slug,\n m.name AS project_name,\n v.id AS version_id,\n v.version_number,\n f.id AS file_id,\n f.filename AS file_name,\n didws.jar,\n didws.file_path,\n didws.severity,\n COALESCE(didv.verdict, 'pending'::delphi_report_issue_status)\n AS local_status,\n didws.status AS effective_status,\n ROW_NUMBER() OVER (\n PARTITION BY didws.key\n ORDER BY didws.id\n ) AS row_num\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n INNER JOIN delphi_reports dr ON dr.id = dri.report_id\n INNER JOIN files f ON f.id = dr.file_id\n INNER JOIN versions v ON v.id = f.version_id\n INNER JOIN mods m ON m.id = v.mod_id\n LEFT JOIN delphi_issue_detail_verdicts didv\n ON didv.project_id = didws.project_id\n AND didv.detail_key = didws.key\n WHERE\n didws.key = ANY($1::text[])\n AND dri.issue_type != '__dummy'\n )\n SELECT\n detail_key AS \"detail_key!\",\n detail_id AS \"detail_id!: DelphiReportIssueDetailsId\",\n issue_id AS \"issue_id!: DelphiReportIssueId\",\n issue_type,\n project_id AS \"project_id!: DBProjectId\",\n project_slug AS \"project_slug?\",\n project_name AS \"project_name!\",\n version_id AS \"version_id!: DBVersionId\",\n v.version_number,\n file_id AS \"file_id!: DBFileId\",\n file_name AS \"file_name!\",\n jar AS \"jar?\",\n file_path AS \"file_path!\",\n severity AS \"severity!: DelphiSeverity\",\n local_status AS \"local_status!: DelphiStatus\",\n effective_status AS \"effective_status!: DelphiStatus\"\n FROM ranked_local_traces v\n WHERE row_num <= $2\n ORDER BY detail_key, detail_id\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "detail_key!",
"type_info": "Text"
},
{
"ordinal": 1,
"name": "detail_id!: DelphiReportIssueDetailsId",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "issue_id!: DelphiReportIssueId",
"type_info": "Int8"
},
{
"ordinal": 3,
"name": "issue_type",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "project_id!: DBProjectId",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "project_slug?",
"type_info": "Varchar"
},
{
"ordinal": 6,
"name": "project_name!",
"type_info": "Varchar"
},
{
"ordinal": 7,
"name": "version_id!: DBVersionId",
"type_info": "Int8"
},
{
"ordinal": 8,
"name": "version_number",
"type_info": "Varchar"
},
{
"ordinal": 9,
"name": "file_id!: DBFileId",
"type_info": "Int8"
},
{
"ordinal": 10,
"name": "file_name!",
"type_info": "Varchar"
},
{
"ordinal": 11,
"name": "jar?",
"type_info": "Text"
},
{
"ordinal": 12,
"name": "file_path!",
"type_info": "Text"
},
{
"ordinal": 13,
"name": "severity!: DelphiSeverity",
"type_info": {
"Custom": {
"name": "delphi_severity",
"kind": {
"Enum": [
"low",
"medium",
"high",
"severe"
]
}
}
}
},
{
"ordinal": 14,
"name": "local_status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 15,
"name": "effective_status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
}
],
"parameters": {
"Left": [
"TextArray",
"Int8"
]
},
"nullable": [
true,
true,
true,
false,
false,
true,
false,
false,
false,
false,
false,
true,
true,
true,
null,
true
]
},
"hash": "87d30e8802ebe69858141d0d918cafb5286f984cfe55ad1a7ac2219ec50539a4"
}
@@ -1,22 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT EXISTS(\n SELECT 1\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n WHERE\n didws.project_id = $1\n AND didws.status = 'pending'\n -- see delphi.rs todo comment\n AND dri.issue_type != '__dummy'\n ) AS \"is_in_tech_review!\"\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "is_in_tech_review!",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
null
]
},
"hash": "8c80f3158fb5772adc8542cdf5419437bb8cd65723a32e587022d0c8decba68d"
}
@@ -0,0 +1,121 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n didws.id AS \"id!: DelphiReportIssueDetailsId\",\n didws.issue_id AS \"issue_id!: DelphiReportIssueId\",\n didws.key AS \"key!: String\",\n didws.jar AS \"jar?: String\",\n didws.file_path AS \"file_path!: String\",\n didws.data AS \"data!: sqlx::types::Json<HashMap<String, serde_json::Value>>\",\n didws.severity AS \"severity!: DelphiSeverity\",\n didws.local_status AS \"local_status?: DelphiStatus\",\n didws.global_status AS \"global_status?: DelphiStatus\",\n didws.status AS \"status!: DelphiStatus\"\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.issue_id = ANY($1::bigint[])\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id!: DelphiReportIssueDetailsId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "issue_id!: DelphiReportIssueId",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "key!: String",
"type_info": "Text"
},
{
"ordinal": 3,
"name": "jar?: String",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "file_path!: String",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "data!: sqlx::types::Json<HashMap<String, serde_json::Value>>",
"type_info": "Jsonb"
},
{
"ordinal": 6,
"name": "severity!: DelphiSeverity",
"type_info": {
"Custom": {
"name": "delphi_severity",
"kind": {
"Enum": [
"low",
"medium",
"high",
"severe"
]
}
}
}
},
{
"ordinal": 7,
"name": "local_status?: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 8,
"name": "global_status?: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
},
{
"ordinal": 9,
"name": "status!: DelphiStatus",
"type_info": {
"Custom": {
"name": "delphi_report_issue_status",
"kind": {
"Enum": [
"pending",
"safe",
"unsafe"
]
}
}
}
}
],
"parameters": {
"Left": [
"Int8Array"
]
},
"nullable": [
true,
true,
true,
true,
true,
true,
true,
true,
true,
true
]
},
"hash": "9070b1b6a5b1e93eb1fd1838c522fa6084ad6a5c86fafbfe8448ea7cc86f38ba"
}
@@ -1,23 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT EXISTS(\n SELECT 1\n FROM unnest($2::text[]) AS incoming(detail_key)\n LEFT JOIN delphi_issue_detail_verdicts didv\n ON didv.project_id = $1 AND didv.detail_key = incoming.detail_key\n WHERE didv.project_id IS NULL\n ) AS \"has_unflagged_issue_details!\"\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "has_unflagged_issue_details!",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Int8",
"TextArray"
]
},
"nullable": [
null
]
},
"hash": "997944b328b628792d84b21747f9e9c670ad40d0f89a175aedece93df1169195"
}
@@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT DISTINCT didws.project_id AS \"project_id!: DBProjectId\"\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.key = ANY($1::text[])\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "project_id!: DBProjectId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"TextArray"
]
},
"nullable": [
true
]
},
"hash": "ba7585f55df2a4596caae265ac956eb23268f26aef664234b898b17d13c09f91"
}
@@ -0,0 +1,60 @@
{
"db_name": "PostgreSQL",
"query": "\n WITH project_ids AS (\n SELECT unnest($1::bigint[]) AS project_id\n )\n SELECT\n p.project_id AS \"project_id!: DBProjectId\",\n EXISTS(\n SELECT 1\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n WHERE\n didws.project_id = p.project_id\n AND didws.status = 'pending'\n AND dri.issue_type != $3\n ) AS \"has_pending_detail!\",\n EXISTS(\n SELECT 1\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n WHERE\n didws.project_id = p.project_id\n AND didws.status = 'unsafe'\n AND dri.issue_type != $3\n ) AS \"has_unsafe_detail!\",\n EXISTS(\n SELECT 1\n FROM delphi_issue_details_with_statuses didws\n INNER JOIN delphi_report_issues dri ON dri.id = didws.issue_id\n WHERE\n didws.project_id = p.project_id\n AND didws.status = 'pending'\n AND dri.issue_type = $3\n ) AS \"has_dummy!\",\n (\n SELECT t.id\n FROM threads t\n WHERE t.mod_id = p.project_id\n ORDER BY t.id\n LIMIT 1\n ) AS \"thread_id: DBThreadId\",\n (\n SELECT tm.body->>'type'\n FROM threads t\n INNER JOIN threads_messages tm ON tm.thread_id = t.id\n WHERE\n t.mod_id = p.project_id\n AND tm.body->>'type' = ANY($2::text[])\n ORDER BY tm.created DESC, tm.id DESC\n LIMIT 1\n ) AS \"last_tech_review_message_type\",\n (\n SELECT dr.id\n FROM versions v\n INNER JOIN files f ON f.version_id = v.id\n INNER JOIN delphi_reports dr ON dr.file_id = f.id\n WHERE v.mod_id = p.project_id\n ORDER BY dr.created DESC, dr.id DESC\n LIMIT 1\n ) AS \"report_id: DelphiReportId\"\n FROM project_ids p\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "project_id!: DBProjectId",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "has_pending_detail!",
"type_info": "Bool"
},
{
"ordinal": 2,
"name": "has_unsafe_detail!",
"type_info": "Bool"
},
{
"ordinal": 3,
"name": "has_dummy!",
"type_info": "Bool"
},
{
"ordinal": 4,
"name": "thread_id: DBThreadId",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "last_tech_review_message_type",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "report_id: DelphiReportId",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8Array",
"TextArray",
"Text"
]
},
"nullable": [
null,
null,
null,
null,
null,
null,
null
]
},
"hash": "bb94018c84f3809b9ad89f35ff08501addc8f203a0a152346aaebd32db52be30"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n to_jsonb(dri)\n || jsonb_build_object(\n -- TODO: replace with `json_array` in Postgres 16\n 'details', (\n SELECT coalesce(jsonb_agg(\n jsonb_build_object(\n 'id', didws.id,\n 'issue_id', didws.issue_id,\n 'key', didws.key,\n 'file_path', didws.file_path,\n 'decompiled_source', didws.decompiled_source,\n 'data', didws.data,\n 'severity', didws.severity,\n 'status', didws.status\n )\n ), '[]'::jsonb)\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.issue_id = dri.id\n )\n ) AS \"data!: sqlx::types::Json<FileIssue>\"\n FROM delphi_report_issues dri\n WHERE dri.id = $1\n ",
"query": "\n SELECT\n to_jsonb(dri)\n || jsonb_build_object(\n -- TODO: replace with `json_array` in Postgres 16\n 'details', (\n SELECT coalesce(jsonb_agg(\n jsonb_build_object(\n 'id', didws.id,\n 'issue_id', didws.issue_id,\n 'key', didws.key,\n 'file_path', didws.file_path,\n 'decompiled_source', didws.decompiled_source,\n 'data', didws.data,\n 'severity', didws.severity,\n 'local_status', didws.local_status,\n 'global_status', didws.global_status,\n 'status', didws.status\n )\n ), '[]'::jsonb)\n FROM delphi_issue_details_with_statuses didws\n WHERE didws.issue_id = dri.id\n )\n ) AS \"data!: sqlx::types::Json<FileIssue>\"\n FROM delphi_report_issues dri\n WHERE dri.id = $1\n ",
"describe": {
"columns": [
{
@@ -18,5 +18,5 @@
null
]
},
"hash": "112bc4904c32afc9ffba30528a9c0e7b7fe259c58411afa5ef86a7ae4bde2703"
"hash": "c3598ed9f64f7151b83d47a15fabfdcf015bda1b3c0a7f2358c7f284feb532c3"
}

Some files were not shown because too many files have changed in this diff Show More