Skip to content

Commit

Permalink
made getting labels from ozone a configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Nov 5, 2024
1 parent a7417d8 commit d2d186e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const envSchema = z.object({
OZONE_URL: z.string().url().default('http://ozone:3000'),
POSTGRES_DATABASE_URL: z.string().url(),
NEWHANDLE_EXPIRY: z.coerce.number().default(2592000),
GET_LABELS_FROM_OZONE: z.boolean().default(false),
DANGEROUSLY_EXPOSE_SECRETS: z
.string()
.toLowerCase()
Expand Down
37 changes: 23 additions & 14 deletions src/lib/getUserDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,44 @@ class UserDetailsFetch extends CachedFetch {
{},
)

const labelsFetch = await fetch(
`${
env.OZONE_URL
}/xrpc/com.atproto.label.queryLabels?uriPatterns=${actorsChunk.join(
'&uriPatterns=',
)}`,
)

const labelsJson: { labels: ComAtprotoLabelDefs.Label[] } =
(await labelsFetch.json()) as {
labels: ComAtprotoLabelDefs.Label[]
}
const gettingLabelsFromOzone = env.GET_LABELS_FROM_OZONE

let labelsMap: { [key: string]: ComAtprotoLabelDefs.Label[] } = {}

if (gettingLabelsFromOzone) {
const labelsFetch = await fetch(
`${
env.OZONE_URL
}/xrpc/com.atproto.label.queryLabels?uriPatterns=${actorsChunk.join(
'&uriPatterns=',
)}`,
)

const labelsJson: { labels: ComAtprotoLabelDefs.Label[] } =
(await labelsFetch.json()) as {
labels: ComAtprotoLabelDefs.Label[]
}

const labelsMap: { [key: string]: ComAtprotoLabelDefs.Label[] } =
labelsJson.labels.reduce((map, label) => {
labelsMap = labelsJson.labels.reduce((map, label) => {
if (!map[label.uri]) {
map[label.uri] = []
}
if (!label.neg) map[label.uri].push(label)
return map
}, {})
}

for (const did of actorsChunk) {
if (profilesMap[did]) {
if (
gettingLabelsFromOzone &&
labelsMap[did] &&
Array.isArray(labelsMap[did]) &&
labelsMap[did].length > 0
) {
if (Array.isArray(profilesMap[did].labels)) {
}

profilesMap[did].labels = labelsMap[did]
logger.debug(
`${did} from ozone ${JSON.stringify(labelsMap[did])}`,
Expand Down

0 comments on commit d2d186e

Please sign in to comment.