Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action !takedown labels in hydrator #2270

Merged
merged 19 commits into from
Mar 12, 2024
14 changes: 10 additions & 4 deletions packages/bsky/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/actor/getProfile'
import AppContext from '../../../../context'
import { setRepoRev } from '../../../util'
import { resHeaders } from '../../../util'
import { createPipeline, noRules } from '../../../../pipeline'
import {
HydrateCtx,
Expand All @@ -15,19 +15,22 @@ export default function (server: Server, ctx: AppContext) {
const getProfile = createPipeline(skeleton, hydration, noRules, presentation)
server.app.bsky.actor.getProfile({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ auth, params, req, res }) => {
handler: async ({ auth, params, req }) => {
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer, includeTakedowns }

const result = await getProfile({ ...params, hydrateCtx }, ctx)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({
repoRev,
labelers,
}),
}
},
})
Expand All @@ -51,7 +54,10 @@ const hydration = async (input: {
skeleton: SkeletonState
}) => {
const { ctx, params, skeleton } = input
return ctx.hydrator.hydrateProfilesDetailed([skeleton.did], params.hydrateCtx)
return ctx.hydrator.hydrateProfilesDetailed([skeleton.did], {
...params.hydrateCtx,
includeTakedowns: true,
})
}

const presentation = (input: {
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/api/app/bsky/actor/getProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/actor/getProfiles'
import AppContext from '../../../../context'
import { setRepoRev } from '../../../util'
import { resHeaders } from '../../../util'
import { createPipeline, noRules } from '../../../../pipeline'
import {
HydrateCtx,
Expand All @@ -15,19 +15,22 @@ export default function (server: Server, ctx: AppContext) {
const getProfile = createPipeline(skeleton, hydration, noRules, presentation)
server.app.bsky.actor.getProfiles({
auth: ctx.authVerifier.standardOptional,
handler: async ({ auth, params, req, res }) => {
handler: async ({ auth, params, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { viewer, labelers }

const result = await getProfile({ ...params, hydrateCtx }, ctx)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({
repoRev,
labelers,
}),
}
},
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { Views } from '../../../../views'
import { DataPlaneClient } from '../../../../data-plane'
import { parseString } from '../../../../hydration/util'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getSuggestions = createPipeline(
Expand All @@ -30,6 +31,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/actor/searchActors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HydrateCtx, Hydrator } from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { DataPlaneClient } from '../../../../data-plane'
import { parseString } from '../../../../hydration/util'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const searchActors = createPipeline(
Expand All @@ -32,6 +33,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/actor/searchActorsTypeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HydrateCtx, Hydrator } from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { DataPlaneClient } from '../../../../data-plane'
import { parseString } from '../../../../hydration/util'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const searchActorsTypeahead = createPipeline(
Expand All @@ -35,6 +36,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getActorFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Views } from '../../../../views'
import { DataPlaneClient } from '../../../../data-plane'
import { parseString } from '../../../../hydration/util'
import { clearlyBadCursor } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getActorFeeds = createPipeline(
Expand All @@ -31,6 +31,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getActorLikes'
import AppContext from '../../../../context'
import { clearlyBadCursor, setRepoRev } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'
import { createPipeline } from '../../../../pipeline'
import {
HydrateCtx,
Expand All @@ -25,19 +25,22 @@ export default function (server: Server, ctx: AppContext) {
)
server.app.bsky.feed.getActorLikes({
auth: ctx.authVerifier.standardOptional,
handler: async ({ params, auth, req, res }) => {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }

const result = await getActorLikes({ ...params, hydrateCtx }, ctx)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({
repoRev,
labelers,
}),
}
},
})
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getAuthorFeed'
import AppContext from '../../../../context'
import { clearlyBadCursor, setRepoRev } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'
import { createPipeline } from '../../../../pipeline'
import {
HydrateCtx,
Expand All @@ -27,19 +27,22 @@ export default function (server: Server, ctx: AppContext) {
)
server.app.bsky.feed.getAuthorFeed({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ params, auth, req, res }) => {
handler: async ({ params, auth, req }) => {
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer, includeTakedowns }

const result = await getAuthorFeed({ ...params, hydrateCtx }, ctx)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({
repoRev,
labelers,
}),
}
},
})
Expand Down
14 changes: 9 additions & 5 deletions packages/bsky/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
isDataplaneError,
unpackIdentityServices,
} from '../../../../data-plane'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getFeed = createPipeline(
Expand All @@ -47,16 +48,19 @@ export default function (server: Server, ctx: AppContext) {
'accept-language': req.headers['accept-language'],
})
// @NOTE feed cursors should not be affected by appview swap
const { timerSkele, timerHydr, resHeaders, ...result } = await getFeed(
{ ...params, hydrateCtx, headers },
ctx,
)
const {
timerSkele,
timerHydr,
resHeaders: feedResHeaders,
...result
} = await getFeed({ ...params, hydrateCtx, headers }, ctx)

return {
encoding: 'application/json',
body: result,
headers: {
...(resHeaders ?? {}),
...(feedResHeaders ?? {}),
...resHeaders({ labelers }),
'server-timing': serverTimingHeader([timerSkele, timerHydr]),
},
}
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getFeedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isDataplaneError,
unpackIdentityServices,
} from '../../../../data-plane'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.feed.getFeedGenerator({
Expand Down Expand Up @@ -63,6 +64,7 @@ export default function (server: Server, ctx: AppContext) {
isOnline: true,
isValid: true,
},
headers: resHeaders({ labelers }),
}
},
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getFeedGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Hydrator,
} from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getFeedGenerators = createPipeline(
Expand All @@ -27,6 +28,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: view,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Views } from '../../../../views'
import { parseString } from '../../../../hydration/util'
import { creatorFromUri } from '../../../../views/util'
import { clearlyBadCursor } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getLikes = createPipeline(skeleton, hydration, noBlocks, presentation)
Expand All @@ -27,6 +27,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
6 changes: 3 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getListFeed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/feed/getListFeed'
import AppContext from '../../../../context'
import { clearlyBadCursor, setRepoRev } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'
import { createPipeline } from '../../../../pipeline'
import {
HydrateCtx,
Expand All @@ -23,19 +23,19 @@ export default function (server: Server, ctx: AppContext) {
)
server.app.bsky.feed.getListFeed({
auth: ctx.authVerifier.standardOptional,
handler: async ({ params, auth, req, res }) => {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }

const result = await getListFeed({ ...params, hydrateCtx }, ctx)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers, repoRev }),
}
},
})
Expand Down
11 changes: 8 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
OutputSchema,
} from '../../../../lexicon/types/app/bsky/feed/getPostThread'
import AppContext from '../../../../context'
import { setRepoRev } from '../../../util'
import { ATPROTO_REPO_REV, resHeaders } from '../../../util'
import {
HydrationFnInput,
PresentationFnInput,
Expand Down Expand Up @@ -37,16 +37,21 @@ export default function (server: Server, ctx: AppContext) {
result = await getPostThread({ ...params, hydrateCtx }, ctx)
} catch (err) {
const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)
if (repoRev) {
res.setHeader(ATPROTO_REPO_REV, repoRev)
}
throw err
}

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({
repoRev,
labelers,
}),
}
},
})
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { creatorFromUri } from '../../../../views/util'
import { resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getPosts = createPipeline(skeleton, hydration, noBlocks, presentation)
Expand All @@ -25,6 +26,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getRepostedBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Views } from '../../../../views'
import { parseString } from '../../../../hydration/util'
import { creatorFromUri } from '../../../../views/util'
import { clearlyBadCursor } from '../../../util'
import { clearlyBadCursor, resHeaders } from '../../../util'

export default function (server: Server, ctx: AppContext) {
const getRepostedBy = createPipeline(
Expand All @@ -31,6 +31,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
}
},
})
Expand Down
Loading
Loading