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

View File

@@ -39,7 +39,7 @@ async def create_adapter(
data: AdapterCreate,
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)
if exists:
raise HTTPException(400, detail="Mount path already exists")
@@ -108,7 +108,7 @@ async def update_adapter(
if not rec:
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)
if existing and existing.id != adapter_id:
raise HTTPException(400, detail="Mount path already exists")

View File

@@ -1,5 +1,5 @@
from typing import Dict, Optional
from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field, field_validator
class AdapterBase(BaseModel):
@@ -7,12 +7,11 @@ class AdapterBase(BaseModel):
type: str = Field(pattern=r"^[a-zA-Z0-9_]+$")
config: Dict = Field(default_factory=dict)
enabled: bool = True
path: str = None
sub_path: Optional[str] = None
class AdapterCreate(AdapterBase):
mount_path: str
@staticmethod
def normalize_mount_path(p: str) -> str:
p = p.strip()
@@ -21,7 +20,7 @@ class AdapterCreate(AdapterBase):
p = p.rstrip('/')
return p or '/'
@validator("mount_path")
@field_validator("path")
def _v_mount(cls, v: str):
if not v:
raise ValueError("mount_path required")
@@ -30,7 +29,8 @@ class AdapterCreate(AdapterBase):
class AdapterOut(AdapterBase):
id: int
mount_path: str = Field(alias='path')
path: str = None
sub_path: Optional[str] = None
class Config:
from_attributes = True

View File

@@ -6,7 +6,7 @@ export interface AdapterItem {
type: string;
config: any;
enabled: boolean;
mount_path?: string | null;
path?: string | null;
sub_path?: string | null;
}

View File

@@ -1,17 +1,8 @@
import { memo, useState, useEffect, useCallback } from 'react';
import { Table, Button, Space, Drawer, Form, Input, Switch, message, Typography, Popconfirm, Select } from 'antd';
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 {
key: string;
@@ -65,7 +56,7 @@ const AdaptersPage = memo(function AdaptersPage() {
form.setFieldsValue({
name: '',
type: defaultType,
mount_path: '/',
path: '/',
sub_path: '',
enabled: true,
config: cfgDefaults
@@ -79,7 +70,7 @@ const AdaptersPage = memo(function AdaptersPage() {
form.setFieldsValue({
name: rec.name,
type: rec.type,
mount_path: rec.mount_path || '/',
path: rec.path || '/',
sub_path: rec.sub_path || '',
enabled: rec.enabled,
config: rec.config || {}
@@ -105,7 +96,7 @@ const AdaptersPage = memo(function AdaptersPage() {
const body = {
name: values.name.trim(),
type: values.type,
mount_path: values.mount_path || '/',
path: values.path || '/',
sub_path: values.sub_path?.trim() || null,
enabled: values.enabled,
config: cfg
@@ -155,7 +146,7 @@ const AdaptersPage = memo(function AdaptersPage() {
const columns = [
{ title: '名称', dataIndex: 'name' },
{ 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: '启用',
@@ -251,7 +242,6 @@ const AdaptersPage = memo(function AdaptersPage() {
placeholder="选择适配器类型"
options={availableTypes.map(t => ({ value: t.type, label: `${t.name} (${t.type})` }))}
onChange={() => {
// 切换类型时刷新默认 config
const t = availableTypes.find(v => v.type === form.getFieldValue('type'));
const cfgDefaults: Record<string, any> = {};
t?.config_schema.forEach(f => {
@@ -261,7 +251,7 @@ const AdaptersPage = memo(function AdaptersPage() {
}}
/>
</Form.Item>
<Form.Item name="mount_path" label="挂载路径" rules={[{ required: true, message: '请输入挂载路径' }]}>
<Form.Item name="path" label="挂载路径" rules={[{ required: true, message: '请输入挂载路径' }]}>
<Input placeholder="/或/drive" />
</Form.Item>
<Form.Item name="sub_path" label="子路径(可选)">

View File

@@ -26,7 +26,7 @@ const SetupPage = () => {
root: values.root_dir
},
sub_path: null,
mount_path: values.mount_path,
path: values.path,
enabled: true
});
window.location.href = '/';
@@ -41,7 +41,7 @@ const SetupPage = () => {
const stepFields = [
['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'],
]
@@ -105,7 +105,7 @@ const SetupPage = () => {
</Form.Item>
<Form.Item
label="挂载路径"
name="mount_path"
name="path"
initialValue="/local"
rules={[{ required: true, message: '请输入挂载路径!' }]}
>