Release 2025-05-22-16vM

This commit is contained in:
pluja
2025-05-22 22:38:41 +00:00
parent d79bedf219
commit 72c238a4dc
12 changed files with 392 additions and 268 deletions

View File

@@ -0,0 +1,4 @@
#!/bin/bash
pwd
just dump-db

View File

@@ -70,7 +70,7 @@ services:
expose:
- 4321
healthcheck:
test: ["CMD", "curl", "-k", "--silent", "--fail", "http://localhost:4321"]
test: ["CMD", "curl", "-k", "--silent", "--fail", "http://localhost:4321/health"]
interval: 10s
timeout: 5s
retries: 5

View File

@@ -19,9 +19,8 @@ ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
# Add entrypoint script and make it executable
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Add knm-migrate command script and make it executable
COPY migrate.sh /usr/local/bin/knm-migrate
RUN chmod +x /usr/local/bin/knm-migrate
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "./dist/server/entry.mjs"]

View File

@@ -16,6 +16,4 @@ for trigger_file in prisma/triggers/*.sql; do
fi
done
# Start the application
echo "Starting the application..."
exec "$@"
echo "Migrations completed."

View File

@@ -19,6 +19,7 @@ type Props<Tag extends 'a' | 'button' | 'label' = 'button'> = Polymorphic<
dataAstroReload?: boolean
children?: never
disabled?: boolean
inlineIcon?: boolean
}
>
@@ -143,6 +144,7 @@ const {
role,
dataAstroReload,
disabled,
inlineIcon,
...htmlProps
} = Astro.props
@@ -164,11 +166,11 @@ const ActualTag = disabled && Tag === 'a' ? 'span' : Tag
{...dataAstroReload && { 'data-astro-reload': dataAstroReload }}
{...htmlProps}
>
{!!icon && <Icon name={icon} class={iconSlot({ class: classNames?.icon })} />}
{!!icon && <Icon name={icon} class={iconSlot({ class: classNames?.icon })} is:inline={inlineIcon} />}
{!!label && <span class={labelSlot({ class: classNames?.label })}>{label}</span>}
{
!!endIcon && (
<Icon name={endIcon} class={endIconSlot({ class: classNames?.endIcon })}>
<Icon name={endIcon} class={endIconSlot({ class: classNames?.endIcon })} is:inline={inlineIcon}>
{endIcon}
</Icon>
)

View File

@@ -88,12 +88,26 @@ const overallScoreInfo = makeOverallScoreInfo(overallScore)
<h3 class="font-title text-lg leading-none font-medium tracking-wide text-white">
{name}{
statusIcon && (
<Tooltip text={statusIcon.label} position="right" class="-my-2 shrink-0">
<Icon
is:inline={inlineIcons}
name={statusIcon.icon}
class={cn('inline-block size-6 shrink-0 rounded-lg p-1', statusIcon.classNames.icon)}
/>
<Tooltip
text={statusIcon.label}
position="right"
class="-my-2 shrink-0 whitespace-nowrap"
enabled={verificationStatus !== 'VERIFICATION_FAILED'}
>
{[
<Icon
is:inline={inlineIcons}
name={statusIcon.icon}
class={cn(
'inline-block size-6 shrink-0 rounded-lg p-1 align-[-0.37em]',
verificationStatus === 'VERIFICATION_FAILED' && 'pr-0',
statusIcon.classNames.icon
)}
/>,
verificationStatus === 'VERIFICATION_FAILED' && (
<span class="text-sm font-bold text-red-500">SCAM</span>
),
]}
</Tooltip>
)
}

View File

@@ -304,9 +304,16 @@ const {
/>
</div>
{
options.attributesByCategory.map(({ category, attributes }) => (
options.attributesByCategory.map(({ categoryInfo, attributes }) => (
<fieldset class="min-w-0">
<legend class="font-title mb-0.5 text-xs tracking-wide text-white">{category}</legend>
<legend class="font-title mb-0.5 inline-flex items-center gap-1 text-[0.8125rem] tracking-wide text-white uppercase">
<Icon
name={categoryInfo.icon}
class={cn('size-4 shrink-0 opacity-80', categoryInfo.classNames.icon)}
aria-hidden="true"
/>
{categoryInfo.label}
</legend>
<ul class="[:not(:has(~_.peer:checked))]:[&>li:not([data-show-always])]:hidden">
{attributes.map((attribute) => {
@@ -371,11 +378,9 @@ const {
</label>
<span
class="bg-night-400 border-night-500 pointer-events-none block h-4 w-px border-y peer-checked/no:w-[0.5px] peer-checked/yes:w-[0.5px]"
class="bg-night-400 border-night-500 before:bg-night-400 before:border-night-600 pointer-events-none block h-4 w-px border-y peer-checked/no:w-[0.5px] peer-checked/yes:w-[0.5px] before:h-full before:w-px before:border-y-2"
aria-hidden="true"
>
<span class="bg-night-400 border-night-600 block h-full w-px border-y-2" />
</span>
/>
<label
for={noId}
@@ -398,8 +403,8 @@ const {
aria-hidden="true"
>
<Icon
name={attribute.info.icon}
class={cn('mr-2 size-3 shrink-0 opacity-80', attribute.info.classNames.icon)}
name={attribute.typeInfo.icon}
class={cn('mr-2 size-3 shrink-0 opacity-80', attribute.typeInfo.classNames.icon)}
aria-hidden="true"
/>
<span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
@@ -413,8 +418,8 @@ const {
aria-hidden="true"
>
<Icon
name={attribute.info.icon}
class={cn('mr-2 size-3 shrink-0 opacity-100', attribute.info.classNames.icon)}
name={attribute.typeInfo.icon}
class={cn('mr-2 size-3 shrink-0 opacity-100', attribute.typeInfo.classNames.icon)}
aria-hidden="true"
/>
<span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
@@ -432,18 +437,18 @@ const {
<>
<input
type="checkbox"
id={`show-more-attributes-${category}`}
id={`show-more-attributes-${categoryInfo.slug}`}
class="peer sr-only"
hx-preserve
/>
<label
for={`show-more-attributes-${category}`}
for={`show-more-attributes-${categoryInfo.slug}`}
class="peer-focus-visible:ring-offset-night-700 mt-2 block cursor-pointer rounded-sm text-sm text-green-500 peer-checked:hidden peer-focus-visible:ring-2 peer-focus-visible:ring-blue-500 peer-focus-visible:ring-offset-2"
>
+ Show more
</label>
<label
for={`show-more-attributes-${category}`}
for={`show-more-attributes-${categoryInfo.slug}`}
class="peer-focus-visible:ring-offset-night-700 mt-2 hidden cursor-pointer rounded-sm text-sm text-green-500 peer-checked:block peer-focus-visible:ring-2 peer-focus-visible:ring-blue-500 peer-focus-visible:ring-offset-2"
>
- Show less

View File

@@ -1,9 +1,11 @@
---
import { Icon } from 'astro-icon/components'
import { uniq } from 'lodash-es'
import { verificationStatusesByValue } from '../constants/verificationStatus'
import { cn } from '../lib/cn'
import { pluralize } from '../lib/pluralize'
import { createPageUrl } from '../lib/urls'
import { createPageUrl, urlWithParams } from '../lib/urls'
import Button from './Button.astro'
import ServiceCard from './ServiceCard.astro'
@@ -20,6 +22,8 @@ type Props = HTMLAttributes<'div'> & {
sortSeed?: string
filters: ServicesFiltersObject
includeScams: boolean
countIfIncludingCommunity: number | null
inlineIcons?: boolean
}
const {
@@ -32,6 +36,8 @@ const {
class: className,
filters,
includeScams,
countIfIncludingCommunity,
inlineIcons,
...divProps
} = Astro.props
@@ -46,34 +52,68 @@ const hasSomeCommunityContributed = !!services?.some((service) =>
)
const totalPages = Math.ceil(total / pageSize) || 1
const urlIfIncludingCommunity = urlWithParams(Astro.url, {
verification: uniq([
...filters.verification.map((v) => verificationStatusesByValue[v].slug),
verificationStatusesByValue.COMMUNITY_CONTRIBUTED.slug,
]),
})
const extraIfIncludingCommunity = Math.max(0, (countIfIncludingCommunity ?? 0) - (services?.length ?? 0))
---
<div {...divProps} class={cn('flex-1', className)}>
<div class="mb-6 flex items-center justify-between">
<div class="flex items-center justify-between">
<span class="text-day-500 text-sm">
{total.toLocaleString()}
{pluralize('result', total)}
{
extraIfIncludingCommunity > 0 && (
<Button
as="a"
href={urlIfIncludingCommunity}
label={`Include +${extraIfIncludingCommunity.toLocaleString()} community contributed`}
size="sm"
class="ml-6 align-[-0.15em]"
icon="ri:search-line"
inlineIcon={inlineIcons}
/>
)
}
<span
id="search-indicator"
class="htmx-request:opacity-100 text-white opacity-0 transition-opacity duration-500"
>
<Icon name="ri:loader-4-line" class="inline-block size-4 animate-spin" />
<Icon name="ri:loader-4-line" class="inline-block size-4 animate-spin" is:inline={inlineIcons} />
Loading...
</span>
</span>
<Button as="a" href="/service-suggestion/new" label="Add service" icon="ri:add-line" />
<Button
as="a"
href="/service-suggestion/new"
label="Add service"
icon="ri:add-line"
inlineIcon={inlineIcons}
/>
</div>
{
hasScams && hasCommunityContributed && (
<div class="font-title mb-6 rounded-lg border border-red-500/30 bg-red-950 px-3 py-2 text-sm text-pretty text-red-500">
<Icon name="ri:alert-fill" class="inline-block size-4 shrink-0 align-[-0.2em] text-red-500" />
<div class="font-title mt-2 rounded-lg bg-red-900/50 px-3 py-2 text-sm text-pretty text-red-400">
<Icon
name="ri:alert-fill"
class="inline-block size-4 shrink-0 align-[-0.2em] text-red-500"
is:inline={inlineIcons}
/>
<Icon
name="ri:question-line"
class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-yellow-500"
class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-yellow-400"
is:inline={inlineIcons}
/>
Results {hasSomeScam || hasSomeCommunityContributed ? 'include' : 'may include'} SCAMS or
Results {hasSomeScam || hasSomeCommunityContributed ? 'include' : 'may include'} SCAMs or
community-contributed services.
</div>
)
@@ -81,8 +121,12 @@ const totalPages = Math.ceil(total / pageSize) || 1
{
hasScams && !hasCommunityContributed && (
<div class="font-title mb-6 rounded-lg border border-red-500/30 bg-red-950 px-3 py-2 text-sm text-pretty text-red-500">
<Icon name="ri:alert-fill" class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-red-500" />
<div class="font-title mt-2 rounded-lg bg-red-900/50 px-3 py-2 text-sm text-pretty text-red-400">
<Icon
name="ri:alert-fill"
class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-red-500"
is:inline={inlineIcons}
/>
Results {hasSomeScam ? 'include' : 'may include'} SCAM services
</div>
)
@@ -90,10 +134,11 @@ const totalPages = Math.ceil(total / pageSize) || 1
{
!hasScams && hasCommunityContributed && (
<div class="font-title mb-6 rounded-lg border border-yellow-500/30 bg-yellow-950 px-3 py-2 text-sm text-pretty text-yellow-500">
<div class="font-title mt-2 rounded-lg bg-yellow-600/30 px-3 py-2 text-sm text-pretty text-yellow-200">
<Icon
name="ri:question-line"
class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-yellow-500"
class="mr-1 inline-block size-4 shrink-0 align-[-0.2em] text-yellow-400"
is:inline={inlineIcons}
/>
Results {hasSomeCommunityContributed ? 'include' : 'may include'} unverified community-contributed
services, some might be scams.
@@ -103,26 +148,37 @@ const totalPages = Math.ceil(total / pageSize) || 1
{
!services || services.length === 0 ? (
<div class="sticky top-20 flex flex-col items-center justify-center rounded-lg border border-green-500/30 bg-black/40 p-12 text-center">
<Icon name="ri:emotion-sad-line" class="mb-4 size-16 text-green-500/50" />
<div class="sticky top-20 mt-6 flex flex-col items-center justify-center py-12 text-center">
<Icon name="ri:emotion-sad-line" class="mb-4 size-16 text-green-500/50" is:inline={inlineIcons} />
<h3 class="font-title mb-3 text-xl text-green-500">No services found</h3>
<p class="text-day-400">Try adjusting your filters to find more services</p>
<a
href={Astro.url.pathname}
class={cn(
'bg-night-800 font-title mt-4 rounded-md px-4 py-2 text-sm tracking-wider text-white uppercase',
hasDefaultFilters && 'hidden'
<div class="mt-4 flex justify-center gap-2">
{!hasDefaultFilters && (
<Button
as="a"
href={Astro.url.pathname}
label="Clear filters"
icon="ri:close-line"
inlineIcon={inlineIcons}
/>
)}
>
Clear filters
</a>
{extraIfIncludingCommunity > 0 && (
<Button
as="a"
href={urlIfIncludingCommunity}
label={`Show ${extraIfIncludingCommunity.toLocaleString()} community contributed`}
icon="ri:search-line"
inlineIcon={inlineIcons}
/>
)}
</div>
</div>
) : (
<>
<div class="grid grid-cols-1 gap-4 sm:gap-6 md:grid-cols-[repeat(auto-fill,minmax(calc(var(--spacing)*80),1fr))]">
<div class="mt-6 grid grid-cols-1 gap-4 sm:gap-6 md:grid-cols-[repeat(auto-fill,minmax(calc(var(--spacing)*80),1fr))]">
{services.map((service, i) => (
<ServiceCard
inlineIcons
inlineIcons={inlineIcons}
service={service}
data-hx-search-results-card
{...(i === services.length - 1 && currentPage < totalPages
@@ -140,7 +196,11 @@ const totalPages = Math.ceil(total / pageSize) || 1
<div class="no-js:hidden mt-8 flex justify-center" id="infinite-scroll-indicator">
<div class="htmx-request:opacity-100 flex items-center gap-2 opacity-0 transition-opacity duration-500">
<Icon name="ri:loader-4-line" class="size-8 animate-spin text-green-500" />
<Icon
name="ri:loader-4-line"
class="size-8 animate-spin text-green-500"
is:inline={inlineIcons}
/>
Loading more services...
</div>
</div>

View File

@@ -48,9 +48,9 @@ export const {
},
{
value: 'pending',
label: commentStatusById.PENDING.label,
label: 'AI pending',
color: commentStatusById.PENDING.color,
icon: commentStatusById.PENDING.icon,
icon: 'ri:robot-2-line',
whereClause: {
OR: [{ status: 'PENDING' }, { status: 'HUMAN_PENDING' }],
},
@@ -60,9 +60,9 @@ export const {
},
{
value: 'human-pending',
label: commentStatusById.HUMAN_PENDING.label,
label: 'Human needed',
color: commentStatusById.HUMAN_PENDING.color,
icon: commentStatusById.HUMAN_PENDING.icon,
icon: 'ri:user-search-line',
whereClause: { status: 'HUMAN_PENDING' },
classNames: {
filter: 'border-blue-500 bg-blue-500/20 text-blue-400',

View File

@@ -82,12 +82,13 @@ const totalPages = Math.ceil(totalComments / PAGE_SIZE)
<a
href={urlWithParams(Astro.url, { status: filter.value })}
class={cn([
'font-title rounded-md border px-3 py-1 text-sm',
'font-title flex items-center gap-2 rounded-md border px-3 py-1 text-sm',
params.status === filter.value
? filter.classNames.filter
: 'border-zinc-700 transition-colors hover:border-green-500/50',
])}
>
<Icon name={filter.icon} class="size-4 shrink-0" />
{filter.label}
</a>
))

16
web/src/pages/health.ts Normal file
View File

@@ -0,0 +1,16 @@
import type { APIRoute } from 'astro'
export const GET: APIRoute = () => {
return new Response(
JSON.stringify({
message: 'OK',
timestamp: new Date().toISOString(),
}),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
}
)
}

View File

@@ -10,6 +10,7 @@ import Pagination from '../components/Pagination.astro'
import ServiceFiltersPill from '../components/ServiceFiltersPill.astro'
import ServicesFilters from '../components/ServicesFilters.astro'
import ServicesSearchResults from '../components/ServicesSearchResults.astro'
import { getAttributeCategoryInfo } from '../constants/attributeCategories'
import { getAttributeTypeInfo } from '../constants/attributeTypes'
import {
currencies,
@@ -204,233 +205,254 @@ const includeScams =
export type ServicesFiltersObject = typeof filters
const [categories, [services, totalServices]] = await Astro.locals.banners.tryMany([
[
'Unable to load category filters.',
() =>
prisma.category.findMany({
select: {
name: true,
slug: true,
icon: true,
_count: {
select: {
services: true,
const groupedAttributes = groupBy(
Object.entries(filters.attr ?? {}).flatMap(([key, value]) => {
const id = parseIntWithFallback(key)
if (id === null) return []
return [{ id, value }]
}),
'value'
)
const where = {
listedAt: {
lte: new Date(),
},
categories: filters.categories.length ? { some: { slug: { in: filters.categories } } } : undefined,
verificationStatus: {
in: includeScams ? uniq([...filters.verification, 'VERIFICATION_FAILED'] as const) : filters.verification,
},
serviceVisibility: ServiceVisibility.PUBLIC,
overallScore: { gte: filters['min-score'] },
acceptedCurrencies: filters.currencies.length
? filters['currency-mode'] === 'and'
? { hasEvery: filters.currencies }
: { hasSome: filters.currencies }
: undefined,
kycLevel: {
lte: filters['max-kyc'],
},
AND: [
...(filters['user-rating'] > 0
? [
{
averageUserRating: {
gte: filters['user-rating'],
},
},
},
}),
],
[
'Unable to load services.',
async () => {
const groupedAttributes = groupBy(
Object.entries(filters.attr ?? {}).flatMap(([key, value]) => {
const id = parseIntWithFallback(key)
if (id === null) return []
return [{ id, value }]
}),
'value'
)
const [unsortedServices, totalServices] = await prisma.service.findManyAndCount({
where: {
listedAt: {
lte: new Date(),
},
categories: filters.categories.length ? { some: { slug: { in: filters.categories } } } : undefined,
verificationStatus: {
in: includeScams
? uniq([...filters.verification, 'VERIFICATION_FAILED'] as const)
: filters.verification,
},
serviceVisibility: ServiceVisibility.PUBLIC,
overallScore: { gte: filters['min-score'] },
acceptedCurrencies: filters.currencies.length
? filters['currency-mode'] === 'and'
? { hasEvery: filters.currencies }
: { hasSome: filters.currencies }
: undefined,
kycLevel: {
lte: filters['max-kyc'],
},
AND: [
...(filters['user-rating'] > 0
? [
{
averageUserRating: {
gte: filters['user-rating'],
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.q
? [
{
OR: [
{ name: { contains: filters.q, mode: 'insensitive' as const } },
{ description: { contains: filters.q, mode: 'insensitive' as const } },
],
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.networks.length
? [
{
OR: [
...(filters.networks.includes('onion') ? [{ onionUrls: { isEmpty: false } }] : []),
...(filters.networks.includes('i2p') ? [{ i2pUrls: { isEmpty: false } }] : []),
...(filters.networks.includes('clearnet') ? [{ serviceUrls: { isEmpty: false } }] : []),
],
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.attr && (groupedAttributes.yes?.length ?? 0) + (groupedAttributes.no?.length ?? 0) > 0
? [
{
AND: [
...(groupedAttributes.yes && groupedAttributes.yes.length > 0
? [
{
[filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.yes.map(
({ id }) =>
({
attributes: {
some: {
attribute: {
id,
},
},
},
}) satisfies Prisma.ServiceWhereInput
),
},
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.q
? [
{
OR: [
{ name: { contains: filters.q, mode: 'insensitive' as const } },
{ description: { contains: filters.q, mode: 'insensitive' as const } },
],
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.networks.length
? [
{
OR: [
...(filters.networks.includes('onion') ? [{ onionUrls: { isEmpty: false } }] : []),
...(filters.networks.includes('i2p') ? [{ i2pUrls: { isEmpty: false } }] : []),
...(filters.networks.includes('clearnet') ? [{ serviceUrls: { isEmpty: false } }] : []),
],
} satisfies Prisma.ServiceWhereInput,
]
: []),
...(filters.attr && (groupedAttributes.yes?.length ?? 0) + (groupedAttributes.no?.length ?? 0) > 0
? [
{
AND: [
...(groupedAttributes.yes && groupedAttributes.yes.length > 0
? [
{
[filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.yes.map(
({ id }) =>
({
attributes: {
some: {
attribute: {
id,
},
},
},
}) satisfies Prisma.ServiceWhereInput
),
]
: []),
...(groupedAttributes.no && groupedAttributes.no.length > 0
? [
{
[filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.no.map(
({ id }) =>
({
attributes: {
none: {
attribute: {
id,
},
},
},
]
: []),
...(groupedAttributes.no && groupedAttributes.no.length > 0
? [
{
[filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.no.map(
({ id }) =>
({
attributes: {
none: {
attribute: {
id,
},
},
},
}) satisfies Prisma.ServiceWhereInput
),
},
]
: []),
],
},
]
: []),
],
},
select: {
id: true,
...(Object.fromEntries(sortOptions.map((option) => [option.orderBy.key, true])) as Record<
(typeof sortOptions)[number]['orderBy']['key'],
true
>),
},
})
const rng = seedrandom(filters['sort-seed'])
const selectedSort = sortOptions.find((sort) => sort.value === filters.sort) ?? defaultSortOption
const sortedServices = orderBy(
unsortedServices,
[selectedSort.orderBy.key, () => rng()],
[selectedSort.orderBy.direction, 'asc']
).slice((filters.page - 1) * PAGE_SIZE, filters.page * PAGE_SIZE)
const unsortedServicesWithInfo = await prisma.service.findMany({
where: {
id: {
in: sortedServices.map((service) => service.id),
}) satisfies Prisma.ServiceWhereInput
),
},
]
: []),
],
},
},
select: {
name: true,
slug: true,
description: true,
overallScore: true,
privacyScore: true,
trustScore: true,
kycLevel: true,
imageUrl: true,
verificationStatus: true,
acceptedCurrencies: true,
attributes: {
select: {
attribute: {
select: {
id: true,
slug: true,
title: true,
category: true,
type: true,
},
]
: []),
],
} as const satisfies Prisma.ServiceWhereInput
const [categories, [services, totalServices], countIfIncludingCommunity, attributes] =
await Astro.locals.banners.tryMany([
[
'Unable to load category filters.',
() =>
prisma.category.findMany({
select: {
name: true,
slug: true,
icon: true,
_count: {
select: {
services: true,
},
},
},
categories: {
select: {
name: true,
icon: true,
}),
],
[
'Unable to load services.',
async () => {
const [unsortedServices, totalServices] = await prisma.service.findManyAndCount({
where,
select: {
id: true,
...(Object.fromEntries(sortOptions.map((option) => [option.orderBy.key, true])) as Record<
(typeof sortOptions)[number]['orderBy']['key'],
true
>),
},
})
const rng = seedrandom(filters['sort-seed'])
const selectedSort = sortOptions.find((sort) => sort.value === filters.sort) ?? defaultSortOption
const sortedServices = orderBy(
unsortedServices,
[selectedSort.orderBy.key, () => rng()],
[selectedSort.orderBy.direction, 'asc']
).slice((filters.page - 1) * PAGE_SIZE, filters.page * PAGE_SIZE)
const unsortedServicesWithInfo = await prisma.service.findMany({
where: {
id: {
in: sortedServices.map((service) => service.id),
},
},
},
})
const sortedServicesWithInfo = orderBy(
unsortedServicesWithInfo,
[
selectedSort.orderBy.key,
// Now we can shuffle indeternimistically, because the pagination was already applied
() => Math.random(),
],
[selectedSort.orderBy.direction, 'asc']
)
return [sortedServicesWithInfo, totalServices] as const
},
[[] as [], 0, false] as const,
],
])
const attributes = await Astro.locals.banners.try(
'Unable to load attribute filters.',
() =>
prisma.attribute.findMany({
select: {
id: true,
slug: true,
title: true,
category: true,
type: true,
_count: {
select: {
services: true,
name: true,
slug: true,
description: true,
overallScore: true,
privacyScore: true,
trustScore: true,
kycLevel: true,
imageUrl: true,
verificationStatus: true,
acceptedCurrencies: true,
attributes: {
select: {
attribute: {
select: {
id: true,
slug: true,
title: true,
category: true,
type: true,
},
},
},
},
categories: {
select: {
name: true,
icon: true,
},
},
},
},
})
const sortedServicesWithInfo = orderBy(
unsortedServicesWithInfo,
[
selectedSort.orderBy.key,
// Now we can shuffle indeternimistically, because the pagination was already applied
() => Math.random(),
],
[selectedSort.orderBy.direction, 'asc']
)
return [sortedServicesWithInfo, totalServices] as const
},
orderBy: [{ category: 'asc' }, { type: 'asc' }, { title: 'asc' }],
}),
[]
)
[[] as [], 0, false] as const,
],
[
'Unable to load count if including community.',
() =>
areEqualArraysWithoutOrder(filters.verification, ['VERIFICATION_SUCCESS', 'APPROVED']) ||
areEqualArraysWithoutOrder(filters.verification, [
'VERIFICATION_SUCCESS',
'APPROVED',
'VERIFICATION_FAILED',
])
? prisma.service.count({
where: {
...where,
verificationStatus: {
...where.verificationStatus,
in: uniq([...where.verificationStatus.in, 'COMMUNITY_CONTRIBUTED'] as const),
},
},
})
: null,
null,
],
[
'Unable to load attribute filters.',
() =>
prisma.attribute.findMany({
select: {
id: true,
slug: true,
title: true,
category: true,
type: true,
_count: {
select: {
services: true,
},
},
},
orderBy: [{ category: 'asc' }, { type: 'asc' }, { title: 'asc' }],
}),
[],
],
])
const attributesByCategory = orderBy(
Object.entries(
groupBy(
attributes.map((attr) => {
return {
info: getAttributeTypeInfo(attr.type),
typeInfo: getAttributeTypeInfo(attr.type),
...attr,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
value: filters.attr?.[attr.id] || undefined,
@@ -440,6 +462,7 @@ const attributesByCategory = orderBy(
)
).map(([category, attributes]) => ({
category,
categoryInfo: getAttributeCategoryInfo(category),
attributes: orderBy(
attributes,
['value', 'type', '_count.services', 'title'],
@@ -684,6 +707,8 @@ const showFiltersId = 'show-filters'
sortSeed={filters['sort-seed']}
filters={filters}
includeScams={includeScams}
countIfIncludingCommunity={countIfIncludingCommunity}
inlineIcons
/>
</div>
{