Release 2025-05-22-16vM

This commit is contained in:
pluja
2025-05-22 22:38:41 +00:00
parent d79bedf219
commit a217d71a69
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: expose:
- 4321 - 4321
healthcheck: healthcheck:
test: ["CMD", "curl", "-k", "--silent", "--fail", "http://localhost:4321"] test: ["CMD", "curl", "-k", "--silent", "--fail", "http://localhost:4321/health"]
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5

View File

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

View File

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

View File

@@ -19,6 +19,7 @@ type Props<Tag extends 'a' | 'button' | 'label' = 'button'> = Polymorphic<
dataAstroReload?: boolean dataAstroReload?: boolean
children?: never children?: never
disabled?: boolean disabled?: boolean
inlineIcon?: boolean
} }
> >
@@ -143,6 +144,7 @@ const {
role, role,
dataAstroReload, dataAstroReload,
disabled, disabled,
inlineIcon,
...htmlProps ...htmlProps
} = Astro.props } = Astro.props
@@ -164,11 +166,11 @@ const ActualTag = disabled && Tag === 'a' ? 'span' : Tag
{...dataAstroReload && { 'data-astro-reload': dataAstroReload }} {...dataAstroReload && { 'data-astro-reload': dataAstroReload }}
{...htmlProps} {...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>} {!!label && <span class={labelSlot({ class: classNames?.label })}>{label}</span>}
{ {
!!endIcon && ( !!endIcon && (
<Icon name={endIcon} class={endIconSlot({ class: classNames?.endIcon })}> <Icon name={endIcon} class={endIconSlot({ class: classNames?.endIcon })} is:inline={inlineIcon}>
{endIcon} {endIcon}
</Icon> </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"> <h3 class="font-title text-lg leading-none font-medium tracking-wide text-white">
{name}{ {name}{
statusIcon && ( statusIcon && (
<Tooltip text={statusIcon.label} position="right" class="-my-2 shrink-0"> <Tooltip
<Icon text={statusIcon.label}
is:inline={inlineIcons} position="right"
name={statusIcon.icon} class="-my-2 shrink-0 whitespace-nowrap"
class={cn('inline-block size-6 shrink-0 rounded-lg p-1', statusIcon.classNames.icon)} 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> </Tooltip>
) )
} }

View File

@@ -304,9 +304,16 @@ const {
/> />
</div> </div>
{ {
options.attributesByCategory.map(({ category, attributes }) => ( options.attributesByCategory.map(({ categoryInfo, attributes }) => (
<fieldset class="min-w-0"> <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"> <ul class="[:not(:has(~_.peer:checked))]:[&>li:not([data-show-always])]:hidden">
{attributes.map((attribute) => { {attributes.map((attribute) => {
@@ -371,11 +378,9 @@ const {
</label> </label>
<span <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" aria-hidden="true"
> />
<span class="bg-night-400 border-night-600 block h-full w-px border-y-2" />
</span>
<label <label
for={noId} for={noId}
@@ -398,8 +403,8 @@ const {
aria-hidden="true" aria-hidden="true"
> >
<Icon <Icon
name={attribute.info.icon} name={attribute.typeInfo.icon}
class={cn('mr-2 size-3 shrink-0 opacity-80', attribute.info.classNames.icon)} class={cn('mr-2 size-3 shrink-0 opacity-80', attribute.typeInfo.classNames.icon)}
aria-hidden="true" aria-hidden="true"
/> />
<span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap"> <span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
@@ -413,8 +418,8 @@ const {
aria-hidden="true" aria-hidden="true"
> >
<Icon <Icon
name={attribute.info.icon} name={attribute.typeInfo.icon}
class={cn('mr-2 size-3 shrink-0 opacity-100', attribute.info.classNames.icon)} class={cn('mr-2 size-3 shrink-0 opacity-100', attribute.typeInfo.classNames.icon)}
aria-hidden="true" aria-hidden="true"
/> />
<span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap"> <span class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
@@ -432,18 +437,18 @@ const {
<> <>
<input <input
type="checkbox" type="checkbox"
id={`show-more-attributes-${category}`} id={`show-more-attributes-${categoryInfo.slug}`}
class="peer sr-only" class="peer sr-only"
hx-preserve hx-preserve
/> />
<label <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" 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 + Show more
</label> </label>
<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" 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 - Show less

View File

@@ -1,9 +1,11 @@
--- ---
import { Icon } from 'astro-icon/components' import { Icon } from 'astro-icon/components'
import { uniq } from 'lodash-es'
import { verificationStatusesByValue } from '../constants/verificationStatus'
import { cn } from '../lib/cn' import { cn } from '../lib/cn'
import { pluralize } from '../lib/pluralize' import { pluralize } from '../lib/pluralize'
import { createPageUrl } from '../lib/urls' import { createPageUrl, urlWithParams } from '../lib/urls'
import Button from './Button.astro' import Button from './Button.astro'
import ServiceCard from './ServiceCard.astro' import ServiceCard from './ServiceCard.astro'
@@ -20,6 +22,8 @@ type Props = HTMLAttributes<'div'> & {
sortSeed?: string sortSeed?: string
filters: ServicesFiltersObject filters: ServicesFiltersObject
includeScams: boolean includeScams: boolean
countIfIncludingCommunity: number | null
inlineIcons?: boolean
} }
const { const {
@@ -32,6 +36,8 @@ const {
class: className, class: className,
filters, filters,
includeScams, includeScams,
countIfIncludingCommunity,
inlineIcons,
...divProps ...divProps
} = Astro.props } = Astro.props
@@ -46,34 +52,68 @@ const hasSomeCommunityContributed = !!services?.some((service) =>
) )
const totalPages = Math.ceil(total / pageSize) || 1 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 {...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"> <span class="text-day-500 text-sm">
{total.toLocaleString()} {total.toLocaleString()}
{pluralize('result', total)} {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 <span
id="search-indicator" id="search-indicator"
class="htmx-request:opacity-100 text-white opacity-0 transition-opacity duration-500" 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... Loading...
</span> </span>
</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> </div>
{ {
hasScams && hasCommunityContributed && ( 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"> <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" /> <Icon
name="ri:alert-fill"
class="inline-block size-4 shrink-0 align-[-0.2em] text-red-500"
is:inline={inlineIcons}
/>
<Icon <Icon
name="ri:question-line" 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. community-contributed services.
</div> </div>
) )
@@ -81,8 +121,12 @@ const totalPages = Math.ceil(total / pageSize) || 1
{ {
hasScams && !hasCommunityContributed && ( 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"> <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" /> <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 Results {hasSomeScam ? 'include' : 'may include'} SCAM services
</div> </div>
) )
@@ -90,10 +134,11 @@ const totalPages = Math.ceil(total / pageSize) || 1
{ {
!hasScams && hasCommunityContributed && ( !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 <Icon
name="ri:question-line" 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 Results {hasSomeCommunityContributed ? 'include' : 'may include'} unverified community-contributed
services, some might be scams. services, some might be scams.
@@ -103,26 +148,37 @@ const totalPages = Math.ceil(total / pageSize) || 1
{ {
!services || services.length === 0 ? ( !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"> <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" /> <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> <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> <p class="text-day-400">Try adjusting your filters to find more services</p>
<a <div class="mt-4 flex justify-center gap-2">
href={Astro.url.pathname} {!hasDefaultFilters && (
class={cn( <Button
'bg-night-800 font-title mt-4 rounded-md px-4 py-2 text-sm tracking-wider text-white uppercase', as="a"
hasDefaultFilters && 'hidden' href={Astro.url.pathname}
label="Clear filters"
icon="ri:close-line"
inlineIcon={inlineIcons}
/>
)} )}
> {extraIfIncludingCommunity > 0 && (
Clear filters <Button
</a> as="a"
href={urlIfIncludingCommunity}
label={`Show ${extraIfIncludingCommunity.toLocaleString()} community contributed`}
icon="ri:search-line"
inlineIcon={inlineIcons}
/>
)}
</div>
</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) => ( {services.map((service, i) => (
<ServiceCard <ServiceCard
inlineIcons inlineIcons={inlineIcons}
service={service} service={service}
data-hx-search-results-card data-hx-search-results-card
{...(i === services.length - 1 && currentPage < totalPages {...(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="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"> <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... Loading more services...
</div> </div>
</div> </div>

View File

@@ -48,9 +48,9 @@ export const {
}, },
{ {
value: 'pending', value: 'pending',
label: commentStatusById.PENDING.label, label: 'AI pending',
color: commentStatusById.PENDING.color, color: commentStatusById.PENDING.color,
icon: commentStatusById.PENDING.icon, icon: 'ri:robot-2-line',
whereClause: { whereClause: {
OR: [{ status: 'PENDING' }, { status: 'HUMAN_PENDING' }], OR: [{ status: 'PENDING' }, { status: 'HUMAN_PENDING' }],
}, },
@@ -60,9 +60,9 @@ export const {
}, },
{ {
value: 'human-pending', value: 'human-pending',
label: commentStatusById.HUMAN_PENDING.label, label: 'Human needed',
color: commentStatusById.HUMAN_PENDING.color, color: commentStatusById.HUMAN_PENDING.color,
icon: commentStatusById.HUMAN_PENDING.icon, icon: 'ri:user-search-line',
whereClause: { status: 'HUMAN_PENDING' }, whereClause: { status: 'HUMAN_PENDING' },
classNames: { classNames: {
filter: 'border-blue-500 bg-blue-500/20 text-blue-400', 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 <a
href={urlWithParams(Astro.url, { status: filter.value })} href={urlWithParams(Astro.url, { status: filter.value })}
class={cn([ 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 params.status === filter.value
? filter.classNames.filter ? filter.classNames.filter
: 'border-zinc-700 transition-colors hover:border-green-500/50', : 'border-zinc-700 transition-colors hover:border-green-500/50',
])} ])}
> >
<Icon name={filter.icon} class="size-4 shrink-0" />
{filter.label} {filter.label}
</a> </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 ServiceFiltersPill from '../components/ServiceFiltersPill.astro'
import ServicesFilters from '../components/ServicesFilters.astro' import ServicesFilters from '../components/ServicesFilters.astro'
import ServicesSearchResults from '../components/ServicesSearchResults.astro' import ServicesSearchResults from '../components/ServicesSearchResults.astro'
import { getAttributeCategoryInfo } from '../constants/attributeCategories'
import { getAttributeTypeInfo } from '../constants/attributeTypes' import { getAttributeTypeInfo } from '../constants/attributeTypes'
import { import {
currencies, currencies,
@@ -204,233 +205,254 @@ const includeScams =
export type ServicesFiltersObject = typeof filters export type ServicesFiltersObject = typeof filters
const [categories, [services, totalServices]] = await Astro.locals.banners.tryMany([ const groupedAttributes = groupBy(
[ Object.entries(filters.attr ?? {}).flatMap(([key, value]) => {
'Unable to load category filters.', const id = parseIntWithFallback(key)
() => if (id === null) return []
prisma.category.findMany({ return [{ id, value }]
select: { }),
name: true, 'value'
slug: true, )
icon: true,
_count: { const where = {
select: { listedAt: {
services: true, 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
[ ? [
'Unable to load services.', {
async () => { OR: [
const groupedAttributes = groupBy( { name: { contains: filters.q, mode: 'insensitive' as const } },
Object.entries(filters.attr ?? {}).flatMap(([key, value]) => { { description: { contains: filters.q, mode: 'insensitive' as const } },
const id = parseIntWithFallback(key) ],
if (id === null) return [] } satisfies Prisma.ServiceWhereInput,
return [{ id, value }] ]
}), : []),
'value' ...(filters.networks.length
) ? [
{
const [unsortedServices, totalServices] = await prisma.service.findManyAndCount({ OR: [
where: { ...(filters.networks.includes('onion') ? [{ onionUrls: { isEmpty: false } }] : []),
listedAt: { ...(filters.networks.includes('i2p') ? [{ i2pUrls: { isEmpty: false } }] : []),
lte: new Date(), ...(filters.networks.includes('clearnet') ? [{ serviceUrls: { isEmpty: false } }] : []),
}, ],
categories: filters.categories.length ? { some: { slug: { in: filters.categories } } } : undefined, } satisfies Prisma.ServiceWhereInput,
verificationStatus: { ]
in: includeScams : []),
? uniq([...filters.verification, 'VERIFICATION_FAILED'] as const) ...(filters.attr && (groupedAttributes.yes?.length ?? 0) + (groupedAttributes.no?.length ?? 0) > 0
: filters.verification, ? [
}, {
serviceVisibility: ServiceVisibility.PUBLIC, AND: [
overallScore: { gte: filters['min-score'] }, ...(groupedAttributes.yes && groupedAttributes.yes.length > 0
acceptedCurrencies: filters.currencies.length ? [
? filters['currency-mode'] === 'and' {
? { hasEvery: filters.currencies } [filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.yes.map(
: { hasSome: filters.currencies } ({ id }) =>
: undefined, ({
kycLevel: { attributes: {
lte: filters['max-kyc'], some: {
}, attribute: {
AND: [ id,
...(filters['user-rating'] > 0 },
? [ },
{ },
averageUserRating: { }) satisfies Prisma.ServiceWhereInput
gte: filters['user-rating'], ),
}, },
} satisfies Prisma.ServiceWhereInput, ]
] : []),
: []), ...(groupedAttributes.no && groupedAttributes.no.length > 0
...(filters.q ? [
? [ {
{ [filters['attribute-mode'] === 'and' ? 'AND' : 'OR']: groupedAttributes.no.map(
OR: [ ({ id }) =>
{ name: { contains: filters.q, mode: 'insensitive' as const } }, ({
{ description: { contains: filters.q, mode: 'insensitive' as const } }, attributes: {
], none: {
} satisfies Prisma.ServiceWhereInput, attribute: {
] id,
: []), },
...(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
: []), ),
...(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),
}, },
}, ]
select: { : []),
name: true, ],
slug: true, } as const satisfies Prisma.ServiceWhereInput
description: true,
overallScore: true, const [categories, [services, totalServices], countIfIncludingCommunity, attributes] =
privacyScore: true, await Astro.locals.banners.tryMany([
trustScore: true, [
kycLevel: true, 'Unable to load category filters.',
imageUrl: true, () =>
verificationStatus: true, prisma.category.findMany({
acceptedCurrencies: true, select: {
attributes: { name: true,
select: { slug: true,
attribute: { icon: true,
select: { _count: {
id: true, select: {
slug: true, services: true,
title: true,
category: true,
type: 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: { 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( const attributesByCategory = orderBy(
Object.entries( Object.entries(
groupBy( groupBy(
attributes.map((attr) => { attributes.map((attr) => {
return { return {
info: getAttributeTypeInfo(attr.type), typeInfo: getAttributeTypeInfo(attr.type),
...attr, ...attr,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
value: filters.attr?.[attr.id] || undefined, value: filters.attr?.[attr.id] || undefined,
@@ -440,6 +462,7 @@ const attributesByCategory = orderBy(
) )
).map(([category, attributes]) => ({ ).map(([category, attributes]) => ({
category, category,
categoryInfo: getAttributeCategoryInfo(category),
attributes: orderBy( attributes: orderBy(
attributes, attributes,
['value', 'type', '_count.services', 'title'], ['value', 'type', '_count.services', 'title'],
@@ -684,6 +707,8 @@ const showFiltersId = 'show-filters'
sortSeed={filters['sort-seed']} sortSeed={filters['sort-seed']}
filters={filters} filters={filters}
includeScams={includeScams} includeScams={includeScams}
countIfIncludingCommunity={countIfIncludingCommunity}
inlineIcons
/> />
</div> </div>
{ {