From 0e4a111f81cceed275d9bec2695f6e401fb654d8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 12 Nov 2021 02:02:25 +0900 Subject: refactoring Resolve #7779 --- src/server/api/openapi/description.ts | 51 ----------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/server/api/openapi/description.ts (limited to 'src/server/api/openapi/description.ts') diff --git a/src/server/api/openapi/description.ts b/src/server/api/openapi/description.ts deleted file mode 100644 index e51b312259..0000000000 --- a/src/server/api/openapi/description.ts +++ /dev/null @@ -1,51 +0,0 @@ -import endpoints from '../endpoints'; -import * as locale from '../../../../locales/index'; -import { kinds as kindsList } from '@/misc/api-permissions'; - -export interface IKindInfo { - endpoints: string[]; - descs: { [x: string]: string; }; -} - -export function kinds() { - const kinds = Object.fromEntries( - kindsList - .map(k => [k, { - endpoints: [], - descs: Object.fromEntries( - Object.keys(locale) - .map(l => [l, locale[l]._permissions[k] as string]) - ) - } as IKindInfo]) - ); - - const errors = [] as string[][]; - - for (const endpoint of endpoints.filter(ep => !ep.meta.secure)) { - if (endpoint.meta.kind) { - const kind = endpoint.meta.kind; - if (kind in kinds) kinds[kind].endpoints.push(endpoint.name); - else errors.push([kind, endpoint.name]); - } - } - - if (errors.length > 0) throw Error('\n ' + errors.map((e) => `Unknown kind (permission) "${e[0]}" found at ${e[1]}.`).join('\n ')); - - return kinds; -} - -export function getDescription(lang = 'ja-JP'): string { - const permissionTable = Object.entries(kinds()) - .map(e => `|${e[0]}|${e[1].descs[lang]}|${e[1].endpoints.map(f => `[${f}](#operation/${f})`).join(', ')}|`) - .join('\n'); - - const descriptions: { [x: string]: string } = { - 'ja-JP': ` -# Permissions -|Permisson (kind)|Description|Endpoints| -|:--|:--|:--| -${permissionTable} -` - }; - return lang in descriptions ? descriptions[lang] : descriptions['ja-JP']; -} -- cgit v1.2.3-freya