Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { ClipboardCopyIcon, DownloadIcon, LoaderCircleIcon, XIcon } from '@modrinth/assets'
import { ButtonStyled, CopyCode, NewModal } from '@modrinth/ui'
import { ButtonStyled, CopyCode, NewModal, useDebugLogger } from '@modrinth/ui'
import { ref, useTemplateRef } from 'vue'

export type UnsafeFile = {
Expand All @@ -16,6 +16,8 @@ const props = defineProps<{
unsafeFiles: UnsafeFile[]
}>()

const debug = useDebugLogger('MaliciousSummaryModal')

const modalRef = useTemplateRef<InstanceType<typeof NewModal>>('modalRef')

const versionDataCache = ref<
Expand All @@ -36,14 +38,19 @@ async function fetchVersionHashes(versionIds: string[]) {
versionDataCache.value.set(versionId, { files: new Map(), loading: true })
try {
// TODO: switch to api-client once truman's vers stuff is merged
const version = (await useBaseFetch(`version/${versionId}`)) as {
const version = (await useBaseFetch(`version/${versionId}`, { apiVersion: 3 })) as {
files: Array<{
id?: string
filename: string
hashes: { sha512: string; sha1: string }
}>
}
const filesMap = new Map<string, string>()
debug('Full version response:', version)
debug(
'Version files:',
version.files.map((f) => ({ id: f.id, filename: f.filename })),
)
for (const file of version.files) {
if (file.id) {
filesMap.set(file.id, file.hashes.sha512)
Expand All @@ -62,7 +69,9 @@ async function fetchVersionHashes(versionIds: string[]) {
}

function getFileHash(versionId: string, fileId: string): string | undefined {
return versionDataCache.value.get(versionId)?.files.get(fileId)
const hash = versionDataCache.value.get(versionId)?.files.get(fileId)
debug('getFileHash:', { versionId, fileId, found: !!hash })
return hash
}

function isHashLoading(versionId: string): boolean {
Expand Down
Loading