Skip to content

Commit

Permalink
Appview: apply hosting status in getRecord (bluesky-social#2620)
Browse files Browse the repository at this point in the history
appview: apply hosting status in getRecord
  • Loading branch information
devinivy authored Jul 2, 2024
1 parent 0529bec commit f05539d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-bsky-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- divy/starter-packs
- divy/appview-getrecord-nohost
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down
47 changes: 28 additions & 19 deletions packages/bsky/src/api/com/atproto/repo/getRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@ import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.repo.getRecord(async ({ params }) => {
const { repo, collection, rkey, cid } = params
const [did] = await ctx.hydrator.actor.getDids([repo])
if (!did) {
throw new InvalidRequestError(`Could not find repo: ${repo}`)
}
server.com.atproto.repo.getRecord({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ auth, params }) => {
const { repo, collection, rkey, cid } = params
const { includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const [did] = await ctx.hydrator.actor.getDids([repo])
if (!did) {
throw new InvalidRequestError(`Could not find repo: ${repo}`)
}

const uri = AtUri.make(did, collection, rkey).toString()
const result = await ctx.hydrator.getRecord(uri, true)
const actors = await ctx.hydrator.actor.getActors([did], includeTakedowns)
if (!actors.get(did)) {
throw new InvalidRequestError(`Could not find repo: ${repo}`)
}

if (!result || (cid && result.cid !== cid)) {
throw new InvalidRequestError(`Could not locate record: ${uri}`)
}
const uri = AtUri.make(did, collection, rkey).toString()
const result = await ctx.hydrator.getRecord(uri, includeTakedowns)

return {
encoding: 'application/json' as const,
body: {
uri: uri,
cid: result.cid,
value: result.record,
},
}
if (!result || (cid && result.cid !== cid)) {
throw new InvalidRequestError(`Could not locate record: ${uri}`)
}

return {
encoding: 'application/json' as const,
body: {
uri: uri,
cid: result.cid,
value: result.record,
},
}
},
})
}
3 changes: 3 additions & 0 deletions packages/ozone/tests/get-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ describe('admin get record view', () => {
cid: sc.posts[sc.dids.alice][0].ref.cidStr,
},
})
await network.bsky.ctx.dataplane.takedownRecord({
recordUri: sc.posts[sc.dids.alice][0].ref.uriStr,
})
})

it('gets a record by uri, even when taken down.', async () => {
Expand Down

0 comments on commit f05539d

Please sign in to comment.