feat: add MCP settings and admin header actions

This commit is contained in:
vastsa committed 2026-10-10 21:07:01 +08:00
1 parent fdb0f3dbd5
commit bcc1dbda06
15 files changed
+525 -169

No files matched your search

+2 -21
View File
@@ -65,18 +65,8 @@
</button>
</div>
<div v-else class="ml-2 flex flex-wrap gap-2">
<a
v-if="isHtmlPreviewable(record)"
:href="getHtmlPreviewUrl(record)"
target="_blank"
rel="noopener noreferrer"
class="rounded-xl px-4 py-2 text-sm font-semibold transition duration-300"
:class="isDarkMode ? 'bg-zinc-200 text-zinc-950 hover:bg-zinc-100' : 'bg-zinc-800 text-white hover:bg-zinc-900'"
>
{{ t('fileRecord.preview') }}
</a>
<button
v-else-if="isPreviewable(record)"
v-if="isPreviewable(record)"
type="button"
class="rounded-xl px-4 py-2 text-sm font-semibold transition duration-300"
:class="isDarkMode ? 'bg-zinc-200 text-zinc-950 hover:bg-zinc-100' : 'bg-zinc-800 text-white hover:bg-zinc-900'"
@@ -138,7 +128,7 @@ import { useI18n } from 'vue-i18n'
import { FileIcon, CalendarIcon, HardDriveIcon, DownloadIcon } from 'lucide-vue-next'
import QRCode from 'qrcode.vue'
import type { ReceivedFileRecord } from '@/types'
import { buildAbsoluteUrl, buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
import { buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
interface Props {
visible: boolean
@@ -160,13 +150,6 @@ const getDownloadUrl = (record: ReceivedFileRecord) => {
return buildDownloadUrl(record.downloadUrl)
}
const isHtmlPreviewable = (record: ReceivedFileRecord) => {
const extension = record.filename.split('.').pop()?.toLowerCase() || ''
return Boolean(record.downloadUrl) && ['html', 'htm'].includes(extension)
}
const getHtmlPreviewUrl = (record: ReceivedFileRecord) =>
buildAbsoluteUrl(`/share/preview/html/${encodeURIComponent(record.code)}`)
const getQRCodeValue = (record: ReceivedFileRecord) => {
return buildReceivedRecordQrValue(record)
@@ -193,8 +176,6 @@ const isPreviewable = (record: ReceivedFileRecord) => {
'm4a',
'flac',
'pdf',
'html',
'htm'
].includes(extension)
}
</script>
+2 -7
View File
@@ -87,7 +87,7 @@ import { XIcon } from 'lucide-vue-next'
import { useI18n } from 'vue-i18n'
import { useInjectedDarkMode } from '@/composables'
import type { ReceivedFileRecord } from '@/types'
import { buildAbsoluteUrl, buildDownloadUrl } from '@/utils/share-url'
import { buildDownloadUrl } from '@/utils/share-url'
interface Props {
visible: boolean
@@ -106,12 +106,7 @@ const extension = computed(() => props.record?.filename.split('.').pop()?.toLowe
const downloadUrl = computed(() =>
props.record?.downloadUrl ? buildDownloadUrl(props.record.downloadUrl) : ''
)
const previewUrl = computed(() => {
if (['html', 'htm'].includes(extension.value) && props.record?.code) {
return buildAbsoluteUrl(`/share/preview/html/${encodeURIComponent(props.record.code)}`)
}
return downloadUrl.value
})
const previewUrl = computed(() => downloadUrl.value)
const mediaType = computed(() => {
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'].includes(extension.value)) return 'image'
if (['mp4', 'webm', 'ogg', 'mov', 'm4v'].includes(extension.value)) return 'video'
+3
View File
@@ -11,4 +11,7 @@ export { useRouteLoading } from './useRouteLoading'
export { useSendFlow } from './useSendFlow'
export { useLocalShare } from './useLocalShare'
export { useSystemConfig } from './useSystemConfig'
export { useMcpSettings } from './useMcpSettings'
export { useTheme } from './useTheme'
export { provideAdminHeaderActions, useAdminHeaderActions } from './useAdminHeaderActions'
export type { AdminHeaderAction, AdminHeaderConfig } from './useAdminHeaderActions'
+71
View File
@@ -0,0 +1,71 @@
import {
inject,
onUnmounted,
provide,
shallowRef,
watch,
type Component,
type ComputedRef,
type InjectionKey
} from 'vue'
export interface AdminHeaderAction {
key: string
label: string
icon: Component
onClick: () => void
variant?: 'primary' | 'secondary' | 'danger' | 'success' | 'outline'
loading?: boolean
disabled?: boolean
}
export interface AdminHeaderConfig {
subtitle?: string
status?: string
statusTone?: 'muted' | 'warning'
actions: AdminHeaderAction[]
}
interface AdminHeaderRegistry {
state: ReturnType<typeof shallowRef<AdminHeaderConfig | null>>
register: (owner: symbol, config: AdminHeaderConfig) => void
clear: (owner: symbol) => void
}
const ADMIN_HEADER_KEY: InjectionKey<AdminHeaderRegistry> = Symbol('admin-header-actions')
export function provideAdminHeaderActions() {
const state = shallowRef<AdminHeaderConfig | null>(null)
let currentOwner: symbol | null = null
provide(ADMIN_HEADER_KEY, {
state,
register(owner, config) {
currentOwner = owner
state.value = config
},
clear(owner) {
if (currentOwner === owner) {
currentOwner = null
state.value = null
}
}
})
return state
}
export function useAdminHeaderActions(config: ComputedRef<AdminHeaderConfig>) {
const registry = inject(ADMIN_HEADER_KEY, null)
const owner = Symbol('admin-header-owner')
const stop = watch(
config,
(value) => registry?.register(owner, value),
{ immediate: true }
)
onUnmounted(() => {
stop()
registry?.clear(owner)
})
}
+64
View File
@@ -0,0 +1,64 @@
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { ConfigService } from '@/services'
import { useAlertStore } from '@/stores/alertStore'
import { copyToClipboard } from '@/utils/clipboard'
import { getErrorMessage } from '@/utils/common'
export function useMcpSettings() {
const { t } = useI18n()
const alertStore = useAlertStore()
const isLoading = ref(false)
const isSaving = ref(false)
const requireToken = ref(0)
const guestUploadOpen = ref(1)
const loadSettings = async () => {
isLoading.value = true
try {
const response = await ConfigService.getConfig()
if (response.code !== 200 || !response.detail) {
throw new Error(t('admin.mcp.loadFailed'))
}
requireToken.value = response.detail.mcp_require_token === 1 ? 1 : 0
guestUploadOpen.value = response.detail.open_upload === 0 ? 0 : 1
} catch (error) {
alertStore.showAlert(getErrorMessage(error, t('admin.mcp.loadFailed')), 'error')
} finally {
isLoading.value = false
}
}
const toggleTokenRequirement = async () => {
if (isSaving.value || isLoading.value) return
const nextValue = requireToken.value === 1 ? 0 : 1
isSaving.value = true
try {
const response = await ConfigService.updateConfig({ mcp_require_token: nextValue })
if (response.code !== 200) throw new Error(t('admin.mcp.saveFailed'))
requireToken.value = nextValue
alertStore.showAlert(t('admin.mcp.saveSuccess'), 'success')
} catch (error) {
alertStore.showAlert(getErrorMessage(error, t('admin.mcp.saveFailed')), 'error')
} finally {
isSaving.value = false
}
}
const copyText = (value: string) =>
copyToClipboard(value, {
successMsg: t('admin.mcp.copySuccess'),
errorMsg: t('admin.mcp.copyFailed'),
notify: (message, type) => alertStore.showAlert(message, type)
})
return {
isLoading,
isSaving,
requireToken,
guestUploadOpen,
loadSettings,
toggleTokenRequirement,
copyText
}
}
+2
View File
@@ -71,6 +71,7 @@ export const ROUTES = {
DASHBOARD: '/admin/dashboard',
FILE_MANAGE: '/admin/files',
LOCAL_SHARE: '/admin/local',
MCP: '/admin/mcp',
SETTINGS: '/admin/settings'
} as const
@@ -82,6 +83,7 @@ export const ROUTE_NAMES = {
DASHBOARD: 'Dashboard',
FILE_MANAGE: 'FileManage',
LOCAL_SHARE: 'LocalShare',
MCP: 'Mcp',
SETTINGS: 'Settings'
} as const
+30 -2
View File
@@ -58,6 +58,36 @@ export default {
loggedIn: 'Signed in, open admin console',
loggedOut: 'Sign in to admin console'
},
mcp: {
title: 'MCP Quick Share',
subtitle: 'Connect FileCodeBox to an AI client to create text and file shares through chat.',
refresh: 'Refresh settings',
endpointLabel: 'MCP endpoint',
transport: 'Transport: Streamable HTTP',
copyEndpoint: 'Copy endpoint',
securityTitle: 'Access control',
securityHelp: 'When enabled, MCP uploads require an admin login token. If guest uploads are disabled, the server always requires a token.',
requireToken: 'Require admin token',
tokenRequiredStatus: 'MCP uploads currently require an admin Bearer token.',
tokenOptionalStatus: 'Tokenless uploads are allowed only while guest uploads are enabled.',
shareTextTitle: 'Share text',
shareTextHelp: 'Create a FileCodeBox text share and return its retrieval link.',
shareFileTitle: 'Share a file',
shareFileHelp: 'Upload Base64 file content within the site file-type, size, and expiration limits.',
aiSetupTitle: 'Configure with AI',
aiSetupHelp: 'Copy setup instructions and paste them into your AI assistant to configure its MCP client.',
aiSetupButton: 'Copy AI setup instructions',
aiSetupFallback: 'Clipboard unavailable. Select and copy the setup text below.',
aiSetupPrivacy: 'Your admin token is never copied. If authentication is required, let the AI ask you for it; do not send it to an untrusted service.',
aiAuthRequired: 'Authorization: Bearer with an admin login token is required',
aiAuthOptional: 'No token required unless guest uploads are disabled',
aiSetupPrompt: 'Please connect FileCodeBox MCP to my current AI client. Use Streamable HTTP and the client format it currently supports.\nEndpoint: {endpoint}\nAuthentication: {authentication}\nTools: share_text (create a text share), share_file (upload a Base64 file and create a share). If a token is needed, ask me for my admin login token and set it only as Authorization: Bearer. Do not guess or reveal the token.',
loadFailed: 'Failed to load MCP settings',
saveFailed: 'Failed to save MCP settings',
saveSuccess: 'MCP settings saved',
copySuccess: 'Copied to clipboard',
copyFailed: 'Could not copy; check browser clipboard permissions'
},
dashboard: {
title: 'Dashboard',
totalFiles: 'Total Files',
@@ -752,8 +782,6 @@ export default {
allowedFileTypesPlaceholder: '* or .rar, .zip, image/*',
allowedFileTypesHelp:
'Separate multiple types with commas. * allows all; extensions and MIME wildcards are supported.',
mcpRequireToken: 'Require admin token for MCP uploads',
mcpRequireTokenHelp: 'When enabled, pass your admin login token as Authorization: Bearer when calling /mcp.',
codeGenerateType: 'Passcode Rule',
codeGenerateNumber: 'Numeric Passcode',
codeGenerateSecret: 'Secret Passcode',
+30 -2
View File
@@ -58,6 +58,36 @@ export default {
loggedIn: '已登录,进入管理后台',
loggedOut: '登录管理后台'
},
mcp: {
title: 'MCP 快捷分享',
subtitle: '把 FileCodeBox 接入 AI 客户端,用对话快速创建文本或文件分享。',
refresh: '刷新配置',
endpointLabel: 'MCP 接口地址',
transport: '传输协议:Streamable HTTP',
copyEndpoint: '复制地址',
securityTitle: '访问控制',
securityHelp: '开启后,调用 MCP 上传工具需要管理员登录 Token。关闭游客上传时,服务仍会强制验证 Token。',
requireToken: '要求管理员 Token',
tokenRequiredStatus: '当前 MCP 上传需要管理员 Bearer Token。',
tokenOptionalStatus: '当前允许免 Token 上传(仅在已开启游客上传时生效)。',
shareTextTitle: '分享文本',
shareTextHelp: 'AI 可将文本创建为 FileCodeBox 分享,并返回取件链接。',
shareFileTitle: '分享文件',
shareFileHelp: 'AI 可上传 Base64 文件内容,遵循本站类型、大小和过期限制。',
aiSetupTitle: '一键让 AI 配置',
aiSetupHelp: '复制连接说明,粘贴给你使用的 AI 助手,让它按当前客户端格式配置 MCP。',
aiSetupButton: '复制给 AI 配置',
aiSetupFallback: '剪贴板不可用,可在下方文本框中手动选择并复制。',
aiSetupPrivacy: '不会复制管理员 Token。需要认证时,AI 应向你索取,不要把 Token 发给不可信的服务。',
aiAuthRequired: '需要 Authorization: Bearer 管理员登录 Token',
aiAuthOptional: '当前无需 Token;若游客上传关闭则仍需管理员 Token',
aiSetupPrompt: '请帮我把 FileCodeBox MCP 接入当前 AI 客户端。请使用 Streamable HTTP,并按客户端当前支持的格式配置。\n服务地址:{endpoint}\n认证要求:{authentication}\n工具:share_text(创建文本分享)、share_file(上传 Base64 文件并创建分享)。如果需要 Token,请先向我索取管理员登录 Token,只设置为 Authorization: Bearer,不要猜测或输出 Token。',
loadFailed: '读取 MCP 配置失败',
saveFailed: '保存 MCP 配置失败',
saveSuccess: 'MCP 配置已保存',
copySuccess: '已复制到剪贴板',
copyFailed: '复制失败,请检查浏览器剪贴板权限'
},
dashboard: {
title: '仪表盘',
totalFiles: '总文件数',
@@ -771,8 +801,6 @@ export default {
allowedFileTypes: '允许上传类型',
allowedFileTypesPlaceholder: '* 或 .rar, .zip, image/*',
allowedFileTypesHelp: '多个类型用英文逗号分隔,* 表示不限制;支持扩展名和 MIME 通配。',
mcpRequireToken: 'MCP 上传需要管理员 Token',
mcpRequireTokenHelp: '启用后调用 /mcp 上传时,需在 Authorization: Bearer 中提供管理员登录 Token。',
codeGenerateType: '取件码规则',
codeGenerateNumber: '数字取件码',
codeGenerateSecret: 'Secret 取件码',
+52 -6
View File
@@ -66,10 +66,45 @@
<header
class="theme-surface border-b transition-colors duration-300 h-16 backdrop-blur-xl"
>
<div class="flex items-center justify-between h-16 px-4">
<button @click="toggleSidebar" class="lg:hidden">
<MenuIcon class="theme-text-muted w-6 h-6" />
<div class="flex h-16 items-center gap-3 px-4">
<button
type="button"
aria-label="Open navigation menu"
@click="toggleSidebar"
class="theme-icon-button flex h-10 w-10 shrink-0 items-center justify-center rounded-lg lg:hidden"
>
<MenuIcon class="h-6 w-6" />
</button>
<h2 class="theme-text-strong min-w-0 flex-1 truncate text-lg font-semibold">
{{ currentPageTitle }}
</h2>
<div class="flex min-w-0 shrink-0 items-center gap-3">
<p v-if="headerActions?.subtitle" class="theme-text-muted hidden max-w-56 truncate text-sm xl:block">
{{ headerActions.subtitle }}
</p>
<p
v-if="headerActions?.status"
class="hidden whitespace-nowrap text-sm sm:block"
:class="headerActions.statusTone === 'warning' ? 'theme-warning' : 'theme-text-muted'"
>
{{ headerActions.status }}
</p>
<BaseButton
v-for="action in headerActions?.actions ?? []"
:key="action.key"
size="sm"
:variant="action.variant ?? 'secondary'"
:loading="action.loading"
:disabled="action.disabled"
:aria-label="action.label"
@click="action.onClick"
>
<template #icon>
<component :is="action.icon" class="mr-2 h-4 w-4 sm:mr-0" />
</template>
<span class="hidden sm:inline">{{ action.label }}</span>
</BaseButton>
</div>
</div>
</header>
@@ -84,7 +119,7 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { computed, ref, onMounted, onUnmounted } from 'vue'
import {
BoxIcon,
MenuIcon,
@@ -93,12 +128,15 @@ import {
HardDriveIcon,
CogIcon,
LayoutDashboardIcon,
LogOutIcon
LogOutIcon,
NetworkIcon
} from 'lucide-vue-next'
import { RouterLink, useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { ROUTE_NAMES, ROUTES } from '@/constants'
import { useAdminSession } from '@/composables'
import BaseButton from '@/components/common/BaseButton.vue'
import { provideAdminHeaderActions } from '@/composables/useAdminHeaderActions'
interface MenuItem {
id: string
@@ -109,8 +147,9 @@ interface MenuItem {
const router = useRouter()
const route = useRoute()
const { t } = useI18n()
const { verifySession, logout } = useAdminSession()
const { t } = useI18n()
const headerActions = provideAdminHeaderActions()
const menuItems: MenuItem[] = [
{
id: ROUTE_NAMES.DASHBOARD,
@@ -130,6 +169,12 @@ const menuItems: MenuItem[] = [
icon: HardDriveIcon,
redirect: ROUTES.LOCAL_SHARE
},
{
id: ROUTE_NAMES.MCP,
name: t('admin.mcp.title'),
icon: NetworkIcon,
redirect: ROUTES.MCP
},
{
id: ROUTE_NAMES.SETTINGS,
name: t('admin.settings.title'),
@@ -137,6 +182,7 @@ const menuItems: MenuItem[] = [
redirect: ROUTES.SETTINGS
}
]
const currentPageTitle = computed(() => menuItems.find((item) => item.id === route.name)?.name ?? '')
const isSidebarOpen = ref(true)
const toggleSidebar = () => {
+9
View File
@@ -68,6 +68,15 @@ const routes: RouteRecordRaw[] = [
title: 'local'
}
},
{
path: 'mcp',
name: ROUTE_NAMES.MCP,
component: () => import('@/views/manage/McpView.vue'),
meta: {
...adminPageMeta,
title: 'mcp'
}
},
{
path: 'settings',
name: ROUTE_NAMES.SETTINGS,
+16 -25
View File
@@ -1,30 +1,5 @@
<template>
<div class="p-6">
<div class="mb-6 flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
<div>
<p class="text-sm" :class="[mutedTextClass]">FileCodeBox Admin</p>
<h2 class="text-2xl font-bold" :class="[primaryTextClass]">
{{ t('admin.dashboard.title') }}
</h2>
<p class="mt-1 text-xs" :class="[mutedTextClass]">
{{ t('admin.dashboard.lastUpdated', { time: lastUpdatedText }) }}
</p>
</div>
<button
type="button"
:disabled="isLoading"
@click="fetchDashboardData"
class="inline-flex items-center justify-center rounded-lg px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-70"
:class="[
isDarkMode
? 'bg-gray-800 text-gray-200 hover:bg-gray-700'
: 'bg-white text-gray-700 shadow-sm hover:bg-gray-50'
]"
>
<RefreshCwIcon class="mr-2 h-4 w-4" :class="{ 'animate-spin': isLoading }" />
{{ isLoading ? t('admin.dashboard.refreshing') : t('admin.dashboard.refresh') }}
</button>
</div>
<div
v-if="errorMessage"
@@ -276,6 +251,8 @@ import { useConfigStore } from '@/stores/configStore'
import type { DashboardHealthAction } from '@/types'
import { buildInfo } from '@/utils/build-info'
import { useAdminHeaderActions } from '@/composables'
const isDarkMode = useInjectedDarkMode()
const { t } = useI18n()
const router = useRouter()
@@ -289,6 +266,20 @@ const { dashboardData, errorMessage, fetchDashboardData, isLoading, lastUpdatedT
const primaryTextClass = computed(() => (isDarkMode.value ? 'text-white' : 'text-gray-900'))
const mutedTextClass = computed(() => (isDarkMode.value ? 'text-zinc-400' : 'text-zinc-500'))
const versionText = computed(() => appVersion.value || t('admin.dashboard.versionPending'))
const headerConfig = computed(() => ({
subtitle: t('admin.dashboard.lastUpdated', { time: lastUpdatedText.value }),
actions: [
{
key: 'refresh',
label: isLoading.value ? t('admin.dashboard.refreshing') : t('admin.dashboard.refresh'),
icon: RefreshCwIcon,
loading: isLoading.value,
onClick: () => void fetchDashboardData()
}
]
}))
useAdminHeaderActions(headerConfig)
const panelClass = computed(() =>
isDarkMode.value
? 'border border-white/10 bg-white/[0.06] shadow-[0_22px_54px_-36px_rgba(255,255,255,0.22)] backdrop-blur-xl'
+25 -29
View File
@@ -1,34 +1,5 @@
<template>
<div class="p-6">
<div class="mb-6 flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
<div>
<h2 class="text-2xl font-bold" :class="[primaryTextClass]">
{{ t('fileManage.title') }}
</h2>
<p class="mt-1 text-sm" :class="[mutedTextClass]">
{{ t('fileManage.subtitle', { count: summary.total_files }) }}
</p>
</div>
<div class="flex flex-wrap items-center gap-2">
<BaseButton variant="secondary" :loading="isLoading" @click="refreshFiles">
<template #icon>
<RefreshCwIcon class="mr-2 h-4 w-4" />
</template>
{{ t('fileManage.refresh') }}
</BaseButton>
<BaseButton
v-if="hasActiveFilters"
variant="outline"
:disabled="isLoading"
@click="handleResetFilters"
>
<template #icon>
<XIcon class="mr-2 h-4 w-4" />
</template>
{{ t('fileManage.resetFilters') }}
</BaseButton>
</div>
</div>
<div class="mb-6 grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
<div
@@ -1217,6 +1188,7 @@ import BaseModal from '@/components/common/BaseModal.vue'
import BaseButton from '@/components/common/BaseButton.vue'
import { useAdminFiles, useInjectedDarkMode } from '@/composables'
import { formatTimestamp } from '@/utils/common'
import { useAdminHeaderActions } from '@/composables'
const { t } = useI18n()
const isDarkMode = useInjectedDarkMode()
@@ -1733,6 +1705,30 @@ watch(
}
)
const headerConfig = computed(() => ({
subtitle: t('fileManage.subtitle', { count: summary.value.total_files }),
actions: [
{
key: 'refresh',
label: t('fileManage.refresh'),
icon: RefreshCwIcon,
loading: isLoading.value,
onClick: () => void refreshFiles()
},
...(hasActiveFilters.value
? [{
key: 'reset-filters',
label: t('fileManage.resetFilters'),
icon: XIcon,
variant: 'outline' as const,
disabled: isLoading.value,
onClick: () => void handleResetFilters()
}]
: [])
]
}))
useAdminHeaderActions(headerConfig)
onMounted(() => {
params.value.health = getRouteHealthFilter()
void loadViewPresets()
+15 -16
View File
@@ -1,21 +1,5 @@
<template>
<div class="p-6">
<div class="mb-6 flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
<div>
<h2 class="text-2xl font-bold" :class="[primaryTextClass]">
{{ t('admin.localShare.title') }}
</h2>
<p class="mt-1 text-sm" :class="[mutedTextClass]">
{{ t('admin.localShare.subtitle') }}
</p>
</div>
<BaseButton variant="secondary" :loading="isLoading" @click="loadDirectory(currentPath)">
<template #icon>
<RefreshCwIcon class="mr-2 h-4 w-4" />
</template>
{{ t('admin.localShare.refresh') }}
</BaseButton>
</div>
<p class="mb-4 rounded-lg border px-4 py-3 text-sm" :class="[hintClass]">
{{ t('admin.localShare.mountHint') }}
@@ -168,6 +152,7 @@ import BaseModal from '@/components/common/BaseModal.vue'
import { ROUTES } from '@/constants'
import { useInjectedDarkMode, useLocalShare } from '@/composables'
import { formatFileSize } from '@/utils/common'
import { useAdminHeaderActions } from '@/composables'
const { t } = useI18n()
const router = useRouter()
@@ -223,6 +208,20 @@ const goToFiles = () => {
void router.push(ROUTES.FILE_MANAGE)
}
const headerConfig = computed(() => ({
subtitle: t('admin.localShare.subtitle'),
actions: [
{
key: 'refresh',
label: t('admin.localShare.refresh'),
icon: RefreshCwIcon,
loading: isLoading.value,
onClick: () => void loadDirectory(currentPath.value)
}
]
}))
useAdminHeaderActions(headerConfig)
onMounted(() => {
void loadDirectory('')
})
+173
View File
@@ -0,0 +1,173 @@
<template>
<div class="space-y-6 p-6">
<section class="theme-panel rounded-2xl border p-5 shadow-sm sm:p-6">
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div class="min-w-0">
<p class="theme-text-muted text-xs font-semibold uppercase tracking-wider">
{{ t('admin.mcp.endpointLabel') }}
</p>
<code class="theme-text-strong mt-2 block break-all text-sm sm:text-base">{{ endpoint }}</code>
<p class="theme-text-muted mt-2 text-xs">{{ t('admin.mcp.transport') }}</p>
</div>
<BaseButton variant="secondary" :disabled="isLoading" @click="copyEndpoint">
<template #icon><CopyIcon class="mr-2 h-4 w-4" /></template>
{{ t('admin.mcp.copyEndpoint') }}
</BaseButton>
</div>
</section>
<section class="theme-panel rounded-2xl border p-5 shadow-sm sm:p-6">
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div class="max-w-2xl">
<h3 class="theme-text-strong text-base font-semibold">{{ t('admin.mcp.securityTitle') }}</h3>
<p class="theme-text-muted mt-1 text-sm">{{ t('admin.mcp.securityHelp') }}</p>
</div>
<fieldset :disabled="isLoading || isSaving" class="m-0 min-w-0 border-0 p-0">
<legend class="sr-only">{{ t('admin.mcp.securityTitle') }}</legend>
<SettingSwitch
:label="t('admin.mcp.requireToken')"
:model-value="requireToken"
:enabled-text="t('common.enabled')"
:disabled-text="t('common.disabled')"
@toggle="toggleTokenRequirement"
/>
</fieldset>
</div>
<p
class="mt-4 rounded-xl border px-4 py-3 text-sm"
:class="effectiveTokenRequired
? 'border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300'
: 'theme-divider theme-text-muted bg-black/[0.02] dark:bg-white/[0.03]'"
>
{{ effectiveTokenRequired ? t('admin.mcp.tokenRequiredStatus') : t('admin.mcp.tokenOptionalStatus') }}
</p>
</section>
<section class="grid gap-4 md:grid-cols-2">
<article
v-for="tool in tools"
:key="tool.name"
class="theme-panel rounded-2xl border p-5 shadow-sm"
>
<div class="flex items-center gap-3">
<div class="theme-brand flex h-10 w-10 items-center justify-center rounded-xl">
<component :is="tool.icon" class="h-5 w-5" aria-hidden="true" />
</div>
<div>
<h3 class="theme-text-strong font-semibold">{{ t(tool.title) }}</h3>
<code class="theme-text-muted text-xs">{{ tool.name }}</code>
</div>
</div>
<p class="theme-text-muted mt-4 text-sm">{{ t(tool.description) }}</p>
</article>
</section>
<section class="rounded-2xl border border-violet-500/20 bg-violet-500/[0.06] p-5 sm:p-6">
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div class="max-w-2xl">
<h3 class="theme-text-strong flex items-center gap-2 text-base font-semibold">
<SparklesIcon class="h-5 w-5 text-violet-500" aria-hidden="true" />
{{ t('admin.mcp.aiSetupTitle') }}
</h3>
<p class="theme-text-muted mt-1 text-sm">{{ t('admin.mcp.aiSetupHelp') }}</p>
</div>
<BaseButton :disabled="isLoading" @click="copyAiSetupPrompt">
<template #icon><SparklesIcon class="mr-2 h-4 w-4" /></template>
{{ t('admin.mcp.aiSetupButton') }}
</BaseButton>
</div>
<label v-if="aiSetupPromptText" class="mt-4 block space-y-2">
<span class="theme-text-muted text-xs">{{ t('admin.mcp.aiSetupFallback') }}</span>
<textarea
:value="aiSetupPromptText"
readonly
rows="7"
class="w-full resize-y rounded-xl border px-3 py-2 font-mono text-xs"
:class="isDarkMode ? 'border-white/10 bg-zinc-950/60 text-zinc-200' : 'border-zinc-200 bg-white/80 text-zinc-800'"
:aria-label="t('admin.mcp.aiSetupFallback')"
@focus="($event.target as HTMLTextAreaElement).select()"
/>
</label>
<p class="theme-text-muted mt-3 text-xs">{{ t('admin.mcp.aiSetupPrivacy') }}</p>
</section>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useInjectedDarkMode } from '@/composables'
import {
CopyIcon,
FileTextIcon,
NetworkIcon,
RefreshCwIcon,
SparklesIcon,
UploadIcon
} from 'lucide-vue-next'
import BaseButton from '@/components/common/BaseButton.vue'
import SettingSwitch from '@/components/common/SettingSwitch.vue'
import { useMcpSettings } from '@/composables'
import { buildAbsoluteUrl } from '@/utils/share-url'
import { useAdminHeaderActions } from '@/composables'
const { t } = useI18n()
const {
isLoading,
isSaving,
requireToken,
guestUploadOpen,
loadSettings,
toggleTokenRequirement,
copyText
} = useMcpSettings()
const aiSetupPromptText = ref('')
const isDarkMode = useInjectedDarkMode()
const endpoint = computed(() => buildAbsoluteUrl('/mcp'))
const effectiveTokenRequired = computed(() => requireToken.value === 1 || guestUploadOpen.value === 0)
const tools = [
{
name: 'share_text',
title: 'admin.mcp.shareTextTitle',
description: 'admin.mcp.shareTextHelp',
icon: FileTextIcon
},
{
name: 'share_file',
title: 'admin.mcp.shareFileTitle',
description: 'admin.mcp.shareFileHelp',
icon: UploadIcon
}
]
const copyEndpoint = () => copyText(endpoint.value)
const copyAiSetupPrompt = async () => {
const authentication = effectiveTokenRequired.value
? t('admin.mcp.aiAuthRequired')
: t('admin.mcp.aiAuthOptional')
const prompt = t('admin.mcp.aiSetupPrompt', { endpoint: endpoint.value, authentication })
const copied = await copyText(prompt)
aiSetupPromptText.value = copied ? '' : prompt
}
const headerConfig = computed(() => ({
subtitle: t('admin.mcp.subtitle'),
actions: [
{
key: 'refresh',
label: t('admin.mcp.refresh'),
icon: RefreshCwIcon,
loading: isLoading.value,
onClick: () => void loadSettings()
}
]
}))
useAdminHeaderActions(headerConfig)
onMounted(() => {
void loadSettings()
})
</script>
+31 -61
View File
@@ -1,12 +1,12 @@
<script setup lang="ts">
import { inject, onMounted } from 'vue'
import { computed, inject, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { RefreshCwIcon, SaveIcon } from 'lucide-vue-next'
import BaseButton from '@/components/common/BaseButton.vue'
import SettingNumberInput from '@/components/common/SettingNumberInput.vue'
import SettingSwitch from '@/components/common/SettingSwitch.vue'
import { useSystemConfig } from '@/composables'
import { useAdminHeaderActions } from '@/composables'
const isDarkMode = inject('isDarkMode')
const { t } = useI18n()
const {
@@ -34,6 +34,35 @@ const updateAllowedFileTypes = (event: Event) => {
.filter(Boolean)
}
const headerConfig = computed(() => ({
status: isDirty.value ? t('manage.settings.unsavedChanges') : t('manage.settings.allChangesSaved'),
statusTone: isDirty.value ? 'warning' as const : 'muted' as const,
actions: [
{
key: 'refresh',
label: isRefreshing.value ? t('manage.settings.refreshing') : t('manage.settings.refreshConfig'),
icon: RefreshCwIcon,
loading: isRefreshing.value,
disabled: isSaving.value || isDirty.value,
onClick: (): void => {
void refreshConfig()
}
},
{
key: 'save',
label: isSaving.value ? t('manage.settings.saving') : t('manage.settings.saveChanges'),
icon: SaveIcon,
variant: 'primary' as const,
loading: isSaving.value,
disabled: !isDirty.value || isRefreshing.value,
onClick: (): void => {
void submitConfig()
}
}
]
}))
useAdminHeaderActions(headerConfig)
onMounted(() => {
void refreshConfig()
})
@@ -41,55 +70,6 @@ onMounted(() => {
<template>
<div class="settings-page p-6">
<div
class="theme-surface sticky top-0 z-20 -mx-6 -mt-6 mb-6 border-b px-6 py-4 backdrop-blur"
>
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
<div>
<h2 class="theme-text-strong text-2xl font-bold">
{{ t('admin.settings.title') }}
</h2>
<p
class="mt-1 text-sm"
:class="isDirty ? 'theme-warning' : 'theme-text-muted'"
>
{{
isDirty ? t('manage.settings.unsavedChanges') : t('manage.settings.allChangesSaved')
}}
</p>
</div>
<div class="flex flex-wrap items-center gap-3">
<BaseButton
variant="secondary"
:loading="isRefreshing"
:disabled="isSaving || isDirty"
:title="
isDirty ? t('manage.settings.refreshBlocked') : t('manage.settings.refreshConfig')
"
@click="refreshConfig"
>
<template #icon>
<RefreshCwIcon class="mr-2 h-4 w-4" />
</template>
{{
isRefreshing ? t('manage.settings.refreshing') : t('manage.settings.refreshConfig')
}}
</BaseButton>
<BaseButton
:loading="isSaving"
:disabled="!isDirty || isRefreshing"
@click="submitConfig"
>
<template #icon>
<SaveIcon class="mr-2 h-4 w-4" />
</template>
{{ isSaving ? t('manage.settings.saving') : t('manage.settings.saveChanges') }}
</BaseButton>
</div>
</div>
</div>
<div
class="theme-panel space-y-6 rounded-2xl border p-6 backdrop-blur-xl"
@@ -743,16 +723,6 @@ onMounted(() => {
{{ t('manage.settings.codeGenerateTypeHelp') }}
</p>
<SettingSwitch
:label="t('manage.settings.mcpRequireToken')"
:model-value="config.mcp_require_token"
:enabled-text="t('common.enabled')"
:disabled-text="t('common.disabled')"
@toggle="toggleConfigFlag('mcp_require_token')"
/>
<p class="text-xs" :class="[isDarkMode ? 'text-zinc-400' : 'text-zinc-500']">
{{ t('manage.settings.mcpRequireTokenHelp') }}
</p>
</div>
<div class="space-y-2">