From f22383cee8feb8b9f761c801ab6e07ad8dc019ed Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 20 Dec 2024 11:58:46 -0600 Subject: [PATCH] Add codegen to support deprecated labels (#3270) * 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 --- .changeset/few-seals-enjoy.md | 5 +++ packages/api/definitions/labels.json | 1 + packages/api/scripts/code/labels.mjs | 42 ++++++++++++++++----- packages/api/src/moderation/const/labels.ts | 24 ++++++++++++ 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 .changeset/few-seals-enjoy.md diff --git a/.changeset/few-seals-enjoy.md b/.changeset/few-seals-enjoy.md new file mode 100644 index 00000000000..f52a424db95 --- /dev/null +++ b/.changeset/few-seals-enjoy.md @@ -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. diff --git a/packages/api/definitions/labels.json b/packages/api/definitions/labels.json index 913ad4365c6..7252f406333 100644 --- a/packages/api/definitions/labels.json +++ b/packages/api/definitions/labels.json @@ -147,6 +147,7 @@ }, { "identifier": "graphic-media", + "alias": ["gore"], "flags": ["adult"], "configurable": true, "defaultSetting": "warn", diff --git a/packages/api/scripts/code/labels.mjs b/packages/api/scripts/code/labels.mjs index 0619d55d1f9..163589c1ffe 100644 --- a/packages/api/scripts/code/labels.mjs +++ b/packages/api/scripts/code/labels.mjs @@ -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 = ${JSON.stringify( @@ -35,13 +65,7 @@ async function gen() { ), )} - export const LABELS: Record = ${JSON.stringify( - Object.fromEntries( - labelsDef.map((label) => [label.identifier, { ...label, locales: [] }]), - ), - null, - 2, - )} + export const LABELS: Record = ${labelDefsStr} `, { semi: false, parser: 'typescript', singleQuote: true }, ) diff --git a/packages/api/src/moderation/const/labels.ts b/packages/api/src/moderation/const/labels.ts index 53be497191f..3ec3350cae3 100644 --- a/packages/api/src/moderation/const/labels.ts +++ b/packages/api/src/moderation/const/labels.ts @@ -9,6 +9,7 @@ export type KnownLabelValue = | 'sexual' | 'nudity' | 'graphic-media' + | 'gore' export const DEFAULT_LABEL_SETTINGS: Record = { porn: 'hide', @@ -193,4 +194,27 @@ export const LABELS: Record = }, 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: [], + }, }