Skip to content

Commit

Permalink
fix:修改挂载参数后报错
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualHotBar committed May 16, 2024
1 parent 4e06760 commit 5e989bc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
34 changes: 21 additions & 13 deletions src/controller/storage/mount/parameters/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { StorageParamItemType } from "../../../../type/controller/storage/info";
import { MountOptions, VfsOptions } from "../../../../type/rclone/storage/mount/parameters";

const vfsCacheModeParam: StorageParamItemType = {
label: 'CacheMode',
name: 'CacheMode',
description: 'CacheMode',
type: 'string',
default: 'full',
required: false,
advanced: false,
isPassword: false,
select: [
{ label: 'Full', value: 'full', help: '' },
{ label: 'Writes', value: 'writes', help: '' },
{ label: 'Minimal', value: 'minimal', help: '' },
{ label: 'Off', value: 'off', help: '' }
]
}

// 示例:初始化VfsOptions和MountOptions的默认值
const defaultVfsConfig: VfsOptions = {
ReadOnly: false,
CacheMaxAge: 3600000000000,
CacheMaxSize: -1,
CacheMode: {
select: 'full',
values: [
'off',
'minimal',
'writes',
'full',
]
},
CacheMode: 'full',
CachePollInterval: 60000000000,
CaseInsensitive: false,
ChunkSize: 67108864,
Expand All @@ -29,7 +38,7 @@ const defaultVfsConfig: VfsOptions = {
ReadAhead: 0,
ReadWait: 20000000,
WriteBack: 5000000000,
WriteWait: 1000000000,
WriteWait: 1000000000,
Refresh: false,
BlockNormDupes: false,
UsedIsSize: false,
Expand All @@ -38,7 +47,6 @@ const defaultVfsConfig: VfsOptions = {
UID: 4294967295,
GID: 4294967295,
Umask: 0,

};

const defaultMountConfig: MountOptions = {
Expand All @@ -58,10 +66,10 @@ const defaultMountConfig: MountOptions = {
NoAppleDouble: true,
NoAppleXattr: false,
WritebackCache: false,
DaemonWait: 0,
DaemonWait: 0,
DeviceName: '',
NetworkMode: false, //挂载为网络驱动器
//CaseInsensitive: null,
};

export { defaultVfsConfig, defaultMountConfig }
export { defaultVfsConfig, defaultMountConfig,vfsCacheModeParam }
4 changes: 2 additions & 2 deletions src/page/mount/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom';
import { ParametersType } from '../../type/defaults';
import { formatPath, getProperties, getURLSearchParam, getWinFspInstallState, showPathInExplorer } from '../../utils/utils';
import { defaultMountConfig, defaultVfsConfig } from '../../controller/storage/mount/parameters/defaults';
import { defaultMountConfig, defaultVfsConfig, vfsCacheModeParam } from '../../controller/storage/mount/parameters/defaults';
import { rcloneInfo } from '../../services/rclone';
import { addMountStorage, getAvailableDriveLetter, getMountStorage, mountStorage } from '../../controller/storage/mount/mount';
import { osInfo } from '../../services/config';
Expand Down Expand Up @@ -152,7 +152,7 @@ export default function AddMount_page() {
{
<div style={{ display: showAllOptions ? 'block' : 'none' }}>
<InputForm_module data={paramsType2FormItems(defaultMountConfig)} onChange={(data) => { parameters.mountOpt = data }} overwriteValues={defaultMountConfig} setFormHook={(form) => { setMountOptFormHook(form) }} />
<InputForm_module data={paramsType2FormItems(defaultVfsConfig)} onChange={(data) => { parameters.vfsOpt = data }} overwriteValues={defaultVfsConfig} setFormHook={(form) => { setVfsOptFormHook(form) }} />
<InputForm_module data={[vfsCacheModeParam,...paramsType2FormItems(defaultVfsConfig,undefined,['CacheMode'])]} onChange={(data) => { parameters.vfsOpt = data }} overwriteValues={defaultVfsConfig} setFormHook={(form) => { setVfsOptFormHook(form) }} />
</div>
}

Expand Down
29 changes: 23 additions & 6 deletions src/page/other/InputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const Row = Grid.Row;
const Col = Grid.Col;
const FormItem = Form.Item;

function paramsType2FormItems(params: ParametersType, isAdvanced: boolean = false) {
function paramsType2FormItems(params: ParametersType, isAdvanced: boolean = false,filter:string[]=[]) {//丢弃key匹配filter的项
const formItems: StorageParamItemType[] = []

getProperties(params).forEach((item) => {
if (filter.includes(item.key)) return;

let valueType: 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' = typeof item.value;
let formItem: StorageParamItemType = {
label: item.key,
Expand All @@ -27,7 +29,7 @@ function paramsType2FormItems(params: ParametersType, isAdvanced: boolean = fals
default: item.value,
advanced: isAdvanced,
isPassword: false,
mark: []
//mark: []
}
switch (valueType) {
case 'boolean':
Expand All @@ -36,6 +38,22 @@ function paramsType2FormItems(params: ParametersType, isAdvanced: boolean = fals
case 'number':
formItem.type = 'number'
break;
case 'object':
if (item.value.select) {//选择器
formItem.type = 'string'
formItem.default = item.value.default
formItem.select = item.value.select.map((item: string) => {
return {
label: item,
value: item,
help: item
}
})

} else {
formItem.type = 'string'
}
break;
default:
formItem.type = 'string'
break;
Expand Down Expand Up @@ -69,7 +87,7 @@ function StorageAndPathInputer({ value, onChange }: { value?: string, onChange?(
if (tempPath.includes('/')) {
value = tempPath.replace('/', ':')
} else {
value = tempPath+':';
value = tempPath + ':';
}
}

Expand Down Expand Up @@ -159,7 +177,7 @@ function InputFormItemContent_module({ data, formValuesResult /* style */ }: {
for (const item of data.select) {
//过滤
const filterState = (formValuesResult && item.filters) ? filter(item.filters, formValuesResult) : true;

if (filterState) selectContent.push(<Select.Option value={item.value} key={item.value}>{t(item.label)}</Select.Option>)
}

Expand All @@ -169,7 +187,6 @@ function InputFormItemContent_module({ data, formValuesResult /* style */ }: {
} else {
content = <Input placeholder={t('please_input')} />
}

break;
}

Expand All @@ -187,7 +204,7 @@ function InputForm_module({ data, style, showAdvanced, footer, onChange, overwri
overwriteValues?: ParametersType;
setFormHook?: (form: FormInstance) => void;
}) {
//console.log(data);
console.log(data);

const { t } = useTranslation()
const [form] = Form.useForm();
Expand Down
3 changes: 1 addition & 2 deletions src/type/rclone/storage/mount/parameters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
//https://github.com/rclone/rclone-webui-react/blob/master/src/utils/MountOptions.js
//http://localhost:5572/options/get
//https://rclone.org/commands/rclone_mount/#options-opt
import { ParametersType, ParamsSelectType } from "../../../defaults";

interface VfsOptions {
CacheMaxAge: number;
CacheMaxSize: number;
CacheMode: ParamsSelectType;
CacheMode: string;
CachePollInterval: number;
CaseInsensitive: boolean;
ChunkSize: number;
Expand Down

0 comments on commit 5e989bc

Please sign in to comment.