Files
MyGoNavi/frontend/src/utils/connectionSecretDraft.ts
tianqijiuyun-latiao 4718755208 feat(security): 完成配置密文存储前后端闭环
- 补齐连接与代理密文字段的保留替换清空语义

- 接通保存复制删除导入接口并返回 secretless 视图

- 刷新 Wails 绑定并补充实现留痕文档
2026-04-05 11:52:59 +08:00

64 lines
1.3 KiB
TypeScript

export interface ConnectionSecretDraftInput {
valueInput?: string;
hasSecret?: boolean;
clearSecret?: boolean;
forceClear?: boolean;
trimInput?: boolean;
}
export interface ConnectionSecretDraftResult {
value: string;
clearStoredSecret: boolean;
keepsStoredSecret: boolean;
hasSecretAfterSave: boolean;
}
export function resolveConnectionSecretDraft(input: ConnectionSecretDraftInput): ConnectionSecretDraftResult {
const rawValue = input.valueInput ?? '';
const value = input.trimInput ? String(rawValue).trim() : String(rawValue);
if (input.forceClear) {
return {
value: '',
clearStoredSecret: true,
keepsStoredSecret: false,
hasSecretAfterSave: false,
};
}
if (value !== '') {
return {
value,
clearStoredSecret: false,
keepsStoredSecret: false,
hasSecretAfterSave: true,
};
}
if (input.clearSecret) {
return {
value: '',
clearStoredSecret: true,
keepsStoredSecret: false,
hasSecretAfterSave: false,
};
}
if (input.hasSecret) {
return {
value: '',
clearStoredSecret: false,
keepsStoredSecret: true,
hasSecretAfterSave: true,
};
}
return {
value: '',
clearStoredSecret: false,
keepsStoredSecret: false,
hasSecretAfterSave: false,
};
}