mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 01:26:23 +00:00
feat: malware warning modal changes (#6721)
* feat: improved warning modals * fix: qa * feat: install to play and update to play changes * fix: dont warn for server projects as already reviewed * fix: lint
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
<ReadyTransition :pending="loading">
|
||||
<ContentPageLayout>
|
||||
<template #modals>
|
||||
<UnknownFileWarningModal
|
||||
ref="unknownFileWarningModal"
|
||||
mode="mod"
|
||||
:file-name="unknownFileName"
|
||||
@cancel="resolveUnknownFileWarning(false)"
|
||||
@continue="handleUnknownFileContinue"
|
||||
/>
|
||||
<ShareModalWrapper
|
||||
ref="shareModal"
|
||||
:share-title="formatMessage(messages.shareTitle)"
|
||||
@@ -87,6 +94,7 @@ import {
|
||||
provideAppBackup,
|
||||
provideContentManager,
|
||||
ReadyTransition,
|
||||
UnknownFileWarningModal,
|
||||
useDebugLogger,
|
||||
useVIntl,
|
||||
versionChangesGameVersion,
|
||||
@@ -113,6 +121,7 @@ import {
|
||||
add_project_from_path,
|
||||
edit,
|
||||
get_linked_modpack_content,
|
||||
is_file_on_modrinth,
|
||||
list,
|
||||
remove_project,
|
||||
switch_project_version_with_dependencies,
|
||||
@@ -121,10 +130,12 @@ import {
|
||||
update_managed_modrinth_version,
|
||||
} from '@/helpers/instance'
|
||||
import { type InstanceContentData, loadInstanceContentData } from '@/helpers/instance-content'
|
||||
import { get as getSettings, set as setSettings } from '@/helpers/settings'
|
||||
import type { CacheBehaviour, GameInstance } from '@/helpers/types'
|
||||
import { highlightModInInstance } from '@/helpers/utils.js'
|
||||
import { injectContentInstall } from '@/providers/content-install'
|
||||
import { useTheming } from '@/store/state'
|
||||
import type { FeatureFlag } from '@/store/theme'
|
||||
|
||||
const messages = defineMessages({
|
||||
shareTitle: {
|
||||
@@ -175,6 +186,7 @@ const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const debug = useDebugLogger('Mods:ContentUpdate')
|
||||
const themeStore = useTheming()
|
||||
const skipUnknownFileWarningFeatureFlag = 'skip_unknown_pack_warning' as FeatureFlag
|
||||
const skipNonEssentialWarnings = computed(() =>
|
||||
themeStore.getFeatureFlag('skip_non_essential_warnings'),
|
||||
)
|
||||
@@ -284,6 +296,9 @@ const exportModal = ref(null)
|
||||
const contentUpdaterModal = ref<InstanceType<typeof ContentUpdaterModal> | null>()
|
||||
const modpackContentModal = ref<InstanceType<typeof ModpackContentModal> | null>()
|
||||
const modpackUpdateConfirmModal = ref<InstanceType<typeof ConfirmModpackUpdateModal> | null>()
|
||||
const unknownFileWarningModal = ref<InstanceType<typeof UnknownFileWarningModal> | null>()
|
||||
const unknownFileName = ref('')
|
||||
let resolveUnknownFileConfirmation: ((confirmed: boolean) => void) | null = null
|
||||
|
||||
const modpackContentQueryKey = computed(() => ['linkedModpackContent', props.instance.id])
|
||||
const modpackContentQuery = useQuery({
|
||||
@@ -482,14 +497,34 @@ async function handleUploadFiles() {
|
||||
if (!props.instance) return
|
||||
const files = await open({ multiple: true })
|
||||
if (!files) return
|
||||
|
||||
const addedFiles: string[] = []
|
||||
const selectedFiles: Array<{ path: string; filename: string }> = []
|
||||
for (const file of files) {
|
||||
const path = (file as { path?: string }).path ?? file
|
||||
const fileName = typeof path === 'string' ? (path.split('/').pop() ?? path) : String(path)
|
||||
if (typeof path !== 'string') continue
|
||||
selectedFiles.push({
|
||||
path,
|
||||
filename: path.split(/[\\/]/).pop() ?? path,
|
||||
})
|
||||
}
|
||||
|
||||
const fileRecognition = await Promise.all(
|
||||
selectedFiles.map(async ({ path }) => {
|
||||
try {
|
||||
return await is_file_on_modrinth(path)
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
const addedFiles: string[] = []
|
||||
for (const [index, { path, filename }] of selectedFiles.entries()) {
|
||||
if (!fileRecognition[index] && !(await confirmUnknownFileInstallation(filename))) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
await add_project_from_path(props.instance.id, path)
|
||||
addedFiles.push(fileName)
|
||||
addedFiles.push(filename)
|
||||
} catch (e) {
|
||||
handleError(e as Error)
|
||||
}
|
||||
@@ -514,6 +549,39 @@ async function handleUploadFiles() {
|
||||
}
|
||||
}
|
||||
|
||||
function confirmUnknownFileInstallation(fileName: string) {
|
||||
if (themeStore.getFeatureFlag(skipUnknownFileWarningFeatureFlag)) {
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
unknownFileName.value = fileName
|
||||
return new Promise<boolean>((resolve) => {
|
||||
resolveUnknownFileConfirmation = resolve
|
||||
void nextTick(() => unknownFileWarningModal.value?.show())
|
||||
})
|
||||
}
|
||||
|
||||
function resolveUnknownFileWarning(confirmed: boolean) {
|
||||
const resolve = resolveUnknownFileConfirmation
|
||||
resolveUnknownFileConfirmation = null
|
||||
unknownFileName.value = ''
|
||||
resolve?.(confirmed)
|
||||
}
|
||||
|
||||
async function handleUnknownFileContinue(dontShowAgain: boolean) {
|
||||
if (dontShowAgain) {
|
||||
themeStore.featureFlags[skipUnknownFileWarningFeatureFlag] = true
|
||||
try {
|
||||
const settings = await getSettings()
|
||||
settings.feature_flags[skipUnknownFileWarningFeatureFlag] = true
|
||||
await setSettings(settings)
|
||||
} catch (error) {
|
||||
handleError(error as Error)
|
||||
}
|
||||
}
|
||||
resolveUnknownFileWarning(true)
|
||||
}
|
||||
|
||||
async function toggleDisableMod(mod: ContentItem, desiredEnabled?: boolean) {
|
||||
if (!mod.file_path) return
|
||||
const operation = beginContentOperation(mod)
|
||||
|
||||
Reference in New Issue
Block a user