chore: remove api token function
This commit is contained in:
@@ -132,7 +132,6 @@ export const api = {
|
||||
getPublicSite: () => request<{ title: string; subtitle: string; icon: string; demo_mode: boolean }>('/settings/public'),
|
||||
updateSite: (data: SiteSettings) =>
|
||||
request('/settings/site', { method: 'PUT', body: JSON.stringify(data) }),
|
||||
generateApiToken: () => request<{ token: string }>('/settings/site/api-token/generate', { method: 'POST' }),
|
||||
generateOpenapiToken: () => request<{ token: string }>('/settings/site/openapi-token/generate', { method: 'POST' }),
|
||||
getScheduler: () => request<SchedulerSettings>('/settings/scheduler'),
|
||||
updateScheduler: (data: SchedulerSettings) =>
|
||||
@@ -437,8 +436,6 @@ export interface SiteSettings {
|
||||
openapi_enabled?: boolean
|
||||
openapi_token?: string
|
||||
openapi_token_expire?: string
|
||||
api_token?: string
|
||||
api_token_expire?: string
|
||||
}
|
||||
|
||||
export interface SchedulerSettings {
|
||||
|
||||
@@ -32,13 +32,10 @@ const form = ref<SiteSettings>({
|
||||
cookie_days: '7',
|
||||
openapi_enabled: false,
|
||||
openapi_token: '',
|
||||
openapi_token_expire: '',
|
||||
api_token: '',
|
||||
api_token_expire: ''
|
||||
openapi_token_expire: ''
|
||||
})
|
||||
const loading = ref(false)
|
||||
const showOpenapiConfirmDialog = ref(false)
|
||||
const showApiConfirmDialog = ref(false)
|
||||
|
||||
const iconPreview = computed(() => {
|
||||
if (!form.value.icon) return ''
|
||||
@@ -92,21 +89,6 @@ async function generateOpenapiToken() {
|
||||
}
|
||||
}
|
||||
|
||||
async function generateToken() {
|
||||
try {
|
||||
const res = await api.settings.generateApiToken()
|
||||
form.value.api_token = res.token
|
||||
|
||||
// 如果没有设置过期时间,默认给一年后
|
||||
if (!form.value.api_token_expire) {
|
||||
const d = new Date()
|
||||
d.setFullYear(d.getFullYear() + 1)
|
||||
form.value.api_token_expire = d.toISOString().split('T')[0]
|
||||
}
|
||||
} catch {
|
||||
toast.error('生成 Token 失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function copyOpenapiToken() {
|
||||
if (!form.value.openapi_token) return
|
||||
@@ -118,15 +100,6 @@ async function copyOpenapiToken() {
|
||||
}
|
||||
}
|
||||
|
||||
async function copyToken() {
|
||||
if (!form.value.api_token) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(form.value.api_token)
|
||||
toast.success('Token 已复制到剪贴板')
|
||||
} catch {
|
||||
toast.error('复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadSettings)
|
||||
</script>
|
||||
@@ -210,38 +183,6 @@ onMounted(loadSettings)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt-6 border-t mt-6">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<h3 class="text-lg font-medium text-foreground">API Token</h3>
|
||||
<Badge variant="secondary"
|
||||
class="font-normal text-xs bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20">
|
||||
实验特性,可能变更,将会在后期下线</Badge>
|
||||
</div>
|
||||
<p class="text-sm text-muted-foreground mb-4">开启全局 API 直接访问能力,配置后可通过请求头 <code
|
||||
class="bg-muted px-1.5 py-0.5 rounded text-xs select-all font-sans">X-API-Token: <在此生成的Token></code>
|
||||
无需登录直接调用系统的所有接口,请妥善保管并设置合理的有效期。</p>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-4 mb-4">
|
||||
<Label class="sm:text-right text-muted-foreground">Token 密钥</Label>
|
||||
<div class="sm:col-span-3 flex w-full max-w-sm items-center space-x-2">
|
||||
<Input v-model="form.api_token" placeholder="点击右侧按钮生成 32 位随机 Token" class="text-sm" />
|
||||
<Button type="button" variant="outline" size="icon" @click="showApiConfirmDialog = true" title="随机生成">
|
||||
<RefreshCw class="w-4 h-4" />
|
||||
</Button>
|
||||
<Button type="button" variant="outline" size="icon" @click="copyToken" title="复制" :disabled="!form.api_token">
|
||||
<Copy class="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-4">
|
||||
<Label class="sm:text-right text-muted-foreground">截止有效期</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Input v-model="form.api_token_expire" type="date" class="w-full max-w-xs dark:[color-scheme:dark]" />
|
||||
<div class="text-xs text-muted-foreground mt-1.5 ml-1">超过此日期后该 Token 将失效,置空代表该特性完全关闭。</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end pt-2">
|
||||
<Button @click="saveSettings" :disabled="loading">
|
||||
{{ loading ? '保存中...' : '保存设置' }}
|
||||
@@ -267,23 +208,5 @@ onMounted(loadSettings)
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<!-- API Token 重新生成确认弹窗 -->
|
||||
<AlertDialog :open="showApiConfirmDialog" @update:open="showApiConfirmDialog = $event">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle class="flex items-center gap-2">
|
||||
<AlertTriangle class="w-5 h-5 text-amber-500" />
|
||||
确认重新生成 Token?
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
此操作将立刻覆盖当前配置框内的旧版 API Token,原有的 Token 在点击【保存设置】后将会永久失效。建议逐步迁移到 OpenAPI Token 后直接将此特性置空关闭。确认要继续吗?
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction @click="generateToken">重新生成</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user