This commit is contained in:
syuilo
2019-04-15 12:20:48 +09:00
parent 31c26354c5
commit 772063aade
5 changed files with 39 additions and 83 deletions

View File

@ -1,29 +0,0 @@
import define from '../define';
import { kindsList } from '../kinds';
export const meta = {
stability: 'stable',
desc: {
'ja-JP': 'パーミッションの一覧を返します。',
'en-US': 'Get the list of permissons.'
},
tags: ['meta'],
requireCredential: false,
params: {
},
res: {
type: 'array',
items: {
type: 'string',
}
},
};
export default define(meta, async () => {
return kindsList;
});

View File

@ -1,8 +1,4 @@
import endpoints from './endpoints';
import * as locale from '../../../locales/';
import { fromEntries } from '../../prelude/array';
export const kindsList = [
export const kinds = [
'read:account',
'write:account',
'read:blocks',
@ -24,35 +20,3 @@ export const kindsList = [
'write:reactions',
'write:votes'
];
export interface IKindInfo {
endpoints: string[];
descs: { [x: string]: string; };
}
export function kinds() {
const kinds = fromEntries(
kindsList
.map(k => [k, {
endpoints: [],
descs: fromEntries(
Object.keys(locale)
.map(l => [l, locale[l].common.permissions[k] as string] as [string, string])
) as { [x: string]: string; }
}] as [ string, IKindInfo ])
) as { [x: string]: 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;
}

View File

@ -1,5 +1,40 @@
import config from '../../../config';
import { IKindInfo, kinds } from '../kinds';
import endpoints from '../endpoints';
import * as locale from '../../../../locales/';
import { fromEntries } from '../../../prelude/array';
import { kinds as kindsList } from '../kinds';
export interface IKindInfo {
endpoints: string[];
descs: { [x: string]: string; };
}
export function kinds() {
const kinds = fromEntries(
kindsList
.map(k => [k, {
endpoints: [],
descs: fromEntries(
Object.keys(locale)
.map(l => [l, locale[l].common.permissions[k] as string] as [string, string])
) as { [x: string]: string; }
}] as [ string, IKindInfo ])
) as { [x: string]: 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()) as [string, IKindInfo][])