refactor: Rename 'mount_path' to 'path' in adapter schemas and related components

This commit is contained in:
shiyu
2025-08-28 17:00:12 +08:00
parent b3b5ae2eac
commit 86e81bf40c
5 changed files with 17 additions and 27 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ async def create_adapter(
data: AdapterCreate, data: AdapterCreate,
current_user: Annotated[User, Depends(get_current_active_user)] current_user: Annotated[User, Depends(get_current_active_user)]
): ):
norm_path = AdapterCreate.normalize_mount_path(data.mount_path) norm_path = AdapterCreate.normalize_mount_path(data.path)
exists = await StorageAdapter.get_or_none(path=norm_path) exists = await StorageAdapter.get_or_none(path=norm_path)
if exists: if exists:
raise HTTPException(400, detail="Mount path already exists") raise HTTPException(400, detail="Mount path already exists")
@@ -108,7 +108,7 @@ async def update_adapter(
if not rec: if not rec:
raise HTTPException(404, detail="Not found") raise HTTPException(404, detail="Not found")
norm_path = AdapterCreate.normalize_mount_path(data.mount_path) norm_path = AdapterCreate.normalize_mount_path(data.path)
existing = await StorageAdapter.get_or_none(path=norm_path) existing = await StorageAdapter.get_or_none(path=norm_path)
if existing and existing.id != adapter_id: if existing and existing.id != adapter_id:
raise HTTPException(400, detail="Mount path already exists") raise HTTPException(400, detail="Mount path already exists")
+5 -5
View File
@@ -1,5 +1,5 @@
from typing import Dict, Optional from typing import Dict, Optional
from pydantic import BaseModel, Field, validator from pydantic import BaseModel, Field, field_validator
class AdapterBase(BaseModel): class AdapterBase(BaseModel):
@@ -7,12 +7,11 @@ class AdapterBase(BaseModel):
type: str = Field(pattern=r"^[a-zA-Z0-9_]+$") type: str = Field(pattern=r"^[a-zA-Z0-9_]+$")
config: Dict = Field(default_factory=dict) config: Dict = Field(default_factory=dict)
enabled: bool = True enabled: bool = True
path: str = None
sub_path: Optional[str] = None sub_path: Optional[str] = None
class AdapterCreate(AdapterBase): class AdapterCreate(AdapterBase):
mount_path: str
@staticmethod @staticmethod
def normalize_mount_path(p: str) -> str: def normalize_mount_path(p: str) -> str:
p = p.strip() p = p.strip()
@@ -21,7 +20,7 @@ class AdapterCreate(AdapterBase):
p = p.rstrip('/') p = p.rstrip('/')
return p or '/' return p or '/'
@validator("mount_path") @field_validator("path")
def _v_mount(cls, v: str): def _v_mount(cls, v: str):
if not v: if not v:
raise ValueError("mount_path required") raise ValueError("mount_path required")
@@ -30,7 +29,8 @@ class AdapterCreate(AdapterBase):
class AdapterOut(AdapterBase): class AdapterOut(AdapterBase):
id: int id: int
mount_path: str = Field(alias='path') path: str = None
sub_path: Optional[str] = None
class Config: class Config:
from_attributes = True from_attributes = True
+1 -1
View File
@@ -6,7 +6,7 @@ export interface AdapterItem {
type: string; type: string;
config: any; config: any;
enabled: boolean; enabled: boolean;
mount_path?: string | null; path?: string | null;
sub_path?: string | null; sub_path?: string | null;
} }
+6 -16
View File
@@ -1,17 +1,8 @@
import { memo, useState, useEffect, useCallback } from 'react'; import { memo, useState, useEffect, useCallback } from 'react';
import { Table, Button, Space, Drawer, Form, Input, Switch, message, Typography, Popconfirm, Select } from 'antd'; import { Table, Button, Space, Drawer, Form, Input, Switch, message, Typography, Popconfirm, Select } from 'antd';
import PageCard from '../components/PageCard'; import PageCard from '../components/PageCard';
import { adaptersApi } from '../api/client'; import { adaptersApi, type AdapterItem } from '../api/client';
interface AdapterItem {
id: number;
name: string;
type: string;
config: any;
enabled: boolean;
mount_path?: string | null;
sub_path?: string | null;
}
interface AdapterTypeField { interface AdapterTypeField {
key: string; key: string;
@@ -65,7 +56,7 @@ const AdaptersPage = memo(function AdaptersPage() {
form.setFieldsValue({ form.setFieldsValue({
name: '', name: '',
type: defaultType, type: defaultType,
mount_path: '/', path: '/',
sub_path: '', sub_path: '',
enabled: true, enabled: true,
config: cfgDefaults config: cfgDefaults
@@ -79,7 +70,7 @@ const AdaptersPage = memo(function AdaptersPage() {
form.setFieldsValue({ form.setFieldsValue({
name: rec.name, name: rec.name,
type: rec.type, type: rec.type,
mount_path: rec.mount_path || '/', path: rec.path || '/',
sub_path: rec.sub_path || '', sub_path: rec.sub_path || '',
enabled: rec.enabled, enabled: rec.enabled,
config: rec.config || {} config: rec.config || {}
@@ -105,7 +96,7 @@ const AdaptersPage = memo(function AdaptersPage() {
const body = { const body = {
name: values.name.trim(), name: values.name.trim(),
type: values.type, type: values.type,
mount_path: values.mount_path || '/', path: values.path || '/',
sub_path: values.sub_path?.trim() || null, sub_path: values.sub_path?.trim() || null,
enabled: values.enabled, enabled: values.enabled,
config: cfg config: cfg
@@ -155,7 +146,7 @@ const AdaptersPage = memo(function AdaptersPage() {
const columns = [ const columns = [
{ title: '名称', dataIndex: 'name' }, { title: '名称', dataIndex: 'name' },
{ title: '类型', dataIndex: 'type', width: 100 }, { title: '类型', dataIndex: 'type', width: 100 },
{ title: '挂载路径', dataIndex: 'mount_path', width: 140, render: (v: string) => v || '-' }, { title: '挂载路径', dataIndex: 'path', width: 140, render: (v: string) => v || '-' },
{ title: '子路径', dataIndex: 'sub_path', width: 140, render: (v: string) => v || '-' }, { title: '子路径', dataIndex: 'sub_path', width: 140, render: (v: string) => v || '-' },
{ {
title: '启用', title: '启用',
@@ -251,7 +242,6 @@ const AdaptersPage = memo(function AdaptersPage() {
placeholder="选择适配器类型" placeholder="选择适配器类型"
options={availableTypes.map(t => ({ value: t.type, label: `${t.name} (${t.type})` }))} options={availableTypes.map(t => ({ value: t.type, label: `${t.name} (${t.type})` }))}
onChange={() => { onChange={() => {
// 切换类型时刷新默认 config
const t = availableTypes.find(v => v.type === form.getFieldValue('type')); const t = availableTypes.find(v => v.type === form.getFieldValue('type'));
const cfgDefaults: Record<string, any> = {}; const cfgDefaults: Record<string, any> = {};
t?.config_schema.forEach(f => { t?.config_schema.forEach(f => {
@@ -261,7 +251,7 @@ const AdaptersPage = memo(function AdaptersPage() {
}} }}
/> />
</Form.Item> </Form.Item>
<Form.Item name="mount_path" label="挂载路径" rules={[{ required: true, message: '请输入挂载路径' }]}> <Form.Item name="path" label="挂载路径" rules={[{ required: true, message: '请输入挂载路径' }]}>
<Input placeholder="/或/drive" /> <Input placeholder="/或/drive" />
</Form.Item> </Form.Item>
<Form.Item name="sub_path" label="子路径(可选)"> <Form.Item name="sub_path" label="子路径(可选)">
+3 -3
View File
@@ -26,7 +26,7 @@ const SetupPage = () => {
root: values.root_dir root: values.root_dir
}, },
sub_path: null, sub_path: null,
mount_path: values.mount_path, path: values.path,
enabled: true enabled: true
}); });
window.location.href = '/'; window.location.href = '/';
@@ -41,7 +41,7 @@ const SetupPage = () => {
const stepFields = [ const stepFields = [
['db_driver', 'vector_db_driver'], ['db_driver', 'vector_db_driver'],
['adapter_name', 'adapter_type', 'mount_path', 'root_dir'], ['adapter_name', 'adapter_type', 'path', 'root_dir'],
['username', 'full_name', 'email', 'password', 'confirm'], ['username', 'full_name', 'email', 'password', 'confirm'],
] ]
@@ -105,7 +105,7 @@ const SetupPage = () => {
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label="挂载路径" label="挂载路径"
name="mount_path" name="path"
initialValue="/local" initialValue="/local"
rules={[{ required: true, message: '请输入挂载路径!' }]} rules={[{ required: true, message: '请输入挂载路径!' }]}
> >