Skip to content

Commit 4689402

Browse files
committed
fix: rclone密码混淆问题修复
- 编辑rclone存储时,过滤未修改的密码字段,避免用混淆值覆盖原密码 - 为密码字段添加提示信息,说明rclone会混淆密码 - 区分rclone和openlist存储,openlist不混淆密码 - 添加多语言翻译支持 Fixes #126
1 parent ca914fd commit 4689402

6 files changed

Lines changed: 59 additions & 14 deletions

File tree

src-tauri/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@
706706
"import": "Import",
707707
"confirm_import": "Confirm Import",
708708
"export_import_config_description": "Export current configuration or restore configuration from file",
709-
"confirm_import_description": "Importing configuration will overwrite all current settings and automatically restart the software. Continue?"
709+
"confirm_import_description": "Importing configuration will overwrite all current settings and automatically restart the software. Continue?",
710+
"password_obscured_hint": "Password is obscured by rclone and cannot be displayed. Please re-enter to modify"
710711
}
711712

src-tauri/locales/zh-cn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,5 +716,6 @@
716716
"forward_archive_requests": "转发归档请求",
717717
"proxy_range": "Proxy Range",
718718
"app_id": "App ID",
719-
"sign_key": "Sign Key"
719+
"sign_key": "Sign Key",
720+
"password_obscured_hint": "密码已被rclone混淆存储,无法显示原始值,如需修改请重新输入"
720721
}

src-tauri/locales/zh-hant.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@
706706
"import": "導入",
707707
"confirm_import": "確認導入",
708708
"export_import_config_description": "導出當前配置或者從文件恢復配置",
709-
"confirm_import_description": "導入配置將覆蓋當前所有配置並自動重啓軟件,是否繼續?"
709+
"confirm_import_description": "導入配置將覆蓋當前所有配置並自動重啓軟件,是否繼續?",
710+
"password_obscured_hint": "密碼已被rclone混淆存儲,無法顯示原始值,如需修改請重新輸入"
710711
}
711712

