Skip to content

Commit

Permalink
search repos
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Dec 20, 2023
1 parent bb86a0f commit c7d6f7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
36 changes: 19 additions & 17 deletions packages/ozone/src/api/com/atproto/admin/searchRepos.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { InvalidRequestError } from '@atproto/xrpc-server'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.admin.searchRepos({
auth: ctx.roleVerifier,
handler: async ({ params }) => {
throw new InvalidRequestError('@TODO')
// const db = ctx.db
// const moderationService = ctx.services.moderation(db)
// const { limit, cursor } = params
// // prefer new 'q' query param over deprecated 'term'
// const query = params.q ?? params.term
// const { results, cursor: resCursor } = await ctx.services
// .actor(db)
// .getSearchResults({ query, limit, cursor, includeSoftDeleted: true })
// return {
// encoding: 'application/json',
// body: {
// cursor: resCursor,
// repos: await moderationService.views.repo(results),
// },
// }
const res = await ctx.appviewAgent.api.com.atproto.admin.searchRepos(
params,
)
const db = ctx.db
const moderationService = ctx.services.moderation(db)
const views = await moderationService.views.repos(
res.data.repos.map((r) => r.did),
)
const repos = res.data.repos.map((r) => ({
...r,
moderation: views.get(r.did)?.moderation ?? {},
}))
return {
encoding: 'application/json',
body: {
cursor: res.data.cursor,
repos,
},
}
},
})
}
9 changes: 9 additions & 0 deletions packages/ozone/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AppContext {
private opts: {
db: Database
appviewAgent: AtpAgent
searchAgent: AtpAgent
cfg: ServerConfig
services: Services
signingKey: Keypair
Expand Down Expand Up @@ -44,6 +45,14 @@ export class AppContext {
return this.opts.services
}

get appviewAgent(): AtpAgent {
return this.opts.appviewAgent
}

get searchAgent(): AtpAgent {
return this.opts.searchAgent
}

get signingKey(): Keypair {
return this.opts.signingKey
}
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/src/services/moderation/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class ModerationViews {
constructor(private db: Database, private appviewAgent: AtpAgent) {}

async repos(dids: string[]): Promise<Map<string, RepoView>> {
if (dids.length === 0) return new Map()
const [appviewRes, subjectStatuses] = await Promise.all([
this.appviewAgent.api.com.atproto.admin.getAccountInfos({ dids }),
this.getSubjectStatus(dids),
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/tests/repo-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('admin repo search view', () => {
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'views_admin_repo_search',
ozone: { enabled: true },
})
agent = network.pds.getClient()
sc = network.getSeedClient()
Expand Down

0 comments on commit c7d6f7a

Please sign in to comment.