From 0c1de7b1b6e9ac10b62d8b3157cb064c79aa21d1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 18 Jul 2020 12:12:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3?= =?UTF-8?q?=E6=89=8B=E5=8B=95=E7=99=BA=E8=A1=8C=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 4 + .../components/token-generate-window.vue | 89 +++++++++++++++++++ src/client/pages/my-settings/api.vue | 20 ++++- .../api/kinds.ts => misc/api-permissions.ts} | 0 src/server/api/endpoints/miauth/gen-token.ts | 6 +- src/server/api/index.ts | 2 +- src/server/api/openapi/description.ts | 2 +- 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 src/client/components/token-generate-window.vue rename src/{server/api/kinds.ts => misc/api-permissions.ts} (100%) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index c6ad01a6d..c3933a417 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -529,6 +529,10 @@ pluginInstallWarn: "信頼できないプラグインはインストールしな deck: "デッキ" undeck: "デッキ解除" useBlurEffectForModal: "モーダルにぼかし効果を使用" +generateAccessToken: "アクセストークンの発行" +permission: "権限" +enableAll: "全て有効にする" +disableAll: "全て無効にする" _theme: explore: "テーマを探す" diff --git a/src/client/components/token-generate-window.vue b/src/client/components/token-generate-window.vue new file mode 100644 index 000000000..5486ae92e --- /dev/null +++ b/src/client/components/token-generate-window.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/src/client/pages/my-settings/api.vue b/src/client/pages/my-settings/api.vue index 79b459fb5..44f099ea1 100644 --- a/src/client/pages/my-settings/api.vue +++ b/src/client/pages/my-settings/api.vue @@ -2,9 +2,7 @@
API
- - {{ $t('token') }} - + {{ $t('generateAccessToken') }} {{ $t('regenerate') }}
@@ -26,6 +24,22 @@ export default Vue.extend({ }; }, methods: { + async generateToken() { + this.$root.new(await import('../../components/token-generate-window.vue').then(m => m.default), { + }).$on('ok', async ({ name, permissions }) => { + const { token } = await this.$root.api('miauth/gen-token', { + session: null, + name: name, + permission: permissions, + }); + + this.$root.dialog({ + type: 'success', + title: this.$t('token'), + text: token + }); + }); + }, regenerateToken() { this.$root.dialog({ title: this.$t('password'), diff --git a/src/server/api/kinds.ts b/src/misc/api-permissions.ts similarity index 100% rename from src/server/api/kinds.ts rename to src/misc/api-permissions.ts diff --git a/src/server/api/endpoints/miauth/gen-token.ts b/src/server/api/endpoints/miauth/gen-token.ts index d8c74ec8d..6476e79d7 100644 --- a/src/server/api/endpoints/miauth/gen-token.ts +++ b/src/server/api/endpoints/miauth/gen-token.ts @@ -13,7 +13,7 @@ export const meta = { params: { session: { - validator: $.str + validator: $.nullable.str }, name: { @@ -52,4 +52,8 @@ export default define(meta, async (ps, user) => { iconUrl: ps.iconUrl, permission: ps.permission, }); + + return { + token: accessToken + }; }); diff --git a/src/server/api/index.ts b/src/server/api/index.ts index 93c6cfdac..aec4a9737 100644 --- a/src/server/api/index.ts +++ b/src/server/api/index.ts @@ -78,7 +78,7 @@ router.post('/miauth/:session/check', async ctx => { session: ctx.params.session }); - if (token && !token.fetched) { + if (token && token.session != null && !token.fetched) { AccessTokens.update(token.id, { fetched: true }); diff --git a/src/server/api/openapi/description.ts b/src/server/api/openapi/description.ts index 15831b3c9..e0527dd1a 100644 --- a/src/server/api/openapi/description.ts +++ b/src/server/api/openapi/description.ts @@ -1,6 +1,6 @@ import endpoints from '../endpoints'; import * as locale from '../../../../locales/'; -import { kinds as kindsList } from '../kinds'; +import { kinds as kindsList } from '../../../misc/api-permissions'; export interface IKindInfo { endpoints: string[];