diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index c6ad01a6de..c3933a417e 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 0000000000..5486ae92e7 --- /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 79b459fb5e..44f099ea1d 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 d8c74ec8d7..6476e79d77 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 93c6cfdac0..aec4a97379 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 15831b3c9a..e0527dd1ae 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[];