src/page/other/InputForm.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,14 @@ function StorageAndPathInputer({
188188

189189
function InputFormItemContent_module({
190190
data,
191-
formValuesResult /* style */,
191+
formValuesResult,
192+
isEditMode,
193+
framework,
192194
}: {
193195
data: StorageParamItemType
194196
formValuesResult?: ParametersType
195-
/* style?: CSSProperties; */
197+
isEditMode?: boolean
198+
framework?: 'rclone' | 'openlist'
196199
}) {
197200
const { t } = useTranslation()
198201

@@ -233,8 +236,11 @@ function InputFormItemContent_module({
233236

234237
content = <Select placeholder={t('please_select')}>{selectContent}</Select>
235238
} else if (data.isPassword) {
236-
//密码
237-
content = <Input.Password placeholder={t('please_input')} />
239+
//密码 - 编辑模式下显示提示(仅rclone存储)
240+
const placeholderText = isEditMode && framework === 'rclone'
241+
? t('password_obscured_hint')
242+
: t('please_input')
243+
content = <Input.Password placeholder={placeholderText} />
238244
} else {
239245
content = <Input placeholder={t('please_input')} />
240246
}
@@ -253,6 +259,8 @@ function InputForm_module({
253259
overwriteValues,
254260
setFormHook,
255261
header,
262+
isEditMode,
263+
framework,
256264
}: {
257265
data: StorageParamItemType[]
258266
footer?: JSX.Element
@@ -262,6 +270,8 @@ function InputForm_module({
262270
onChange?: (data: ParametersType) => void
263271
overwriteValues?: ParametersType
264272
setFormHook?: (form: FormInstance) => void
273+
isEditMode?: boolean
274+
framework?: 'rclone' | 'openlist'
265275
}) {
266276
const { t } = useTranslation()
267277
const [form] = Form.useForm()
@@ -320,7 +330,7 @@ function InputForm_module({
320330
}
321331
style={{ ...style }}
322332
>
323-
{InputFormItemContent_module({ data: dataItem, formValuesResult: formValuesResult })}
333+
{InputFormItemContent_module({ data: dataItem, formValuesResult: formValuesResult, isEditMode: isEditMode, framework: framework })}
324334
</FormItem>
325335
)
326336
}

src/page/storage/add.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function AddStorage_page() {
6060
const [submitting, setSubmitting] = useState(false) //提交中状态
6161

6262
const [storageParams, setStorageParams] = useState<ParametersType>() //编辑模式下,覆盖默认参数
63+
const [originalPasswordValues, setOriginalPasswordValues] = useState<ParametersType>({}) //保存原始密码值(混淆后的)
6364

6465
//let parameters: ParametersType = {};
6566

@@ -71,8 +72,23 @@ function AddStorage_page() {
7172

7273
const editMode = async () => {
7374
const name = getURLSearchParam('name')
74-
setStorageTypeName(searchStorageInfo(getURLSearchParam('type')).label)
75-
setStorageParams(await getStorageParams(name))
75+
const type = getURLSearchParam('type')
76+
const currentStorageInfo = searchStorageInfo(type)
77+
setStorageTypeName(currentStorageInfo.label)
78+
const params = await getStorageParams(name)
79+
setStorageParams(params)
80+
81+
// 保存原始密码值(混淆后的),用于后续比较(仅rclone存储需要)
82+
if (params && currentStorageInfo?.defaultParams?.parameters && currentStorageInfo.framework === 'rclone') {
83+
const passwordFields: ParametersType = {}
84+
for (const param of currentStorageInfo.defaultParams.parameters) {
85+
if (param.isPassword && params[param.name] !== undefined) {
86+
passwordFields[param.name] = params[param.name]
87+
}
88+
}
89+
setOriginalPasswordValues(passwordFields)
90+
}
91+
7692
setStorageName(name)
7793
setStep('setParams')
7894
}
@@ -232,14 +248,15 @@ function AddStorage_page() {
232248
</FormItem>
233249
}
234250
data={[
235-
...storageInfo.defaultParams
236-
.parameters /* ,...storageInfo.defaultParams.exParameters?.openlist?.additional||[] */,
251+
...(storageInfo?.defaultParams?.parameters || []) /* ,...storageInfo.defaultParams.exParameters?.openlist?.additional||[] */,
237252
]}
238253
showAdvanced={showAdvanced}
239254
overwriteValues={storageParams || {}}
240255
setFormHook={hook => {
241256
setFormHook(hook)
242257
}}
258+
isEditMode={isEditMode}
259+
framework={storageInfo?.framework}
243260
/>
244261
<br />
245262

@@ -321,10 +338,21 @@ function AddStorage_page() {
321338
return
322339
}
323340

324-
const parameters: ParametersType =
341+
let parameters: ParametersType =
325342
storageInfo.framework === 'rclone'
326343
? formHook.getFieldsValue(formHook.getTouchedFields())
327344
: formHook.getFieldsValue()
345+
346+
// 编辑模式下,过滤掉未修改的密码字段,避免用混淆值覆盖原密码
347+
if (isEditMode && storageInfo.framework === 'rclone') {
348+
for (const fieldName of Object.keys(originalPasswordValues)) {
349+
// 如果密码值与原始混淆值相同,说明用户没有修改,删除该字段
350+
if (parameters[fieldName] === originalPasswordValues[fieldName]) {
351+
delete parameters[fieldName]
352+
}
353+
}
354+
}
355+
328356
console.log(parameters)
329357

330358
//return

src/utils/openlist/openlist.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ async function modifyOpenlistConfig(
245245
}
246246
// 将路径标准化为使用正斜杠
247247
const normalizedPath = absolutePath.replace(/\\/g, '/')
248-
const normalizedDataDir = dataDir.replace(/\\/g, '/')
248+
let normalizedDataDir = dataDir.replace(/\\/g, '/')
249+
// 确保数据目录以斜杠结尾,避免错误匹配
250+
if (!normalizedDataDir.endsWith('/')) {
251+
normalizedDataDir += '/'
252+
}
249253
// 如果路径以数据目录开头,转换为相对路径
250254
if (normalizedPath.startsWith(normalizedDataDir)) {
251255
const relativePath = normalizedPath.substring(normalizedDataDir.length)

0 commit comments

Comments
 (0)