21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
export function accessModeOptions(protocol: string): { value: string; label: string }[] {
|
|
const options = [{ value: 'readonly', label: '只读' }, { value: 'readwrite', label: '读写' }];
|
|
if (protocol === 'mysql') options.push({ value: 'unrestricted', label: '全放行' });
|
|
return options;
|
|
}
|
|
|
|
export function accessModeLabel(protocol: string, mode?: string): string {
|
|
if (protocol === 'ssh' || protocol === 'sftp') return 'SSH 会话';
|
|
if (mode === 'readonly') return '只读';
|
|
if (protocol === 'mysql') return mode === 'unrestricted' ? '全放行' : '读写';
|
|
return '读写';
|
|
}
|
|
|
|
export function gatewayAccessModeLabel(config: any): string {
|
|
if (config.accessMode === 'readonly') return accessModeLabel(config.type, 'readonly');
|
|
const modes = new Set((config.gatewayAccounts || []).filter((account: any) => !account.disabled)
|
|
.map((account: any) => accessModeLabel(config.type, account.accessMode || config.accessMode)));
|
|
if (modes.size > 1) return '按账号设置';
|
|
return (modes.values().next().value as string | undefined) || accessModeLabel(config.type, config.accessMode);
|
|
}
|