Skip to content

Commit

Permalink
search using new threat sigs route
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Nov 5, 2024
1 parent 24ed941 commit fce2a24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
41 changes: 23 additions & 18 deletions app/repositories/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { RepositoriesTable } from '@/repositories/RepositoriesTable'
import { useSearchParams } from 'next/navigation'
import { useInfiniteQuery } from '@tanstack/react-query'
import { useTitle } from 'react-use'
import { Agent, ToolsOzoneModerationDefs } from '@atproto/api'
import {
Agent,
ToolsOzoneModerationDefs,
ComAtprotoAdminSearchAccounts,
} from '@atproto/api'
import { useLabelerAgent } from '@/shell/ConfigurationContext'
import { ActionButton } from '@/common/buttons'
import { useWorkspaceAddItemsMutation } from '@/workspace/hooks'
Expand All @@ -13,8 +17,8 @@ import { ConfirmationModal } from '@/common/modals/confirmation'
import { WorkspacePanel } from '@/workspace/Panel'
import { useWorkspaceOpener } from '@/common/useWorkspaceOpener'

const isEmailSearch = (q: string) =>
q.startsWith('email:') || q.startsWith('ip:') || q.startsWith('hcap:')
const isEmailSearch = (q: string) => q.startsWith('email:')
const isSignatureSearch = (q: string) => q.startsWith('sig:')

const getRepos =
({ q, labelerAgent }: { q: string; labelerAgent: Agent }) =>
Expand All @@ -27,7 +31,7 @@ const getRepos =
}) => {
const limit = 25

if (!isEmailSearch(q)) {
if (!isEmailSearch(q) && !isSignatureSearch(q)) {
const { data } = await labelerAgent.tools.ozone.moderation.searchRepos({
q,
limit,
Expand All @@ -37,22 +41,23 @@ const getRepos =
return data
}

const email = q
.replace('email:', '')
.replace('ip:', '')
.replace('hcap:', '')
.trim()

if (!email) {
return { repos: [], cursor: undefined }
let data: ComAtprotoAdminSearchAccounts.OutputSchema
if (isSignatureSearch(q)) {
const value = q.replace('sig:', '').trim()
const res = await labelerAgent.tools.ozone.signature.searchAccounts({
values: [value],
})
data = res.data
} else {
const email = q.replace('email:', '').trim()
const res = await labelerAgent.com.atproto.admin.searchAccounts({
email,
limit,
cursor: pageParam,
})
data = res.data
}

const { data } = await labelerAgent.com.atproto.admin.searchAccounts({
email,
limit,
cursor: pageParam,
})

if (!data.accounts.length) {
return { repos: [], cursor: data.cursor }
}
Expand Down
8 changes: 5 additions & 3 deletions components/repositories/AccountView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ function Details({
>
{obscureIp(registrationIp)}{' '}
<Link
href={`/repositories?term=ip:${encodeURIComponent(
href={`/repositories?term=sig:${encodeURIComponent(
registrationIp,
)}`}
>
Expand All @@ -554,7 +554,9 @@ function Details({
<DataField value={lastSigninIp} label="Last Signin IP" showCopyButton>
{obscureIp(lastSigninIp)}{' '}
<Link
href={`/repositories?term=ip:${encodeURIComponent(lastSigninIp)}`}
href={`/repositories?term=sig:${encodeURIComponent(
lastSigninIp,
)}`}
>
<MagnifyingGlassIcon className="h-3 w-3 inline" />
</Link>
Expand All @@ -570,7 +572,7 @@ function Details({
{hcapDetail?.map(({ property, value }) => (
<Link
key={property}
href={`/repositories?term=hcap:${encodeURIComponent(value)}`}
href={`/repositories?term=sig:${encodeURIComponent(value)}`}
>
<LabelChip>
<MagnifyingGlassIcon className="h-3 w-3 inline" />
Expand Down

0 comments on commit fce2a24

Please sign in to comment.