diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2019-04-15 12:10:40 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-04-15 12:10:40 +0900 |
| commit | 94f8a145eca5e1ed6b979c2c237e399cc7a96083 (patch) | |
| tree | 96380b38f12fd6d1763154edd6e5460fc93a975a /src/server/api/kinds.ts | |
| parent | Clean up (diff) | |
| download | sharkey-94f8a145eca5e1ed6b979c2c237e399cc7a96083.tar.gz sharkey-94f8a145eca5e1ed6b979c2c237e399cc7a96083.tar.bz2 sharkey-94f8a145eca5e1ed6b979c2c237e399cc7a96083.zip | |
Better permisson Fix #2341 (#4611)
* Better permisson Fix #2341
* add kinds.ts
* test
* fix
* v11
* fix
Diffstat (limited to 'src/server/api/kinds.ts')
| -rw-r--r-- | src/server/api/kinds.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/server/api/kinds.ts b/src/server/api/kinds.ts new file mode 100644 index 0000000000..d496fa6919 --- /dev/null +++ b/src/server/api/kinds.ts @@ -0,0 +1,58 @@ +import endpoints from './endpoints'; +import * as locale from '../../../locales/'; +import { fromEntries } from '../../prelude/array'; + +export const kindsList = [ + 'read:account', + 'write:account', + 'read:blocks', + 'write:blocks', + 'read:drive', + 'write:drive', + 'read:favorites', + 'write:favorites', + 'read:following', + 'write:following', + 'read:messaging', + 'write:messaging', + 'read:mutes', + 'write:mutes', + 'write:notes', + 'read:notifications', + 'write:notifications', + 'read:reactions', + '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; +} |