Skip to content

Commit db830ef

Browse files
authored
feat: prevent .mrpack being uploaded as additional file (#6582)
1 parent 08f44b3 commit db830ef

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

apps/frontend/src/providers/version/manage-version-modal.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ export function createManageVersionContext(
313313
// detect primary file if no primary file is set
314314
const primaryFileIndex = primaryFile.value ? null : detectPrimaryFileIndex(newFiles)
315315

316+
if (hasSupplementaryMrpackFile(newFiles, primaryFileIndex)) {
317+
notifyInvalidSupplementaryMrpack()
318+
handlingNewFiles.value = false
319+
return
320+
}
321+
316322
newFiles.forEach((file) => filesToAdd.value.push({ file }))
317323

318324
if (primaryFileIndex !== null) {
@@ -567,6 +573,29 @@ export function createManageVersionContext(
567573
})
568574

569575
// File handling helpers
576+
function isMrpackFile(file: File): boolean {
577+
const name = file.name.toLowerCase()
578+
return name.endsWith('.mrpack') || name.endsWith('.mrpack-primary')
579+
}
580+
581+
function hasSupplementaryMrpackFile(
582+
files: File[] | Labrinth.Versions.v3.DraftVersionFile[],
583+
primaryFileIndex: number | null = 0,
584+
): boolean {
585+
return files.some((file, index) => {
586+
const rawFile = 'file' in file ? file.file : file
587+
return index !== primaryFileIndex && isMrpackFile(rawFile)
588+
})
589+
}
590+
591+
function notifyInvalidSupplementaryMrpack() {
592+
addNotification({
593+
title: 'Invalid supplementary file',
594+
text: 'mrpacks cannot be uploaded as supplementary files, only as the primary file',
595+
type: 'error',
596+
})
597+
}
598+
570599
function detectPrimaryFileIndex(files: File[]): number {
571600
const extensionPriority = ['.jar', '.zip', '.litemod', '.mrpack', '.mrpack-primary']
572601

@@ -738,6 +767,12 @@ export function createManageVersionContext(
738767
async function handleCreateVersion() {
739768
const version = toRaw(draftVersion.value)
740769
const files = toRaw(filesToAdd.value)
770+
771+
if (hasSupplementaryMrpackFile(files)) {
772+
notifyInvalidSupplementaryMrpack()
773+
return
774+
}
775+
741776
isSubmitting.value = true
742777
isUploading.value = true
743778

0 commit comments

Comments
 (0)