show example after api token generated
This commit is contained in:
@@ -123,7 +123,8 @@ func (a *TokensApi) TokenGenerateAPIHandler(c *core.WebContext) (any, *errs.Erro
|
||||
log.Infof(c, "[tokens.TokenGenerateAPIHandler] user \"uid:%d\" has generated api token, new token will be expired at %d", user.Uid, claims.ExpiresAt)
|
||||
|
||||
generateAPITokenResp := &models.TokenGenerateAPIResponse{
|
||||
Token: token,
|
||||
Token: token,
|
||||
APIBaseUrl: a.CurrentConfig().RootUrl + "api",
|
||||
}
|
||||
|
||||
return generateAPITokenResp, nil
|
||||
|
||||
@@ -44,7 +44,8 @@ type TokenRevokeRequest struct {
|
||||
|
||||
// TokenGenerateAPIResponse represents all response parameters of generated api token
|
||||
type TokenGenerateAPIResponse struct {
|
||||
Token string `json:"token"`
|
||||
Token string `json:"token"`
|
||||
APIBaseUrl string `json:"apiBaseUrl"`
|
||||
}
|
||||
|
||||
// TokenGenerateMCPResponse represents all response parameters of generated mcp token
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Deaktivieren",
|
||||
"Disabled": "Deaktiviert",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Kopieren",
|
||||
"Visible": "Sichtbar",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Disable",
|
||||
"Disabled": "Disabled",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Copy",
|
||||
"Visible": "Visible",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Desactivar",
|
||||
"Disabled": "Desactivado",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Copiar",
|
||||
"Visible": "Visible",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Désactiver",
|
||||
"Disabled": "Désactivé",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Jeton",
|
||||
"Copy": "Copier",
|
||||
"Visible": "Visible",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Disabilita",
|
||||
"Disabled": "Disabilitato",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Copia",
|
||||
"Visible": "Visibile",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "無効",
|
||||
"Disabled": "無効になっています",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "コピー",
|
||||
"Visible": "見える",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "비활성화",
|
||||
"Disabled": "비활성화됨",
|
||||
"Configuration": "설정",
|
||||
"Example": "Example",
|
||||
"Token": "토큰",
|
||||
"Copy": "복사",
|
||||
"Visible": "표시",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Uitschakelen",
|
||||
"Disabled": "Uitgeschakeld",
|
||||
"Configuration": "Configuratie",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Kopiëren",
|
||||
"Visible": "Zichtbaar",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Desabilitar",
|
||||
"Disabled": "Desabilitado",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Copiar",
|
||||
"Visible": "Visível",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Отключить",
|
||||
"Disabled": "Отключено",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Копировать",
|
||||
"Visible": "Видимый",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "ปิดใช้งาน",
|
||||
"Disabled": "ปิดใช้งานแล้ว",
|
||||
"Configuration": "การตั้งค่า",
|
||||
"Example": "Example",
|
||||
"Token": "โทเค็น",
|
||||
"Copy": "คัดลอก",
|
||||
"Visible": "มองเห็น",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Вимкнути",
|
||||
"Disabled": "Вимкнено",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Копіювати",
|
||||
"Visible": "Видимий",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "Tắt",
|
||||
"Disabled": "Đã tắt",
|
||||
"Configuration": "Configuration",
|
||||
"Example": "Example",
|
||||
"Token": "Token",
|
||||
"Copy": "Sao chép",
|
||||
"Visible": "Hiển thị",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "禁用",
|
||||
"Disabled": "禁用",
|
||||
"Configuration": "配置",
|
||||
"Example": "示例",
|
||||
"Token": "令牌",
|
||||
"Copy": "复制",
|
||||
"Visible": "可见",
|
||||
|
||||
@@ -1453,6 +1453,7 @@
|
||||
"Disable": "停用",
|
||||
"Disabled": "停用",
|
||||
"Configuration": "設定",
|
||||
"Example": "範例",
|
||||
"Token": "令牌",
|
||||
"Copy": "複製",
|
||||
"Visible": "可見",
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface TokenRevokeRequest {
|
||||
|
||||
export interface TokenGenerateAPIResponse {
|
||||
readonly token: string;
|
||||
readonly apiBaseUrl: string;
|
||||
}
|
||||
|
||||
export interface TokenGenerateMCPResponse {
|
||||
|
||||
@@ -7,6 +7,17 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<v-card-text class="py-0 w-100 d-flex justify-center" v-if="tokenType === 'api' && generatedToken && serverUrl">
|
||||
<v-switch class="bidirectional-switch" color="secondary"
|
||||
:label="tt('Example')"
|
||||
v-model="showAPIExample"
|
||||
@click="showAPIExample = !showAPIExample">
|
||||
<template #prepend>
|
||||
<span>{{ tt('Token') }}</span>
|
||||
</template>
|
||||
</v-switch>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-text class="py-0 w-100 d-flex justify-center" v-if="tokenType === 'mcp' && generatedToken && serverUrl">
|
||||
<v-switch class="bidirectional-switch" color="secondary"
|
||||
:label="tt('Configuration')"
|
||||
@@ -78,11 +89,14 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
<div class="w-100 code-container" v-if="generatedToken">
|
||||
<v-textarea class="w-100 always-cursor-text" :readonly="true"
|
||||
:rows="4" :value="generatedToken" v-if="!showMCPConfiguration || !serverUrl" />
|
||||
:rows="4" :value="generatedToken" v-if="(tokenType === 'api' && (!showAPIExample || !serverUrl)) || (tokenType === 'mcp' && (!showMCPConfiguration || !serverUrl))" />
|
||||
<v-textarea class="w-100 always-cursor-text" :readonly="true"
|
||||
:rows="15" :value="mcpServerConfiguration" v-if="showMCPConfiguration && serverUrl" />
|
||||
:rows="5" :value="apiExample" v-if="tokenType === 'api' && showAPIExample && serverUrl" />
|
||||
<v-textarea class="w-100 always-cursor-text" :readonly="true"
|
||||
:rows="15" :value="mcpServerConfiguration" v-if="tokenType === 'mcp' && showMCPConfiguration && serverUrl" />
|
||||
</div>
|
||||
</v-card-text>
|
||||
|
||||
@@ -121,7 +135,7 @@ import { useI18n } from '@/locales/helpers.ts';
|
||||
import { useTokensStore } from '@/stores/token.ts';
|
||||
|
||||
import { type NameValue } from '@/core/base.ts';
|
||||
import { type TokenGenerateMCPResponse } from '@/models/token.ts';
|
||||
import { type TokenGenerateAPIResponse, type TokenGenerateMCPResponse } from '@/models/token.ts';
|
||||
|
||||
import { isAPITokenEnabled, isMCPServerEnabled } from '@/lib/server_settings.ts';
|
||||
import { copyTextToClipboard } from '@/lib/ui/common.ts';
|
||||
@@ -144,6 +158,7 @@ const tokenExpirationTime = ref<number>(86400);
|
||||
const tokenCustomExpirationTime = ref<number>(86400);
|
||||
const currentPassword = ref<string>('');
|
||||
const generating = ref<boolean>(false);
|
||||
const showAPIExample = ref<boolean>(false);
|
||||
const showMCPConfiguration = ref<boolean>(false);
|
||||
const serverUrl = ref<string>('');
|
||||
const generatedToken = ref<string>('');
|
||||
@@ -162,6 +177,10 @@ const tokenTypeOptions = computed<NameValue[]>(() => {
|
||||
return options;
|
||||
});
|
||||
|
||||
const apiExample = computed<string>(() => {
|
||||
return `curl -H 'Authorization: Bearer ${generatedToken.value}' '${serverUrl.value}/v1/users/profile/get.json'`;
|
||||
});
|
||||
|
||||
const mcpServerConfiguration = computed<string>(() => {
|
||||
return '{\n' +
|
||||
' "mcpServers": {\n' +
|
||||
@@ -183,6 +202,7 @@ function open(): Promise<void> {
|
||||
tokenExpirationTime.value = 86400;
|
||||
tokenCustomExpirationTime.value = 86400;
|
||||
generating.value = false;
|
||||
showAPIExample.value = false;
|
||||
showMCPConfiguration.value = false;
|
||||
serverUrl.value = '';
|
||||
generatedToken.value = '';
|
||||
@@ -208,7 +228,9 @@ function generateToken(): void {
|
||||
generating.value = false;
|
||||
currentPassword.value = '';
|
||||
|
||||
if (tokenType.value === 'mcp') {
|
||||
if (tokenType.value === 'api') {
|
||||
serverUrl.value = (result as TokenGenerateAPIResponse).apiBaseUrl;
|
||||
} else if (tokenType.value === 'mcp') {
|
||||
serverUrl.value = (result as TokenGenerateMCPResponse).mcpUrl;
|
||||
}
|
||||
|
||||
@@ -223,7 +245,9 @@ function generateToken(): void {
|
||||
}
|
||||
|
||||
function copy(): void {
|
||||
if (showMCPConfiguration.value) {
|
||||
if (tokenType.value === 'api' && showAPIExample.value) {
|
||||
copyTextToClipboard(apiExample.value, buttonContainer.value);
|
||||
} else if (tokenType.value === 'mcp' && showMCPConfiguration.value) {
|
||||
copyTextToClipboard(mcpServerConfiguration.value, buttonContainer.value);
|
||||
} else {
|
||||
copyTextToClipboard(generatedToken.value, buttonContainer.value);
|
||||
|
||||
Reference in New Issue
Block a user