2019-04-15 05:20:48 +02:00
|
|
|
import endpoints from '../endpoints';
|
|
|
|
import * as locale from '../../../../locales/';
|
2021-03-23 09:43:07 +01:00
|
|
|
import { kinds as kindsList } from '@/misc/api-permissions';
|
2019-04-15 05:20:48 +02:00
|
|
|
|
|
|
|
export interface IKindInfo {
|
|
|
|
endpoints: string[];
|
|
|
|
descs: { [x: string]: string; };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function kinds() {
|
2020-05-23 16:21:09 +02:00
|
|
|
const kinds = Object.fromEntries(
|
2019-04-15 05:20:48 +02:00
|
|
|
kindsList
|
|
|
|
.map(k => [k, {
|
|
|
|
endpoints: [],
|
2020-05-23 16:21:09 +02:00
|
|
|
descs: Object.fromEntries(
|
2019-04-15 05:20:48 +02:00
|
|
|
Object.keys(locale)
|
2020-05-23 16:21:09 +02:00
|
|
|
.map(l => [l, locale[l]._permissions[k] as string])
|
|
|
|
)
|
|
|
|
} as IKindInfo])
|
|
|
|
);
|
2019-04-15 05:20:48 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-04-15 05:10:40 +02:00
|
|
|
|
|
|
|
export function getDescription(lang = 'ja-JP'): string {
|
2020-05-23 16:21:09 +02:00
|
|
|
const permissionTable = Object.entries(kinds())
|
2019-04-15 05:10:40 +02:00
|
|
|
.map(e => `|${e[0]}|${e[1].descs[lang]}|${e[1].endpoints.map(f => `[${f}](#operation/${f})`).join(', ')}|`)
|
|
|
|
.join('\n');
|
|
|
|
|
2020-05-23 16:21:09 +02:00
|
|
|
const descriptions: { [x: string]: string } = {
|
2020-03-27 12:24:32 +01:00
|
|
|
'ja-JP': `
|
2019-04-23 15:35:26 +02:00
|
|
|
# Permissions
|
2019-04-15 05:10:40 +02:00
|
|
|
|Permisson (kind)|Description|Endpoints|
|
|
|
|
|:--|:--|:--|
|
|
|
|
${permissionTable}
|
|
|
|
`
|
2020-05-23 16:21:09 +02:00
|
|
|
};
|
2019-04-15 05:10:40 +02:00
|
|
|
return lang in descriptions ? descriptions[lang] : descriptions['ja-JP'];
|
|
|
|
}
|