Skip to content

Commit

Permalink
Add codegen to support deprecated labels (#3270)
Browse files Browse the repository at this point in the history
* Port app code into SDK, remapping gore to graphic-media

* Support deprecated gore label by duplicated graphic-media

* Add alias field, codegen with deprecation comment

* Format

* Changeset
  • Loading branch information
estrattonbailey authored Dec 20, 2024
1 parent 672243a commit f22383c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-seals-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/api": patch
---

Add support for label def aliases, deprecation notices. This provides support for the deprecated `gore` label until a full cleanup effort can be completed.
1 change: 1 addition & 0 deletions packages/api/definitions/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
},
{
"identifier": "graphic-media",
"alias": ["gore"],
"flags": ["adult"],
"configurable": true,
"defaultSetting": "warn",
Expand Down
42 changes: 33 additions & 9 deletions packages/api/scripts/code/labels.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,42 @@ writeFileSync(
)

async function gen() {
const knownValues = new Set()
const flattenedLabelDefs = []

for (const { alias: aliases, ...label } of labelsDef) {
knownValues.add(label.identifier)
flattenedLabelDefs.push([label.identifier, { ...label, locales: [] }])

if (aliases) {
for (const alias of aliases) {
knownValues.add(alias)
flattenedLabelDefs.push([
alias,
{
...label,
identifier: alias,
locales: [],
comment: `@deprecated alias for \`${label.identifier}\``,
},
])
}
}
}

let labelDefsStr = `{`
for (const [key, { comment, ...value }] of flattenedLabelDefs) {
const commentStr = comment ? `\n/** ${comment} */\n` : ''
labelDefsStr += `${commentStr}'${key}': ${JSON.stringify(value, null, 2)},`
}
labelDefsStr += `}`

return prettier.format(
`/** this doc is generated by ./scripts/code/labels.mjs **/
import {InterpretedLabelValueDefinition, LabelPreference} from '../types'
export type KnownLabelValue = ${labelsDef
.map((label) => `"${label.identifier}"`)
export type KnownLabelValue = ${Array.from(knownValues)
.map((value) => `"${value}"`)
.join(' | ')}
export const DEFAULT_LABEL_SETTINGS: Record<string, LabelPreference> = ${JSON.stringify(
Expand All @@ -35,13 +65,7 @@ async function gen() {
),
)}
export const LABELS: Record<KnownLabelValue, InterpretedLabelValueDefinition> = ${JSON.stringify(
Object.fromEntries(
labelsDef.map((label) => [label.identifier, { ...label, locales: [] }]),
),
null,
2,
)}
export const LABELS: Record<KnownLabelValue, InterpretedLabelValueDefinition> = ${labelDefsStr}
`,
{ semi: false, parser: 'typescript', singleQuote: true },
)
Expand Down
24 changes: 24 additions & 0 deletions packages/api/src/moderation/const/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type KnownLabelValue =
| 'sexual'
| 'nudity'
| 'graphic-media'
| 'gore'

export const DEFAULT_LABEL_SETTINGS: Record<string, LabelPreference> = {
porn: 'hide',
Expand Down Expand Up @@ -193,4 +194,27 @@ export const LABELS: Record<KnownLabelValue, InterpretedLabelValueDefinition> =
},
locales: [],
},
/** @deprecated alias for `graphic-media` */
gore: {
identifier: 'gore',
flags: ['adult'],
configurable: true,
defaultSetting: 'warn',
severity: 'none',
blurs: 'media',
behaviors: {
account: {
avatar: 'blur',
banner: 'blur',
},
profile: {
avatar: 'blur',
banner: 'blur',
},
content: {
contentMedia: 'blur',
},
},
locales: [],
},
}

0 comments on commit f22383c

Please sign in to comment.