You've already forked AstralRinth
forked from didirus/AstralRinth
* chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix postgres version mismatch * fix version creation * Implement routes * fix up tech review * Allow adding a moderation comment to Delphi rejections * fix up rebase * exclude rejected projects from tech review * add status change msg to tech review thread * cargo sqlx prepare * also ignore withheld projects * More filtering on issue search * wip: report routes * Fix up for build * cargo sqlx prepare * fix thread message privacy * New tech review search route * submit route * details have statuses now * add default to drid status * dedup issue details * fix sqlx query on empty files * fixes * Dedupe issue detail statuses and message on entering tech rev * Fix qa issues * Fix qa issues * fix review comments * typos * fix ci * feat: tech review frontend (#4781) * chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix ci * fix postgres version mismatch * fix version creation * Implement routes * feat: batch scan alert * feat: layout * feat: introduce surface variables * fix: theme selector * feat: rough draft of tech review card * feat: tab switcher * feat: batch scan btn * feat: api-client module for tech review * draft: impl * feat: auto icons * fix: layout issues * feat: fixes to code blocks + flag labels * feat: temp remove mock data * fix: search sort types * fix: intl & lint * chore: re-enable mock data * fix: flag badges + auto open first issue in file tab * feat: update for new routes * fix: more qa issues * feat: lazy load sources * fix: re-enable auth middleware * feat: impl threads * fix: lint & severity * feat: download btn + switch to using NavTabs with new local mode option * feat: re-add toplevel btns * feat: reports page consistency * fix: consistency on project queue * fix: icons + sizing * fix: colors and gaps * fix: impl endpoints * feat: load all flags on file tab * feat: thread generics changes * feat: more qa * feat: fix collapse * fix: qa * feat: msg modal * fix: ISO import * feat: qa fixes * fix: empty state basic * fix: collapsible region * fix: collapse thread by default * feat: rough draft of new process/flow * fix labrinth build * fix thread message privacy * New tech review search route * feat: qa fixes * feat: QA changes * fix: verdict on detail not whole issue * fix: lint + intl * fix: lint * fix: thread message for tech rev verdict * feat: use anim frames * fix: exports + typecheck * polish: qa changes * feat: qa * feat: qa polish * feat: fix malic modal * fix: lint * fix: qa + lint * fix: pagination * fix: lint * fix: qa * intl extract * fix ci --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: aecsocket <aecsocket@tutanota.com> --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: Calum H. <contact@cal.engineer>
303 lines
8.0 KiB
Vue
303 lines
8.0 KiB
Vue
<template>
|
|
<div class="flex flex-col gap-4">
|
|
<div class="flex flex-col justify-between gap-3 lg:flex-row">
|
|
<div class="iconified-input flex-1 lg:max-w-md">
|
|
<SearchIcon aria-hidden="true" class="text-lg" />
|
|
<input
|
|
v-model="query"
|
|
class="h-[40px]"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
type="text"
|
|
:placeholder="formatMessage(messages.searchPlaceholder)"
|
|
@input="goToPage(1)"
|
|
/>
|
|
<Button v-if="query" class="r-btn" @click="() => (query = '')">
|
|
<XIcon />
|
|
</Button>
|
|
</div>
|
|
|
|
<div v-if="totalPages > 1" class="hidden flex-1 justify-center lg:flex">
|
|
<Pagination :page="currentPage" :count="totalPages" @switch-page="goToPage" />
|
|
</div>
|
|
|
|
<div class="flex flex-col justify-end gap-2 sm:flex-row lg:flex-shrink-0">
|
|
<Combobox
|
|
v-model="currentFilterType"
|
|
class="!w-full flex-grow sm:!w-[280px] sm:flex-grow-0 lg:!w-[280px]"
|
|
:options="filterTypes"
|
|
:placeholder="formatMessage(messages.filterBy)"
|
|
@select="goToPage(1)"
|
|
>
|
|
<template #selected>
|
|
<span class="flex flex-row gap-2 align-middle font-semibold">
|
|
<ListFilterIcon class="size-5 flex-shrink-0 text-secondary" />
|
|
<span class="truncate text-contrast"
|
|
>{{ currentFilterType }} ({{ filteredReports.length }})</span
|
|
>
|
|
</span>
|
|
</template>
|
|
</Combobox>
|
|
|
|
<Combobox
|
|
v-model="currentSortType"
|
|
class="!w-full flex-grow sm:!w-[150px] sm:flex-grow-0 lg:!w-[150px]"
|
|
:options="sortTypes"
|
|
:placeholder="formatMessage(messages.sortBy)"
|
|
@select="goToPage(1)"
|
|
>
|
|
<template #selected>
|
|
<span class="flex flex-row gap-2 align-middle font-semibold">
|
|
<SortAscIcon
|
|
v-if="currentSortType === 'Oldest'"
|
|
class="size-5 flex-shrink-0 text-secondary"
|
|
/>
|
|
<SortDescIcon v-else class="size-5 flex-shrink-0 text-secondary" />
|
|
<span class="truncate text-contrast">{{ currentSortType }}</span>
|
|
</span>
|
|
</template>
|
|
</Combobox>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="totalPages > 1" class="flex justify-center lg:hidden">
|
|
<Pagination :page="currentPage" :count="totalPages" @switch-page="goToPage" />
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-4">
|
|
<div v-if="paginatedReports.length === 0" class="universal-card h-24 animate-pulse"></div>
|
|
<ReportCard v-for="report in paginatedReports" v-else :key="report.id" :report="report" />
|
|
</div>
|
|
|
|
<div v-if="totalPages > 1" class="mt-4 flex justify-center">
|
|
<Pagination :page="currentPage" :count="totalPages" @switch-page="goToPage" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ListFilterIcon, SearchIcon, SortAscIcon, SortDescIcon, XIcon } from '@modrinth/assets'
|
|
import type { ExtendedReport } from '@modrinth/moderation'
|
|
import { Button, Combobox, type ComboboxOption, Pagination } from '@modrinth/ui'
|
|
import type { Report } from '@modrinth/utils'
|
|
import { defineMessages, useVIntl } from '@vintl/vintl'
|
|
import Fuse from 'fuse.js'
|
|
|
|
import ReportCard from '~/components/ui/moderation/ModerationReportCard.vue'
|
|
import { enrichReportBatch } from '~/helpers/moderation.ts'
|
|
|
|
const { formatMessage } = useVIntl()
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
|
|
const messages = defineMessages({
|
|
searchPlaceholder: {
|
|
id: 'moderation.search.placeholder',
|
|
defaultMessage: 'Search...',
|
|
},
|
|
filterBy: {
|
|
id: 'moderation.filter.by',
|
|
defaultMessage: 'Filter by',
|
|
},
|
|
sortBy: {
|
|
id: 'moderation.sort.by',
|
|
defaultMessage: 'Sort by',
|
|
},
|
|
})
|
|
|
|
const { data: allReports } = await useLazyAsyncData('new-moderation-reports', async () => {
|
|
const startTime = performance.now()
|
|
let currentOffset = 0
|
|
const REPORT_ENDPOINT_COUNT = 350
|
|
const allReports: ExtendedReport[] = []
|
|
|
|
const enrichmentPromises: Promise<ExtendedReport[]>[] = []
|
|
|
|
let reports: Report[]
|
|
do {
|
|
reports = (await useBaseFetch(`report?count=${REPORT_ENDPOINT_COUNT}&offset=${currentOffset}`, {
|
|
apiVersion: 3,
|
|
})) as Report[]
|
|
|
|
if (reports.length === 0) break
|
|
|
|
const enrichmentPromise = enrichReportBatch(reports)
|
|
enrichmentPromises.push(enrichmentPromise)
|
|
|
|
currentOffset += reports.length
|
|
|
|
if (enrichmentPromises.length >= 3) {
|
|
const completed = await Promise.all(enrichmentPromises.splice(0, 2))
|
|
allReports.push(...completed.flat())
|
|
}
|
|
} while (reports.length === REPORT_ENDPOINT_COUNT)
|
|
|
|
const remainingBatches = await Promise.all(enrichmentPromises)
|
|
allReports.push(...remainingBatches.flat())
|
|
|
|
const endTime = performance.now()
|
|
const duration = endTime - startTime
|
|
|
|
console.debug(
|
|
`Reports fetched and processed in ${duration.toFixed(2)}ms (${(duration / 1000).toFixed(2)}s)`,
|
|
)
|
|
|
|
return allReports
|
|
})
|
|
|
|
const query = ref(route.query.q?.toString() || '')
|
|
|
|
watch(
|
|
query,
|
|
(newQuery) => {
|
|
const currentQuery = { ...route.query }
|
|
if (newQuery) {
|
|
currentQuery.q = newQuery
|
|
} else {
|
|
delete currentQuery.q
|
|
}
|
|
|
|
router.replace({
|
|
path: route.path,
|
|
query: currentQuery,
|
|
})
|
|
},
|
|
{ immediate: false },
|
|
)
|
|
|
|
watch(
|
|
() => route.query.q,
|
|
(newQueryParam) => {
|
|
const newValue = newQueryParam?.toString() || ''
|
|
if (query.value !== newValue) {
|
|
query.value = newValue
|
|
}
|
|
},
|
|
)
|
|
|
|
const currentFilterType = ref('All')
|
|
const filterTypes: ComboboxOption<string>[] = [
|
|
{ value: 'All', label: 'All' },
|
|
{ value: 'Unread', label: 'Unread' },
|
|
{ value: 'Read', label: 'Read' },
|
|
]
|
|
|
|
const currentSortType = ref('Oldest')
|
|
const sortTypes: ComboboxOption<string>[] = [
|
|
{ value: 'Oldest', label: 'Oldest' },
|
|
{ value: 'Newest', label: 'Newest' },
|
|
]
|
|
|
|
const currentPage = ref(1)
|
|
const itemsPerPage = 15
|
|
const totalPages = computed(() => Math.ceil((filteredReports.value?.length || 0) / itemsPerPage))
|
|
|
|
const fuse = computed(() => {
|
|
if (!allReports.value || allReports.value.length === 0) return null
|
|
return new Fuse(allReports.value, {
|
|
keys: [
|
|
{
|
|
name: 'id',
|
|
weight: 3,
|
|
},
|
|
{
|
|
name: 'body',
|
|
weight: 3,
|
|
},
|
|
{
|
|
name: 'report_type',
|
|
weight: 3,
|
|
},
|
|
{
|
|
name: 'item_id',
|
|
weight: 2,
|
|
},
|
|
{
|
|
name: 'reporter_user.username',
|
|
weight: 2,
|
|
},
|
|
'project.name',
|
|
'project.slug',
|
|
'user.username',
|
|
'version.name',
|
|
'target.name',
|
|
'target.slug',
|
|
],
|
|
includeScore: true,
|
|
threshold: 0.4,
|
|
})
|
|
})
|
|
|
|
const memberRoleMap = computed(() => {
|
|
if (!allReports.value?.length) return new Map()
|
|
|
|
const map = new Map()
|
|
for (const report of allReports.value) {
|
|
if (report.thread?.members?.length) {
|
|
const roleMap = new Map()
|
|
for (const member of report.thread.members) {
|
|
roleMap.set(member.id, member.role)
|
|
}
|
|
map.set(report.id, roleMap)
|
|
}
|
|
}
|
|
return map
|
|
})
|
|
|
|
const searchResults = computed(() => {
|
|
if (!query.value || !fuse.value) return null
|
|
return fuse.value.search(query.value).map((result) => result.item)
|
|
})
|
|
|
|
const baseFiltered = computed(() => {
|
|
if (!allReports.value) return []
|
|
return query.value && searchResults.value ? searchResults.value : [...allReports.value]
|
|
})
|
|
|
|
const typeFiltered = computed(() => {
|
|
if (currentFilterType.value === 'All') return baseFiltered.value
|
|
|
|
return baseFiltered.value.filter((report) => {
|
|
const messages = report.thread?.messages || []
|
|
|
|
if (messages.length === 0) {
|
|
return currentFilterType.value === 'Unread'
|
|
}
|
|
|
|
const lastMessage = messages[messages.length - 1]
|
|
if (!lastMessage.author_id) return false
|
|
|
|
const roleMap = memberRoleMap.value.get(report.id)
|
|
if (!roleMap) return false
|
|
|
|
const authorRole = roleMap.get(lastMessage.author_id)
|
|
const isModeratorMessage = authorRole === 'moderator' || authorRole === 'admin'
|
|
|
|
return currentFilterType.value === 'Read' ? isModeratorMessage : !isModeratorMessage
|
|
})
|
|
})
|
|
|
|
const filteredReports = computed(() => {
|
|
const filtered = [...typeFiltered.value]
|
|
|
|
if (currentSortType.value === 'Oldest') {
|
|
filtered.sort((a, b) => new Date(a.created).getTime() - new Date(b.created).getTime())
|
|
} else {
|
|
filtered.sort((a, b) => new Date(b.created).getTime() - new Date(a.created).getTime())
|
|
}
|
|
|
|
return filtered
|
|
})
|
|
|
|
const paginatedReports = computed(() => {
|
|
if (!filteredReports.value) return []
|
|
const start = (currentPage.value - 1) * itemsPerPage
|
|
const end = start + itemsPerPage
|
|
return filteredReports.value.slice(start, end)
|
|
})
|
|
|
|
function goToPage(page: number) {
|
|
currentPage.value = page
|
|
}
|
|
</script>
|